org.makumba.db.hibernate
Class HibernateTransaction

java.lang.Object
  extended by org.makumba.db.TransactionImplementation
      extended by org.makumba.db.hibernate.HibernateTransaction
All Implemented Interfaces:
Database, Transaction

public class HibernateTransaction
extends TransactionImplementation

Hibernate-specific implementation of a Transaction

Version:
$Id: HibernateTransaction.java,v 1.1 02.11.2007 14:08:53 Manuel Exp $
Author:
Manuel Gay

Field Summary
(package private) static Pattern namedParam
           
 org.hibernate.Session s
           
 org.hibernate.Transaction t
           
 
Fields inherited from class org.makumba.db.TransactionImplementation
qp, tp
 
Constructor Summary
HibernateTransaction(String dataSource, DataDefinitionProvider ddp, HibernateTransactionProvider hibernateTransactionProvider)
           
HibernateTransaction(TransactionProvider tp)
           
 
Method Summary
 org.hibernate.Transaction beginTransaction()
           
 void close()
          Give this connection back to the system.
 void commit()
          Commit the transaction associated with this connection.
 Vector<Dictionary<String,Object>> execute(String query, Object args, int offset, int limit)
           
 Vector<Dictionary<String,Object>> executeQuery(String query, Object parameterValues)
          Executes a query with the given parameters.
 Vector<Dictionary<String,Object>> executeQuery(String query, Object args, int offset, int limit)
          Executes a query with the given parameters.
protected  Vector executeReadQuery(Pointer p, StringBuffer sb)
           
protected  int executeUpdate(String type, String set, String where, Object args)
          Executes an UPDATE statement or a DELETE FROM statement, depending on the value of set.
 String getDataSource()
          Returns the name of the data source to which this Transaction is connected
 String getName()
          Get the name of the database in the form host[_port]_dbprotocol_dbname
 String getNullConstant()
           
 String getParameterName()
           
 String getPrimaryKeyName()
           
 String getPrimaryKeyName(String s)
           
 String getSetJoinSyntax()
           
 Vector<Pointer> insert(String type, Collection<Dictionary<String,Object>> data)
          Performs a batch insert.
protected  int insertFromQueryImpl(String type, String OQL, Object parameterValues)
           
 void lock(String symbol)
          Acquire a lock associated to the given application-specific symbol.
 void rollback()
          Rollback the transaction associated with this connection.
 String transformTypeName(String name)
           
protected  Object[] treatParam(Object args)
           
 void unlock(String symbol)
          Free the lock on the given symbol, if any exists.
protected  StringBuffer writeReadQuery(Pointer p, Enumeration e)
           
 
Methods inherited from class org.makumba.db.TransactionImplementation
delete, delete, delete1, extractReadFields, getTransactionProvider, insert, insert, insertFromQuery, paramsToMap, paramsToMap1, read, readCharEnumValues, readExternalSetValues, readIntEnumValues, readSetValues, setContext, update, update, updateSet, updateWithValueDiff
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

t

public org.hibernate.Transaction t

s

public org.hibernate.Session s

namedParam

static Pattern namedParam
Constructor Detail

HibernateTransaction

public HibernateTransaction(TransactionProvider tp)

HibernateTransaction

public HibernateTransaction(String dataSource,
                            DataDefinitionProvider ddp,
                            HibernateTransactionProvider hibernateTransactionProvider)
Method Detail

close

public void close()
Description copied from interface: Transaction
Give this connection back to the system. This will automatically commit the transaction if it was not committed. A connection cannot be used after closing.

Specified by:
close in interface Database
Specified by:
close in interface Transaction
Specified by:
close in class TransactionImplementation

commit

public void commit()
Description copied from interface: Transaction
Commit the transaction associated with this connection. Normally, simply closing the connection will do, but more often committs may be needed. The business logic manager will close (and therefore commit) all transaction that it provides for usage.

Specified by:
commit in interface Database
Specified by:
commit in interface Transaction
Specified by:
commit in class TransactionImplementation

writeReadQuery

protected StringBuffer writeReadQuery(Pointer p,
                                      Enumeration e)
Specified by:
writeReadQuery in class TransactionImplementation

executeReadQuery

protected Vector executeReadQuery(Pointer p,
                                  StringBuffer sb)
Specified by:
executeReadQuery in class TransactionImplementation

executeUpdate

protected int executeUpdate(String type,
                            String set,
                            String where,
                            Object args)
Description copied from class: TransactionImplementation
Executes an UPDATE statement or a DELETE FROM statement, depending on the value of set.

Specified by:
executeUpdate in class TransactionImplementation
Parameters:
type - the type on which to perform the operation
set - the SET part of the query. if null, this performs a DELETE FROM statement
where - the WHERE part of the query
args - the query arguments
Returns:
either (1) the row count for INSERT, UPDATE, or DELETE statements or (2) 0 for SQL statements that return nothing

getName

public String getName()
Description copied from interface: Transaction
Get the name of the database in the form host[_port]_dbprotocol_dbname

Specified by:
getName in interface Database
Specified by:
getName in interface Transaction
Specified by:
getName in class TransactionImplementation

lock

public void lock(String symbol)
Description copied from interface: Transaction
Acquire a lock associated to the given application-specific symbol. This method will block as long as the lock is already taken on another Database object. The commit() and rollback() methods unlcok all locks acquired on this connection

Specified by:
lock in interface Database
Specified by:
lock in interface Transaction
Specified by:
lock in class TransactionImplementation

rollback

public void rollback()
Description copied from interface: Transaction
Rollback the transaction associated with this connection. Typically rollback should be doneif an error occurs in a business logic operation. The business logic manager will rollback a transaction that it provided for usage if it catches any exception during the business logic execution.

Specified by:
rollback in interface Database
Specified by:
rollback in interface Transaction
Specified by:
rollback in class TransactionImplementation

unlock

public void unlock(String symbol)
Description copied from interface: Transaction
Free the lock on the given symbol, if any exists. This will allow the continuation of a thread that needs a lock on the same symbol and uses another Database object

Specified by:
unlock in interface Database
Specified by:
unlock in interface Transaction
Specified by:
unlock in class TransactionImplementation

executeQuery

public Vector<Dictionary<String,Object>> executeQuery(String query,
                                                      Object args,
                                                      int offset,
                                                      int limit)
Executes a query with the given parameters.

Specified by:
executeQuery in interface Database
Specified by:
executeQuery in interface Transaction
Specified by:
executeQuery in class TransactionImplementation
Parameters:
query - the HQL query
args - the parameters of the query. Can be a Map containing named parameters, or a Vector, Object[] or Object for not named parameters.
offset - the offset from which the results should be returned
limit - the maximum number of results to be returned
Returns:
a Vector of Dictionaries containing the results

executeQuery

public Vector<Dictionary<String,Object>> executeQuery(String query,
                                                      Object parameterValues)
Executes a query with the given parameters.

Specified by:
executeQuery in interface Database
Specified by:
executeQuery in interface Transaction
Specified by:
executeQuery in class TransactionImplementation
Parameters:
query - the HQL query
args - the parameters of the query. Can be a Map containing named parameters, or a Vector, Object[] or Object for not named parameters.
Returns:
a Vector of Dictionaries containing the results
See Also:
Transaction.executeQuery(java.lang.String,java.lang.Object,int,int)

execute

public Vector<Dictionary<String,Object>> execute(String query,
                                                 Object args,
                                                 int offset,
                                                 int limit)

insert

public Vector<Pointer> insert(String type,
                              Collection<Dictionary<String,Object>> data)
Description copied from interface: Transaction
Performs a batch insert. The way of providing data is the same as for Transaction.insert(String, Dictionary), only that a collection is provided instead of a single Dictionary.

Specified by:
insert in interface Transaction
Overrides:
insert in class TransactionImplementation
Parameters:
type - the makumba type to create a new record for
data - a set of field-value mapping for the new record.
Returns:
a Vector containing the pointers of the inserted records, in the order in which they were inserted.

insertFromQueryImpl

protected int insertFromQueryImpl(String type,
                                  String OQL,
                                  Object parameterValues)
Specified by:
insertFromQueryImpl in class TransactionImplementation

transformTypeName

public String transformTypeName(String name)
Overrides:
transformTypeName in class TransactionImplementation

getParameterName

public String getParameterName()
Overrides:
getParameterName in class TransactionImplementation

getPrimaryKeyName

public String getPrimaryKeyName()
Overrides:
getPrimaryKeyName in class TransactionImplementation

getSetJoinSyntax

public String getSetJoinSyntax()
Overrides:
getSetJoinSyntax in class TransactionImplementation

getPrimaryKeyName

public String getPrimaryKeyName(String s)
Overrides:
getPrimaryKeyName in class TransactionImplementation

getNullConstant

public String getNullConstant()
Specified by:
getNullConstant in class TransactionImplementation

getDataSource

public String getDataSource()
Description copied from interface: Transaction
Returns the name of the data source to which this Transaction is connected

Specified by:
getDataSource in interface Transaction
Specified by:
getDataSource in class TransactionImplementation

beginTransaction

public org.hibernate.Transaction beginTransaction()

treatParam

protected Object[] treatParam(Object args)