SlideShare a Scribd company logo
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

More Related Content

What's hot

ES6: The Awesome Parts
ES6: The Awesome PartsES6: The Awesome Parts
ES6: The Awesome Parts
Domenic Denicola
 
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
Ben 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 Stack
GaryCoady
 
Requery overview
Requery overviewRequery overview
Requery overview
Sunghyouk Bae
 
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
 
JavaScript Promise
JavaScript PromiseJavaScript Promise
JavaScript Promise
Joseph Chiang
 
async/await in Swift
async/await in Swiftasync/await in Swift
async/await in Swift
Peter Friese
 
Rethink Async With RXJS
Rethink Async With RXJSRethink Async With RXJS
Rethink Async With RXJS
Ryan Anklam
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
L&T Technology Services Limited
 
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 Converset
CocoaHeads France
 
Getting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETGetting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NET
Tomas 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 promises
Ankit 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
 
Promises, Promises
Promises, PromisesPromises, Promises
Promises, Promises
Domenic Denicola
 
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
DroidConTLV
 
Domains!
Domains!Domains!

What's hot (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!
 

Viewers also liked

Introduction to Realm Mobile Platform
Introduction to Realm Mobile PlatformIntroduction to Realm Mobile Platform
Introduction to Realm Mobile Platform
Christian 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 Realm
Martin Grider
 
Realm Presentation
Realm PresentationRealm Presentation
Realm Presentation
Phạm Khắc
 
Diameter Overview
Diameter OverviewDiameter Overview
Diameter Overview
John Loughney
 
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 experience
Hussien 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 Signaling
PT
 
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
Mahindra Comviva
 
Introduction to Diameter Protocol - Part1
Introduction to Diameter Protocol - Part1Introduction to Diameter Protocol - Part1
Introduction to Diameter Protocol - Part1
Basim Aly (JNCIP-SP, JNCIP-ENT)
 
Diameter Presentation
Diameter PresentationDiameter Presentation
Diameter Presentation
Beny Haddad
 
PCRF-Policy Charging System-Functional Analysis
PCRF-Policy Charging System-Functional AnalysisPCRF-Policy Charging System-Functional Analysis
PCRF-Policy Charging System-Functional Analysis
Biju M R
 

Viewers also liked (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
 

Similar to Realm - Phoenix Mobile Festival

CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on AndroidSven Haiges
 
mobl
moblmobl
mobl
zefhemel
 
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 Development
FITC
 
混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaveryangdj
 
After max+phonegap
After max+phonegapAfter max+phonegap
After max+phonegapyangdj
 
What's New in Android
What's New in AndroidWhat's New in Android
What's New in Android
Robert Cooper
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best PracticesYekmer Simsek
 
Android dev toolbox - Shem Magnezi, WeWork
Android dev toolbox - Shem Magnezi, WeWorkAndroid dev toolbox - Shem Magnezi, WeWork
Android dev toolbox - Shem Magnezi, WeWork
DroidConTLV
 
Android Developer Toolbox 2017
Android Developer Toolbox 2017Android Developer Toolbox 2017
Android Developer Toolbox 2017
Shem Magnezi
 
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
Guy 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 2015
Fernando 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 platforms
Ayush 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 Web
Heiko 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 edition
Christian 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 2018
Codemotion
 
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
Hassan Abid
 

Similar to 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
 
混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver
 
After max+phonegap
After max+phonegapAfter max+phonegap
After max+phonegap
 
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 dev toolbox - Shem Magnezi, WeWork
Android dev toolbox - Shem Magnezi, WeWorkAndroid dev toolbox - Shem Magnezi, WeWork
Android dev toolbox - Shem Magnezi, WeWork
 
Android Developer Toolbox 2017
Android Developer Toolbox 2017Android Developer Toolbox 2017
Android Developer Toolbox 2017
 
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
 

Recently uploaded

Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
SupreethSP4
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 

Recently uploaded (20)

Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 

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

Editor's Notes

  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