public class DatabaseUtils extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
DatabaseUtils.JdbcUnitOfWork<T>
Represents a unit of work (transaction).
|
static interface |
DatabaseUtils.TableSet
Represents a set of tables.
|
static interface |
DatabaseUtils.TableSetOperation
Operation to be executed on a set of tables for each table individually.
|
Constructor and Description |
---|
DatabaseUtils(DataSource aDataSource)
Constructs the database utils.
|
Modifier and Type | Method and Description |
---|---|
void |
cleanDatabase(org.dbunit.dataset.filter.ITableFilterSimple aSelection)
Cleans a number of database tables.
|
int |
countResultSet(ResultSet aResultSet)
Counts the results in a result set.
|
org.dbunit.IDatabaseTester |
createDbTester(org.dbunit.dataset.filter.ITableFilterSimple aTables)
Creates database tester.
|
org.dbunit.IDatabaseTester |
createDbTester(String[] aTables)
Creates database tester.
|
void |
dropTable(String aTable)
Drops a table.
|
void |
dropTables(org.dbunit.dataset.filter.ITableFilterSimple aTables)
Drops tables.
|
void |
emptyTable(String aTable)
Deprecated.
|
void |
emptyTables(org.dbunit.dataset.filter.ITableFilterSimple aSelection)
Deprecated.
|
<T> T |
executeInTransaction(DatabaseUtils.JdbcUnitOfWork<T> aWork)
Executes a unit of work within a transaction.
|
void |
executeOnTables(org.dbunit.dataset.filter.ITableFilterSimple aTables,
DatabaseUtils.TableSetOperation aOperation)
Executes an operation on a set of tables.
|
ResultSet |
executeQuery(Connection aConnection,
String aSql)
Executes an SQL query.
|
ResultSet |
executeQuery(Connection aConnection,
String aSql,
Object aArg)
Executes a query with a single argument.
|
ResultSet |
executeQuery(Connection aConnection,
String aSql,
Object[] aArgs)
Executes a query.
|
int |
executeSql(String aSql)
Executes an SQL statement within a transaction.
|
int |
executeSql(String aSql,
Object aArg)
Executes an SQL statement within a transaction.
|
int |
executeSql(String aSql,
Object[] aArgs)
Executes an sql statement.
|
int |
executeUpdate(Connection aConnection,
String aSql,
Object... aArgs)
Executes an update.
|
String[] |
getTableNames(org.dbunit.dataset.filter.ITableFilterSimple aSelection)
Returns table names based on a table filter.
|
int |
getTableSize(String aTable)
Gets the table size.
|
void |
start()
Starts the database utils.
|
void |
stop()
Stops the database utils, closing any JDBC connections that were created
by this utility.
|
public DatabaseUtils(DataSource aDataSource)
start()
must be
called.aDataSource
- Datasource.public void start()
public void stop()
public org.dbunit.IDatabaseTester createDbTester(org.dbunit.dataset.filter.ITableFilterSimple aTables) throws Exception
aTables
- Tables to create the tester for.Exception
public org.dbunit.IDatabaseTester createDbTester(String[] aTables) throws Exception
aTables
- Tables to create the tester for.Exception
public void executeOnTables(org.dbunit.dataset.filter.ITableFilterSimple aTables, DatabaseUtils.TableSetOperation aOperation) throws Exception
aTables
- Tables.aOperation
- Operation.Exception
public void cleanDatabase(org.dbunit.dataset.filter.ITableFilterSimple aSelection) throws Exception
aSelection
- Tables.Exception
public <T> T executeInTransaction(DatabaseUtils.JdbcUnitOfWork<T> aWork) throws Exception
T
- Result type of th ework.aWork
- Unit of work.Exception
public String[] getTableNames(org.dbunit.dataset.filter.ITableFilterSimple aSelection) throws Exception
aSelection
- Table filter.Exception
@Deprecated public void emptyTables(org.dbunit.dataset.filter.ITableFilterSimple aSelection) throws Exception
cleanDatabase(ITableFilterSimple)
instead.Exception
@Deprecated public void emptyTable(String aTable) throws Exception
cleanDatabase(ITableFilterSimple)
instead.Exception
public void dropTables(org.dbunit.dataset.filter.ITableFilterSimple aTables) throws Exception
aTables
- Tables to drop.Exception
public void dropTable(String aTable) throws Exception
aTable
- Table to drop.Exception
public int executeSql(String aSql) throws Exception
aSql
- SQL statement.Exception
public int executeSql(String aSql, Object aArg) throws Exception
setPreparedParam(int, PreparedStatement, Object)
for details on
supported argument types.aSql
- SQL statement.aArg
- Argument of the sql statement.Exception
public int executeSql(String aSql, Object[] aArgs) throws Exception
setPreparedParam(int, PreparedStatement, Object)
for details on
supported argument types.aSql
- SQL query to execute.aArgs
- Arguments.Exception
public ResultSet executeQuery(Connection aConnection, String aSql)
aSql
- Query to execute.public ResultSet executeQuery(Connection aConnection, String aSql, Object aArg)
setPreparedParam(int, PreparedStatement, Object)
for details on
supported argument types.aSql
- Query.aArg
- Argument.public ResultSet executeQuery(Connection aConnection, String aSql, Object[] aArgs)
setPreparedParam(int, PreparedStatement, Object)
for details on
supported argument types.aSql
- Sql query.aArgs
- Arguments to the query.public int executeUpdate(Connection aConnection, String aSql, Object... aArgs)
aConnection
- Connection to use.aSql
- SQL update to use.aArgs
- Arguments to the update.public int getTableSize(String aTable) throws Exception
aTable
- Table.SQLException
Exception
public int countResultSet(ResultSet aResultSet) throws SQLException
aResultSet
- Resultset.SQLException
Copyright © 2022. All rights reserved.