How Odb Store Objects

Here, we explain the sequence of operations that ODB executes for the four basict database operations :

  • Insert
  • Update
  • Select
  • Delete

Insert and Update are described together because the two operations are very similar. As you can see, ODB does not have two different methods insert and update, it only has store. ODB will decide the right operation automatically.

Here is the sequence of operations that ODB execute to insert/update an object

1-User creates/opens a database

ODB odb =<base name>);

org.neodatis.odb.main.ODB is an interface.

The ODBFactory returns an instance of org.neodatis.odb.main.LocalODB. LocalODB is a facade that delegates all the calls to an instance.

The default implementation of IStorageEngine is

2-User creates an instance

Sport sport = new Sport("volley-ball");

3-User calls the method object);
  1. calls LocalODB extends ODBAdapter.
  2. calls
    1. Checks if database is open
    2. calls LocalStorageengine.internalStore(object)
      1. Check if database has been rollbacked
      2. Check if object is not null
      3. Check if object is not an array. ODB does not support storing arrays directly.
      4. Check if object is not a native object like String. ODB dos not support to store String directly.
      5. Check if class already exist in the database meta model. If not, then creates it(updates database meta model)
      6. Transform the object (Layer 3) into a NonNativeObjectInfo (Layer 2 : MetaRepresentation of the object)
      7. Call <NonNativeObjectInfo> )

ODB does not have an insert and update method. It only have a store method. So ODB will discover by itself if it must insert a new object or update an existing one.

To update an object, it must be previously loaded by ODB. By doing this, ODB puts this object in a cache (org.neodatis.odb.core.session.ICache) to be abble to detect new objects from existing objects. So, to discover if it must execute an update or an insert, ODB will check if object exist in cache, if it does, it is an update, if it does not, it is an insert.

If it is an insert call ObjectWriter.insertNonNativeObject

  1. Triggers 'BeforeInsert Triggers' : org.neodatis.odb.core.trigger.TriggerManager.manageInsertTriggerBefore
  2. Avoid cyclic references : Check if object is not already being inserted.
  3. Mark the object as being inserted (Temporary Cache)
  4. Call ObjectWriter.writeNonNativeObjectInfo
      1. Recheck if class exist in meta model!
      2. Get the position where the object is going to be written in the database file (
      3. Check if OID (Object Id) is null : if null, Ask ODB a new OID, if not update the object position for the OID.
      4. Set the new OID to the NonNAtiveObjectInfo instance
      5. Updates the NonNativeObjectInfo classOInfo attribute from the meta model.
      6. If Object is new, updates The class info pointers (Nb objects, first object OID, last object OID)
      7. Writes the object bytes in the database file. Check the odb-file-format for more details.
      8. Update indexes : ObjectWriter.manageIndexesForInsert(object)
      9. Adds the new object in the cache
      10. Triggers 'AfterInsert Triggers' : org.neodatis.odb.core.trigger.TriggerManager.manageInsertTriggerAfter(object)
      11. Returns the OID of the new object

If it is an update call ObjectWriter.updateNonNativeObjectInfo

Update is a bit more complicated. When possible ODB tries to do 'In Place Update'.

When In Place Update is not possible, ODB will rewrite the entire object in a new place (using ObjectWriter.insertNonNativeObject) and mark the block where the current object is written in the database file as deleted. In this case, ODB will also updates the OID of the object : updates the position of the new created object.

ODB also will execute manageUpdateTriggerBefore and manageUpdateTriggerAfter triggers and update indexes (ObjectWriter.manageIndexesForUpdate()) if necessary.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License