com.onewebsql.dao
Class BaseDAO<T>

java.lang.Object
  extended by com.onewebsql.dao.BaseDAO<T>
All Implemented Interfaces:
DAO<T>

public abstract class BaseDAO<T>
extends Object
implements DAO<T>

This class provides auxiliary functions used by generated DAO classes.


Field Summary
protected  DaoMonitor daoMonitor
          An object monitoring DAO operations.
protected  DataSource dataSource
          Data source used by this DAO object.
protected  DBAdapter dbAdapter
          Database adapter used by this DAO object.
protected  DaoSchema schema
          Name of a database schema where DAO object is represented.
 
Constructor Summary
BaseDAO(DataSource dataSource, DBAdapter dbAdapter)
          Constructor
BaseDAO(DataSource dataSource, DBAdapter dbAdapter, DaoMonitor daoMonitor)
          Constructor.
BaseDAO(DataSource dataSource, DBAdapter dbAdapter, DaoSchema schema)
          Constructor.
BaseDAO(DataSource dataSource, DBAdapter dbAdapter, DaoSchema schema, DaoMonitor daoMonitor)
          Constructor.
 
Method Summary
 List<Exp> aliasTableExpressionColumns(TableExpression tableExpression, String tableExpressionAlias)
          Returns the list of columns of table expression aliased with the specified alias.
 Integer delete(DeleteQuery deleteStatement)
          Invokes a DELETE statement.
 DaoMonitor getDaoMonitor()
          Returns the DAO monitor used by this DAO object.
 DataSource getDataSource()
          Returns the data source object used by this DAO object.
 DBAdapter getDbAdapter()
          Returns the database adapter used by this DAO object.
 Long getNextId(TableExpression tableExpression)
          Returns the next row id for the given table expression.
 DaoSchema getSchema()
          Returns the database schema associated with this DAO's table expression.
 Integer insert(InsertQuery insertStatement)
          Invokes an INSERT statement.
<U> U
selectObject(SelectQuery query, RowHandler<U> rowHandler)
          Runs a SELECT query and returns the only object (created with the specified RowHandler object) returned by the query.
<U> SelectObjectListResult<U>
selectObjectList(SelectQuery query, RowHandler<U> rowHandler)
          Runs a SELECT query and returns a list of objects created from the result with the help of a given RowHandler object.
 void setDaoMonitor(DaoMonitor daoMonitor)
          Sets the DAO monitor used by this DAO object.
 void setDataSource(DataSource dataSource)
          Set the data source object used by this DAO object.
 void setDbAdapter(DBAdapter dbAdapter)
          Sets the database adapter used by this DAO object.
 void setSchema(DaoSchema schema)
          Sets the database schema associated with this DAO's table expression.
 Integer update(UpdateQuery updateStatement)
          Invokes an UPDATE statement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.onewebsql.dao.DAO
getPojoClass, getRowHandler, getTableExpression
 

Field Detail

daoMonitor

protected DaoMonitor daoMonitor
An object monitoring DAO operations.


dataSource

protected DataSource dataSource
Data source used by this DAO object.


dbAdapter

protected DBAdapter dbAdapter
Database adapter used by this DAO object.


schema

protected DaoSchema schema
Name of a database schema where DAO object is represented. May be changed at runtime.

Constructor Detail

BaseDAO

public BaseDAO(DataSource dataSource,
               DBAdapter dbAdapter)
Constructor

Parameters:
dataSource - data source used by this DAO object.
dbAdapter - adapter used by this DAO object.

BaseDAO

public BaseDAO(DataSource dataSource,
               DBAdapter dbAdapter,
               DaoSchema schema)
Constructor.

Parameters:
dataSource - data source used by this DAO object.
dbAdapter - database adapter used by this DAO object.
schema - database schema of the table represented by this DAO object.

BaseDAO

public BaseDAO(DataSource dataSource,
               DBAdapter dbAdapter,
               DaoMonitor daoMonitor)
Constructor.

Parameters:
dataSource - data source used by this DAO object.
dbAdapter - database adapter used by this DAO object.
daoMonitor - object monitoring this DAO operations.

BaseDAO

public BaseDAO(DataSource dataSource,
               DBAdapter dbAdapter,
               DaoSchema schema,
               DaoMonitor daoMonitor)
Constructor.

Parameters:
dataSource - data source used by this DAO object.
dbAdapter - database adapter used by this DAO object.
schema - database schema of the table represented by this DAO object.
daoMonitor - object monitoring this DAO operations.
Method Detail

selectObjectList

public <U> SelectObjectListResult<U> selectObjectList(SelectQuery query,
                                                      RowHandler<U> rowHandler)
Runs a SELECT query and returns a list of objects created from the result with the help of a given RowHandler object.

Specified by:
selectObjectList in interface DAO<T>
Parameters:
query - SQL query.
rowHandler - row handler object which creates Java objects from SQL query results
Returns:
object containing query result

selectObject

public <U> U selectObject(SelectQuery query,
                          RowHandler<U> rowHandler)
Runs a SELECT query and returns the only object (created with the specified RowHandler object) returned by the query. If the query returns more than one row, the method throws an exception.

Specified by:
selectObject in interface DAO<T>
Parameters:
query - SQL query
rowHandler - an object which creates Java objects from the query result
Returns:
the object created by the RowHandler object from the first (the only) row returned by the SQL query
Throws:
QueryFetchException - if the SQL query returns more than one row

aliasTableExpressionColumns

public List<Exp> aliasTableExpressionColumns(TableExpression tableExpression,
                                             String tableExpressionAlias)
Returns the list of columns of table expression aliased with the specified alias.

Parameters:
tableExpression - table expression to alias
tableExpressionAlias - table expression alias
Returns:
the list of Exp expressions which represent the columns of the aliased table expression

getNextId

public Long getNextId(TableExpression tableExpression)
Returns the next row id for the given table expression.

Specified by:
getNextId in interface DAO<T>
Parameters:
tableExpression - table expression
Returns:
the next row id

insert

public Integer insert(InsertQuery insertStatement)
Invokes an INSERT statement. The method invokes the specified INSERT statement and logs the operation in an appropriate way.

Specified by:
insert in interface DAO<T>
Parameters:
insertStatement - INSERT statement to run
Returns:
the number of rows modified by the statement

update

public Integer update(UpdateQuery updateStatement)
Invokes an UPDATE statement. The method invokes the specified UPDATE statement and logs the operation in an appropriate way.

Specified by:
update in interface DAO<T>
Parameters:
updateStatement - UPDATE statement to run
Returns:
the number of rows modified by the statement

delete

public Integer delete(DeleteQuery deleteStatement)
Invokes a DELETE statement. The method invokes the specified DELETE statement and logs the operation in an appropriate way.

Specified by:
delete in interface DAO<T>
Parameters:
deleteStatement - UPDATE statement to run
Returns:
the number of rows modified by the statement

getDataSource

public DataSource getDataSource()
Returns the data source object used by this DAO object.

Specified by:
getDataSource in interface DAO<T>
Returns:
data source used by this DAO

setDataSource

public void setDataSource(DataSource dataSource)
Set the data source object used by this DAO object.

Parameters:
dataSource - data source used by this DAO

getDbAdapter

public DBAdapter getDbAdapter()
Returns the database adapter used by this DAO object.

Specified by:
getDbAdapter in interface DAO<T>
Returns:
database adapter used by this DAO

setDbAdapter

public void setDbAdapter(DBAdapter dbAdapter)
Sets the database adapter used by this DAO object.

Parameters:
dbAdapter - database adapter used by this DAO

getDaoMonitor

public DaoMonitor getDaoMonitor()
Returns the DAO monitor used by this DAO object.

Specified by:
getDaoMonitor in interface DAO<T>
Returns:
DAO monitor used by this DAO

setDaoMonitor

public void setDaoMonitor(DaoMonitor daoMonitor)
Sets the DAO monitor used by this DAO object.

Specified by:
setDaoMonitor in interface DAO<T>
Parameters:
daoMonitor - DAO monitor used by this DAO

getSchema

public DaoSchema getSchema()
Returns the database schema associated with this DAO's table expression.

Specified by:
getSchema in interface DAO<T>
Returns:
database schema associated with this DAO's table expression

setSchema

public void setSchema(DaoSchema schema)
Sets the database schema associated with this DAO's table expression.

Parameters:
schema - database schema associated with this DAO's table expression


Copyright © 2011-2013 e-point SA. All Rights Reserved.