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

Realm_Android_Meetup.pdf

Michal Jenicek
October 13, 2016
6

 Realm_Android_Meetup.pdf

Michal Jenicek

October 13, 2016
Tweet

Transcript

  1. REALM IO
    Alternative to SQLite on Android

    View Slide

  2. SCHEDULE FOR THIS REALM TALK
    ● How I looked for persistence
    ● Why I decided to use Realm
    ● What issues I had solve with Realm

    View Slide

  3. PERSIST DATA
    ● Shared preferences
    ● Internal storage
    ● External storage
    ● Network connections
    ● Database

    View Slide

  4. PERSIST MODEL
    ● Shared preferences
    ● Internal storage
    ● External storage
    ● Network connections
    ● Local database

    View Slide

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

    View Slide

  6. DATABASE FRAMEWORK
    ● SQLite & ORM
    ○ DBFlow
    ○ ORMLite
    ○ GreenDao
    ○ ...

    View Slide

  7. DATABASE FRAMEWORK
    ● SQLite & ORM
    ○ DBFlow
    ○ ORMLite
    ○ GreenDao
    ○ ...
    ● Realm (Tightdb engine)

    View Slide

  8. DATABASE FRAMEWORK
    ● SQLite & ORM
    ○ DBFlow (reference)
    ○ ORMLite
    ○ GreenDao
    ○ ...
    ● Realm

    View Slide

  9. WHY TO CHOOSE THE REALM
    Performance?

    View Slide

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

    View Slide

  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 )

    View Slide

  12. RELATIONS MODEL

    View Slide

  13. SIMPLE? RELATIONS WITH DBFLOW

    View Slide

  14. SIMPLE? RELATIONS WITH DBFLOW

    View Slide

  15. SIMPLE RELATIONS WITH REALM

    View Slide

  16. SIMPLE RELATIONS WITH REALM

    View Slide

  17. QUERY WITH REALM

    View Slide

  18. QUERY WITH REALM

    View Slide

  19. SIMPLE QUERY WITH REALM

    View Slide

  20. SIMPLE INIT FROM ASSET/RAW

    View Slide

  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.

    View Slide

  22. INTEGRATE STETHO WITH REALM

    View Slide

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

    View Slide

  24. BUILD IN REMOTE AUTO SYNC

    View Slide

  25. PAIN OF THE REALM
    ● Limited support for data types
    ● Missing support for inheritance
    ● Missing support for auto-delete

    View Slide

  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

    View Slide

  27. LIMITED DATA TYPE SUPPORT & ENUMS

    View Slide

  28. LIMITED DATA TYPE SUPPORT & LISTS

    View Slide

  29. LIMITED DATA TYPE SUPPORT & LISTS

    View Slide

  30. MISSING INHERITANCE SUPPORT & WORKAROUND

    View Slide

  31. MISSING INHERITANCE SUPPORT & WORKAROUND

    View Slide

  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.

    View Slide

  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.

    View Slide

  34. Aren’t you afraid of mentioned
    pains of the Realm ?
    Want to simply persist the model ?
    IF SO, USE THE REALM

    View Slide

  35. REALM IO
    Ready for Android, React Native, Xamarin, Objective C & Swift.
    Designed for mobile.

    View Slide

  36. MORE ON REALM IO DOC
    https://realm.io/docs/java/latest/

    View Slide

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

    View Slide

  38. View Slide

  39. QUESTIONS

    View Slide