org.xerial.db.sql
Interface DatabaseAccess

All Known Implementing Classes:
DatabaseAccessBase, MySQLAccess, PostgresAccess, SQLiteAccess

public interface DatabaseAccess

An interface to access relational databases

Author:
leo

Method Summary
<T> T
accumulate(String sql, ResultSetHandler<T> handler)
          Accumulate the query result within the ResultSetHandler, then return the result from the handler
 void dispose()
          Close all connections managed by this database access
 Relation getRelation(String tableName)
          Gets the relation (schema) information of the table.
 List<String> getTableNameList()
          Gets the table names contained in this database.
<T> int
insert(String tableName, T bean)
          Inserts a bean into a table
<T> void
query(String sql, BeanResultHandler<T> beanResultHandler)
          Performs an SQL query, while consuming the results with the given handler
<T> List<T>
query(String sql, Class<T> resultRowType)
          perform the given SQL query, then output its results
<T> void
query(String sql, ResultSetHandler<T> resultSetHandler)
          Performs an SQL query, while consuming the results with the given 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
<T> List<T>
singleColumnQuery(String sql, String targetColumn, Class<T> resultColumnType)
          Retrieves only the single column from the SQL query result
<T> void
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.
 

Method Detail

getTableNameList

List<String> getTableNameList()
                              throws DBException
Gets the table names contained in this database.

Returns:
the list of table names
Throws:
DBException

getRelation

Relation getRelation(String tableName)
                     throws DBException
Gets the relation (schema) information of the table.

Parameters:
tableName - the target table name
Returns:
the relation of the table
Throws:
DBException

query

<T> List<T> query(String sql,
                  Class<T> resultRowType)
              throws DBException
perform the given SQL query, then output its results

Type Parameters:
T - row type : Bean class type to which the result will be transformed
Parameters:
sql - An SQL statement
resultRowType - Bean class type to which the result will be transformed
result - the list of the result beans
Throws:
DBException

query

<T> void query(String sql,
               ResultSetHandler<T> resultSetHandler)
           throws DBException
Performs an SQL query, while consuming the results with the given handler

Type Parameters:
T -
Parameters:
sql - the SQL query expression
resultSetHandler - the result set handler that consumes the result set of the query.
Throws:
DBException

query

<T> void query(String sql,
               BeanResultHandler<T> beanResultHandler)
           throws DBException
Performs an SQL query, while consuming the results with the given handler

Type Parameters:
T -
Parameters:
sql -
beanResultHandler -
Throws:
DBException

toJSON

<T> void toJSON(String sql,
                Class<T> beanClass,
                Writer writer)
            throws DBException,
                   IOException
Type Parameters:
T -
Parameters:
sql -
beanClass -
writer -
Throws:
DBException
IOException

singleColumnQuery

<T> List<T> singleColumnQuery(String sql,
                              String targetColumn,
                              Class<T> resultColumnType)
                          throws DBException
Retrieves only the single column from the SQL query result

Type Parameters:
T -
Parameters:
sql -
targetColumn - the target column
resultColumnType - the target column type to be transformed
Returns:
the list of the specified column data
Throws:
DBException

accumulate

<T> T accumulate(String sql,
                 ResultSetHandler<T> handler)
             throws DBException
Accumulate the query result within the ResultSetHandler, then return the result from the handler

Type Parameters:
T -
Parameters:
sql -
handler -
Returns:
Throws:
DBException

update

int update(String sql)
           throws DBException
Performs the update query

Parameters:
sql - the update SQL query
Returns:
the number of rows updated
Throws:
DBException

update

int update(String sql,
           boolean autoCommit)
           throws DBException
Performs the update query

Parameters:
sql - the update SQL query
autoCommit - true when enable auto commit arounc this update query, false otherwise
Returns:
the number of rows updated
Throws:
DBException

updateWithPreparedStatement

int updateWithPreparedStatement(String sqlForPreparedStatement,
                                PreparedStatementHandler handler)
                                throws DBException
Performs the update using prepared statement. You can set the tuple values in the PreparedStatementHandler via PreparedStatement.setBytes(int, byte[]), etc.

Parameters:
sqlForPreparedStatement - the update SQL statement that may contain '?' mark that will be filled in the PreparedStatementHandler
handler - the handler for filling '?' marks in the sql statement
Returns:
Throws:
DBException

insert

<T> int insert(String tableName,
               T bean)
           throws DBException
Inserts a bean into a table

Type Parameters:
T -
Parameters:
tableName -
bean -
Returns:
the number of rows updated (1 if succeeded)
Throws:
DBException

setQueryTimeout

void setQueryTimeout(int sec)
Sets the time of the query until it will be terminated in seconds

Parameters:
sec - timeout (sec.)

setAutoCommit

void setAutoCommit(boolean enableAutoCommit)
Enable/disable auto commit mode for all subsequent queries.


dispose

void dispose()
             throws DBException
Close all connections managed by this database access

Throws:
DBException


Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.1 Japan License.