org.neodatis.odb.impl.core.transaction
Class CrossSessionCache

java.lang.Object
  extended by org.neodatis.odb.impl.core.transaction.CrossSessionCache
All Implemented Interfaces:
ICrossSessionCache

public class CrossSessionCache
extends java.lang.Object
implements ICrossSessionCache

A cache that survives the sessions. It is uses to automatically reconnect object to sessions

 When active, the cross session cache keeps track of all objects and their OID. It contains a map.
 When objects are stored or deleted in NeoDatis, if cross session cache is on, NeoDatis check if the object is in the cross session cache
 If it is, the object is then added to the session cache (this is the reconnection).
 
 When an object is deleted from the database, the object is also removed from the cross session cache. When the deleted is done by OID, it is not 
 immediately deleted, instead, it is inserted in a map of deleted object (as it would be very expensive to iterate throw all oids to find the right one.
 
 Issues:
        
 1) when deleting object using cross session cache : as the cross session cache is static, it is not session dependent, when deleting an object
        from the cross session cache, it will be seen as deleted by all the transactions even before committed. This is bad. 
  
 2) as cross session cache is static, the following case can happen:
        - create a NeoDatis database test1.neodatis. Create an object o1 and it. delete the database. re-create the database with the same name and store the o1 object.
 as o1 is the cross session cache, NeoDatis will try to reconnect the object and will fail as the OID won't exist.
 see for more details 
 
 

Author:
mayworm,olivier

Constructor Summary
protected CrossSessionCache()
          Protected constructor for factory-based construction
 
Method Summary
 void addObject(java.lang.Object o, OID oid)
          Associates the specified OID with the specified object(key) in this cache
 void clear()
          Removes all mappings from this cache.
static void clearAll()
           
 boolean existObject(java.lang.Object object)
          Returns true if this cache maps one key to the specified object.
static ICrossSessionCache getInstance(java.lang.String baseIdentification)
          Gets the unique instance for the cache for the identification
 OID getOid(java.lang.Object object)
          Return the specific OID
 boolean isEmpty()
          Returns true if this map contains no key-value mappings.
static void release(java.lang.String baseIdentification)
          removes the cross session cache from static cache
 void removeObject(java.lang.Object object)
          Removes the mapping for this object from this cache if it is present.
 void removeOid(OID oid)
          Mark the object with the oid as deleted.
 int size()
          Returns the number of key-value mappings in this cache.
 boolean slowExistObject(java.lang.Object object)
           
 java.lang.String toString()
          Returns a String writing down the objects
static java.lang.String toStringAll()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CrossSessionCache

protected CrossSessionCache()
Protected constructor for factory-based construction

Method Detail

getInstance

public static ICrossSessionCache getInstance(java.lang.String baseIdentification)
Gets the unique instance for the cache for the identification


release

public static void release(java.lang.String baseIdentification)
removes the cross session cache from static cache

Parameters:
baseIdentification -

addObject

public void addObject(java.lang.Object o,
                      OID oid)
Description copied from interface: ICrossSessionCache
Associates the specified OID with the specified object(key) in this cache

Specified by:
addObject in interface ICrossSessionCache
Parameters:
o - The key. This parameter can not be null

clear

public void clear()
Description copied from interface: ICrossSessionCache
Removes all mappings from this cache.

Specified by:
clear in interface ICrossSessionCache

existObject

public boolean existObject(java.lang.Object object)
Description copied from interface: ICrossSessionCache
Returns true if this cache maps one key to the specified object.

Specified by:
existObject in interface ICrossSessionCache
Returns:
boolean

slowExistObject

public boolean slowExistObject(java.lang.Object object)

getOid

public OID getOid(java.lang.Object object)
Description copied from interface: ICrossSessionCache
Return the specific OID

Specified by:
getOid in interface ICrossSessionCache
Parameters:
object - The key on the cache for a OID. This parameter can not be null
Returns:
OID. Returns null in case no find key.

isEmpty

public boolean isEmpty()
Description copied from interface: ICrossSessionCache
Returns true if this map contains no key-value mappings.

Specified by:
isEmpty in interface ICrossSessionCache
Returns:
boolean

removeObject

public void removeObject(java.lang.Object object)
Description copied from interface: ICrossSessionCache
Removes the mapping for this object from this cache if it is present.

Specified by:
removeObject in interface ICrossSessionCache
Parameters:
object - that contains the reference to OID. This parameter can not be null

removeOid

public void removeOid(OID oid)
Description copied from interface: ICrossSessionCache
Mark the object with the oid as deleted.

Specified by:
removeOid in interface ICrossSessionCache
Parameters:
oid - that must be marked as deleted.
            When objects are deleted by oid, the cost is too high to search the object by the oid, so we just keep the deleted oid,
 and when looking for an object, check if the oid if is the deleted oids
            
            

size

public int size()
Description copied from interface: ICrossSessionCache
Returns the number of key-value mappings in this cache.

Specified by:
size in interface ICrossSessionCache
Returns:
int The amount of objects on the cache

toString

public java.lang.String toString()
Description copied from interface: ICrossSessionCache
Returns a String writing down the objects

Specified by:
toString in interface ICrossSessionCache
Overrides:
toString in class java.lang.Object
Returns:
String

toStringAll

public static java.lang.String toStringAll()

clearAll

public static void clearAll()