org.olat.core.commons.persistence
Class DBJunitImpl

java.lang.Object
  extended by org.olat.core.commons.persistence.DBJunitImpl
All Implemented Interfaces:
DB, DBJunit

public class DBJunitImpl
extends java.lang.Object
implements DBJunit

Extends DB interface with methods for Junit testing.

Author:
Andreas Ch. Kapp, Christian Guretzki

Method Summary
 void addTransactionListener(ITransactionListener listener)
          Add an ITransactionListener to this DB instance.
 void clearDatabase()
          Delete all data from database, when used by an OLATTestCase.
 void closeSession()
          Close the database session.
 void commit()
          Call this to commit current changes.
 void commitAndCloseSession()
          Checks if the transaction needs to be committed and does so if this is the case, plus closes the connection in any case guaranteed.
 DBQuery createQuery(java.lang.String query)
          Create a DBQuery
 int delete(java.lang.String query, java.lang.Object[] values, org.hibernate.type.Type[] types)
          Deletion query.
 int delete(java.lang.String query, java.lang.Object value, org.hibernate.type.Type type)
          Deletion query.
 void deleteObject(java.lang.Object object)
          Delete an object.
 java.util.List find(java.lang.String query)
          Find objects based on query
 java.util.List find(java.lang.String query, java.lang.Object[] values, org.hibernate.type.Type[] types)
          Find objects based on query
 java.util.List find(java.lang.String query, java.lang.Object value, org.hibernate.type.Type type)
          Find objects based on query
 java.lang.Object findObject(java.lang.Class theClass, java.lang.Long key)
          Find an object.
 void forceSetDebugLogLevel(boolean enabled)
          temp debug only
static DBJunit getJunitInstance()
           
 org.hibernate.stat.Statistics getStatistics()
          Statistics must be enabled first, when you want to use it.
 void intermediateCommit()
          Call this to intermediate commit current changes.
 boolean isError()
           
 java.lang.Object loadObject(java.lang.Class theClass, java.lang.Long key)
          Load an object.
 Persistable loadObject(Persistable persistable)
          see DB.loadObject(Persistable persistable, boolean forceReloadFromDB)
 Persistable loadObject(Persistable persistable, boolean forceReloadFromDB)
          loads an object if needed.
 void removeTransactionListener(ITransactionListener listener)
          Removes an ITransactionListener from this DB instance.
 void rollback()
          Call this to rollback current changes.
 void rollbackAndCloseSession()
          Calls rollback and closes the connection guaranteed.
 void saveObject(java.lang.Object object)
          Save an object.
 void updateObject(java.lang.Object object)
          Update an object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isError

public boolean isError()
Specified by:
isError in interface DB
Returns:
True if any errors occured in the previous DB call.

getJunitInstance

public static DBJunit getJunitInstance()

clearDatabase

public void clearDatabase()
Delete all data from database, when used by an OLATTestCase.

Specified by:
clearDatabase in interface DBJunit

closeSession

public void closeSession()
Description copied from interface: DB
Close the database session.

Specified by:
closeSession in interface DB

commitAndCloseSession

public void commitAndCloseSession()
Description copied from interface: DB
Checks if the transaction needs to be committed and does so if this is the case, plus closes the connection in any case guaranteed.

Use this rather than commit() directly wherever possible!

Specified by:
commitAndCloseSession in interface DB

commit

public void commit()
Description copied from interface: DB
Call this to commit current changes.

Specified by:
commit in interface DB

rollbackAndCloseSession

public void rollbackAndCloseSession()
Description copied from interface: DB
Calls rollback and closes the connection guaranteed.

Note that this method checks whether the connection and the transaction are open and if they're not, then this method doesn't do anything.

Specified by:
rollbackAndCloseSession in interface DB

rollback

public void rollback()
Description copied from interface: DB
Call this to rollback current changes.

Specified by:
rollback in interface DB

createQuery

public DBQuery createQuery(java.lang.String query)
Description copied from interface: DB
Create a DBQuery

Specified by:
createQuery in interface DB
Returns:
DBQuery

delete

public int delete(java.lang.String query,
                  java.lang.Object value,
                  org.hibernate.type.Type type)
Description copied from interface: DB
Deletion query.

Specified by:
delete in interface DB
Returns:
nr of values deleted

delete

public int delete(java.lang.String query,
                  java.lang.Object[] values,
                  org.hibernate.type.Type[] types)
Description copied from interface: DB
Deletion query.

Specified by:
delete in interface DB
Returns:
nr of deleted rows

deleteObject

public void deleteObject(java.lang.Object object)
Description copied from interface: DB
Delete an object.

Specified by:
deleteObject in interface DB

find

public java.util.List find(java.lang.String query,
                           java.lang.Object value,
                           org.hibernate.type.Type type)
Description copied from interface: DB
Find objects based on query

Specified by:
find in interface DB
Returns:
List of results.

find

public java.util.List find(java.lang.String query,
                           java.lang.Object[] values,
                           org.hibernate.type.Type[] types)
Description copied from interface: DB
Find objects based on query

Specified by:
find in interface DB
Returns:
List of results.

find

public java.util.List find(java.lang.String query)
Description copied from interface: DB
Find objects based on query

Specified by:
find in interface DB
Returns:
List of results.

findObject

public java.lang.Object findObject(java.lang.Class theClass,
                                   java.lang.Long key)
Description copied from interface: DB
Find an object.

Specified by:
findObject in interface DB
Returns:
Object, if any found. or null otherwise

loadObject

public java.lang.Object loadObject(java.lang.Class theClass,
                                   java.lang.Long key)
Description copied from interface: DB
Load an object.

Specified by:
loadObject in interface DB
Returns:
Object.

loadObject

public Persistable loadObject(Persistable persistable)
Description copied from interface: DB
see DB.loadObject(Persistable persistable, boolean forceReloadFromDB)

Specified by:
loadObject in interface DB
Returns:
the loaded object, never null

loadObject

public Persistable loadObject(Persistable persistable,
                              boolean forceReloadFromDB)
Description copied from interface: DB
loads an object if needed. this makes sense if you have an object which had been generated in a previous hibernate session AND you need to access a Set or a attribute which was defined as a proxy.

Specified by:
loadObject in interface DB
Parameters:
persistable - the object which needs to be reloaded
forceReloadFromDB - if true, force a reload from the db (e.g. to catch up to an object commited by another thread which is still in this thread's session cache
Returns:
the loaded Object, never null

saveObject

public void saveObject(java.lang.Object object)
Description copied from interface: DB
Save an object.

Specified by:
saveObject in interface DB

updateObject

public void updateObject(java.lang.Object object)
Description copied from interface: DB
Update an object.

Specified by:
updateObject in interface DB

getStatistics

public org.hibernate.stat.Statistics getStatistics()
Description copied from interface: DB
Statistics must be enabled first, when you want to use it.

Specified by:
getStatistics in interface DB
Returns:
Return Hibernates statistics object.

intermediateCommit

public void intermediateCommit()
Description copied from interface: DB
Call this to intermediate commit current changes. Use this method in startup process and bulk changes.

Specified by:
intermediateCommit in interface DB

addTransactionListener

public void addTransactionListener(ITransactionListener listener)
Description copied from interface: DB
Add an ITransactionListener to this DB instance.

The ITransactionListener will be informed about commit and rollbacks.

Adding the same listener twice has no effect.

Specified by:
addTransactionListener in interface DB
Parameters:
listener - the listener to be added

removeTransactionListener

public void removeTransactionListener(ITransactionListener listener)
Description copied from interface: DB
Removes an ITransactionListener from this DB instance.

If the ITransactionListener is currently not registered, this call has no effect.

Specified by:
removeTransactionListener in interface DB

forceSetDebugLogLevel

public void forceSetDebugLogLevel(boolean enabled)
Description copied from interface: DB
temp debug only

Specified by:
forceSetDebugLogLevel in interface DB