Author: wspeirs Date: Thu Feb 28 19:19:32 2013 New Revision: 1451297 URL: http://svn.apache.org/r1451297 Log: Changed "go" methods to execute - Updated all Executor classes - Updated AsyncExecutor class - Updated examples
Modified: commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils/AsyncExecutor.java commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils/BatchExecutor.java commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils/InsertExecutor.java commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils/QueryExecutor.java commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils/UpdateExecutor.java commons/proper/dbutils/branches/2_0/src/site/xdoc/examples.xml commons/proper/dbutils/branches/2_0/src/test/java/org/apache/commons/dbutils/AsyncExecutorTest.java commons/proper/dbutils/branches/2_0/src/test/java/org/apache/commons/dbutils/BatchExecutorTest.java commons/proper/dbutils/branches/2_0/src/test/java/org/apache/commons/dbutils/InsertExecutorTest.java commons/proper/dbutils/branches/2_0/src/test/java/org/apache/commons/dbutils/QueryExecutorTest.java commons/proper/dbutils/branches/2_0/src/test/java/org/apache/commons/dbutils/UpdateExecutorTest.java Modified: commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils/AsyncExecutor.java URL: http://svn.apache.org/viewvc/commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils/AsyncExecutor.java?rev=1451297&r1=1451296&r2=1451297&view=diff ============================================================================== --- commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils/AsyncExecutor.java (original) +++ commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils/AsyncExecutor.java Thu Feb 28 19:19:32 2013 @@ -46,12 +46,12 @@ public class AsyncExecutor { * @return A <code>Future</code> which returns the result of the batch call. * @throws SQLException if a database access error occurs */ - public Future<int[]> batch(final BatchExecutor executor) throws SQLException { + public Future<int[]> execute(final BatchExecutor executor) throws SQLException { return executorService.submit(new Callable<int[]>() { @Override public int[] call() throws Exception { - return executor.batch(); + return executor.execute(); } }); @@ -64,12 +64,12 @@ public class AsyncExecutor { * @return A <code>Future</code> which returns the result of the query call. * @throws SQLException if a database access error occurs */ - public <T> Future<T> query(final QueryExecutor executor, final ResultSetHandler<T> handler) throws SQLException { + public <T> Future<T> execute(final QueryExecutor executor, final ResultSetHandler<T> handler) throws SQLException { return executorService.submit(new Callable<T>() { @Override public T call() throws Exception { - return executor.query(handler); + return executor.execute(handler); } }); @@ -81,12 +81,12 @@ public class AsyncExecutor { * @return A <code>Future</code> which returns the result of the query call. * @throws SQLException if a database access error occurs */ - public Future<Integer> update(final UpdateExecutor executor) throws SQLException { + public Future<Integer> execute(final UpdateExecutor executor) throws SQLException { return executorService.submit(new Callable<Integer>() { @Override public Integer call() throws Exception { - return executor.update(); + return executor.execute(); } }); @@ -99,12 +99,28 @@ public class AsyncExecutor { * @return A <code>Future</code> which returns the result of the query call. * @throws SQLException if a database access error occurs */ - public <T> Future<T> insert(final InsertExecutor executor, final ResultSetHandler<T> handler) throws SQLException { + public <T> Future<T> execute(final InsertExecutor executor, final ResultSetHandler<T> handler) throws SQLException { return executorService.submit(new Callable<T>() { @Override public T call() throws Exception { - return executor.insert(handler); + return executor.execute(handler); + } + + }); + } + + /** + * Execute a {@link org.apache.commons.dbutils.InsertExecutor} given a handler. + * @return A <code>Future</code> which returns the number of rows inserted. + * @throws SQLException if a database access error occurs + */ + public Future<Integer> execute(final InsertExecutor executor) throws SQLException { + return executorService.submit(new Callable<Integer>() { + + @Override + public Integer call() throws Exception { + return executor.execute(); } }); Modified: commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils/BatchExecutor.java URL: http://svn.apache.org/viewvc/commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils/BatchExecutor.java?rev=1451297&r1=1451296&r2=1451297&view=diff ============================================================================== --- commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils/BatchExecutor.java (original) +++ commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils/BatchExecutor.java Thu Feb 28 19:19:32 2013 @@ -98,7 +98,7 @@ public class BatchExecutor extends Abstr * @throws SQLException If there are database or parameter errors. * @see org.apache.commons.dbutils.UpdateExecutor.update() */ - public int[] batch() throws SQLException { + public int[] execute() throws SQLException { try { return getStatement().executeBatch(); } catch (SQLException e) { Modified: commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils/InsertExecutor.java URL: http://svn.apache.org/viewvc/commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils/InsertExecutor.java?rev=1451297&r1=1451296&r2=1451297&view=diff ============================================================================== --- commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils/InsertExecutor.java (original) +++ commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils/InsertExecutor.java Thu Feb 28 19:19:32 2013 @@ -39,7 +39,7 @@ public class InsertExecutor extends Abst * @return An object generated by the handler. * @throws SQLException If there are database or parameter errors. */ - public <T> T insert(ResultSetHandler<T> handler) throws SQLException { + public <T> T execute(ResultSetHandler<T> handler) throws SQLException { // throw an exception if there are unmapped parameters this.throwIfUnmappedParams(); @@ -75,16 +75,16 @@ public class InsertExecutor extends Abst /** * Executes the given INSERT SQL statement. - * + * @return the number of rows updated. * @throws SQLException If there are database or parameter errors. */ - public void insert() throws SQLException { + public int execute() throws SQLException { // throw an exception if there are unmapped parameters this.throwIfUnmappedParams(); try { // execute the insert - getStatement().executeUpdate(); + return getStatement().executeUpdate(); } catch (SQLException e) { this.rethrow(e); } finally { @@ -93,6 +93,8 @@ public class InsertExecutor extends Abst close(getConnection()); } } + + return 0; // only get here on an error } } Modified: commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils/QueryExecutor.java URL: http://svn.apache.org/viewvc/commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils/QueryExecutor.java?rev=1451297&r1=1451296&r2=1451297&view=diff ============================================================================== --- commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils/QueryExecutor.java (original) +++ commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils/QueryExecutor.java Thu Feb 28 19:19:32 2013 @@ -43,7 +43,7 @@ class QueryExecutor extends AbstractExec * @return The results of the query. * @throws SQLException If there are database or parameter errors. */ - public <T> T query(ResultSetHandler<T> handler) throws SQLException { + public <T> T execute(ResultSetHandler<T> handler) throws SQLException { // throw an exception if there are unmapped parameters this.throwIfUnmappedParams(); Modified: commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils/UpdateExecutor.java URL: http://svn.apache.org/viewvc/commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils/UpdateExecutor.java?rev=1451297&r1=1451296&r2=1451297&view=diff ============================================================================== --- commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils/UpdateExecutor.java (original) +++ commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils/UpdateExecutor.java Thu Feb 28 19:19:32 2013 @@ -34,7 +34,7 @@ public class UpdateExecutor extends Abst * @return The number of rows updated. * @throws SQLException If there are database or parameter errors. */ - public int update() throws SQLException { + public int execute() throws SQLException { // throw an exception if there are unmapped parameters this.throwIfUnmappedParams(); Modified: commons/proper/dbutils/branches/2_0/src/site/xdoc/examples.xml URL: http://svn.apache.org/viewvc/commons/proper/dbutils/branches/2_0/src/site/xdoc/examples.xml?rev=1451297&r1=1451296&r2=1451297&view=diff ============================================================================== --- commons/proper/dbutils/branches/2_0/src/site/xdoc/examples.xml (original) +++ commons/proper/dbutils/branches/2_0/src/site/xdoc/examples.xml Thu Feb 28 19:19:32 2013 @@ -60,7 +60,7 @@ QueryExecutor executor = runner.query("S // Bind our parameters and execute the query Object[] result = executor.bind("first_name", "John") .bind("last_name", "Doe") - .query(handler); + .execute(handler); ]]> </source> @@ -85,7 +85,7 @@ try{ // Bind our parameters and execute the query Object[] result = executor.bind("first_name", "John") // note you don't need a colon .bind(":last_name", "Doe") // or you can add one, doesn't matter! - .query(conn, handler); + .execute(conn, handler); } finally { // Use this helper method so we don't have to check for null DbUtils.close(conn); @@ -108,13 +108,13 @@ try runner.insert("INSERT INTO Person (name,height) VALUES (:name,:height)") .bind("name", "John Doe") .bind("height", 1.82) - .insert(); + .execute(); // Now it's time to rise to the occation... int updates = runner.update("UPDATE Person SET height=:height WHERE name=:name") .bind("name", "John Doe") .bind("height", 2.05) - .update(); + .execute(); } catch(SQLException sqle) { // Handle it @@ -141,7 +141,7 @@ try .bind("name", "John Doe"); // Returns a Future for the update call - Future<Integer> callable = asyncRun.update(executor); + Future<Integer> callable = asyncRun.execute(executor); } catch(SQLException sqle) { // Handle it } @@ -189,7 +189,7 @@ ResultSetHandler<Person> handler = new B // return the results in a new Person object generated by the BeanHandler. Person p = runner.query("SELECT * FROM Person WHERE name=:name") .bind("name", "John Doe") - .query(handler); + .execute(handler); ]]> </source> @@ -208,7 +208,7 @@ ResultSetHandler<List<Person>> handler = // Execute the SQL statement and return the results in a List of // Person objects generated by the BeanListHandler. -List<Person> persons = runner.query("SELECT * FROM Person").query(handler); +List<Person> persons = runner.query("SELECT * FROM Person").execute(handler); ]]> </source> Modified: commons/proper/dbutils/branches/2_0/src/test/java/org/apache/commons/dbutils/AsyncExecutorTest.java URL: http://svn.apache.org/viewvc/commons/proper/dbutils/branches/2_0/src/test/java/org/apache/commons/dbutils/AsyncExecutorTest.java?rev=1451297&r1=1451296&r2=1451297&view=diff ============================================================================== --- commons/proper/dbutils/branches/2_0/src/test/java/org/apache/commons/dbutils/AsyncExecutorTest.java (original) +++ commons/proper/dbutils/branches/2_0/src/test/java/org/apache/commons/dbutils/AsyncExecutorTest.java Thu Feb 28 19:19:32 2013 @@ -46,47 +46,47 @@ public class AsyncExecutorTest { @Test public void testQueryExecutor() throws Exception { - runner.query(queryExecutor, handler).get(); + runner.execute(queryExecutor, handler).get(); - verify(queryExecutor, times(1)).query(handler); + verify(queryExecutor, times(1)).execute(handler); } @Test(expected=ExecutionException.class) public void testQueryExecutorException() throws Exception { - doThrow(SQLException.class).when(queryExecutor).query(handler); - runner.query(queryExecutor, handler).get(); + doThrow(SQLException.class).when(queryExecutor).execute(handler); + runner.execute(queryExecutor, handler).get(); - verify(queryExecutor, times(1)).query(handler); + verify(queryExecutor, times(1)).execute(handler); } @Test public void testUpdateExecutor() throws Exception { - runner.update(updateExecutor).get(); + runner.execute(updateExecutor).get(); - verify(updateExecutor, times(1)).update(); + verify(updateExecutor, times(1)).execute(); } @Test(expected=ExecutionException.class) public void testUpdateExecutorException() throws Exception { - doThrow(SQLException.class).when(updateExecutor).update(); - runner.update(updateExecutor).get(); + doThrow(SQLException.class).when(updateExecutor).execute(); + runner.execute(updateExecutor).get(); - verify(updateExecutor, times(1)).update(); + verify(updateExecutor, times(1)).execute(); } @Test public void testInsertExecutor() throws Exception { - runner.insert(insertExecutor, handler).get(); + runner.execute(insertExecutor, handler).get(); - verify(insertExecutor, times(1)).insert(handler); + verify(insertExecutor, times(1)).execute(handler); } @Test(expected=ExecutionException.class) public void testInsertExecutorException() throws Exception { - doThrow(SQLException.class).when(insertExecutor).insert(handler); - runner.insert(insertExecutor, handler).get(); + doThrow(SQLException.class).when(insertExecutor).execute(handler); + runner.execute(insertExecutor, handler).get(); - verify(insertExecutor, times(1)).insert(handler); + verify(insertExecutor, times(1)).execute(handler); } Modified: commons/proper/dbutils/branches/2_0/src/test/java/org/apache/commons/dbutils/BatchExecutorTest.java URL: http://svn.apache.org/viewvc/commons/proper/dbutils/branches/2_0/src/test/java/org/apache/commons/dbutils/BatchExecutorTest.java?rev=1451297&r1=1451296&r2=1451297&view=diff ============================================================================== --- commons/proper/dbutils/branches/2_0/src/test/java/org/apache/commons/dbutils/BatchExecutorTest.java (original) +++ commons/proper/dbutils/branches/2_0/src/test/java/org/apache/commons/dbutils/BatchExecutorTest.java Thu Feb 28 19:19:32 2013 @@ -54,7 +54,7 @@ public class BatchExecutorTest { createExecutor("insert into blah"); executor.addBatch(); - int[] ret = executor.batch(); + int[] ret = executor.execute(); assertEquals(3, ret.length); assertEquals(2, ret[0]); Modified: commons/proper/dbutils/branches/2_0/src/test/java/org/apache/commons/dbutils/InsertExecutorTest.java URL: http://svn.apache.org/viewvc/commons/proper/dbutils/branches/2_0/src/test/java/org/apache/commons/dbutils/InsertExecutorTest.java?rev=1451297&r1=1451296&r2=1451297&view=diff ============================================================================== --- commons/proper/dbutils/branches/2_0/src/test/java/org/apache/commons/dbutils/InsertExecutorTest.java (original) +++ commons/proper/dbutils/branches/2_0/src/test/java/org/apache/commons/dbutils/InsertExecutorTest.java Thu Feb 28 19:19:32 2013 @@ -57,7 +57,7 @@ public class InsertExecutorTest { public void testGoodSQL() throws Exception { createExecutor("insert into blah"); - Object ret = executor.insert(handler); + Object ret = executor.execute(handler); assertNotNull(ret); verify(handler, times(1)).handle(resultSet); @@ -69,7 +69,7 @@ public class InsertExecutorTest { public void testUnmappedParams() throws Exception { createExecutor("insert into blah (:something)"); - Object ret = executor.insert(handler); + Object ret = executor.execute(handler); assertNotNull(ret); verify(handler, times(1)).handle(resultSet); @@ -81,7 +81,7 @@ public class InsertExecutorTest { public void testNullHandler() throws Exception { createExecutor("insert into blah"); - Object ret = executor.insert(null); + Object ret = executor.execute(null); assertNotNull(ret); verify(handler, times(1)).handle(resultSet); Modified: commons/proper/dbutils/branches/2_0/src/test/java/org/apache/commons/dbutils/QueryExecutorTest.java URL: http://svn.apache.org/viewvc/commons/proper/dbutils/branches/2_0/src/test/java/org/apache/commons/dbutils/QueryExecutorTest.java?rev=1451297&r1=1451296&r2=1451297&view=diff ============================================================================== --- commons/proper/dbutils/branches/2_0/src/test/java/org/apache/commons/dbutils/QueryExecutorTest.java (original) +++ commons/proper/dbutils/branches/2_0/src/test/java/org/apache/commons/dbutils/QueryExecutorTest.java Thu Feb 28 19:19:32 2013 @@ -57,7 +57,7 @@ public class QueryExecutorTest { public void testGoodSQL() throws Exception { createExecutor("insert into blah"); - Object ret = executor.query(handler); + Object ret = executor.execute(handler); assertNotNull(ret); verify(handler, times(1)).handle(resultSet); @@ -69,7 +69,7 @@ public class QueryExecutorTest { public void testUnmappedParams() throws Exception { createExecutor("insert into blah (:something)"); - Object ret = executor.query(handler); + Object ret = executor.execute(handler); assertNotNull(ret); verify(handler, times(1)).handle(resultSet); @@ -81,7 +81,7 @@ public class QueryExecutorTest { public void testNullHandler() throws Exception { createExecutor("insert into blah"); - Object ret = executor.query(null); + Object ret = executor.execute(null); assertNotNull(ret); verify(handler, times(1)).handle(resultSet); Modified: commons/proper/dbutils/branches/2_0/src/test/java/org/apache/commons/dbutils/UpdateExecutorTest.java URL: http://svn.apache.org/viewvc/commons/proper/dbutils/branches/2_0/src/test/java/org/apache/commons/dbutils/UpdateExecutorTest.java?rev=1451297&r1=1451296&r2=1451297&view=diff ============================================================================== --- commons/proper/dbutils/branches/2_0/src/test/java/org/apache/commons/dbutils/UpdateExecutorTest.java (original) +++ commons/proper/dbutils/branches/2_0/src/test/java/org/apache/commons/dbutils/UpdateExecutorTest.java Thu Feb 28 19:19:32 2013 @@ -53,7 +53,7 @@ public class UpdateExecutorTest { public void testGoodSQL() throws Exception { createExecutor("insert into blah"); - int ret = executor.update(); + int ret = executor.execute(); assertEquals(20, ret); verify(conn, times(1)).close(); @@ -64,7 +64,7 @@ public class UpdateExecutorTest { public void testUnmappedParams() throws Exception { createExecutor("insert into blah (:something)"); - int ret = executor.update(); + int ret = executor.execute(); assertEquals(20, ret); verify(conn, times(1)).close();