org.neodatis.odb.impl.core.layers.layer3.engine
Class ObjectReader

java.lang.Object
  extended by org.neodatis.odb.impl.core.layers.layer3.engine.ObjectReader
All Implemented Interfaces:
IObjectReader
Direct Known Subclasses:
ServerObjectReader

public class ObjectReader
extends java.lang.Object
implements IObjectReader

Manage all IO Reading

Author:
olivier smadja

Field Summary
protected  IByteArrayConverter byteArrayConverter
           
static long calls
           
static java.lang.String LOG_ID
           
 IStorageEngine storageEngine
          The storage engine
static long timeToGetObjectFromId
           
protected  ITriggerManager triggerManager
           
 
Constructor Summary
ObjectReader(IStorageEngine engine)
          The constructor
 
Method Summary
protected  IInstanceBuilder buildInstanceBuilder()
           
 java.lang.Object buildOneInstance(NonNativeObjectInfo objectInfo)
           
 void close()
           
 java.lang.String depthToSpaces()
          A small method for indentation
 java.util.List<FullIDInfo> getAllIdInfos(java.lang.String objectTypeToDisplay, byte idType, boolean displayObject)
           
 java.util.List<java.lang.Long> getAllIds(byte idType)
          Returns information about all OIDs of the database
 java.lang.String getBaseIdentification()
           
 OID getIdOfObjectAt(long position, boolean includeDeleted)
          Returns the id of an object by reading the object header
 IInstanceBuilder getInstanceBuilder()
           
 OID getNextObjectOID(OID oid)
          Gets the next object oid of the object with the specific oid
 java.lang.Object getObjectFromOid(OID oid, boolean returnInstance, boolean useCache)
           
 ObjectInfoHeader getObjectInfoHeader(OID oid, long position, boolean useCache, ICache cache)
           
 IOdbList<ObjectInfoHeader> getObjectInfoHeaderList(ClassInfo classInfo)
          This is an utility method to get the linked list of All Object Info Header.
<T> Objects<T>
getObjectInfos(IQuery query, boolean inMemory, int startIndex, int endIndex, boolean returnObjects, IMatchingObjectAction queryResultAction)
          Return Objects.
<T> Objects<T>
getObjectInfos(java.lang.String fullClassName, boolean inMemory, int startIndex, int endIndex, boolean returnOjects)
           
 long getObjectPositionFromItsOid(OID oid, boolean useCache, boolean throwException)
          Gets the real object position from its OID
<T> Objects<T>
getObjects(java.lang.Class clazz, boolean inMemory, int startIndex, int endIndex)
           
<T> Objects<T>
getObjects(IQuery query, boolean inMemory, int startIndex, int endIndex)
          Get a list of object matching the query
<T> Objects<T>
getObjects(java.lang.String fullClassName, boolean inMemory, int startIndex, int endIndex)
           
 java.lang.String getObjectTypeFromPosition(long objectPosition)
          Returns the name of the class of an object from its position
 ISession getSession()
           
 Values getValues(IValuesQuery valuesQuery, int startIndex, int endIndex)
          Get a list of values matching the query
 AtomicNativeObjectInfo readAtomicNativeObjectInfo(long position, int odbTypeId)
          Reads an atomic object
 java.lang.Object readAtomicNativeObjectInfoAsObject(long position, int odbTypeId)
           
protected  ClassInfo readClassInfoBody(ClassInfo classInfo)
          Reads the body of a class info
protected  ClassInfo readClassInfoHeader(OID classInfoOid)
          Read the class info header with the specific oid
 IOdbList<ClassInfoIndex> readClassInfoIndexesAt(long position, ClassInfo classInfo)
           
protected  java.lang.String readDatabaseCharacterEncoding()
          Reads the database character encoding
 void readDatabaseHeader(java.lang.String user, java.lang.String password)
          see http://wiki.neodatis.org/odb-file-format
protected  boolean readEncryptionFlag()
          Read the encryption flag of the database file
 EnumNativeObjectInfo readEnumObjectInfo(long position, int odbTypeId)
          Reads an enum object
protected  long readFirstClassOid()
          Reads the first class OID
protected  boolean readLastODBCloseStatus()
          Reads the status of the last odb close
protected  TransactionId readLastTransactionId(DatabaseId databaseId)
          Read the last transaction id
 MetaModel readMetaModel(MetaModel metaModel, boolean full)
          Reads the database meta model
protected  NativeAttributeHeader readNativeAttributeHeader()
          Read the header of a native attribute
 java.lang.Object readNonNativeObjectAtPosition(long position, boolean useCache, boolean returnInstance)
          Reads an object at the specific position
 NonNativeObjectInfo readNonNativeObjectInfoFromOid(ClassInfo classInfo, OID oid, boolean useCache, boolean returnObjects)
           
 NonNativeObjectInfo readNonNativeObjectInfoFromPosition(ClassInfo classInfo, OID oid, long position, boolean useCache, boolean returnInstance)
          Reads a non non native Object Info (Layer2) from its position
protected  long readNumberOfClasses()
          Reads the number of classes in database file
 AbstractObjectInfo readObjectInfo(long objectIdentification, boolean useCache, boolean returnObjects)
           
 AbstractObjectInfo readObjectInfoFromPosition(ClassInfo classInfo, long objectPosition, boolean useCache, boolean returnObjects)
          Reads an object info(Object meta information like its type and its values) from the database file

 ObjectInfoHeader readObjectInfoHeaderFromOid(OID oid, boolean useCache)
          Reads the pointers(ids or positions) of an object that has the specific oid
 ObjectInfoHeader readObjectInfoHeaderFromPosition(OID oid, long position, boolean useCache)
           
 AttributeValuesMap readObjectInfoValuesFromOID(ClassInfo classInfo, OID oid, boolean useCache, IOdbList<java.lang.String> attributeNames, IOdbList<java.lang.String> relationAttributeNames, int recursionLevel, java.lang.String[] orderByFields, boolean useOidForObject)
          reads some attributes of an object.
protected  AttributeValuesMap readObjectInfoValuesFromPosition(ClassInfo classInfo, OID oid, long position, boolean useCache, IOdbList<java.lang.String> attributeNames, IOdbList<java.lang.String> relationAttributeNames, int recursionLevel, java.lang.String[] orderByFields, boolean useOidForObject)
           
 long readOidPosition(OID oid)
           
protected  boolean readReplicationFlag()
          Read the replication flag of the database file
protected  int readVersion()
          Read the version of the database file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

timeToGetObjectFromId

public static long timeToGetObjectFromId

calls

public static long calls

LOG_ID

public static final java.lang.String LOG_ID
See Also:
Constant Field Values

storageEngine

public IStorageEngine storageEngine
The storage engine


byteArrayConverter

protected IByteArrayConverter byteArrayConverter

triggerManager

protected ITriggerManager triggerManager
Constructor Detail

ObjectReader

public ObjectReader(IStorageEngine engine)
The constructor

Parameters:
engine -
triggerManager -
Method Detail

depthToSpaces

public java.lang.String depthToSpaces()
A small method for indentation


buildInstanceBuilder

protected IInstanceBuilder buildInstanceBuilder()

readVersion

protected int readVersion()
Read the version of the database file


readEncryptionFlag

protected boolean readEncryptionFlag()
Read the encryption flag of the database file


readReplicationFlag

protected boolean readReplicationFlag()
Read the replication flag of the database file


readLastTransactionId

protected TransactionId readLastTransactionId(DatabaseId databaseId)
Read the last transaction id


readNumberOfClasses

protected long readNumberOfClasses()
Reads the number of classes in database file


readFirstClassOid

protected long readFirstClassOid()
Reads the first class OID


readLastODBCloseStatus

protected boolean readLastODBCloseStatus()
Reads the status of the last odb close


readDatabaseCharacterEncoding

protected java.lang.String readDatabaseCharacterEncoding()
Reads the database character encoding


readDatabaseHeader

public void readDatabaseHeader(java.lang.String user,
                               java.lang.String password)
see http://wiki.neodatis.org/odb-file-format

Specified by:
readDatabaseHeader in interface IObjectReader

readMetaModel

public MetaModel readMetaModel(MetaModel metaModel,
                               boolean full)
Description copied from interface: IObjectReader
Reads the database meta model

Specified by:
readMetaModel in interface IObjectReader
Parameters:
metaModel - An empty meta model
full - To indicate if a full read must be done
Returns:
The modified metamodel

readClassInfoHeader

protected ClassInfo readClassInfoHeader(OID classInfoOid)
Read the class info header with the specific oid

Parameters:
startPosition -
Returns:
The read class info object @

readClassInfoBody

protected ClassInfo readClassInfoBody(ClassInfo classInfo)
Reads the body of a class info

Parameters:
classInfo - The class info to be read with already read header
Returns:
The read class info @

readClassInfoIndexesAt

public IOdbList<ClassInfoIndex> readClassInfoIndexesAt(long position,
                                                       ClassInfo classInfo)
Specified by:
readClassInfoIndexesAt in interface IObjectReader

readNonNativeObjectAtPosition

public java.lang.Object readNonNativeObjectAtPosition(long position,
                                                      boolean useCache,
                                                      boolean returnInstance)
Reads an object at the specific position

Parameters:
position - The position to read
useCache - To indicate if cache must be used
To - indicate if an instance must be return of just the meta info
Returns:
The object with position @

readObjectInfo

public AbstractObjectInfo readObjectInfo(long objectIdentification,
                                         boolean useCache,
                                         boolean returnObjects)

readObjectInfoHeaderFromOid

public ObjectInfoHeader readObjectInfoHeaderFromOid(OID oid,
                                                    boolean useCache)
Reads the pointers(ids or positions) of an object that has the specific oid

Specified by:
readObjectInfoHeaderFromOid in interface IObjectReader
Parameters:
oid - The oid of the object we want to read the pointers
Returns:
The ObjectInfoHeader @

readObjectInfoHeaderFromPosition

public ObjectInfoHeader readObjectInfoHeaderFromPosition(OID oid,
                                                         long position,
                                                         boolean useCache)

readObjectInfoFromPosition

public AbstractObjectInfo readObjectInfoFromPosition(ClassInfo classInfo,
                                                     long objectPosition,
                                                     boolean useCache,
                                                     boolean returnObjects)
Reads an object info(Object meta information like its type and its values) from the database file

             reads its type and then read all its attributes.
             If one attribute is a non native object, it will be read (recursivly).
            <p/>
 

Parameters:
classInfo - If null, we are probably reading a native instance : String for example
position -
useCache - To indicate if cache must be used. If not, the old version of the object will read
Returns:
The object abstract meta representation @

readNonNativeObjectInfoFromOid

public NonNativeObjectInfo readNonNativeObjectInfoFromOid(ClassInfo classInfo,
                                                          OID oid,
                                                          boolean useCache,
                                                          boolean returnObjects)
Specified by:
readNonNativeObjectInfoFromOid in interface IObjectReader

readNonNativeObjectInfoFromPosition

public NonNativeObjectInfo readNonNativeObjectInfoFromPosition(ClassInfo classInfo,
                                                               OID oid,
                                                               long position,
                                                               boolean useCache,
                                                               boolean returnInstance)
Reads a non non native Object Info (Layer2) from its position

Specified by:
readNonNativeObjectInfoFromPosition in interface IObjectReader
Parameters:
classInfo -
oid - can be null
position -
useCache -
returnInstance -
Returns:
The meta representation of the object @

readObjectInfoValuesFromOID

public AttributeValuesMap readObjectInfoValuesFromOID(ClassInfo classInfo,
                                                      OID oid,
                                                      boolean useCache,
                                                      IOdbList<java.lang.String> attributeNames,
                                                      IOdbList<java.lang.String> relationAttributeNames,
                                                      int recursionLevel,
                                                      java.lang.String[] orderByFields,
                                                      boolean useOidForObject)
Description copied from interface: IObjectReader
reads some attributes of an object.
     example of method call
     readObjectInfoValues(classinfo,18000,true,["profile.name","profile.email"],["profile.name","profile.email"],0)
     readObjectInfoValues(classinfo,21789,true,["name"],["profile.name"],1)
 

Specified by:
readObjectInfoValuesFromOID in interface IObjectReader
Parameters:
classInfo - If null, we are probably reading a native instance : String for example
oid - The oid of the object to read. if -1,the read will be done by position
useCache - To indicate if cache must be used. If not, the old version of the object will read
attributeNames - The names of attributes to read the values, an attributename can contain relation like profile.name
relationAttributeNames - The original names of attributes to read the values, an attributename can contain relation like profile.name
recursionLevel - The recursion level of this method call
useOidForObject - To indicate that if the object being read has an attribute that is not native, we will put the oid of the attribute (object) instead of reading the whole object
Returns:
The map with attribute values

readObjectInfoValuesFromPosition

protected AttributeValuesMap readObjectInfoValuesFromPosition(ClassInfo classInfo,
                                                              OID oid,
                                                              long position,
                                                              boolean useCache,
                                                              IOdbList<java.lang.String> attributeNames,
                                                              IOdbList<java.lang.String> relationAttributeNames,
                                                              int recursionLevel,
                                                              java.lang.String[] orderByFields,
                                                              boolean useOidForObject)
Parameters:
classInfo - The class info of the objects to be returned
oid - The Object id of the object to return data
position - The position of the object to read
useCache - To indicate if cache must be used
attributeNames - The list of the attribute name for which we need to return a value, an attributename can contain relation like profile.name
relationAttributeNames - The original names of attributes to read the values, an attributename can contain relation like profile.name
recursionLevel - The recursion level of this call
orderByFields - ?
useOidForObject - To indicate that if the object being read has an attribute that is not native, we will put the oid of the attribute (object) instead of reading the whole object
Returns:
A Map where keys are attributes names and values are the values of there attributes @

getObjectInfoHeader

public ObjectInfoHeader getObjectInfoHeader(OID oid,
                                            long position,
                                            boolean useCache,
                                            ICache cache)

readNativeAttributeHeader

protected NativeAttributeHeader readNativeAttributeHeader()
Read the header of a native attribute
 
 
 
 The header contains
  - The block size = int
  - The block type = byte
  - The OdbType ID = int
  - A boolean to indicate if object is nulls.
  
  This method reads all the bytes and then convert the byte array to the values
 

Parameters:
odbTypeId -
isNull -
writeDataInTransaction -

readAtomicNativeObjectInfoAsObject

public java.lang.Object readAtomicNativeObjectInfoAsObject(long position,
                                                           int odbTypeId)
Specified by:
readAtomicNativeObjectInfoAsObject in interface IObjectReader

readAtomicNativeObjectInfo

public AtomicNativeObjectInfo readAtomicNativeObjectInfo(long position,
                                                         int odbTypeId)
Reads an atomic object

Specified by:
readAtomicNativeObjectInfo in interface IObjectReader

readEnumObjectInfo

public EnumNativeObjectInfo readEnumObjectInfo(long position,
                                               int odbTypeId)
Reads an enum object


getNextObjectOID

public OID getNextObjectOID(OID oid)
Gets the next object oid of the object with the specific oid

Specified by:
getNextObjectOID in interface IObjectReader
Parameters:
position -
Returns:
The position of the next object. If there is no next object, return -1 @

readOidPosition

public long readOidPosition(OID oid)
Specified by:
readOidPosition in interface IObjectReader

getObjectFromOid

public java.lang.Object getObjectFromOid(OID oid,
                                         boolean returnInstance,
                                         boolean useCache)
Specified by:
getObjectFromOid in interface IObjectReader

getObjectTypeFromPosition

public java.lang.String getObjectTypeFromPosition(long objectPosition)
Returns the name of the class of an object from its position

Parameters:
objectPosition -
Returns:
The object class name @

getObjectPositionFromItsOid

public long getObjectPositionFromItsOid(OID oid,
                                        boolean useCache,
                                        boolean throwException)
Gets the real object position from its OID

Specified by:
getObjectPositionFromItsOid in interface IObjectReader
Parameters:
oid - The oid of the object to get the position
throwException - To indicate if an exception must be thrown if object is not found
Returns:
The object position, if object has been marked as deleted then return StorageEngineConstant.DELETED_OBJECT_POSITION @

getAllIds

public java.util.List<java.lang.Long> getAllIds(byte idType)
Returns information about all OIDs of the database

Specified by:
getAllIds in interface IObjectReader
Parameters:
idType -
Returns:
@

getAllIdInfos

public java.util.List<FullIDInfo> getAllIdInfos(java.lang.String objectTypeToDisplay,
                                                byte idType,
                                                boolean displayObject)
Specified by:
getAllIdInfos in interface IObjectReader

getIdOfObjectAt

public OID getIdOfObjectAt(long position,
                           boolean includeDeleted)
Description copied from interface: IObjectReader
Returns the id of an object by reading the object header

Specified by:
getIdOfObjectAt in interface IObjectReader
Returns:
The oid of the object at the specific position

close

public void close()
Specified by:
close in interface IObjectReader

buildOneInstance

public java.lang.Object buildOneInstance(NonNativeObjectInfo objectInfo)
Specified by:
buildOneInstance in interface IObjectReader

getObjects

public <T> Objects<T> getObjects(java.lang.Class clazz,
                                 boolean inMemory,
                                 int startIndex,
                                 int endIndex)

getObjects

public <T> Objects<T> getObjects(java.lang.String fullClassName,
                                 boolean inMemory,
                                 int startIndex,
                                 int endIndex)

getObjects

public <T> Objects<T> getObjects(IQuery query,
                                 boolean inMemory,
                                 int startIndex,
                                 int endIndex)
Description copied from interface: IObjectReader
Get a list of object matching the query

Specified by:
getObjects in interface IObjectReader
Returns:
The list of objects

getValues

public Values getValues(IValuesQuery valuesQuery,
                        int startIndex,
                        int endIndex)
Description copied from interface: IObjectReader
Get a list of values matching the query

Specified by:
getValues in interface IObjectReader
Returns:
The list of values

getSession

public ISession getSession()

getObjectInfos

public <T> Objects<T> getObjectInfos(IQuery query,
                                     boolean inMemory,
                                     int startIndex,
                                     int endIndex,
                                     boolean returnObjects,
                                     IMatchingObjectAction queryResultAction)
Description copied from interface: IObjectReader
Return Objects. Match the query without instantiating objects. Only instantiate object for object that match the query

Specified by:
getObjectInfos in interface IObjectReader
Parameters:
query - The query to select objects
inMemory - To indicate if object must be all loaded in memory
startIndex - First object index
endIndex - Last object index
returnObjects - To indicate if object instances must be created
Returns:
The list of objects

getObjectInfos

public <T> Objects<T> getObjectInfos(java.lang.String fullClassName,
                                     boolean inMemory,
                                     int startIndex,
                                     int endIndex,
                                     boolean returnOjects)

getBaseIdentification

public java.lang.String getBaseIdentification()
Specified by:
getBaseIdentification in interface IObjectReader

getObjectInfoHeaderList

public IOdbList<ObjectInfoHeader> getObjectInfoHeaderList(ClassInfo classInfo)
This is an utility method to get the linked list of All Object Info Header. For debug purpose

Parameters:
classInfo -

getInstanceBuilder

public IInstanceBuilder getInstanceBuilder()
Specified by:
getInstanceBuilder in interface IObjectReader