org.makumba.db.makumba
Class DBConnection

java.lang.Object
  extended by org.makumba.db.TransactionImplementation
      extended by org.makumba.db.makumba.DBConnection
All Implemented Interfaces:
Database, Transaction
Direct Known Subclasses:
DBConnectionWrapper, SQLDBConnection

public abstract class DBConnection
extends TransactionImplementation

This is the Makumba-specific implementation of a Transaction

Version:
$Id: DBConnection.java 5154 2010-05-18 22:01:40Z rosso_nero $
Author:
Cristian Bogdan, Manuel Gay

Field Summary
protected  String dataSource
           
protected  Database db
           
(package private)  Hashtable<String,Object> lockRecord
           
(package private)  Map<String,Pointer> locks
           
(package private) static String whereDelim
           
 
Fields inherited from class org.makumba.db.TransactionImplementation
ddp, qp, tp
 
Constructor Summary
  DBConnection(Database database, String dataSource, TransactionProvider tp)
           
  DBConnection(Database database, TransactionProvider tp)
           
protected DBConnection(TransactionProvider tp)
           
 
Method Summary
protected  void deleteLock(String symbol)
           
 Vector<Dictionary<String,Object>> executeQuery(String OQL, Object args)
          Execute query without limiting the results.
 Vector<Dictionary<String,Object>> executeQuery(String OQL, Object args, int offset, int limit)
          Execute a parametrized OQL query.
protected  Vector<Dictionary<String,Object>> executeReadQuery(Pointer p, StringBuffer sb)
           
 int executeUpdate(String type, String set, String where, Object args)
          Execute a parametrized update or delete.
 String getDataSource()
          Returns the name of the data source to which this Transaction is connected
 Database getHostDatabase()
           
 String getName()
          Get the name of the database in the form host[_port]_dbprotocol_dbname
 String getNullConstant()
           
 Query getQuery(String OQL)
           
 Vector<Pointer> insert(String type, Collection<Dictionary<String,Object>> data)
          mass insert of a record
 Pointer insert(String type, Dictionary<String,Object> data)
          insert a record
protected  int insertFromQueryImpl(String type, String OQL, Object args)
           
 void lock(String symbol)
          Acquire a lock associated to the given application-specific symbol.
 void setDataSource(String dataSource)
           
protected  Object[] treatParam(Object args)
           
 void unlock(String symbol)
          Free the lock on the given symbol, if any exists.
protected  void unlockAll()
           
protected  StringBuffer writeReadQuery(Pointer p, Enumeration<String> e)
           
 
Methods inherited from class org.makumba.db.TransactionImplementation
close, commit, delete, delete, delete1, extractReadFields, getParameterName, getPrimaryKeyName, getPrimaryKeyName, getSetJoinSyntax, getTransactionProvider, insert, insertFromQuery, paramsToMap, paramsToMap1, read, readCharEnumValues, readExternalSetValues, readIntEnumValues, readSetValues, rollback, setContext, transformTypeName, update, update, updateSet, updateWithValueDiff
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dataSource

protected String dataSource

db

protected Database db

locks

Map<String,Pointer> locks

lockRecord

Hashtable<String,Object> lockRecord

whereDelim

static final String whereDelim
See Also:
Constant Field Values
Constructor Detail

DBConnection

protected DBConnection(TransactionProvider tp)

DBConnection

public DBConnection(Database database,
                    TransactionProvider tp)

DBConnection

public DBConnection(Database database,
                    String dataSource,
                    TransactionProvider tp)
Method Detail

getHostDatabase

public Database getHostDatabase()

getName

public String getName()
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

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

deleteLock

protected void deleteLock(String symbol)

unlockAll

protected void unlockAll()

writeReadQuery

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

executeReadQuery

protected Vector<Dictionary<String,Object>> executeReadQuery(Pointer p,
                                                             StringBuffer sb)
Specified by:
executeReadQuery in class TransactionImplementation

insert

public Pointer insert(String type,
                      Dictionary<String,Object> data)
insert a record

Specified by:
insert in interface Database
Specified by:
insert in interface Transaction
Overrides:
insert in class TransactionImplementation
Parameters:
type - the makumba type to create a new record for
data - the field-value mapping for the new record.
The ommitted fields will be set to null.
To insert an set of integets (set int {...}) pass a Vector of Integers. (or null, or an empty vector).
To insert an set of strings (set char {...}) pass a Vector of String. (or null, or an empty vector).
To refer to a field of base record or subrecord, indicate the pointer that leads to the record, and the respective field, like ptr1.ptr2.field. Every mentioned base record and subrecord will be inserted.
Returns:
a Pointer to the inserted record

insert

public Vector<Pointer> insert(String type,
                              Collection<Dictionary<String,Object>> data)
mass insert of a record

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.

executeQuery

public Vector<Dictionary<String,Object>> executeQuery(String OQL,
                                                      Object args,
                                                      int offset,
                                                      int limit)
Execute a parametrized OQL query.

Specified by:
executeQuery in interface Database
Specified by:
executeQuery in interface Transaction
Specified by:
executeQuery in class TransactionImplementation
Parameters:
OQL - the query to execute. Refers to parameters as $1, $2 ...
args - the arguments of the queries. Should be null if there are none. If there is only one parameter, it can be indicated directly. If there are more parameters, they can be indicated in a Object[] or a java.util.Vector. Named parameters can be indicated in a Map.
offset - the offset of the first record to return, 0 for first
limit - the maximum number of records to return, -1 for all
Returns:
a Vector of Dictionaries

insertFromQueryImpl

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

executeQuery

public Vector<Dictionary<String,Object>> executeQuery(String OQL,
                                                      Object args)
Description copied from interface: Transaction
Execute query without limiting the results.

Specified by:
executeQuery in interface Database
Specified by:
executeQuery in interface Transaction
Specified by:
executeQuery in class TransactionImplementation
See Also:
Transaction.executeQuery(java.lang.String,java.lang.Object,int,int)

executeUpdate

public int executeUpdate(String type,
                         String set,
                         String where,
                         Object args)
Execute a parametrized update or delete. A null set means "delete"

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:
a Vector of Dictionaries

getQuery

public Query getQuery(String OQL)

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

setDataSource

public void setDataSource(String dataSource)

treatParam

protected Object[] treatParam(Object args)