org.yawlfoundation.yawl.cost.data
Class HibernateEngine

java.lang.Object
  extended by org.yawlfoundation.yawl.cost.data.HibernateEngine

public class HibernateEngine
extends Object

This singleton class provides db & persistence support via Hibernate.

Author:
Michael Adams
Created/Last Date:
03/08/2007 last update: 26/08/2010 (for v2.2)

Field Summary
static int DB_DELETE
           
static int DB_INSERT
           
static int DB_UPDATE
           
 
Method Summary
 org.hibernate.Transaction beginTransaction()
           
 void closeFactory()
           
 void commit()
           
 org.hibernate.Query createQuery(String queryString)
           
 boolean exec(Object obj, int action)
           
 boolean exec(Object obj, int action, boolean commit)
          persists the object instance passed
 boolean exec(Object obj, int action, org.hibernate.Transaction tx)
          persists the object instance passed
 List execJoinQuery(String table, String field, String value)
          executes a join query.
 List execQuery(String queryString)
          executes a Query object based on the sql string passed
 int execUpdate(String queryString)
           
 int execUpdate(String queryString, boolean commit)
           
 Object get(Class claz, Serializable key)
           
static HibernateEngine getInstance(boolean persistenceOn)
          returns the current HibernateEngine instance
 List getObjectsForClass(String className)
          returns all the instances currently persisted for the class passed
 List getObjectsForClassWhere(String className, String whereClause)
          returns all the instances currently persisted for the class passed that match the condition specified in the where clause
 org.hibernate.Transaction getOrBeginTransaction()
           
 boolean isAvailable(String tableName)
           
 boolean isPersisting()
           
 Object load(Class claz, Serializable key)
           
 void rollback()
           
 Object selectScalar(String className, String field, String value)
          gets a scalar value (as an object) based on the sql string passed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DB_UPDATE

public static final int DB_UPDATE
See Also:
Constant Field Values

DB_DELETE

public static final int DB_DELETE
See Also:
Constant Field Values

DB_INSERT

public static final int DB_INSERT
See Also:
Constant Field Values
Method Detail

getInstance

public static HibernateEngine getInstance(boolean persistenceOn)
returns the current HibernateEngine instance


isAvailable

public boolean isAvailable(String tableName)
Returns:
true if a table of 'tableName' currently exists and has at least one row

isPersisting

public boolean isPersisting()
Returns:
true if this instance is persisting

exec

public boolean exec(Object obj,
                    int action)

exec

public boolean exec(Object obj,
                    int action,
                    boolean commit)
persists the object instance passed

Parameters:
obj - - an instance of the object to persist
action - - type type of action performed
Returns:
true if persist was successful, false if otherwise

exec

public boolean exec(Object obj,
                    int action,
                    org.hibernate.Transaction tx)
persists the object instance passed

Parameters:
obj - - an instance of the object to persist
action - - type type of action performed
tx - - an active Transaction object. NOTE: Any objects persisted via this method will not be permanently actioned until the transaction is committed via a call to 'commit()'.
Returns:
true if persist was successful, false if otherwise

getOrBeginTransaction

public org.hibernate.Transaction getOrBeginTransaction()

execQuery

public List execQuery(String queryString)
executes a Query object based on the sql string passed

Parameters:
queryString - - the sql query to execute
Returns:
the List of objects returned, or null if the query has some problem

execUpdate

public int execUpdate(String queryString)

execUpdate

public int execUpdate(String queryString,
                      boolean commit)

createQuery

public org.hibernate.Query createQuery(String queryString)

beginTransaction

public org.hibernate.Transaction beginTransaction()

load

public Object load(Class claz,
                   Serializable key)

get

public Object get(Class claz,
                  Serializable key)

commit

public void commit()

rollback

public void rollback()

closeFactory

public void closeFactory()

execJoinQuery

public List execJoinQuery(String table,
                          String field,
                          String value)
executes a join query. For example, passing ("car", "part", "pid") will return a list of 'car' objects that have in their 'part' property (a Set) a part with a key id="pid"

Parameters:
table - the parent table - returned objects are of this class
field - the property name of the [Set] column in the parent table
value - the id of the child object in the set to match
Returns:
a List of objects of class 'table' that have, in their [Set] property called 'field', an object with an key field value of 'value'

selectScalar

public Object selectScalar(String className,
                           String field,
                           String value)
gets a scalar value (as an object) based on the sql string passed

Parameters:
className - - the type of object to select
field - - the column name which contains the queried value
value - - the value to find in the 'field' column
Returns:
the first (or only) object matching 'where [field] = [value]'

getObjectsForClass

public List getObjectsForClass(String className)
returns all the instances currently persisted for the class passed

Parameters:
className - - the name of the class to retrieve instances of
Returns:
a List of the instances retrieved

getObjectsForClassWhere

public List getObjectsForClassWhere(String className,
                                    String whereClause)
returns all the instances currently persisted for the class passed that match the condition specified in the where clause

Parameters:
className - the name of the class to retrieve instances of
whereClause - the condition (without the 'where' part) e.g. "age=21"
Returns:
a List of the instances retrieved


Copyright © 2004-2012 The YAWL Foundation.