|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.dbmaintain.database.impl.DefaultSQLHandler
public class DefaultSQLHandler
Class to which database updates and queries are passed. Is in fact a utility class, but is a concrete instance to enable decorating it or switching it with another implementation, allowing things like a dry run, creating a script file or logging updates to a log file or database table.
Constructor Summary | |
---|---|
DefaultSQLHandler()
Constructs a new instance that connects to the given DataSource |
|
DefaultSQLHandler(boolean doExecuteUpdates)
Constructs a new instance that connects to the given DataSource |
Method Summary | |
---|---|
void |
closeAllConnections()
Closes all connections that were created and cached by this SQLHandler. |
void |
endTransactionAndCommit(DataSource dataSource)
Ends a transaction that was started using startTransaction by committing and turning auto commit back on. |
void |
endTransactionAndRollback(DataSource dataSource)
Ends a transaction that was started using startTransaction by rolling back and turning auto commit back on. |
void |
execute(String sql,
DataSource dataSource)
Executes the given statement. |
int |
executeUpdateAndCommit(String sql,
DataSource dataSource)
Executes the given statement and commits the changes to the database |
boolean |
exists(String sql,
DataSource dataSource)
Returns true if the query returned a record. |
protected Connection |
getConnection(DataSource dataSource)
Returns a Connection to the given DataSource. |
long |
getItemAsLong(String sql,
DataSource dataSource)
Returns the long extracted from the result of the given query. |
String |
getItemAsString(String sql,
DataSource dataSource)
Returns the value extracted from the result of the given query. |
Set<String> |
getItemsAsStringSet(String sql,
DataSource dataSource)
Returns the items extracted from the result of the given query. |
void |
startTransaction(DataSource dataSource)
Starts a transaction by turning of auto commit. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DefaultSQLHandler()
public DefaultSQLHandler(boolean doExecuteUpdates)
doExecuteUpdates
- Boolean indicating whether updates should effectively be executed on the underlying
databaseMethod Detail |
---|
public void execute(String sql, DataSource dataSource)
SQLHandler
execute
in interface SQLHandler
sql
- The sql string for retrieving the itemsdataSource
- The dataSource, not nullpublic int executeUpdateAndCommit(String sql, DataSource dataSource)
SQLHandler
executeUpdateAndCommit
in interface SQLHandler
sql
- The sql string for retrieving the itemsdataSource
- The dataSource, not null
public long getItemAsLong(String sql, DataSource dataSource)
SQLHandler
DbMaintainException
is thrown.
getItemAsLong
in interface SQLHandler
sql
- The sql string for retrieving the itemsdataSource
- The dataSource, not null
public String getItemAsString(String sql, DataSource dataSource)
SQLHandler
DbMaintainException
is thrown.
getItemAsString
in interface SQLHandler
sql
- The sql string for retrieving the itemsdataSource
- The dataSource, not null
public Set<String> getItemsAsStringSet(String sql, DataSource dataSource)
SQLHandler
getItemsAsStringSet
in interface SQLHandler
sql
- The sql string for retrieving the itemsdataSource
- The dataSource, not null
public boolean exists(String sql, DataSource dataSource)
SQLHandler
exists
in interface SQLHandler
sql
- The sql string for checking the existencedataSource
- The dataSource, not null
public void startTransaction(DataSource dataSource)
startTransaction
in interface SQLHandler
dataSource
- The data source, not nullpublic void endTransactionAndCommit(DataSource dataSource)
endTransactionAndCommit
in interface SQLHandler
dataSource
- The data source, not nullpublic void endTransactionAndRollback(DataSource dataSource)
endTransactionAndRollback
in interface SQLHandler
dataSource
- The data source, not nullpublic void closeAllConnections()
closeAllConnections
in interface SQLHandler
protected Connection getConnection(DataSource dataSource)
dataSource
- provides access to the database
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |