Please enable JavaScript.
Coggle requires JavaScript to display documents.
Realm (Java (Realms (In-Memory Realm (using inMemory() in…
Realm
Model
-
Support public, protected, private fields as well as custom methods
Field types
primary(boolean, byte, short, int, long ...)
-
-
The boxed types (Boolean, Byte, Short, Integer, Long, Float, Double)
Null
required annotation can be used to tell Realm to enforce checks to disallow null values (Boolean, Byte, Short, Interger ... byte[], and Date)
Compiling will fail when files with other types have the Required annotation
-
-
-
Only support indexing: String. byte, short, int, long, boolean and Date fields
-
-
Primary keys
-
The filed type has to be either string (String) or integer (byte, short, int, or long)+ boxed variants (Byte, Short, Integer, Long)
Using a string filed as a primary key implies that the field is indexed(the annotation PrimaryKey implicitly sets the annotation Index)
copyToRealmOrUpdate() it possible to use(If classes without primary keys , an exception will be thrown)
When calling Realm.createObject(), -> new object will all fileds set to the default value -> ... suggested soule using copyToRealm() method
If using String and boxed integer(Byte, Short, Integer, and Long) can have null primary keys unless the using Required annotation
-
RealmModel interface
Extending the RealmObject base class is implementing the RealmModel interface and adding the RealmClass annotation
Relationships
-
-
Support Link queries
RealmResult<Persion> r1 = relam.where(Persion.class)
.equalTo("dogs.name", "Fluffy")
.findAll()
Inverse relationships
-
-
Querry (realmResults<Dog> brownFluffies) = realm.where(Dog.class)
.equalTo("color", "Brown")
.equalTo("name","Fluffy")
.findAll()
RealmResults<Dog> dogs = realm.where(Dog.class).equalTo("persions.name", "Jane").findAll()
Writes
All action(adding, modifying, removing objects) must be wrapped in write transactions
All the change will wring to disk when end transtaction by cancelTranscation() or commitTransaction()
when creating write transactions on both the UI and backgroud threads ant the same time -> ANR errors (use async transactions when creating write transactions on the UI thread)
Realm is crash safe when Exception happening inside a transtaction only data curent the transtaction will be lost
-
Read & write access in Realm is ACID (Atomicity , Consistency , Isolation , Durable )
Transactons
-
should be use executeTransactionAsync() to execute a transaction in backgroud and transaction.cancle() in onStrop() UI
-
Queries
-
Fintering
-
-
-
-
-
-
-
-
Create the query
to ensure the query completed and RealmResults object is updated, you can register a RealmChangeListener -> unregister in onStop() or forcue load an asynchronous query by using findAllAsync() + realmResults.load()
Realms
-
RelmConfiguration config = new realmConfiguration.Builder().build(): How a Realm is created -> call to default.realm located in Context.getFilesDir()
-
-
-
-
-
Dynamic realms
a Dynamic realm is a variant of the conventional Realm that makes it possible to work with Realm data without using realmObject subclasses
ignore any configured schema, migration, and schema version
-
-
-
Schemas
We can use RealmModule to build config for subset of class
-
-
-
-
If we change model classes(remove a fields...) there will be a mismatch between what Realm sees defined in code & the data Realm sees on disk -> thrown Exception
-
If we change model everytime ( for ex: testing or debug) We should using deleteRealmIfMigrationNeeded() in realmConfiguration
-
the following Realm classes can be exposed as an Observerble: Realm, RealmResults, RealmObject, DynamicRealms and DynamicRealmObject
This is link intro about how to use it
Default Realm using RxJava<=1.1 or not you can config Rx version by using rxFactory(new MyRxFactory()) in RealmConfiguration
Debug and testing
When debug by android studio or IntelliJ we must add a watch for any of the accessories will yield correct values (because Realm creates a proxy object behind the scenes and overrides the getters and setter in order to access the persisted data in the Realm)
-
A new kind of database
- Realm like a database(A lightweight Object container)
- The user can be queried and filtered, interconnected, and persisted
- Object in a Realm are native objects(you’re always working with the “live,” real object)
- Objects always stay in sync
Client-side, Embedded data storage
(Support offline model)
Not depends heavily on API calls over mobile networks to keep data up to day -> embeds a full featured database on device( execute all function on local(CRUD) even in the case of very large data sets) -> sync data later when network connectivity is available
-
-
Cross-Platform, Object database (Not an ORM)
- Realm is simple object-oriented structure
- The develop set the data model in code
- Cross-platform (the same data layer can be shared cross-platform apps running on any major mobile platform)
Life Objects
Realm automatically initiates data synchronization and updates the object in realtime (Realm attaches ?listeners?to data that react (or file callback methods)when that datachanges.)
Reactive architecture
- Multi version concurrency control provides concurrent access to the Realm Mobile Database across threads. (Never blocked against and data writer)
- Ensuring realm's ACID(atomicity, consistency, isolation, durability) compliance
-
-
-
Scalability
- Depending on the app and hardware environment
- Single realm Object Server can handle well over ten thousand current users
- The enterprise edition makes it possible to deploy multiple instances of the Realm Object Server in parallel (It can support more than one million concurrent users and deliver the same realtime experience to everyone)
Continuous backups
The platform enables you to create automatic backups of your production data on the Realm Object Serve -> save to secondary server at the location of your choice
-
-
Node
the Realm-Transformer, which relies on the Transform API, cannot be used with Jack.
Use Retrolambda instead of Jack for Java 8 feature support.