Slide 1

Slide 1 text

In the name of God

Slide 2

Slide 2 text

Who Am I? Seyed Mohammad Hossein Jafari Android Team Lead @ Noavaran

Slide 3

Slide 3 text

Android Offline

Slide 4

Slide 4 text

How? Persistence By persisting data we mean to store our data in a place that we can access it later even if system goes through restart/shutdown. Usually done by writing files on disks.

Slide 5

Slide 5 text

File With? Shared Preferences DataBase

Slide 6

Slide 6 text

File Pros and Cons Shared Preferences DataBase ● No Structure ● Bulk Read/Write ● Easy (no need to learn) API ● Binary data ● Synchronized ● Key-Value based ● Small data ● Framework Managed ● Small API ● Observing Changes (Surprised?) ● Synchronized ● OEM Bugs! ● Structural ● Transactional ● Large Data sets ● Relational ● New API ● Observing Changes ● UnSynchronized ● Lot’s of third party Libs

Slide 7

Slide 7 text

File/DB

Slide 8

Slide 8 text

Structured Query Language SQL / RDBMS / Relation Types of DataBases Non-SQL or non-relational No-SQL

Slide 9

Slide 9 text

SQL Wikipedia: “ SQL is a domain-specific language used in programming and designed for managing data held in a relational database management system (RDBMS), or for stream processing in a relational data stream management system (RDSMS).”

Slide 10

Slide 10 text

NoSQL Wikipedia: “ NoSQL database provides a mechanism for storage and retrieval of data that is modeled in means other than the tabular relations used in relational databases. ”

Slide 11

Slide 11 text

Android DataBase SQLite

Slide 12

Slide 12 text

Why to use Database on Android ● Content received from remote data source (Caching) ● User entered data and application generated data ● Storing app states and User Management ● Storing Requests and Works (WorkManager)

Slide 13

Slide 13 text

SQLite

Slide 14

Slide 14 text

Object Relational Mapping (ORM)

Slide 15

Slide 15 text

Beyond the basics SQL NoSQL

Slide 16

Slide 16 text

Room GreenDAO SQLDelight Realm Objectbox

Slide 17

Slide 17 text

GreenDAO Room SQLDelight ORM

Slide 18

Slide 18 text

Realm Objectbox NoSQL

Slide 19

Slide 19 text

Too many options? Which one to choose?

Slide 20

Slide 20 text

ORMs ● Native ● Fully backward compatible ● Small Size ● Minimum method Count ● Easy to migrate Pros ● SQLite base ● Very Slow ● Not Fully Crossplatform ● Not many features ● Lots of people suggest not to use it any more Cons

Slide 21

Slide 21 text

NoSQL DBs ● Fast ● Scalable ● Constant Update ● Fully featured ● No more SQL ● Cross platform ● Easy to use Pros ● Extra C binaries ● Huge method count ● Not Fully backward compatible(9/15) Cons

Slide 22

Slide 22 text

What does Stats say?

Slide 23

Slide 23 text

Room GreenDao SQLDelight Realm ObjectBox Size 50-100KB 3-4MB 1-2MB Methods 300 2000 1500

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

Testing

Slide 30

Slide 30 text

Room ● No Real Unit Testing Only Instrumentation test ● In Memory DB Realm ● No Real Unit Testing Only Instrumentation test ● Mock master! ● In Memory DB Objectbox ● Write tests on JVM ● No need to mock ● Use real configuration not stub version

Slide 31

Slide 31 text

Satisfied?

Slide 32

Slide 32 text

Where to begin with ObjectBox? https://docs.objectbox.io/getting-started

Slide 33

Slide 33 text

Entities(Tables) @Entity data class StudentEntity( @Id var id: Long = 0, val name: String )

Slide 34

Slide 34 text

DataBase Instance val store = MyObjectBox .builder() .androidContext(applicationContext) .build(); val box: Box = store .boxFor(StudentEntity::class.java)

Slide 35

Slide 35 text

Create store.put(student)

Slide 36

Slide 36 text

Read store.get(studentID) store.getAll() store.find(StudentEntity_.name, "name")

Slide 37

Slide 37 text

Update store.put(student)

Slide 38

Slide 38 text

Delete store.remove(studentID)

Slide 39

Slide 39 text

Thank you

Slide 40

Slide 40 text

Forget SQL Try Objectbox Today https://objectbox.io https://github.com/objectbox Twitter : @worldsnas https://worldsanas.com

Slide 41

Slide 41 text

The End