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 3533 2009-01-03 00:54:39Z manuel_gay $
Author:
Cristian Bogdan, Manuel Gay

Nested Class Summary
(package private)  class DBConnection.QueryAndArgs
           
 
Field Summary
protected  String dataSource
           
protected  Database db
           
(package private)  Hashtable<String,Object> lockRecord
           
(package private)  Map<String,Pointer> locks
           
(package private)  NamedResources queries
           
(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)
           
 Pointer insert(String type, Dictionary<String,Object> data)
          insert a record
 int insertFromQuery(String type, String OQL, Object args)
          Insert the results of the query in the given type.
 void lock(String symbol)
          Acquire a lock associated to the given application-specific symbol.
 void setDataSource(String dataSource)
           
 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, paramsToMap, paramsToMap1, read, rollback, setContext, transformTypeName, treatParam, update, update
 
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

queries

NamedResources queries

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

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

insertFromQuery

public int insertFromQuery(String type,
                           String OQL,
                           Object args)
Description copied from interface: Transaction
Insert the results of the query in the given type. Generates an INSERT...SELECT. The labels of the OQL query must match field names of the given type.

Specified by:
insertFromQuery in interface Transaction
Specified by:
insertFromQuery in class TransactionImplementation
Parameters:
type - the type where to insert
OQL - the OQL query to execute. Refers to parameters as $1, $2 ...
args - the parameter values. Should be null if there are no parameters. 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
Returns:
the number of records inserted

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)