MicroStream is designed to work with object graphs. Thus, storing data means to store an object graph. This includes the object's value fields and references to other objects. Storing an object will also store all instances referenced by this objects that have not been stored before. While storing your data most of the work MicroStream performs for you. You only need to call the store method on the correct object. The rule is: "The Object that has been modified has to be stored!".
Storing objects that are not part of an object graph is most likely pointless.
To store the registered root instance just call the
storeRoot()method of a
// Init storage manager
final EmbeddedStorageManager storageManager = EmbeddedStorage.start(root);
// Store the root object
To store a newly created object, store the "owner" of the object. In the example below a new object is created and added to the
myObjectslist of the root object. Then the modified list gets stored. This will also store the new object.
// Add a new data object to the list in root
MyData dataItem = new MyData("Alice");
// Store the modified list
Before storing a modified object keep in your mind that the modified object needs to be stored.
In case of a value types, like
int, it is the object that has the int field as a member:
// Modify a value type memeber and store it
Don't forget immutable objects
Immutable objects like
Stringcannot be modified.
Assigning a new value to a String does not modify the String object. Instead a new String instance is created and the reference is changed!
// Change a string object and store it