org.neodatis.odb.impl.core.layers.layer3.oid
Class DefaultIdManager

java.lang.Object
  extended by org.neodatis.odb.impl.core.layers.layer3.oid.DefaultIdManager
All Implemented Interfaces:
IIdManager
Direct Known Subclasses:
DefaultServerIdManager

public class DefaultIdManager
extends java.lang.Object
implements IIdManager

Class to manage the ids of all the objects of the database.

Author:
osmadja

Field Summary
protected  long[] lastIdPositions
           
protected  OID[] lastIds
          Contains the last ids: id value,id position, id value, id position=> the array is created with twice the size
 OID maxId
           
 OID nextId
           
protected  IObjectReader objectReader
           
protected  IObjectWriter objectWriter
           
protected  ISession session
           
 
Constructor Summary
DefaultIdManager(IObjectWriter objectWriter, IObjectReader objectReader, long currentBlockIdPosition, int currentBlockIdNumber, OID currentMaxId)
           
 
Method Summary
 void clear()
           
 OID consultNextOid()
           
 OID getNextClassId(long objectPosition)
          Gets an id for a class
(package private)  OID getNextId(long objectPosition, byte idType, byte idStatus, java.lang.String label)
          Gets an id for an object (instance)
 OID getNextObjectId(long objectPosition)
          Gets an id for an object (instance)
 long getObjectPositionWithOid(OID oid, boolean useCache)
           
protected  ISession getSession()
           
 boolean mustShift()
          To check if the id block must shift: that a new id block must be created
 void reserveIds(long nbIds)
           
 void updateClassPositionForId(OID classId, long objectPosition, boolean writeInTransaction)
           
 void updateIdStatus(OID id, byte newStatus)
           
 void updateObjectPositionForOid(OID oid, long objectPosition, boolean writeInTransaction)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nextId

public OID nextId

maxId

public OID maxId

objectWriter

protected IObjectWriter objectWriter

objectReader

protected IObjectReader objectReader

session

protected ISession session

lastIds

protected OID[] lastIds
Contains the last ids: id value,id position, id value, id position=> the array is created with twice the size


lastIdPositions

protected long[] lastIdPositions
Constructor Detail

DefaultIdManager

public DefaultIdManager(IObjectWriter objectWriter,
                        IObjectReader objectReader,
                        long currentBlockIdPosition,
                        int currentBlockIdNumber,
                        OID currentMaxId)
Parameters:
objectWriter - The object writer
objectReader - The object reader
currentBlockIdPosition - The position of the current block
currentBlockIdNumber - The number of the current block
currentMaxId - Maximum Database id
Method Detail

mustShift

public boolean mustShift()
To check if the id block must shift: that a new id block must be created

Specified by:
mustShift in interface IIdManager
Returns:
a boolean value to check if block of id is full

getNextId

OID getNextId(long objectPosition,
              byte idType,
              byte idStatus,
              java.lang.String label)
Gets an id for an object (instance)

Parameters:
objectPosition - the object position (instance)
idType - The type id : object,class, unknown
label - A label for debug
Returns:
The id

getNextObjectId

public OID getNextObjectId(long objectPosition)
Description copied from interface: IIdManager
Gets an id for an object (instance)

Specified by:
getNextObjectId in interface IIdManager
Parameters:
objectPosition - the object position (instance)
Returns:
The id

getNextClassId

public OID getNextClassId(long objectPosition)
Description copied from interface: IIdManager
Gets an id for a class

Specified by:
getNextClassId in interface IIdManager
Parameters:
objectPosition - the object position (class)
Returns:
The id

updateObjectPositionForOid

public void updateObjectPositionForOid(OID oid,
                                       long objectPosition,
                                       boolean writeInTransaction)
Specified by:
updateObjectPositionForOid in interface IIdManager

updateClassPositionForId

public void updateClassPositionForId(OID classId,
                                     long objectPosition,
                                     boolean writeInTransaction)
Specified by:
updateClassPositionForId in interface IIdManager

updateIdStatus

public void updateIdStatus(OID id,
                           byte newStatus)
Specified by:
updateIdStatus in interface IIdManager

consultNextOid

public OID consultNextOid()
Specified by:
consultNextOid in interface IIdManager

reserveIds

public void reserveIds(long nbIds)
Specified by:
reserveIds in interface IIdManager

getObjectPositionWithOid

public long getObjectPositionWithOid(OID oid,
                                     boolean useCache)
Specified by:
getObjectPositionWithOid in interface IIdManager

clear

public void clear()
Specified by:
clear in interface IIdManager

getSession

protected ISession getSession()