org.datanucleus.store.db4o
Class DB4OPersistenceHandler

java.lang.Object
  extended by org.datanucleus.store.AbstractPersistenceHandler
      extended by org.datanucleus.store.db4o.DB4OPersistenceHandler
All Implemented Interfaces:
org.datanucleus.store.StorePersistenceHandler

public class DB4OPersistenceHandler
extends org.datanucleus.store.AbstractPersistenceHandler

Persistence handler for persisting to DB4O datastores.


Field Summary
protected static org.datanucleus.util.Localiser LOCALISER
          Localiser for messages.
protected  DB4OStoreManager storeMgr
          Manager for the store.
 
Constructor Summary
DB4OPersistenceHandler(org.datanucleus.store.StoreManager storeMgr)
          Constructor.
 
Method Summary
 void close()
          Method to close the handler and release any resources.
 void deleteObject(org.datanucleus.StateManager sm)
          Deletes a persistent object from the database.
 void fetchObject(org.datanucleus.StateManager sm, int[] fieldNumbers)
          Fetches fields of a persistent object from the database.
 java.lang.Object findObject(org.datanucleus.ObjectManager om, java.lang.Object id)
          Accessor for an (at least) hollow PersistenceCapable object matching the given id.
 void insertObject(org.datanucleus.StateManager sm)
          Inserts a persistent object into the database.
 void locateObject(org.datanucleus.StateManager sm)
          Locates this object in the datastore.
 void updateObject(org.datanucleus.StateManager sm, int[] fieldNumbers)
          Updates a persistent object in the database.
 
Methods inherited from class org.datanucleus.store.AbstractPersistenceHandler
batchEnd, batchStart, findObjects, locateObjects
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALISER

protected static final org.datanucleus.util.Localiser LOCALISER
Localiser for messages.


storeMgr

protected final DB4OStoreManager storeMgr
Manager for the store.

Constructor Detail

DB4OPersistenceHandler

public DB4OPersistenceHandler(org.datanucleus.store.StoreManager storeMgr)
Constructor.

Parameters:
storeMgr - Manager for the datastore
Method Detail

close

public void close()
Method to close the handler and release any resources.


insertObject

public void insertObject(org.datanucleus.StateManager sm)
Inserts a persistent object into the database. Provides persist-by-reachability using PersistFieldManager to go through all related PC fields. If this is the principal object for this thread (the object that the user invoked makePersistent on) then this will actually update the object in DB4O when all reachables have been processed. The reachability process means that we assign StateManagers down the object graph, and that object states are set up. Only a single DB4O "set" command is invoked per user makePersistent() call, using DB4Os ability to persist by reachability.

Parameters:
sm - The state manager of the object to be inserted.
Throws:
org.datanucleus.exceptions.NucleusDataStoreException - when an error occurs in the datastore communication

updateObject

public void updateObject(org.datanucleus.StateManager sm,
                         int[] fieldNumbers)
Updates a persistent object in the database. Provides reachability via PersistFieldManager, meaning that all PC fields that have been updated will be attached/updated too. Each call to "update" here will result in a call to DB4O "set".

Parameters:
sm - The state manager of the object to be updated.
fieldNumbers - The numbers of the fields to be updated.
Throws:
org.datanucleus.exceptions.NucleusDataStoreException - when an error occurs in the datastore communication
org.datanucleus.exceptions.NucleusOptimisticException - thrown if version checking fails

deleteObject

public void deleteObject(org.datanucleus.StateManager sm)
Deletes a persistent object from the database. Performs delete-by-reachability ("cascade-delete") via DeleteFieldManager. If this is the principal object to be deleted (via the users deletePersistent call) then after processing the object graph will call DB4O "delete" for that object and use DB4Os cascade-on-delete.

Parameters:
sm - The state manager of the object to be deleted.
Throws:
org.datanucleus.exceptions.NucleusDataStoreException - when an error occurs in the datastore communication
org.datanucleus.exceptions.NucleusOptimisticException - thrown if version checking fails on an optimistic transaction for this object

fetchObject

public void fetchObject(org.datanucleus.StateManager sm,
                        int[] fieldNumbers)
Fetches fields of a persistent object from the database. In the context of DB4O this method activates the supplied object if it is currently inactive and, in doing so, handles any fields that have been made dirty in the meantime. The requested fields are activated, replaced by SCO wrappers (if SCO mutable) and any PC field values have StateManagers connected.

Parameters:
sm - The state manager of the object to be fetched.
fieldNumbers - The numbers of the fields to be fetched.
Throws:
org.datanucleus.exceptions.NucleusDataStoreException - when an error occurs in the datastore communication

findObject

public java.lang.Object findObject(org.datanucleus.ObjectManager om,
                                   java.lang.Object id)
Accessor for an (at least) hollow PersistenceCapable object matching the given id. In this sense, the StoreManager may be seen as a kind of level-3-cache. But this methods servers an important purpose: if the StoreManager is managing the in-memory object instantiation (as part of co-managing the object lifecycle in general), then the StoreManager has to create the object during this call (if it is not already created. Most relational databases leave the in-memory object instantion to Core, but some object databases may manage the in-memory object instantion. Implementations may simply return null, indicating that they leave the object instantiate to us. Other implementations may instantiate the object in question (whether the implementation may trust that the object is not already instantiated has still to be determined). If an implementation believes that an object with the given ID should exist, but in fact does not exist, then the implementation should throw a RuntimeException. It should not silently return null in this case.

Parameters:
om - the ObjectManager which will manage the object
id - the id of the object in question.
Returns:
a persistable object with a valid state (for example: hollow) or null, indicating that the implementation leaves the instantiation work to us.

locateObject

public void locateObject(org.datanucleus.StateManager sm)
Locates this object in the datastore.

Parameters:
sm - The StateManager for the object to be found
Throws:
org.datanucleus.exceptions.NucleusObjectNotFoundException - if the object doesnt exist
org.datanucleus.exceptions.NucleusDataStoreException - when an error occurs in the datastore communication


Copyright © 2010. All Rights Reserved.