org.neodatis.odb.impl.main
Class ThreadSafeLocalODB

java.lang.Object
  extended by org.neodatis.odb.impl.main.ThreadSafeLocalODB
All Implemented Interfaces:
ODB

public class ThreadSafeLocalODB
extends java.lang.Object
implements ODB

Used to synchronized access to the db in multi thread.

Author:
olivier

Field Summary
protected  ODB localOdb
           
protected  boolean multiThreadExclusive
          neodatiesee : when true, the mutex is only released on commit or close, which would prevent another thread acessing the db before commit.
protected  Mutex mutex
           
protected static java.lang.String THREAD_MUTEX_PREFIX
          time out to acquire the mutex
 
Constructor Summary
ThreadSafeLocalODB(ODB odb)
           
 
Method Summary
protected  void acquireMutex()
           
 void addDeleteTrigger(java.lang.Class clazz, DeleteTrigger trigger)
          USed to add a delete trigger callback for the specific class
 void addInsertTrigger(java.lang.Class clazz, InsertTrigger trigger)
          Used to add an insert trigger callback for the specific class
 void addSelectTrigger(java.lang.Class clazz, SelectTrigger trigger)
          Used to add a select trigger callback for the specific class
 void addUpdateTrigger(java.lang.Class clazz, UpdateTrigger trigger)
          Used to add an update trigger callback for the specific class
 void close()
          Closes the database.
 void commit()
          Commit all the change of the database @
 java.math.BigInteger count(CriteriaQuery query)
          Returns the number of objects that satisfy the query
 CriteriaQuery criteriaQuery(java.lang.Class clazz)
           
 CriteriaQuery criteriaQuery(java.lang.Class clazz, ICriterion criterio)
           
 void defragmentTo(java.lang.String newFileName)
          Defragment ODB Database
 OID delete(java.lang.Object object)
          Delete an object from database
 OID deleteCascade(java.lang.Object object)
          Delete an object and all its sub objects
 void deleteObjectWithId(OID oid)
          Delete an object from the database with the id
 void disconnect(java.lang.Object object)
          Used to disconnect the object from the current session.
 ODBExt ext()
          Get the extension of ODB to get access to advanced functions
 ClassRepresentation getClassRepresentation(java.lang.Class clazz)
          Get an abstract representation of a class
 ClassRepresentation getClassRepresentation(java.lang.String fullClassName)
          Get an abstract representation of a class
 ClassRepresentation getClassRepresentation(java.lang.String fullClassName, boolean laodClass)
           
 java.lang.String getName()
          Return the name of the database
 ODB getNonThreadSafeOdb()
           
 java.lang.Object getObjectFromId(OID id)
          Get the object with a specific id *
 OID getObjectId(java.lang.Object object)
          Get the id of an ODB-aware object
<T> Objects<T>
getObjects(java.lang.Class clazz)
          Get all objects of a specific type
<T> Objects<T>
getObjects(java.lang.Class clazz, boolean inMemory)
          Get all objects of a specific type
<T> Objects<T>
getObjects(java.lang.Class clazz, boolean inMemory, int startIndex, int endIndex)
           
<T> Objects<T>
getObjects(IQuery query)
          Search for objects that matches the query.
<T> Objects<T>
getObjects(IQuery query, boolean inMemory)
          Search for objects that matches the native query.
<T> Objects<T>
getObjects(IQuery query, boolean inMemory, int startIndex, int endIndex)
          Return a list of objects that matches the query
 IRefactorManager getRefactorManager()
          Returns the object used to refactor the database
 Values getValues(IValuesQuery query)
          Search for objects that matches the query.
protected  boolean holdsTheMutex(java.lang.String threadName)
           
 boolean isClosed()
           
 void reconnect(java.lang.Object object)
           
protected  void releaseMutex()
           
 void rollback()
          Undo all uncommitted changes
 OID store(java.lang.Object object)
          Store a plain java Object in the ODB Database
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

localOdb

protected ODB localOdb

THREAD_MUTEX_PREFIX

protected static final java.lang.String THREAD_MUTEX_PREFIX
time out to acquire the mutex

See Also:
Constant Field Values

mutex

protected Mutex mutex

multiThreadExclusive

protected boolean multiThreadExclusive
neodatiesee : when true, the mutex is only released on commit or close, which would prevent another thread acessing the db before commit. if false, the mutex is released after the getObjects, store and delete

Constructor Detail

ThreadSafeLocalODB

public ThreadSafeLocalODB(ODB odb)
Method Detail

getNonThreadSafeOdb

public ODB getNonThreadSafeOdb()

holdsTheMutex

protected boolean holdsTheMutex(java.lang.String threadName)

acquireMutex

protected void acquireMutex()

releaseMutex

protected void releaseMutex()

addDeleteTrigger

public void addDeleteTrigger(java.lang.Class clazz,
                             DeleteTrigger trigger)
Description copied from interface: ODB
USed to add a delete trigger callback for the specific class

Specified by:
addDeleteTrigger in interface ODB

addInsertTrigger

public void addInsertTrigger(java.lang.Class clazz,
                             InsertTrigger trigger)
Description copied from interface: ODB
Used to add an insert trigger callback for the specific class

Specified by:
addInsertTrigger in interface ODB

addSelectTrigger

public void addSelectTrigger(java.lang.Class clazz,
                             SelectTrigger trigger)
Description copied from interface: ODB
Used to add a select trigger callback for the specific class

Specified by:
addSelectTrigger in interface ODB

addUpdateTrigger

public void addUpdateTrigger(java.lang.Class clazz,
                             UpdateTrigger trigger)
Description copied from interface: ODB
Used to add an update trigger callback for the specific class

Specified by:
addUpdateTrigger in interface ODB

close

public void close()
Description copied from interface: ODB
Closes the database. Automatically commit uncommitted changes

Specified by:
close in interface ODB

commit

public void commit()
Description copied from interface: ODB
Commit all the change of the database @

Specified by:
commit in interface ODB

count

public java.math.BigInteger count(CriteriaQuery query)
Description copied from interface: ODB
Returns the number of objects that satisfy the query

Specified by:
count in interface ODB
Returns:
The number of objects that satisfy the query

criteriaQuery

public CriteriaQuery criteriaQuery(java.lang.Class clazz,
                                   ICriterion criterio)
Specified by:
criteriaQuery in interface ODB

criteriaQuery

public CriteriaQuery criteriaQuery(java.lang.Class clazz)
Specified by:
criteriaQuery in interface ODB

defragmentTo

public void defragmentTo(java.lang.String newFileName)
Description copied from interface: ODB
Defragment ODB Database

Specified by:
defragmentTo in interface ODB

delete

public OID delete(java.lang.Object object)
Description copied from interface: ODB
Delete an object from database

Specified by:
delete in interface ODB

deleteCascade

public OID deleteCascade(java.lang.Object object)
Description copied from interface: ODB
Delete an object and all its sub objects

Specified by:
deleteCascade in interface ODB
Returns:

deleteObjectWithId

public void deleteObjectWithId(OID oid)
Description copied from interface: ODB
Delete an object from the database with the id

Specified by:
deleteObjectWithId in interface ODB
Parameters:
oid - The object id to be deleted

disconnect

public void disconnect(java.lang.Object object)
Description copied from interface: ODB
Used to disconnect the object from the current session. The object is removed from the cache

Specified by:
disconnect in interface ODB

ext

public ODBExt ext()
Description copied from interface: ODB
Get the extension of ODB to get access to advanced functions

Specified by:
ext in interface ODB

getClassRepresentation

public ClassRepresentation getClassRepresentation(java.lang.Class clazz)
Description copied from interface: ODB
Get an abstract representation of a class

Specified by:
getClassRepresentation in interface ODB
Returns:
a public meta-representation of a class

getClassRepresentation

public ClassRepresentation getClassRepresentation(java.lang.String fullClassName)
Description copied from interface: ODB
Get an abstract representation of a class

Specified by:
getClassRepresentation in interface ODB
Returns:
a public meta-representation of a class

getClassRepresentation

public ClassRepresentation getClassRepresentation(java.lang.String fullClassName,
                                                  boolean laodClass)
Specified by:
getClassRepresentation in interface ODB

getName

public java.lang.String getName()
Description copied from interface: ODB
Return the name of the database

Specified by:
getName in interface ODB
Returns:
the file name in local mode and the base id (alias) in client server mode.

getObjectFromId

public java.lang.Object getObjectFromId(OID id)
Description copied from interface: ODB
Get the object with a specific id *

Specified by:
getObjectFromId in interface ODB
Returns:
The object with the specific id @

getObjectId

public OID getObjectId(java.lang.Object object)
Description copied from interface: ODB
Get the id of an ODB-aware object

Specified by:
getObjectId in interface ODB
Returns:
The ODB internal object id

getObjects

public <T> Objects<T> getObjects(java.lang.Class clazz,
                                 boolean inMemory,
                                 int startIndex,
                                 int endIndex)
Specified by:
getObjects in interface ODB
Parameters:
clazz - The type of the objects
inMemory - if true, preload all objects,if false,load on demand
startIndex - The index of the first object
endIndex - The index of the last object that must be returned
Returns:
A List of objects

getObjects

public <T> Objects<T> getObjects(java.lang.Class clazz,
                                 boolean inMemory)
Description copied from interface: ODB
Get all objects of a specific type

Specified by:
getObjects in interface ODB
Parameters:
clazz - The type of the objects
inMemory - if true, preload all objects,if false,load on demand
Returns:
The list of objects

getObjects

public <T> Objects<T> getObjects(java.lang.Class clazz)
Description copied from interface: ODB
Get all objects of a specific type

Specified by:
getObjects in interface ODB
Parameters:
clazz - The type of the objects
Returns:
The list of objects

getObjects

public <T> Objects<T> getObjects(IQuery query,
                                 boolean inMemory,
                                 int startIndex,
                                 int endIndex)
Description copied from interface: ODB
Return a list of objects that matches the query

Specified by:
getObjects in interface ODB
inMemory - if true, preload all objects,if false,load on demand
startIndex - The index of the first object
endIndex - The index of the last object that must be returned
Returns:
A List of objects, if start index and end index are -1, they are ignored. If not, the length of the sublist is endIndex - startIndex

getObjects

public <T> Objects<T> getObjects(IQuery query,
                                 boolean inMemory)
Description copied from interface: ODB
Search for objects that matches the native query.

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

getObjects

public <T> Objects<T> getObjects(IQuery query)
Description copied from interface: ODB
Search for objects that matches the query.

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

getRefactorManager

public IRefactorManager getRefactorManager()
Description copied from interface: ODB
Returns the object used to refactor the database

Specified by:
getRefactorManager in interface ODB

getValues

public Values getValues(IValuesQuery query)
Description copied from interface: ODB
Search for objects that matches the query.

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

isClosed

public boolean isClosed()
Specified by:
isClosed in interface ODB
Returns:

reconnect

public void reconnect(java.lang.Object object)
Specified by:
reconnect in interface ODB

rollback

public void rollback()
Description copied from interface: ODB
Undo all uncommitted changes

Specified by:
rollback in interface ODB

store

public OID store(java.lang.Object object)
Description copied from interface: ODB
Store a plain java Object in the ODB Database

Specified by:
store in interface ODB
Parameters:
object - A plain Java Object