org.olat.core.commons.persistence
Class DBImpl

java.lang.Object
  extended by org.olat.core.logging.LogDelegator
      extended by org.olat.core.commons.persistence.DBImpl
All Implemented Interfaces:
DB

public class DBImpl
extends LogDelegator
implements DB

A DB is a central place to get a Hibernate Session. It acts as a facade to the database, transactions and Queries. The hibernateSession is lazy loaded per thread.

Author:
Andreas Ch. Kapp, Christian Guretzki

Method Summary
 void addTransactionListener(ITransactionListener listener)
          Add an ITransactionListener to this DB instance.
 void closeSession()
          Close the database session.
 void commit()
          Call this to commit a transaction opened by beginTransaction().
 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
 java.lang.Exception getError()
          Get any errors from a previous DB call.
 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

closeSession

public void closeSession()
Close the database session.

Specified by:
closeSession in interface DB

createQuery

public DBQuery createQuery(java.lang.String query)
Create a DBQuery

Specified by:
createQuery in interface DB
Parameters:
query -
Returns:
DBQuery

deleteObject

public void deleteObject(java.lang.Object object)
Delete an object.

Specified by:
deleteObject in interface DB
Parameters:
object -

delete

public int delete(java.lang.String query,
                  java.lang.Object value,
                  org.hibernate.type.Type type)
Deletion query.

Specified by:
delete in interface DB
Parameters:
query -
value -
type -
Returns:
nr of deleted rows

delete

public int delete(java.lang.String query,
                  java.lang.Object[] values,
                  org.hibernate.type.Type[] types)
Deletion query.

Specified by:
delete in interface DB
Parameters:
query -
values -
types -
Returns:
nr of deleted rows

find

public java.util.List find(java.lang.String query,
                           java.lang.Object value,
                           org.hibernate.type.Type type)
Find objects based on query

Specified by:
find in interface DB
Parameters:
query -
value -
type -
Returns:
List of results.

find

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

Specified by:
find in interface DB
Parameters:
query -
values -
types -
Returns:
List of results.

find

public java.util.List find(java.lang.String query)
Find objects based on query

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

findObject

public java.lang.Object findObject(java.lang.Class theClass,
                                   java.lang.Long key)
Find an object.

Specified by:
findObject in interface DB
Parameters:
theClass -
key -
Returns:
Object, if any found. Null, if non exist.

loadObject

public java.lang.Object loadObject(java.lang.Class theClass,
                                   java.lang.Long key)
Load an object.

Specified by:
loadObject in interface DB
Parameters:
theClass -
key -
Returns:
Object.

saveObject

public void saveObject(java.lang.Object object)
Save an object.

Specified by:
saveObject in interface DB
Parameters:
object -

updateObject

public void updateObject(java.lang.Object object)
Update an object.

Specified by:
updateObject in interface DB
Parameters:
object -

getError

public java.lang.Exception getError()
Get any errors from a previous DB call.

Returns:
Exception, if any.

isError

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

loadObject

public Persistable loadObject(Persistable persistable)
see DB.loadObject(Persistable persistable, boolean forceReloadFromDB)

Specified by:
loadObject in interface DB
Parameters:
persistable -
Returns:
the loaded object

loadObject

public Persistable loadObject(Persistable persistable,
                              boolean forceReloadFromDB)
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

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

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

commit

public void commit()
Call this to commit a transaction opened by beginTransaction().

Specified by:
commit in interface DB

rollback

public void rollback()
Call this to rollback current changes.

Specified by:
rollback in interface DB

getStatistics

public org.hibernate.stat.Statistics getStatistics()
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
See Also:
DB.intermediateCommit()

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)
temp debug only

Specified by:
forceSetDebugLogLevel in interface DB