|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.unitils.core.dbsupport.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(DataSource dataSource)
Constructs a new instance that connects to the given DataSource |
|
DefaultSQLHandler(DataSource dataSource,
boolean doExecuteUpdates)
Constructs a new instance that connects to the given DataSource |
Method Summary | |
---|---|
void |
executeQuery(String sql)
Executes the given query. |
int |
executeUpdate(String sql)
Executes the given statement. |
int |
executeUpdateAndCommit(String sql)
Executes the given statement and commits. |
boolean |
exists(String sql)
Returns true if the query returned a record. |
DataSource |
getDataSource()
|
long |
getItemAsLong(String sql)
Returns the long extracted from the result of the given query. |
String |
getItemAsString(String sql)
Returns the value extracted from the result of the given query. |
Set<String> |
getItemsAsStringSet(String sql)
Returns the items extracted from the result of the given query. |
boolean |
isDoExecuteUpdates()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DefaultSQLHandler(DataSource dataSource)
dataSource
- The data source, not nullpublic DefaultSQLHandler(DataSource dataSource, boolean doExecuteUpdates)
dataSource
- The data source, not nulldoExecuteUpdates
- Boolean indicating whether updates should effectively be executed on the underlying
databaseMethod Detail |
---|
public int executeUpdate(String sql)
SQLHandler
executeUpdate
in interface SQLHandler
sql
- The sql statement
public void executeQuery(String sql)
SQLHandler
executeQuery
in interface SQLHandler
sql
- The sql querypublic int executeUpdateAndCommit(String sql)
SQLHandler
executeUpdateAndCommit
in interface SQLHandler
sql
- The sql statement
public long getItemAsLong(String sql)
SQLHandler
UnitilsException
is thrown.
getItemAsLong
in interface SQLHandler
sql
- The sql string for retrieving the items
public String getItemAsString(String sql)
SQLHandler
UnitilsException
is thrown.
getItemAsString
in interface SQLHandler
sql
- The sql string for retrieving the items
public Set<String> getItemsAsStringSet(String sql)
SQLHandler
getItemsAsStringSet
in interface SQLHandler
sql
- The sql string for retrieving the items
public boolean exists(String sql)
SQLHandler
exists
in interface SQLHandler
sql
- The sql string for checking the existence
public DataSource getDataSource()
getDataSource
in interface SQLHandler
public boolean isDoExecuteUpdates()
isDoExecuteUpdates
in interface SQLHandler
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |