SlideShare ist ein Scribd-Unternehmen logo
1 von 30
DJ RAUSCH
ANDROID ENGINEER @ MOKRIYA
DJRAUSCH.COM
REALM
REALM - A MOBILE DATABASE REPLACEMENT
PHOENIX MOBILE FESTIVAL
▸Use #phxmobi as the twitter hashtag and follow
@phxmobifestival for updates.
▸Download Phoenix Mobile Festival App (search for
'phxmobi') from AppStore or Google Play. From the app you
can create your own agenda for the day and provide
feedback on the sessions.
REALM - A MOBILE DATABASE REPLACEMENT
WHO AM I?
▸Android Developer at Mokriya.
▸Developing Android apps since the start (first Android phone
was the Droid)
▸Before working at Mokriya, worked for Jaybird, and a few
smaller companies
▸Self published a few apps - Spotilarm, Volume Sync, Bill
Tracker
REALM - A MOBILE DATABASE REPLACEMENT
WHAT IS REALM?
▸It’s a database.
▸A replacement for Sqlite.
▸It is NOT an ORM for Sqlite.
REALM - A MOBILE DATABASE REPLACEMENT
WHY SHOULD I USE IT?
▸Easy Setup
▸Cross Platform
▸ Android, iOS (Objective-C and Swift), Xamarin, React Native
▸FAST
REALM - A MOBILE DATABASE REPLACEMENT
WHO IS USING REALM?
REALM - A MOBILE DATABASE REPLACEMENT
FEATURES OF REALM
▸Fluent Interface
▸Field Annotations
▸Migrations
▸Encryption
▸Auto Updates and Notifications
▸RxJava Support
REALM - A MOBILE DATABASE REPLACEMENT
FLUENT INTERFACE
getRealm().where(Bill.class)
.equalTo("deleted", false)
.between("dueDate", new
DateTime().minusWeeks(1).toDate(), new
DateTime().plusWeeks(1).plusDays(1)
.toDate())
.findAll();
https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/util/BillUtil.jav
a#L46
REALM - A MOBILE DATABASE REPLACEMENT
FIELD ANNOTATIONS
▸@PrimaryKey
▸Table PK
▸@Required
▸Require a value, not null
▸@Ignore
▸Do not persist field to disk
REALM - A MOBILE DATABASE REPLACEMENT
MIGRATIONS
public class Migration implements RealmMigration {
@Override
public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
RealmSchema schema = realm.getSchema();
if (oldVersion == 0) {
//Add pay url to bill
schema.get("Bill")
.addField("payUrl", String.class);
oldVersion++;
}…
}
}
https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/models/Migration.java
REALM - A MOBILE DATABASE REPLACEMENT
ENCRYPTION
RealmConfiguration config = new
RealmConfiguration.Builder(context)
.encryptionKey(getKey())
.build();
Realm realm = Realm.getInstance(config);
https://realm.io/docs/java/latest/#encryption
REALM - A MOBILE DATABASE REPLACEMENT
AUTO UPDATES & NOTIFICATIONS
bills.addChangeListener(new RealmChangeListener<RealmResults<Bill>>() {
@Override
public void onChange(RealmResults<Bill> element) {
if (adapter.getItemCount() == 0) {
noBillsLayout.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE);
} else {
noBillsLayout.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}
}
});
https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/MainActivity.java#L132
REALM - A MOBILE DATABASE REPLACEMENT
RXJAVA
getRealm().where(Bill.class).contains(“uuid”, billUuid).findFirst().asObservable()
.filter(new Func1<Bill, Boolean>() {
@Override
public Boolean call(Bill bill) {
return bill.isLoaded();
}
}).subscribe(new Action1<Bill>() {
@Override
public void call(Bill bill) {
setUI(bill);
if (bill.paidDates != null) {
if (adapter == null) {
adapter = new PaidDateRecyclerViewAdapter(ViewBillDetails.this, bill.getPaidDates());
recyclerView.setLayoutManager(new LinearLayoutManager(ViewBillDetails.this));
recyclerView.setAdapter(adapter);
}
}
}
});
https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/AddOrEditBillActivity.java#L109
https://realm.io/docs/java/latest/#rxjava
REALM - A MOBILE DATABASE REPLACEMENT
OK, SO HOW DO I USE IT?
▸There is no schema set up
▸Simply have your model classes extend RealmObject
public class Bill extends RealmObject {
@PrimaryKey
public String uuid;
public String name;
public String description;
public int repeatingType = 0;
public Date dueDate;
public String payUrl;
public RealmList<BillNote> notes;
public RealmList<BillPaid> paidDates;
public boolean deleted = false;
public int amountDue = 0;
https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/models/Bill.java
REALM - A MOBILE DATABASE REPLACEMENT
FIELD TYPES
▸Supports standard field types including Date
Realm supports the following field types: boolean, byte, short, int, long, float,
double, String, Date and byte[]. The integer types byte, short, int, and long are all
mapped to the same type (long actually) within Realm. Moreover, subclasses of
RealmObject and RealmList<? extends RealmObject> are supported to model
relationships.
The boxed types Boolean, Byte, Short, Integer, Long, Float and Double can also
be used in model classes. Using these types, it is possible to set the value of a
field to null.
https://realm.io/docs/java/latest/#field-types
REALM - A MOBILE DATABASE REPLACEMENT
QUERIES - CONDITIONS
‣ between(), greaterThan(), lessThan(),
greaterThanOrEqualTo() & lessThanOrEqualTo()
‣ equalTo() & notEqualTo()
‣ contains(), beginsWith() & endsWith()
‣ isNull() & isNotNull()
‣ isEmpty() & isNotEmpty()
https://realm.io/docs/java/latest/#conditions
REALM - A MOBILE DATABASE REPLACEMENT
QUERIES
▸You can group conditions for complex queries
RealmResults<User> r = realm.where(User.class)
.greaterThan("age", 10) //implicit AND
.beginGroup()
.equalTo("name", "Peter")
.or()
.contains("name", "Jo")
.endGroup()
.findAll();
https://realm.io/docs/java/latest/#logical-operators
REALM - A MOBILE DATABASE REPLACEMENT
CREATING MODEL
realm.beginTransaction();
User user = realm.createObject(User.class);
user.setName("John");
user.setEmail("john@corporation.com");
realm.commitTransaction();
https://realm.io/docs/java/latest/#creating-objects
REALM - A MOBILE DATABASE REPLACEMENT
CREATING MODEL
final Bill b = new Bill(name.getText().toString(), "", repeatingItem.code,
selectedDueDate.toDate(), payUrl.getText().toString(), (int) (amount.getValue() *
100));
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
realm.copyToRealm(b);
}
});
https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/AddOrEditBillActivity.jav
a#L171
REALM - A MOBILE DATABASE REPLACEMENT
READING MODEL
BillTrackerApplication.getRealm().where(Bill.class).contains("
uuid", billUuid).findFirst()
‣ findFirst()
‣ findAll()
‣ findAllSorted()
‣ These all have an async version as well
https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/AddOrEditBill
Activity.java#L109
REALM - A MOBILE DATABASE REPLACEMENT
UPDATING MODEL
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
editBill.setName(name.getText().toString());
editBill.setRepeatingType(repeatingItem.code);
editBill.setDueDate(selectedDueDate.toDate());
editBill.setPayUrl(payUrl.getText().toString());
editBill.setAmountDue((int) (amount.getValue() * 100));
}
});
https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/AddOrEditBill
Activity.java#L155
REALM - A MOBILE DATABASE REPLACEMENT
DELETING MODEL
getRealm().executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
bill.deleteFromRealm();
}
});
https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/AddOrEditBill
Activity.java#L218
REALM - A MOBILE DATABASE REPLACEMENT
RELATIONSHIPS
▸Many-to-One
▸Used for One-to-One
▸Many-to-Many
https://realm.io/docs/java/latest/#relationships
REALM - A MOBILE DATABASE REPLACEMENT
MANY-TO-ONE
public class Contact extends RealmObject {
private Email email;
// Other fields…
}
https://realm.io/docs/java/latest/#many-to-one
REALM - A MOBILE DATABASE REPLACEMENT
MANY-TO-MANY
public class Bill extends RealmObject {
…
public RealmList<BillPaid> paidDates;
…
}
final BillPaid billPaid = new BillPaid(new Date());
BillTrackerApplication.getRealm().executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
bill.setDueDate(DateUtil.createNextDueDate(bill));
bill.getPaidDates().add(billPaid);
}
});
https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/models/Bill.java#L28
https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/util/BillUtil.java#L20
https://realm.io/docs/java/latest/#many-to-many
REALM - A MOBILE DATABASE REPLACEMENT
THREADING
The only rule to using Realm across threads is to remember that
Realm, RealmObject or RealmResults instances cannot be passed
across threads.
Get Realm in any thread you need it.
getRealm().where(Bill.class).equalTo("deleted",
false).findAllSortedAsync("dueDate");
https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/util/BillUtil.java#L43
REALM - A MOBILE DATABASE REPLACEMENT
USING WITH RETROFIT
It just works!
apiService.getUserBills(BillTrackerApplication.getUserToken()).enqueue(new Callback<List<Bill>>() {
@Override
public void onResponse(Call<List<Bill>> call, final Response<List<Bill>> response) {
for (Bill b : response.body()) {
Log.d("Bill", b.toString());
}
BillTrackerApplication.getRealm().executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
realm.copyToRealmOrUpdate(response.body());
}
});
}
});
https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/network/controller
s/BillApi.java#L45
REALM - A MOBILE DATABASE REPLACEMENT
ADAPTERS
‣ RealmRecyclerViewAdapter
‣ Keeps the data updated from a RealmResult or RealmList
‣ No need to notifyDataSetChanged()
https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/adapters/M
ainRecyclerViewAdapter.java
https://realm.io/docs/java/latest/#adapters
REALM - A MOBILE DATABASE REPLACEMENT
LIMITATIONS
▸The upper limit of class names is 57 characters. Realm for Android
prepend class_ to all names, and the browser will show it as part of
the name.
▸The length of field names has a upper limit of 63 character.
▸Nested transactions are not supported, and an exception is thrown if
they are detected.
▸Strings and byte arrays (byte[]) cannot be larger than 16 MB.
▸Does not support lists of primitive types (String, Ints, etc), yet.
https://realm.io/docs/java/latest/#current-limitations
REALM - A MOBILE DATABASE REPLACEMENT
QUESTIONS?
▸Use #phxmobi as the twitter hashtag and follow
@phxmobifestival for updates.
▸Download Phoenix Mobile Festival App (search for 'phxmobi')
from AppStore or Google Play. From the app you can create your
own agenda for the day and provide feedback on the sessions.
▸Slides will be on djraus.ch/realm soon!
▸Bill Tracker is open source -
https://github.com/djrausch/BillTracker

Weitere ähnliche Inhalte

Was ist angesagt?

Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016Ben Lesh
 
Http4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web StackHttp4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web StackGaryCoady
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KThomas Fuchs
 
async/await in Swift
async/await in Swiftasync/await in Swift
async/await in SwiftPeter Friese
 
Rethink Async With RXJS
Rethink Async With RXJSRethink Async With RXJS
Rethink Async With RXJSRyan Anklam
 
The Promised Land (in Angular)
The Promised Land (in Angular)The Promised Land (in Angular)
The Promised Land (in Angular)Domenic Denicola
 
Talk KVO with rac by Philippe Converset
Talk KVO with rac by Philippe ConversetTalk KVO with rac by Philippe Converset
Talk KVO with rac by Philippe ConversetCocoaHeads France
 
Getting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETGetting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETTomas Jansson
 
Avoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promisesAvoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promisesAnkit Agarwal
 
Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots DeepAnshu Sharma
 
Source Code for Dpilot
Source Code for Dpilot Source Code for Dpilot
Source Code for Dpilot Nidhi Chauhan
 
Lean way write asynchronous code with Kotlin’s coroutines - Ronen Sabag, Gett
Lean way write asynchronous code with Kotlin’s coroutines - Ronen Sabag, GettLean way write asynchronous code with Kotlin’s coroutines - Ronen Sabag, Gett
Lean way write asynchronous code with Kotlin’s coroutines - Ronen Sabag, GettDroidConTLV
 

Was ist angesagt? (20)

ES6: The Awesome Parts
ES6: The Awesome PartsES6: The Awesome Parts
ES6: The Awesome Parts
 
Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016
 
Http4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web StackHttp4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web Stack
 
Requery overview
Requery overviewRequery overview
Requery overview
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
 
JavaScript Promise
JavaScript PromiseJavaScript Promise
JavaScript Promise
 
async/await in Swift
async/await in Swiftasync/await in Swift
async/await in Swift
 
Rethink Async With RXJS
Rethink Async With RXJSRethink Async With RXJS
Rethink Async With RXJS
 
Promise pattern
Promise patternPromise pattern
Promise pattern
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 
The Promised Land (in Angular)
The Promised Land (in Angular)The Promised Land (in Angular)
The Promised Land (in Angular)
 
Talk KVO with rac by Philippe Converset
Talk KVO with rac by Philippe ConversetTalk KVO with rac by Philippe Converset
Talk KVO with rac by Philippe Converset
 
Getting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETGetting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NET
 
greenDAO
greenDAOgreenDAO
greenDAO
 
Avoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promisesAvoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promises
 
Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots
 
Source Code for Dpilot
Source Code for Dpilot Source Code for Dpilot
Source Code for Dpilot
 
Promises, Promises
Promises, PromisesPromises, Promises
Promises, Promises
 
Lean way write asynchronous code with Kotlin’s coroutines - Ronen Sabag, Gett
Lean way write asynchronous code with Kotlin’s coroutines - Ronen Sabag, GettLean way write asynchronous code with Kotlin’s coroutines - Ronen Sabag, Gett
Lean way write asynchronous code with Kotlin’s coroutines - Ronen Sabag, Gett
 
Domains!
Domains!Domains!
Domains!
 

Andere mochten auch

Introduction to Realm Mobile Platform
Introduction to Realm Mobile PlatformIntroduction to Realm Mobile Platform
Introduction to Realm Mobile PlatformChristian Melchior
 
Realm of the Mobile Database: an introduction to Realm
Realm of the Mobile Database: an introduction to RealmRealm of the Mobile Database: an introduction to Realm
Realm of the Mobile Database: an introduction to RealmMartin Grider
 
Scaling Diameter for LTE
Scaling Diameter for LTEScaling Diameter for LTE
Scaling Diameter for LTEAcmePacket
 
Policy and Charging Control - LTE / HSPA / EPC ‘knowledge nuggets’
Policy and Charging Control - LTE / HSPA / EPC ‘knowledge nuggets’Policy and Charging Control - LTE / HSPA / EPC ‘knowledge nuggets’
Policy and Charging Control - LTE / HSPA / EPC ‘knowledge nuggets’4G-Seminar
 
Lte epc trial experience
Lte epc trial experienceLte epc trial experience
Lte epc trial experienceHussien Mahmoud
 
Introduction to Diameter: The Evolution of Signaling
Introduction to Diameter: The Evolution of SignalingIntroduction to Diameter: The Evolution of Signaling
Introduction to Diameter: The Evolution of SignalingPT
 
What is PCRF? – Detailed PCRF architecture and functioning
What is PCRF? – Detailed PCRF architecture and functioningWhat is PCRF? – Detailed PCRF architecture and functioning
What is PCRF? – Detailed PCRF architecture and functioningMahindra Comviva
 
Diameter Presentation
Diameter PresentationDiameter Presentation
Diameter PresentationBeny Haddad
 
PCRF-Policy Charging System-Functional Analysis
PCRF-Policy Charging System-Functional AnalysisPCRF-Policy Charging System-Functional Analysis
PCRF-Policy Charging System-Functional AnalysisBiju M R
 

Andere mochten auch (12)

Introduction to Realm Mobile Platform
Introduction to Realm Mobile PlatformIntroduction to Realm Mobile Platform
Introduction to Realm Mobile Platform
 
Realm of the Mobile Database: an introduction to Realm
Realm of the Mobile Database: an introduction to RealmRealm of the Mobile Database: an introduction to Realm
Realm of the Mobile Database: an introduction to Realm
 
Realm Presentation
Realm PresentationRealm Presentation
Realm Presentation
 
Diameter Overview
Diameter OverviewDiameter Overview
Diameter Overview
 
Scaling Diameter for LTE
Scaling Diameter for LTEScaling Diameter for LTE
Scaling Diameter for LTE
 
Policy and Charging Control - LTE / HSPA / EPC ‘knowledge nuggets’
Policy and Charging Control - LTE / HSPA / EPC ‘knowledge nuggets’Policy and Charging Control - LTE / HSPA / EPC ‘knowledge nuggets’
Policy and Charging Control - LTE / HSPA / EPC ‘knowledge nuggets’
 
Lte epc trial experience
Lte epc trial experienceLte epc trial experience
Lte epc trial experience
 
Introduction to Diameter: The Evolution of Signaling
Introduction to Diameter: The Evolution of SignalingIntroduction to Diameter: The Evolution of Signaling
Introduction to Diameter: The Evolution of Signaling
 
What is PCRF? – Detailed PCRF architecture and functioning
What is PCRF? – Detailed PCRF architecture and functioningWhat is PCRF? – Detailed PCRF architecture and functioning
What is PCRF? – Detailed PCRF architecture and functioning
 
Introduction to Diameter Protocol - Part1
Introduction to Diameter Protocol - Part1Introduction to Diameter Protocol - Part1
Introduction to Diameter Protocol - Part1
 
Diameter Presentation
Diameter PresentationDiameter Presentation
Diameter Presentation
 
PCRF-Policy Charging System-Functional Analysis
PCRF-Policy Charging System-Functional AnalysisPCRF-Policy Charging System-Functional Analysis
PCRF-Policy Charging System-Functional Analysis
 

Ähnlich wie Realm - Phoenix Mobile Festival

CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on AndroidSven Haiges
 
GDG Mediterranean Dev Fest Code lab #DevFestMed15 da android ad android wear ...
GDG Mediterranean Dev Fest Code lab #DevFestMed15 da android ad android wear ...GDG Mediterranean Dev Fest Code lab #DevFestMed15 da android ad android wear ...
GDG Mediterranean Dev Fest Code lab #DevFestMed15 da android ad android wear ...Bruno Salvatore Belluccia
 
Slightly Advanced Android Wear ;)
Slightly Advanced Android Wear ;)Slightly Advanced Android Wear ;)
Slightly Advanced Android Wear ;)Alfredo Morresi
 
Functional Web Development
Functional Web DevelopmentFunctional Web Development
Functional Web DevelopmentFITC
 
After max+phonegap
After max+phonegapAfter max+phonegap
After max+phonegapyangdj
 
混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaveryangdj
 
What's New in Android
What's New in AndroidWhat's New in Android
What's New in AndroidRobert Cooper
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best PracticesYekmer Simsek
 
Android Developer Toolbox 2017
Android Developer Toolbox 2017Android Developer Toolbox 2017
Android Developer Toolbox 2017Shem Magnezi
 
Android dev toolbox - Shem Magnezi, WeWork
Android dev toolbox - Shem Magnezi, WeWorkAndroid dev toolbox - Shem Magnezi, WeWork
Android dev toolbox - Shem Magnezi, WeWorkDroidConTLV
 
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScriptjQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScriptGuy Royse
 
WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015Fernando Daciuk
 
Flask and Angular: An approach to build robust platforms
Flask and Angular:  An approach to build robust platformsFlask and Angular:  An approach to build robust platforms
Flask and Angular: An approach to build robust platformsAyush Sharma
 
The 2016 Android Developer Toolbox [MOBILIZATION]
The 2016 Android Developer Toolbox [MOBILIZATION]The 2016 Android Developer Toolbox [MOBILIZATION]
The 2016 Android Developer Toolbox [MOBILIZATION]Nilhcem
 
beyond tellerrand: Mobile Apps with JavaScript – There's More Than Web
beyond tellerrand: Mobile Apps with JavaScript – There's More Than Webbeyond tellerrand: Mobile Apps with JavaScript – There's More Than Web
beyond tellerrand: Mobile Apps with JavaScript – There's More Than WebHeiko Behrens
 
My way to clean android - Android day salamanca edition
My way to clean android - Android day salamanca editionMy way to clean android - Android day salamanca edition
My way to clean android - Android day salamanca editionChristian Panadero
 
Bringing order to the chaos! - Paulo Lopes - Codemotion Amsterdam 2018
Bringing order to the chaos! - Paulo Lopes - Codemotion Amsterdam 2018Bringing order to the chaos! - Paulo Lopes - Codemotion Amsterdam 2018
Bringing order to the chaos! - Paulo Lopes - Codemotion Amsterdam 2018Codemotion
 
Building Modern Apps using Android Architecture Components
Building Modern Apps using Android Architecture ComponentsBuilding Modern Apps using Android Architecture Components
Building Modern Apps using Android Architecture ComponentsHassan Abid
 

Ähnlich wie Realm - Phoenix Mobile Festival (20)

CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
 
mobl
moblmobl
mobl
 
GDG Mediterranean Dev Fest Code lab #DevFestMed15 da android ad android wear ...
GDG Mediterranean Dev Fest Code lab #DevFestMed15 da android ad android wear ...GDG Mediterranean Dev Fest Code lab #DevFestMed15 da android ad android wear ...
GDG Mediterranean Dev Fest Code lab #DevFestMed15 da android ad android wear ...
 
Slightly Advanced Android Wear ;)
Slightly Advanced Android Wear ;)Slightly Advanced Android Wear ;)
Slightly Advanced Android Wear ;)
 
Android workshop
Android workshopAndroid workshop
Android workshop
 
Functional Web Development
Functional Web DevelopmentFunctional Web Development
Functional Web Development
 
After max+phonegap
After max+phonegapAfter max+phonegap
After max+phonegap
 
混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver
 
What's New in Android
What's New in AndroidWhat's New in Android
What's New in Android
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
 
Android Developer Toolbox 2017
Android Developer Toolbox 2017Android Developer Toolbox 2017
Android Developer Toolbox 2017
 
Android dev toolbox - Shem Magnezi, WeWork
Android dev toolbox - Shem Magnezi, WeWorkAndroid dev toolbox - Shem Magnezi, WeWork
Android dev toolbox - Shem Magnezi, WeWork
 
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScriptjQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
 
WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015
 
Flask and Angular: An approach to build robust platforms
Flask and Angular:  An approach to build robust platformsFlask and Angular:  An approach to build robust platforms
Flask and Angular: An approach to build robust platforms
 
The 2016 Android Developer Toolbox [MOBILIZATION]
The 2016 Android Developer Toolbox [MOBILIZATION]The 2016 Android Developer Toolbox [MOBILIZATION]
The 2016 Android Developer Toolbox [MOBILIZATION]
 
beyond tellerrand: Mobile Apps with JavaScript – There's More Than Web
beyond tellerrand: Mobile Apps with JavaScript – There's More Than Webbeyond tellerrand: Mobile Apps with JavaScript – There's More Than Web
beyond tellerrand: Mobile Apps with JavaScript – There's More Than Web
 
My way to clean android - Android day salamanca edition
My way to clean android - Android day salamanca editionMy way to clean android - Android day salamanca edition
My way to clean android - Android day salamanca edition
 
Bringing order to the chaos! - Paulo Lopes - Codemotion Amsterdam 2018
Bringing order to the chaos! - Paulo Lopes - Codemotion Amsterdam 2018Bringing order to the chaos! - Paulo Lopes - Codemotion Amsterdam 2018
Bringing order to the chaos! - Paulo Lopes - Codemotion Amsterdam 2018
 
Building Modern Apps using Android Architecture Components
Building Modern Apps using Android Architecture ComponentsBuilding Modern Apps using Android Architecture Components
Building Modern Apps using Android Architecture Components
 

Kürzlich hochgeladen

PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLManishPatel169454
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spaintimesproduction05
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSrknatarajan
 

Kürzlich hochgeladen (20)

PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spain
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
 

Realm - Phoenix Mobile Festival

  • 1. DJ RAUSCH ANDROID ENGINEER @ MOKRIYA DJRAUSCH.COM REALM
  • 2. REALM - A MOBILE DATABASE REPLACEMENT PHOENIX MOBILE FESTIVAL ▸Use #phxmobi as the twitter hashtag and follow @phxmobifestival for updates. ▸Download Phoenix Mobile Festival App (search for 'phxmobi') from AppStore or Google Play. From the app you can create your own agenda for the day and provide feedback on the sessions.
  • 3. REALM - A MOBILE DATABASE REPLACEMENT WHO AM I? ▸Android Developer at Mokriya. ▸Developing Android apps since the start (first Android phone was the Droid) ▸Before working at Mokriya, worked for Jaybird, and a few smaller companies ▸Self published a few apps - Spotilarm, Volume Sync, Bill Tracker
  • 4. REALM - A MOBILE DATABASE REPLACEMENT WHAT IS REALM? ▸It’s a database. ▸A replacement for Sqlite. ▸It is NOT an ORM for Sqlite.
  • 5. REALM - A MOBILE DATABASE REPLACEMENT WHY SHOULD I USE IT? ▸Easy Setup ▸Cross Platform ▸ Android, iOS (Objective-C and Swift), Xamarin, React Native ▸FAST
  • 6. REALM - A MOBILE DATABASE REPLACEMENT WHO IS USING REALM?
  • 7. REALM - A MOBILE DATABASE REPLACEMENT FEATURES OF REALM ▸Fluent Interface ▸Field Annotations ▸Migrations ▸Encryption ▸Auto Updates and Notifications ▸RxJava Support
  • 8. REALM - A MOBILE DATABASE REPLACEMENT FLUENT INTERFACE getRealm().where(Bill.class) .equalTo("deleted", false) .between("dueDate", new DateTime().minusWeeks(1).toDate(), new DateTime().plusWeeks(1).plusDays(1) .toDate()) .findAll(); https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/util/BillUtil.jav a#L46
  • 9. REALM - A MOBILE DATABASE REPLACEMENT FIELD ANNOTATIONS ▸@PrimaryKey ▸Table PK ▸@Required ▸Require a value, not null ▸@Ignore ▸Do not persist field to disk
  • 10. REALM - A MOBILE DATABASE REPLACEMENT MIGRATIONS public class Migration implements RealmMigration { @Override public void migrate(DynamicRealm realm, long oldVersion, long newVersion) { RealmSchema schema = realm.getSchema(); if (oldVersion == 0) { //Add pay url to bill schema.get("Bill") .addField("payUrl", String.class); oldVersion++; }… } } https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/models/Migration.java
  • 11. REALM - A MOBILE DATABASE REPLACEMENT ENCRYPTION RealmConfiguration config = new RealmConfiguration.Builder(context) .encryptionKey(getKey()) .build(); Realm realm = Realm.getInstance(config); https://realm.io/docs/java/latest/#encryption
  • 12. REALM - A MOBILE DATABASE REPLACEMENT AUTO UPDATES & NOTIFICATIONS bills.addChangeListener(new RealmChangeListener<RealmResults<Bill>>() { @Override public void onChange(RealmResults<Bill> element) { if (adapter.getItemCount() == 0) { noBillsLayout.setVisibility(View.VISIBLE); recyclerView.setVisibility(View.GONE); } else { noBillsLayout.setVisibility(View.GONE); recyclerView.setVisibility(View.VISIBLE); } } }); https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/MainActivity.java#L132
  • 13. REALM - A MOBILE DATABASE REPLACEMENT RXJAVA getRealm().where(Bill.class).contains(“uuid”, billUuid).findFirst().asObservable() .filter(new Func1<Bill, Boolean>() { @Override public Boolean call(Bill bill) { return bill.isLoaded(); } }).subscribe(new Action1<Bill>() { @Override public void call(Bill bill) { setUI(bill); if (bill.paidDates != null) { if (adapter == null) { adapter = new PaidDateRecyclerViewAdapter(ViewBillDetails.this, bill.getPaidDates()); recyclerView.setLayoutManager(new LinearLayoutManager(ViewBillDetails.this)); recyclerView.setAdapter(adapter); } } } }); https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/AddOrEditBillActivity.java#L109 https://realm.io/docs/java/latest/#rxjava
  • 14. REALM - A MOBILE DATABASE REPLACEMENT OK, SO HOW DO I USE IT? ▸There is no schema set up ▸Simply have your model classes extend RealmObject public class Bill extends RealmObject { @PrimaryKey public String uuid; public String name; public String description; public int repeatingType = 0; public Date dueDate; public String payUrl; public RealmList<BillNote> notes; public RealmList<BillPaid> paidDates; public boolean deleted = false; public int amountDue = 0; https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/models/Bill.java
  • 15. REALM - A MOBILE DATABASE REPLACEMENT FIELD TYPES ▸Supports standard field types including Date Realm supports the following field types: boolean, byte, short, int, long, float, double, String, Date and byte[]. The integer types byte, short, int, and long are all mapped to the same type (long actually) within Realm. Moreover, subclasses of RealmObject and RealmList<? extends RealmObject> are supported to model relationships. The boxed types Boolean, Byte, Short, Integer, Long, Float and Double can also be used in model classes. Using these types, it is possible to set the value of a field to null. https://realm.io/docs/java/latest/#field-types
  • 16. REALM - A MOBILE DATABASE REPLACEMENT QUERIES - CONDITIONS ‣ between(), greaterThan(), lessThan(), greaterThanOrEqualTo() & lessThanOrEqualTo() ‣ equalTo() & notEqualTo() ‣ contains(), beginsWith() & endsWith() ‣ isNull() & isNotNull() ‣ isEmpty() & isNotEmpty() https://realm.io/docs/java/latest/#conditions
  • 17. REALM - A MOBILE DATABASE REPLACEMENT QUERIES ▸You can group conditions for complex queries RealmResults<User> r = realm.where(User.class) .greaterThan("age", 10) //implicit AND .beginGroup() .equalTo("name", "Peter") .or() .contains("name", "Jo") .endGroup() .findAll(); https://realm.io/docs/java/latest/#logical-operators
  • 18. REALM - A MOBILE DATABASE REPLACEMENT CREATING MODEL realm.beginTransaction(); User user = realm.createObject(User.class); user.setName("John"); user.setEmail("john@corporation.com"); realm.commitTransaction(); https://realm.io/docs/java/latest/#creating-objects
  • 19. REALM - A MOBILE DATABASE REPLACEMENT CREATING MODEL final Bill b = new Bill(name.getText().toString(), "", repeatingItem.code, selectedDueDate.toDate(), payUrl.getText().toString(), (int) (amount.getValue() * 100)); realm.executeTransaction(new Realm.Transaction() { @Override public void execute(Realm realm) { realm.copyToRealm(b); } }); https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/AddOrEditBillActivity.jav a#L171
  • 20. REALM - A MOBILE DATABASE REPLACEMENT READING MODEL BillTrackerApplication.getRealm().where(Bill.class).contains(" uuid", billUuid).findFirst() ‣ findFirst() ‣ findAll() ‣ findAllSorted() ‣ These all have an async version as well https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/AddOrEditBill Activity.java#L109
  • 21. REALM - A MOBILE DATABASE REPLACEMENT UPDATING MODEL realm.executeTransaction(new Realm.Transaction() { @Override public void execute(Realm realm) { editBill.setName(name.getText().toString()); editBill.setRepeatingType(repeatingItem.code); editBill.setDueDate(selectedDueDate.toDate()); editBill.setPayUrl(payUrl.getText().toString()); editBill.setAmountDue((int) (amount.getValue() * 100)); } }); https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/AddOrEditBill Activity.java#L155
  • 22. REALM - A MOBILE DATABASE REPLACEMENT DELETING MODEL getRealm().executeTransaction(new Realm.Transaction() { @Override public void execute(Realm realm) { bill.deleteFromRealm(); } }); https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/AddOrEditBill Activity.java#L218
  • 23. REALM - A MOBILE DATABASE REPLACEMENT RELATIONSHIPS ▸Many-to-One ▸Used for One-to-One ▸Many-to-Many https://realm.io/docs/java/latest/#relationships
  • 24. REALM - A MOBILE DATABASE REPLACEMENT MANY-TO-ONE public class Contact extends RealmObject { private Email email; // Other fields… } https://realm.io/docs/java/latest/#many-to-one
  • 25. REALM - A MOBILE DATABASE REPLACEMENT MANY-TO-MANY public class Bill extends RealmObject { … public RealmList<BillPaid> paidDates; … } final BillPaid billPaid = new BillPaid(new Date()); BillTrackerApplication.getRealm().executeTransaction(new Realm.Transaction() { @Override public void execute(Realm realm) { bill.setDueDate(DateUtil.createNextDueDate(bill)); bill.getPaidDates().add(billPaid); } }); https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/models/Bill.java#L28 https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/util/BillUtil.java#L20 https://realm.io/docs/java/latest/#many-to-many
  • 26. REALM - A MOBILE DATABASE REPLACEMENT THREADING The only rule to using Realm across threads is to remember that Realm, RealmObject or RealmResults instances cannot be passed across threads. Get Realm in any thread you need it. getRealm().where(Bill.class).equalTo("deleted", false).findAllSortedAsync("dueDate"); https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/util/BillUtil.java#L43
  • 27. REALM - A MOBILE DATABASE REPLACEMENT USING WITH RETROFIT It just works! apiService.getUserBills(BillTrackerApplication.getUserToken()).enqueue(new Callback<List<Bill>>() { @Override public void onResponse(Call<List<Bill>> call, final Response<List<Bill>> response) { for (Bill b : response.body()) { Log.d("Bill", b.toString()); } BillTrackerApplication.getRealm().executeTransaction(new Realm.Transaction() { @Override public void execute(Realm realm) { realm.copyToRealmOrUpdate(response.body()); } }); } }); https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/network/controller s/BillApi.java#L45
  • 28. REALM - A MOBILE DATABASE REPLACEMENT ADAPTERS ‣ RealmRecyclerViewAdapter ‣ Keeps the data updated from a RealmResult or RealmList ‣ No need to notifyDataSetChanged() https://github.com/djrausch/BillTracker/blob/master/app/src/main/java/com/djrausch/billtracker/adapters/M ainRecyclerViewAdapter.java https://realm.io/docs/java/latest/#adapters
  • 29. REALM - A MOBILE DATABASE REPLACEMENT LIMITATIONS ▸The upper limit of class names is 57 characters. Realm for Android prepend class_ to all names, and the browser will show it as part of the name. ▸The length of field names has a upper limit of 63 character. ▸Nested transactions are not supported, and an exception is thrown if they are detected. ▸Strings and byte arrays (byte[]) cannot be larger than 16 MB. ▸Does not support lists of primitive types (String, Ints, etc), yet. https://realm.io/docs/java/latest/#current-limitations
  • 30. REALM - A MOBILE DATABASE REPLACEMENT QUESTIONS? ▸Use #phxmobi as the twitter hashtag and follow @phxmobifestival for updates. ▸Download Phoenix Mobile Festival App (search for 'phxmobi') from AppStore or Google Play. From the app you can create your own agenda for the day and provide feedback on the sessions. ▸Slides will be on djraus.ch/realm soon! ▸Bill Tracker is open source - https://github.com/djrausch/BillTracker

Hinweis der Redaktion

  1. Migrations work much like onUpgrade in Sqlite boxed types
  2. I haven’t used this yet. Android KeyStore
  3. Note, I am not using the new RealmResults. It is recommended to only use this to notify the UI of any data changes.
  4. I am still new with RxJava so this isn’t that advanced. Realm docs go into more details on this
  5. POJO Can have public, private, protected methods as well
  6. contains is like where clause in sql
  7. If using this method, and want to perform action on the bill, you must use the object returned by copyToRealm
  8. Append async to method
  9. Update the model as you would any object. Do it inside a transaction (should probably use Async transaction)
  10. Setting the value to null for a RealmList field will clear the list. That is, the list will be empty (length zero), but no objects have been deleted. The getter for a RealmList will never return null. The returned object is always a list but the length might be zero.
  11. The realm instance cannot be shared between threads. Just get the instance again, and data in the other thread will be updated due to the auto updates