Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Realm_Android_Meetup.pdf

76655285ce09413e5e739ecb60add953?s=47 Michal Jenicek
October 13, 2016
4

 Realm_Android_Meetup.pdf

76655285ce09413e5e739ecb60add953?s=128

Michal Jenicek

October 13, 2016
Tweet

Transcript

  1. REALM IO Alternative to SQLite on Android

  2. SCHEDULE FOR THIS REALM TALK • How I looked for

    persistence • Why I decided to use Realm • What issues I had solve with Realm
  3. PERSIST DATA • Shared preferences • Internal storage • External

    storage • Network connections • Database
  4. PERSIST MODEL • Shared preferences • Internal storage • External

    storage • Network connections • Local database
  5. PERSIST MODEL OFFLINE • Shared preferences • Internal storage •

    External storage • Network connections • Local database
  6. DATABASE FRAMEWORK • SQLite & ORM ◦ DBFlow ◦ ORMLite

    ◦ GreenDao ◦ ...
  7. DATABASE FRAMEWORK • SQLite & ORM ◦ DBFlow ◦ ORMLite

    ◦ GreenDao ◦ ... • Realm (Tightdb engine)
  8. DATABASE FRAMEWORK • SQLite & ORM ◦ DBFlow (reference) ◦

    ORMLite ◦ GreenDao ◦ ... • Realm
  9. WHY TO CHOOSE THE REALM Performance?

  10. WHY TO CHOOSE THE REALM Performance? • NO ( performance

    is good, but DBFlow has also good performance)
  11. WHY TO CHOOSE THE REALM Performance? • NO ( performance

    is good, but DBFlow has also good performance ) • Simplicity ( keep implementation simple ) • Live realm (choice in between using live realm or close connection like in sqlite) • Easy to integrate (GSON, Parceler, Retrofit, Roboelectric, RxJava, Kotlin, Stetho...) • Build in features ( use advanced build-in features )
  12. RELATIONS MODEL

  13. SIMPLE? RELATIONS WITH DBFLOW

  14. SIMPLE? RELATIONS WITH DBFLOW

  15. SIMPLE RELATIONS WITH REALM

  16. SIMPLE RELATIONS WITH REALM

  17. QUERY WITH REALM

  18. QUERY WITH REALM

  19. SIMPLE QUERY WITH REALM

  20. SIMPLE INIT FROM ASSET/RAW

  21. SUPPORT FOR LIVE REALM Live realm • Operate on live

    objects: the auto updating view to database • Don’t forget to close realm when your scope (app/activity) is finishing. • Use it for design case, when realm data are the basics for your model. Copying data • Just copy the data from live realm and close this realm immediately. • Use it for design case, when realm data are the backup of your model.
  22. INTEGRATE STETHO WITH REALM

  23. BUILD IN SECURITY Encrypt/decrypt *.realm (using 512-bit encryption key) with

    standard AES-256 encryption
  24. BUILD IN REMOTE AUTO SYNC

  25. PAIN OF THE REALM • Limited support for data types

    • Missing support for inheritance • Missing support for auto-delete
  26. LIMITED DATA TYPE SUPPORT Basic types • boolean, byte •

    short, int, long, float, double • String, Date, byte[] Boxed types • Boolean, Byte • Short, Integer, Long, Float, Double And what the others? NO WAY, but! • Serializable & in edge case Parcelable objects
  27. LIMITED DATA TYPE SUPPORT & ENUMS

  28. LIMITED DATA TYPE SUPPORT & LISTS

  29. LIMITED DATA TYPE SUPPORT & LISTS

  30. MISSING INHERITANCE SUPPORT & WORKAROUND

  31. MISSING INHERITANCE SUPPORT & WORKAROUND

  32. LIMITED SUPPORT FOR AUTODELETE • Child objects are not deleted

    from realm with their parent’s removal! • Check it on your case and eventually handle delete sequence yourself.
  33. NOTE ABOUT REALM CONCURRENCY RULES Threads • Realm files can

    be accessed by multiple threads concurrently • You can’t hand over Realm objects, queries, and results between threads. Processes • Realms can only be accessed by a single process at a time. • Different processes should either copy *.realm files or create their own. • Multi-process support is promised coming soon.
  34. Aren’t you afraid of mentioned pains of the Realm ?

    Want to simply persist the model ? IF SO, USE THE REALM
  35. REALM IO Ready for Android, React Native, Xamarin, Objective C

    & Swift. Designed for mobile.
  36. MORE ON REALM IO DOC https://realm.io/docs/java/latest/

  37. DB SHOWCASE https://github.com/kotomisak/db-showcase-android

  38. THANK YOU michal.jenicek@strv.com

  39. QUESTIONS