Persisting data is the heart of any database or caching mechanism. Onyx Database can efficiently persist data in a few different ways either by saving an entity, batch saving operations, or cascading through a relationship. This tutorial guides you through how to declare an entity and persist it.
Declare an entity.
All entities must implement IManagedEntity or extend the abstract ManagedEntity class.
Below illustrates how to use the @Attribute annotation to declare fields as persistable.
When annotating the attributes you have the option to specify whether the attribute is nullable. Nullable only applies to mutable objects. Primitive typed attributes cannot be null.
All non transient fields have the @Attribute annotation.
Only class properties can be annotated. Getters and Setters are ignored.
An attribute can also specify the max size using the size parameter. Max size only applies to Strings
When your entity implements Comparable<Person> it will automatically be sorted based on your compareTo logic when being retrieved as a child collection of another entity.
Make sure to declare a primary key with the @Identifier annotation.
The @Identifier can be any the supported Onyx data types:
If the data type is numeric, you can choose to auto increment the identifier using Onyx Database's built-in sequencer.
Generator types include IdentifierGenerator.SEQUENCE or by default IdentifierGenerator.NONE.
You can only specify one attribute as the Identifier.
You must annotate the primary key property with @Identifier and @Attribute annotation.
The identifier as well as the attribute access modifier can be private, protected, or public.
Get an instance of an Entity Persistence Manager via the Persistence Manager Factory
Create an instance of the entity you declared in step 1 and set all applicable attributes.
Invoke the PersistenceManager#saveEntity method using the Persistence Manager.
Onyx does not differentiate between updating or inserting managed com.onyxdevtools.entities.
If an entity with a matching primary key already exists,
Onyx Database will assume you are updating the entity specified and overwrite the existing
Verify that the instance has been persisted using the PersistenceManager#find method.