org.dbmaintain.database
Interface SQLHandler

All Known Implementing Classes:
DefaultSQLHandler

public interface SQLHandler


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.
 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.
 

Method Detail

execute

void execute(String sql,
             DataSource dataSource)
Executes the given statement.

Parameters:
sql - The sql string for retrieving the items
dataSource - The dataSource, not null

executeUpdateAndCommit

int executeUpdateAndCommit(String sql,
                           DataSource dataSource)
Executes the given statement and commits the changes to the database

Parameters:
sql - The sql string for retrieving the items
dataSource - The dataSource, not null
Returns:
The nr of updates

getItemAsLong

long getItemAsLong(String sql,
                   DataSource dataSource)
Returns the long extracted from the result of the given query. If no value is found, a DbMaintainException is thrown.

Parameters:
sql - The sql string for retrieving the items
dataSource - The dataSource, not null
Returns:
The long item value

getItemAsString

String getItemAsString(String sql,
                       DataSource dataSource)
Returns the value extracted from the result of the given query. If no value is found, a DbMaintainException is thrown.

Parameters:
sql - The sql string for retrieving the items
dataSource - The dataSource, not null
Returns:
The string item value

getItemsAsStringSet

Set<String> getItemsAsStringSet(String sql,
                                DataSource dataSource)
Returns the items extracted from the result of the given query.

Parameters:
sql - The sql string for retrieving the items
dataSource - The dataSource, not null
Returns:
The items, not null

exists

boolean exists(String sql,
               DataSource dataSource)
Returns true if the query returned a record.

Parameters:
sql - The sql string for checking the existence
dataSource - The dataSource, not null
Returns:
True if a record was returned

startTransaction

void startTransaction(DataSource dataSource)
Starts a transaction by turning of auto commit. Make sure to call endTransaction at the end of the transaction

Parameters:
dataSource - The data source, not null

endTransactionAndCommit

void endTransactionAndCommit(DataSource dataSource)
Ends a transaction that was started using startTransaction by committing and turning auto commit back on.

Parameters:
dataSource - The data source, not null

endTransactionAndRollback

void endTransactionAndRollback(DataSource dataSource)
Ends a transaction that was started using startTransaction by rolling back and turning auto commit back on.

Parameters:
dataSource - The data source, not null

closeAllConnections

void closeAllConnections()
Closes all connections that were created and cached by this SQLHandler. This method must always be invoked before disposing this object.



Copyright © 2011. All Rights Reserved.