org.neodatis.odb.impl.core.transaction
Class CrossSessionCache
- java.lang.Object
-
- 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 sessionsWhen active, the cross session cache keeps track of all objects and their OID. It contains a map<Object,OID>. 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
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddObject(java.lang.Object o, OID oid)Associates the specifiedOIDwith the specified object(key) in this cachevoidclear()Removes all mappings from this cache.static voidclearAll()booleanexistObject(java.lang.Object object)Returns true if this cache maps one key to the specified object.static ICrossSessionCachegetInstance(java.lang.String baseIdentification)Gets the unique instance for the cache for the identificationOIDgetOid(java.lang.Object object)Return the specificOIDbooleanisEmpty()Returns true if this map contains no key-value mappings.static voidrelease(java.lang.String baseIdentification)removes the cross session cache from static cachevoidremoveObject(java.lang.Object object)Removes the mapping for this object from this cache if it is present.voidremoveOid(OID oid)Mark the object with the oid as deleted.intsize()Returns the number of key-value mappings in this cache.booleanslowExistObject(java.lang.Object object)java.lang.StringtoString()Returns a String writing down the objectsstatic java.lang.StringtoStringAll()
-
-
-
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:ICrossSessionCacheAssociates the specifiedOIDwith the specified object(key) in this cache- Specified by:
addObjectin interfaceICrossSessionCache- Parameters:
o- The key. This parameter can not benull
-
clear
public void clear()
Description copied from interface:ICrossSessionCacheRemoves all mappings from this cache.- Specified by:
clearin interfaceICrossSessionCache
-
existObject
public boolean existObject(java.lang.Object object)
Description copied from interface:ICrossSessionCacheReturns true if this cache maps one key to the specified object.- Specified by:
existObjectin interfaceICrossSessionCache- Returns:
- boolean
-
slowExistObject
public boolean slowExistObject(java.lang.Object object)
-
getOid
public OID getOid(java.lang.Object object)
Description copied from interface:ICrossSessionCacheReturn the specificOID- Specified by:
getOidin interfaceICrossSessionCache- Parameters:
object- The key on the cache for aOID. This parameter can not benull- Returns:
OID. Returnsnullin case no find key.
-
isEmpty
public boolean isEmpty()
Description copied from interface:ICrossSessionCacheReturns true if this map contains no key-value mappings.- Specified by:
isEmptyin interfaceICrossSessionCache- Returns:
- boolean
-
removeObject
public void removeObject(java.lang.Object object)
Description copied from interface:ICrossSessionCacheRemoves the mapping for this object from this cache if it is present.- Specified by:
removeObjectin interfaceICrossSessionCache- Parameters:
object- that contains the reference toOID. This parameter can not benull
-
removeOid
public void removeOid(OID oid)
Description copied from interface:ICrossSessionCacheMark the object with the oid as deleted.- Specified by:
removeOidin interfaceICrossSessionCache- 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:ICrossSessionCacheReturns the number of key-value mappings in this cache.- Specified by:
sizein interfaceICrossSessionCache- Returns:
- int The amount of objects on the cache
-
toString
public java.lang.String toString()
Description copied from interface:ICrossSessionCacheReturns a String writing down the objects- Specified by:
toStringin interfaceICrossSessionCache- Overrides:
toStringin classjava.lang.Object- Returns:
- String
-
toStringAll
public static java.lang.String toStringAll()
-
clearAll
public static void clearAll()
-
-
DataMelt 3.0 © DataMelt by jWork.ORG