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

java.lang.Object
  extended by org.neodatis.odb.impl.core.transaction.Cache
All Implemented Interfaces:
ICache
Direct Known Subclasses:
LazyCache, ServerCache

public class Cache
extends java.lang.Object
implements ICache

A cache of object.

   Cache objects by object, by position, by oids,...
 

Author:
olivier s

Field Summary
protected  java.util.Map<java.lang.Object,ObjectInsertingInfo> insertingObjects
          To resolve cyclic reference, keep track of objects being inserted
protected  java.lang.String name
           
protected static int nbCallsToGetObjectInfoHeaderFromObject
           
protected static int nbCallsToGetObjectInfoHeaderFromOid
           
protected static int nbCallsToGetObjectWithOid
           
protected static int nbObjectPositionByIds
           
protected static int nbObjects
           
protected static int nbOids
           
protected static int nbOih
           
protected static int nbTransactionOids
           
protected  java.util.Map<OID,ObjectInfoHeader> objectInfoPointersCacheFromOid
          Entry to get object info pointers (position,next object pos, previous object pos and class info pos) from the id
protected  java.util.Map<OID,IdInfo> objectPositionsByIds
           To resolve the update of an id object position: When an object is full updated(the current object is being deleted and a new one os being created), the id remain the same but its position change.
protected  java.util.Map<java.lang.Object,OID> objects
          object cache - used to know if object exist in the cache TODO use hashcode instead?
protected  java.util.Map<OID,java.lang.Object> oids
          Entry to get an object from its oid
protected  java.util.Map<OID,java.lang.Object[]> readingObjectInfo
          To resolve cyclic reference, keep track of objects being read
protected  ISession session
           
protected  java.util.Map<OID,OID> unconnectedZoneOids
          To keep track of the oid that have been created or modified in the current transaction
protected  boolean useCache
           
 
Constructor Summary
Cache(ISession session, java.lang.String name)
           
 
Method Summary
 void addObject(OID oid, java.lang.Object object, ObjectInfoHeader objectInfoHeader)
           
 void addObjectInfo(ObjectInfoHeader objectInfoHeader)
          Only adds the Object info - used for non committed objects
 void addOIDToUnconnectedZone(OID oid)
           
protected  boolean checkHeaderPosition()
           
 void clear(boolean setToNull)
           
 void clearInsertingObjects()
           
 void clearOnCommit()
           
 void endInsertingObject(java.lang.Object object)
           
 void endReadingObjectInfo(OID oid)
           
 boolean existObject(java.lang.Object object)
           
 int getNumberOfObjectHeader()
           
 int getNumberOfObjects()
           
 ObjectInfoHeader getObjectInfoHeaderFromObject(java.lang.Object object, boolean throwExceptionIfNotFound)
           
 ObjectInfoHeader getObjectInfoHeaderFromOid(OID oid, boolean throwExceptionIfNotFound)
           
 java.util.Map<OID,ObjectInfoHeader> getObjectInfoPointersCacheFromOid()
           
 long getObjectPositionByOid(OID oid)
          Returns the position or -1 if it is not is the cache or StorageEngineConstant.NULL_OBJECT_ID_ID if it has been marked as deleted
 java.util.Map<java.lang.Object,OID> getObjects()
           
 java.lang.Object getObjectWithOid(OID oid)
           
 OID getOid(java.lang.Object object, boolean throwExceptionIfNotFound)
           
 java.util.Map<OID,java.lang.Object> getOids()
           
 NonNativeObjectInfo getReadingObjectInfoFromOid(OID oid)
           
 OID idOfInsertingObject(java.lang.Object object)
           
protected  void init(ISession session, java.lang.String name)
           
 int insertingLevelOf(java.lang.Object object)
           
 boolean isDeleted(OID oid)
           
 boolean isReadingObjectInfoWithOid(OID oid)
           
protected  void manageFullCache()
           
 void markIdAsDeleted(OID oid)
           
 boolean objectWithIdIsInCommitedZone(OID oid)
           
 void removeObject(java.lang.Object object)
           
 void removeObjectWithOid(OID oid)
           
 void savePositionOfObjectWithOid(OID oid, long objectPosition)
          To resolve uncommitted updates where the oid change and is not committed yet
 void setObjectInfoPointersCacheFromOid(java.util.Map<OID,ObjectInfoHeader> objectInfoPointersCacheFromOid)
           
 void setObjects(java.util.Map<java.lang.Object,OID> objects)
           
 void setOids(java.util.Map<OID,java.lang.Object> oids)
           
 void startInsertingObjectWithOid(java.lang.Object object, OID oid, NonNativeObjectInfo nnoi)
           
 void startReadingObjectInfoWithOid(OID oid, NonNativeObjectInfo objectInfo)
          To resolve cyclic reference, keep track of objects being read The read count is used to store how many times the object has been recursively read
 java.lang.String toCompleteString()
           
 java.lang.String toString()
           
 void updateIdOfInsertingObject(java.lang.Object object, OID oid)
           
static java.lang.String usage()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nbObjects

protected static int nbObjects

nbOids

protected static int nbOids

nbOih

protected static int nbOih

nbTransactionOids

protected static int nbTransactionOids

nbObjectPositionByIds

protected static int nbObjectPositionByIds

nbCallsToGetObjectInfoHeaderFromOid

protected static int nbCallsToGetObjectInfoHeaderFromOid

nbCallsToGetObjectInfoHeaderFromObject

protected static int nbCallsToGetObjectInfoHeaderFromObject

nbCallsToGetObjectWithOid

protected static int nbCallsToGetObjectWithOid

objects

protected java.util.Map<java.lang.Object,OID> objects
object cache - used to know if object exist in the cache TODO use hashcode instead?


oids

protected java.util.Map<OID,java.lang.Object> oids
Entry to get an object from its oid


insertingObjects

protected java.util.Map<java.lang.Object,ObjectInsertingInfo> insertingObjects
To resolve cyclic reference, keep track of objects being inserted


readingObjectInfo

protected java.util.Map<OID,java.lang.Object[]> readingObjectInfo
To resolve cyclic reference, keep track of objects being read


objectPositionsByIds

protected java.util.Map<OID,IdInfo> objectPositionsByIds
    To resolve the update of an id object position:
    When an object is full updated(the current object is being deleted and a new one os being created), 
    the id remain the same but its position change.
    But the update is done in transaction, so it is not flushed until the commit happens
    So after the update when i need the position to make the old object a pointer, i have no way to get 
    the right position. To resolve this, i keep a cache of ids where i keep the non commited value
 


unconnectedZoneOids

protected java.util.Map<OID,OID> unconnectedZoneOids
To keep track of the oid that have been created or modified in the current transaction


session

protected ISession session

name

protected java.lang.String name

objectInfoPointersCacheFromOid

protected java.util.Map<OID,ObjectInfoHeader> objectInfoPointersCacheFromOid
Entry to get object info pointers (position,next object pos, previous object pos and class info pos) from the id


useCache

protected boolean useCache
Constructor Detail

Cache

public Cache(ISession session,
             java.lang.String name)
Method Detail

init

protected void init(ISession session,
                    java.lang.String name)

addObject

public void addObject(OID oid,
                      java.lang.Object object,
                      ObjectInfoHeader objectInfoHeader)
Specified by:
addObject in interface ICache

addObjectInfo

public void addObjectInfo(ObjectInfoHeader objectInfoHeader)
Only adds the Object info - used for non committed objects

Specified by:
addObjectInfo in interface ICache

manageFullCache

protected void manageFullCache()

startInsertingObjectWithOid

public void startInsertingObjectWithOid(java.lang.Object object,
                                        OID oid,
                                        NonNativeObjectInfo nnoi)
Specified by:
startInsertingObjectWithOid in interface ICache

updateIdOfInsertingObject

public void updateIdOfInsertingObject(java.lang.Object object,
                                      OID oid)
Specified by:
updateIdOfInsertingObject in interface ICache

endInsertingObject

public void endInsertingObject(java.lang.Object object)
Specified by:
endInsertingObject in interface ICache

removeObjectWithOid

public void removeObjectWithOid(OID oid)
Specified by:
removeObjectWithOid in interface ICache

removeObject

public void removeObject(java.lang.Object object)
Specified by:
removeObject in interface ICache

existObject

public boolean existObject(java.lang.Object object)
Specified by:
existObject in interface ICache

getObjectWithOid

public java.lang.Object getObjectWithOid(OID oid)
Specified by:
getObjectWithOid in interface ICache

getObjectInfoHeaderFromObject

public ObjectInfoHeader getObjectInfoHeaderFromObject(java.lang.Object object,
                                                      boolean throwExceptionIfNotFound)
Specified by:
getObjectInfoHeaderFromObject in interface ICache

getObjectInfoHeaderFromOid

public ObjectInfoHeader getObjectInfoHeaderFromOid(OID oid,
                                                   boolean throwExceptionIfNotFound)
Specified by:
getObjectInfoHeaderFromOid in interface ICache

getOid

public OID getOid(java.lang.Object object,
                  boolean throwExceptionIfNotFound)
Specified by:
getOid in interface ICache

savePositionOfObjectWithOid

public void savePositionOfObjectWithOid(OID oid,
                                        long objectPosition)
Description copied from interface: ICache
To resolve uncommitted updates where the oid change and is not committed yet

Specified by:
savePositionOfObjectWithOid in interface ICache

markIdAsDeleted

public void markIdAsDeleted(OID oid)
Specified by:
markIdAsDeleted in interface ICache

isDeleted

public boolean isDeleted(OID oid)
Specified by:
isDeleted in interface ICache

getObjectPositionByOid

public long getObjectPositionByOid(OID oid)
Returns the position or -1 if it is not is the cache or StorageEngineConstant.NULL_OBJECT_ID_ID if it has been marked as deleted

Specified by:
getObjectPositionByOid in interface ICache

clearOnCommit

public void clearOnCommit()
Specified by:
clearOnCommit in interface ICache

clear

public void clear(boolean setToNull)
Specified by:
clear in interface ICache

clearInsertingObjects

public void clearInsertingObjects()
Specified by:
clearInsertingObjects in interface ICache

toString

public java.lang.String toString()
Specified by:
toString in interface ICache
Overrides:
toString in class java.lang.Object

toCompleteString

public java.lang.String toCompleteString()
Specified by:
toCompleteString in interface ICache

getNumberOfObjects

public int getNumberOfObjects()
Specified by:
getNumberOfObjects in interface ICache

getNumberOfObjectHeader

public int getNumberOfObjectHeader()
Specified by:
getNumberOfObjectHeader in interface ICache

idOfInsertingObject

public OID idOfInsertingObject(java.lang.Object object)
Specified by:
idOfInsertingObject in interface ICache

insertingLevelOf

public int insertingLevelOf(java.lang.Object object)
Specified by:
insertingLevelOf in interface ICache

isReadingObjectInfoWithOid

public boolean isReadingObjectInfoWithOid(OID oid)
Specified by:
isReadingObjectInfoWithOid in interface ICache

getReadingObjectInfoFromOid

public NonNativeObjectInfo getReadingObjectInfoFromOid(OID oid)
Specified by:
getReadingObjectInfoFromOid in interface ICache

startReadingObjectInfoWithOid

public void startReadingObjectInfoWithOid(OID oid,
                                          NonNativeObjectInfo objectInfo)
Description copied from interface: ICache
To resolve cyclic reference, keep track of objects being read The read count is used to store how many times the object has been recursively read

Specified by:
startReadingObjectInfoWithOid in interface ICache
Parameters:
oid - The Object OID
objectInfo - The object info (not fully set) that is being read

endReadingObjectInfo

public void endReadingObjectInfo(OID oid)
Specified by:
endReadingObjectInfo in interface ICache

getOids

public java.util.Map<OID,java.lang.Object> getOids()
Specified by:
getOids in interface ICache

setOids

public void setOids(java.util.Map<OID,java.lang.Object> oids)

getObjectInfoPointersCacheFromOid

public java.util.Map<OID,ObjectInfoHeader> getObjectInfoPointersCacheFromOid()
Specified by:
getObjectInfoPointersCacheFromOid in interface ICache

setObjectInfoPointersCacheFromOid

public void setObjectInfoPointersCacheFromOid(java.util.Map<OID,ObjectInfoHeader> objectInfoPointersCacheFromOid)

getObjects

public java.util.Map<java.lang.Object,OID> getObjects()
Specified by:
getObjects in interface ICache

setObjects

public void setObjects(java.util.Map<java.lang.Object,OID> objects)

objectWithIdIsInCommitedZone

public boolean objectWithIdIsInCommitedZone(OID oid)
Specified by:
objectWithIdIsInCommitedZone in interface ICache

addOIDToUnconnectedZone

public void addOIDToUnconnectedZone(OID oid)
Specified by:
addOIDToUnconnectedZone in interface ICache

usage

public static java.lang.String usage()

checkHeaderPosition

protected boolean checkHeaderPosition()