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

Simple Disk Storage with ObjectBox by Vincent Carrier

Simple Disk Storage with ObjectBox by Vincent Carrier

1b77dd441f657f5aefb3e21283b252e6?s=128

GDG Montreal

October 25, 2017
Tweet

More Decks by GDG Montreal

Other Decks in Technology

Transcript

  1. Simple Disk Storage with ObjectBox By Vincent Carrier

  2. Why do we need (yet) another database library? – Object-relational

    mappers (i.e. Room, GreenDAO) – Need to write SQL for every request – No auto-completion, no type safety – Migrations are scary – Realm – Complex – Inheritance-based – Custom types (e.g. JodaTime) suck – Weird threading requirements – Migrations are scary
  3. Why do we need (yet) another database library? – ObjectBox

    – No need to write SQL – Super fast – Great Kotlin support – RxJava 2 support – Annotation-based – Easy to learn – Safe, easy migrations – Web-based data browser – Local unit tests
  4. Why do we need (yet) another database library? – ObjectBox

    – No need to write SQL – Super fast – Great Kotlin support – RxJava 2 support – Annotation-based – Easy to learn – Safe, easy migrations – Web-based data browser – Local unit tests
  5. Setup

  6. Setup Set automatically by the library VERY IMPORTANT: You need

    to provide ObjectBox either an empty constructor or an all-args one. Otherwise your queries will fail silently because ObjectBox cannot set the ID of your entities.
  7. Setup Generated after writing your first entity class. Just rebuild

    J
  8. Demo

  9. The basics Note: If you don’t like RxJava, you can

    also use ObjectBox’s own data observers put() will update an object if the ID is already in the database. Your objects aren’t “live” like in Realm. Your changes need to be persisted with put()
  10. Custom Types

  11. ToOne<T> Relations Note: ToOne<T> and and ToMany properties are automatically

    initialized by the gradle plugin
  12. ToMany<T> Relations – Implements java.util.List (you can also just a

    normal List and track changes yourself) – Tracks changes to be persisted (using put()) – Use with @Backlink annotation to link with a ToOne<T> property and create a One-To-Many relation
  13. Migrations – Adding and removing properties is done automatically –

    For ambiguous schema modifications (i.e. changing the name or type of a property), annotate your entity class with @Uid, build your project and follow the instructions – UIDs are stored in a file called default.json. Make sure to add it to Git.
  14. Data browser

  15. Thank you for listening!