org.datanucleus.store.neodatis
Class NeoDatisPersistenceHandler

java.lang.Object
  extended by org.datanucleus.store.neodatis.NeoDatisPersistenceHandler
All Implemented Interfaces:
org.datanucleus.store.StorePersistenceHandler

public class NeoDatisPersistenceHandler
extends java.lang.Object
implements org.datanucleus.store.StorePersistenceHandler

Persistence handler for persisting to NeoDatis datastores.


Field Summary
protected static org.datanucleus.util.Localiser LOCALISER
          Localiser for messages.
static boolean neodatisDebug
           
protected  NeoDatisManager storeMgr
          Manager for the store.
 
Constructor Summary
NeoDatisPersistenceHandler(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 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 NeoDatisManager storeMgr
Manager for the store.


neodatisDebug

public static boolean neodatisDebug
Constructor Detail

NeoDatisPersistenceHandler

public NeoDatisPersistenceHandler(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.

Specified by:
close in interface org.datanucleus.store.StorePersistenceHandler

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 NeoDatis 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 NeoDatis "set" command is invoked per user makePersistent() call, using NeoDatis' ability to persist by reachability.

Specified by:
insertObject in interface org.datanucleus.store.StorePersistenceHandler
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 NeoDatis "set".

Specified by:
updateObject in interface org.datanucleus.store.StorePersistenceHandler
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 primary object to be deleted (via the users deletePersistent call) then after processing the object graph will call NeoDatis "delete" for that object and use NeoDatis' delete by reachability.

Specified by:
deleteObject in interface org.datanucleus.store.StorePersistenceHandler
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. This method is called when we need to load a field. NeoDatis doesn't have a concept of "unloaded" for fields and so we may get this called when accessing an object from HOLLOW state and OM.refresh() is called, or when sm.validate() is called on it when getting it from the L1 cache.

Specified by:
fetchObject in interface org.datanucleus.store.StorePersistenceHandler
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 instantiation to DataNucleus, but some object databases may manage the in-memory object instantion. Implementations may simply return null, indicating that they leave the object instantiate to NeoDatis. 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.

Specified by:
findObject in interface org.datanucleus.store.StorePersistenceHandler
Parameters:
om - the ObjectManager which will manage the object
id - the id of the object in question.
Returns:
a Persistable with a valid state (for example: hollow) or null, indicating that the implementation leaves the instantiation work to NeoDatis.

locateObject

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

Specified by:
locateObject in interface org.datanucleus.store.StorePersistenceHandler
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 © 2009. All Rights Reserved.