|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.xerial.db.sql.DatabaseAccessBase
public class DatabaseAccessBase
A base implementation of the DatabaseAccess interface.
| Constructor Summary | |
|---|---|
DatabaseAccessBase(ConnectionPool connectionPool)
|
|
| Method Summary | ||
|---|---|---|
|
accumulate(String sql,
ResultSetHandler<T> handler)
Accumulate the query result within the ResultSetHandler, then return the result from the handler |
|
protected Statement |
createStatement(Connection connection)
|
|
protected String |
createValueTupleFromBean(String tableName,
Object bean)
Align the content of a bean object so that it matches with the corresponding relation (table schema) For example, give a bean class, e.g. |
|
void |
dispose()
Close all connections managed by this database access |
|
ConnectionPool |
getConnectionPool()
|
|
Relation |
getRelation(String tableName)
Gets the relation (schema) information of the table. |
|
List<String> |
getTableNameList()
Gets the table names contained in this database. |
|
|
insert(String tableName,
T bean)
Inserts a bean into a table |
|
|
query(String sql,
BeanResultHandler<T> beanResultHandler)
Performs an SQL query, while consuming the results with the given handler |
|
|
query(String sql,
Class<T> resultRowType)
perforam a given SQL query, then output its results |
|
|
query(String sql,
ResultSetHandler<T> pullHandler)
Performs an SQL query, while consuming the results with the given handler |
|
|
queryWithHandler(String sql,
ResultSetHandler<T> handler)
|
|
void |
setAutoCommit(boolean enableAutoCommit)
Enable/disable auto commit mode for all subsequent queries. |
|
void |
setQueryTimeout(int sec)
Sets the time of the query until it will be terminated in seconds |
|
|
singleColumnQuery(String sql,
String targetColumn,
Class<T> resultColumnType)
Retrieves only the single column from the SQL query result |
|
|
toJSON(String sql,
Class<T> beanClass,
Writer writer)
|
|
int |
update(String sql)
Performs the update query |
|
int |
update(String sql,
boolean autoCommit)
Performs the update query |
|
int |
updateWithPreparedStatement(String sqlForPreparedStatement,
PreparedStatementHandler handler)
Performs the update using prepared statement. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DatabaseAccessBase(ConnectionPool connectionPool)
throws DBException
DBException| Method Detail |
|---|
public void dispose()
throws DBException
DatabaseAccess
dispose in interface DatabaseAccessDBException
protected Statement createStatement(Connection connection)
throws SQLException
SQLException
public <T> List<T> query(String sql,
Class<T> resultRowType)
throws DBException
query in interface DatabaseAccessT - row type : Bean class typesql - sql statementresultRowType - it must be equal to the Tresult -
DBException
public <T> void query(String sql,
ResultSetHandler<T> pullHandler)
throws DBException
DatabaseAccess
query in interface DatabaseAccesssql - the SQL query expressionpullHandler - the result set handler that consumes the result set of the
query.
DBException
public <T> List<T> queryWithHandler(String sql,
ResultSetHandler<T> handler)
throws DBException
DBException
public <T> T accumulate(String sql,
ResultSetHandler<T> handler)
throws DBException
accumulate in interface DatabaseAccessT - sql - handler -
DBException
public int updateWithPreparedStatement(String sqlForPreparedStatement,
PreparedStatementHandler handler)
throws DBException
DatabaseAccessPreparedStatementHandler via
PreparedStatement.setBytes(int, byte[]), etc.
updateWithPreparedStatement in interface DatabaseAccesssqlForPreparedStatement - the update SQL statement that may contain '?' mark that will
be filled in the PreparedStatementHandlerhandler - the handler for filling '?' marks in the sql statement
DBException
public int update(String sql)
throws DBException
DatabaseAccess
update in interface DatabaseAccesssql - the update SQL query
DBException
public int update(String sql,
boolean autoCommit)
throws DBException
DatabaseAccess
update in interface DatabaseAccesssql - the update SQL queryautoCommit - true when enable auto commit arounc this update query, false
otherwise
DBExceptionpublic ConnectionPool getConnectionPool()
public void setAutoCommit(boolean enableAutoCommit)
DatabaseAccess
setAutoCommit in interface DatabaseAccesspublic void setQueryTimeout(int sec)
DatabaseAccess
setQueryTimeout in interface DatabaseAccesssec - timeout (sec.)
public Relation getRelation(String tableName)
throws DBException
DatabaseAccess
getRelation in interface DatabaseAccesstableName - the target table name
DBException
public List<String> getTableNameList()
throws DBException
DatabaseAccess
getTableNameList in interface DatabaseAccessDBException
public <T> List<T> singleColumnQuery(String sql,
String targetColumn,
Class<T> resultColumnType)
throws DBException
DatabaseAccess
singleColumnQuery in interface DatabaseAccesstargetColumn - the target columnresultColumnType - the target column type to be transformed
DBException
public <T> void query(String sql,
BeanResultHandler<T> beanResultHandler)
throws DBException
DatabaseAccess
query in interface DatabaseAccessDBException
public <T> int insert(String tableName,
T bean)
throws DBException
DatabaseAccess
insert in interface DatabaseAccessDBException
protected String createValueTupleFromBean(String tableName,
Object bean)
throws DBException,
BeanException
class Person { int id; String name; (getters are ommited) }
and a table named person with a schema 'id, name', the
createValueTupleFromBean("person", (a Person object)) will give a tuple
representation of the Person object (id=1, name="leo"), that is
'1,"leo"'.
This returned string can be used as it is within an insert statement of
the SQL, i.e., insert into person values(1, "leo")
tableName - bean -
DBException
InvalidBeanException
BeanException
public <T> void toJSON(String sql,
Class<T> beanClass,
Writer writer)
throws DBException,
IOException
toJSON in interface DatabaseAccessDBException
IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
