(no commit message)
[utils] / test / enterprise / src / main / java / org / wamblee / test / persistence / DatabaseUtils.java
index c4e38f4d0a6e1c89325b3cbd1a675894675ac0ed..dc7c040445a890ea0412c7ce1a3a31251abd285d 100644 (file)
@@ -47,7 +47,7 @@ public class DatabaseUtils {
 
     /**
      * Represents a set of tables.
-     *  
+     * 
      * @author Erik Brakkee
      */
     public static interface TableSet {
@@ -58,29 +58,33 @@ public class DatabaseUtils {
      * Represents a unit of work (transaction).
      * 
      * @author Erik Brakkee
-     *
-     * @param <T> Type of return value. 
+     * 
+     * @param <T>
+     *            Type of return value.
      */
     public static interface JdbcUnitOfWork<T> {
         /**
-         * Executes statement within a transaction. 
-         * @param aConnection Connection. 
-         * @return Result of the work. 
+         * Executes statement within a transaction.
+         * 
+         * @param aConnection
+         *            Connection.
+         * @return Result of the work.
          * @throws Exception
          */
         T execute(Connection aConnection) throws Exception;
     }
 
     /**
-     * Operation to be executed on a set of tables for each table 
-     * individually. 
+     * Operation to be executed on a set of tables for each table individually.
      * 
      * @author Erik Brakkee
      */
     public static interface TableSetOperation {
         /**
-         * Executes on a table. 
-         * @param aTable Table name. 
+         * Executes on a table.
+         * 
+         * @param aTable
+         *            Table name.
          * @throws Exception
          */
         void execute(String aTable) throws Exception;
@@ -97,37 +101,39 @@ public class DatabaseUtils {
 
     private IDatabaseTester dbtester;
     /**
-     * List of connections that were created for dbtesters. 
-     * This list will be closed in the {@link #stop()} method. 
+     * List of connections that were created for dbtesters. This list will be
+     * closed in the {@link #stop()} method.
      */
-    private List<IDatabaseConnection> connections; 
-    
+    private List<IDatabaseConnection> connections;
+
     /**
-     * Constructs the database utils. 
-     * Before use, {@link #start()} must be called. 
-     * @param aDataSource Datasource.  
+     * Constructs the database utils. Before use, {@link #start()} must be
+     * called.
+     * 
+     * @param aDataSource
+     *            Datasource.
      */
     public DatabaseUtils(DataSource aDataSource) {
         dataSource = aDataSource;
         dbtester = new DataSourceDatabaseTester(dataSource);
-        connections = new ArrayList<IDatabaseConnection>(); 
+        connections = new ArrayList<IDatabaseConnection>();
     }
 
     /**
-     * Starts the database utils. 
+     * Starts the database utils.
      */
-    public void start() { 
-        // Empty. No operation currently. 
+    public void start() {
+        // Empty. No operation currently.
     }
 
     /**
      * Stops the database utils, closing any JDBC connections that were created
-     * by this utility. Note that connections obtained from the datasource directly 
-     * must still be closed by the user. The involved connections are only those that
-     * are created by this utility. 
+     * by this utility. Note that connections obtained from the datasource
+     * directly must still be closed by the user. The involved connections are
+     * only those that are created by this utility.
      */
     public void stop() {
-        for (IDatabaseConnection connection: connections) { 
+        for (IDatabaseConnection connection : connections) {
             try {
                 connection.close();
             } catch (SQLException e) {
@@ -138,19 +144,24 @@ public class DatabaseUtils {
     }
 
     /**
-     * Creates database tester. 
-     * @param aTables Tables to create the tester for. 
-     * @return Database tester. 
+     * Creates database tester.
+     * 
+     * @param aTables
+     *            Tables to create the tester for.
+     * @return Database tester.
      * @throws Exception
      */
-    public IDatabaseTester createDbTester(ITableFilterSimple aTables) throws Exception {
+    public IDatabaseTester createDbTester(ITableFilterSimple aTables)
+        throws Exception {
         return createDbTester(getTableNames(aTables));
     }
-    
+
     /**
-     * Creates database tester. 
-     * @param aTables Tables to create the tester for. 
-     * @return Database tester. 
+     * Creates database tester.
+     * 
+     * @param aTables
+     *            Tables to create the tester for.
+     * @return Database tester.
      * @throws Exception
      */
     public IDatabaseTester createDbTester(String[] aTables) throws Exception {
@@ -161,9 +172,12 @@ public class DatabaseUtils {
     }
 
     /**
-     * Executes an operation on a set of tables. 
-     * @param aTables Tables. 
-     * @param aOperation Operation. 
+     * Executes an operation on a set of tables.
+     * 
+     * @param aTables
+     *            Tables.
+     * @param aOperation
+     *            Operation.
      * @throws Exception
      */
     public void executeOnTables(ITableFilterSimple aTables,
@@ -180,9 +194,12 @@ public class DatabaseUtils {
     }
 
     /**
-     * Cleans a number of database tables. This means deleting the content not dropping the tables. 
-     * This may fail in case of cyclic dependencies between the tables (current limitation). 
-     * @param aSelection Tables.
+     * Cleans a number of database tables. This means deleting the content not
+     * dropping the tables. This may fail in case of cyclic dependencies between
+     * the tables (current limitation).
+     * 
+     * @param aSelection
+     *            Tables.
      * @throws Exception
      */
     public void cleanDatabase(ITableFilterSimple aSelection) throws Exception {
@@ -205,14 +222,16 @@ public class DatabaseUtils {
     }
 
     /**
-     * Executes a unit of work within a transaction. 
-     * @param <T> Result type of th ework. 
-     * @param aWork Unit of work. 
+     * Executes a unit of work within a transaction.
+     * 
+     * @param <T>
+     *            Result type of th ework.
+     * @param aWork
+     *            Unit of work.
      * @return
      * @throws Exception
      */
-    public <T> T executeInTransaction(JdbcUnitOfWork<T> aWork)
-        throws Exception {
+    public <T> T executeInTransaction(JdbcUnitOfWork<T> aWork) throws Exception {
         Connection connection = dataSource.getConnection();
         connection.setAutoCommit(false);
         try {
@@ -223,11 +242,13 @@ public class DatabaseUtils {
             connection.close();
         }
     }
-    
+
     /**
-     * Returns table names based on a table filter. 
-     * @param aSelection Table filter. 
-     * @return Table names. 
+     * Returns table names based on a table filter.
+     * 
+     * @param aSelection
+     *            Table filter.
+     * @return Table names.
      * @throws Exception
      */
     public String[] getTableNames(ITableFilterSimple aSelection)
@@ -254,7 +275,7 @@ public class DatabaseUtils {
     }
 
     /**
-     * Use {@link #cleanDatabase(ITableFilterSimple)} instead. 
+     * Use {@link #cleanDatabase(ITableFilterSimple)} instead.
      */
     @Deprecated
     public void emptyTables(final ITableFilterSimple aSelection)
@@ -267,7 +288,7 @@ public class DatabaseUtils {
     }
 
     /**
-     * User {@link #cleanDatabase(ITableFilterSimple)} instead. 
+     * User {@link #cleanDatabase(ITableFilterSimple)} instead.
      */
     @Deprecated
     public void emptyTable(String aTable) throws Exception {
@@ -275,8 +296,11 @@ public class DatabaseUtils {
     }
 
     /**
-     * Drops tables. This only works if there are no cyclic dependencies between the tables. 
-     * @param aTables Tables to drop. 
+     * Drops tables. This only works if there are no cyclic dependencies between
+     * the tables.
+     * 
+     * @param aTables
+     *            Tables to drop.
      * @throws Exception
      */
     public void dropTables(ITableFilterSimple aTables) throws Exception {
@@ -299,8 +323,10 @@ public class DatabaseUtils {
     }
 
     /**
-     * Drops a table. 
-     * @param aTable Table to drop. 
+     * Drops a table.
+     * 
+     * @param aTable
+     *            Table to drop.
      * @throws Exception
      */
     public void dropTable(final String aTable) throws Exception {
@@ -413,11 +439,15 @@ public class DatabaseUtils {
     }
 
     /**
-     * Executes an update. 
-     * @param aConnection Connection to use. 
-     * @param aSql SQL update to use. 
-     * @param aArgs Arguments to the update. 
-     * @return Number of rows updated. 
+     * Executes an update.
+     * 
+     * @param aConnection
+     *            Connection to use.
+     * @param aSql
+     *            SQL update to use.
+     * @param aArgs
+     *            Arguments to the update.
+     * @return Number of rows updated.
      */
     public int executeUpdate(Connection aConnection, final String aSql,
         final Object... aArgs) {
@@ -476,9 +506,11 @@ public class DatabaseUtils {
     }
 
     /**
-     * Gets the table size. 
-     * @param aTable Table. 
-     * @return Table size. 
+     * Gets the table size.
+     * 
+     * @param aTable
+     *            Table.
+     * @return Table size.
      * @throws SQLException
      */
     public int getTableSize(final String aTable) throws Exception {
@@ -494,9 +526,11 @@ public class DatabaseUtils {
     }
 
     /**
-     * Counts the results in a result set. 
-     * @param aResultSet Resultset. 
-     * @return Number of rows in the set. 
+     * Counts the results in a result set.
+     * 
+     * @param aResultSet
+     *            Resultset.
+     * @return Number of rows in the set.
      * @throws SQLException
      */
     public int countResultSet(ResultSet aResultSet) throws SQLException {