dgraham 2004/03/08 19:05:51
Modified: dbutils/src/test/org/apache/commons/dbutils
BaseTestCase.java
dbutils project.xml
Added: dbutils/src/test/org/apache/commons/dbutils/handlers
ColumnListHandlerTest.java
dbutils/src/java/org/apache/commons/dbutils/handlers
ColumnListHandler.java
Log:
Added ColumnListHandler implementation of ResultSetHandler interface.
PR: 27377
Patches provided by: P�ter Bagyinszki
Revision Changes Path
1.7 +3 -0
jakarta-commons/dbutils/src/test/org/apache/commons/dbutils/BaseTestCase.java
Index: BaseTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/dbutils/src/test/org/apache/commons/dbutils/BaseTestCase.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- BaseTestCase.java 28 Feb 2004 00:12:22 -0000 1.6
+++ BaseTestCase.java 9 Mar 2004 03:05:51 -0000 1.7
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.commons.dbutils;
import java.math.BigInteger;
@@ -28,6 +29,7 @@
import org.apache.commons.dbutils.handlers.ArrayListHandlerTest;
import org.apache.commons.dbutils.handlers.BeanHandlerTest;
import org.apache.commons.dbutils.handlers.BeanListHandlerTest;
+import org.apache.commons.dbutils.handlers.ColumnListHandlerTest;
import org.apache.commons.dbutils.handlers.MapHandlerTest;
import org.apache.commons.dbutils.handlers.MapListHandlerTest;
import org.apache.commons.dbutils.handlers.ScalarHandlerTest;
@@ -150,6 +152,7 @@
suite.addTestSuite(MapHandlerTest.class);
suite.addTestSuite(MapListHandlerTest.class);
suite.addTestSuite(ScalarHandlerTest.class);
+ suite.addTestSuite(ColumnListHandlerTest.class);
suite.addTestSuite(StringTrimmedResultSetTest.class);
suite.addTestSuite(SqlNullCheckedResultSetTest.class);
1.1
jakarta-commons/dbutils/src/test/org/apache/commons/dbutils/handlers/ColumnListHandlerTest.java
Index: ColumnListHandlerTest.java
===================================================================
/*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.dbutils.handlers;
import java.sql.SQLException;
import java.util.List;
import org.apache.commons.dbutils.BaseTestCase;
import org.apache.commons.dbutils.ResultSetHandler;
/**
* ColumnListHandlerTest
*/
public class ColumnListHandlerTest extends BaseTestCase {
public ColumnListHandlerTest(String name) {
super(name);
}
public void testHandle() throws SQLException {
ResultSetHandler h = new ColumnListHandler();
List results = (List) h.handle(this.rs);
assertNotNull(results);
assertEquals(ROWS, results.size());
assertEquals("1", results.get(0));
assertEquals("4", results.get(1));
}
public void testColumnIndexHandle() throws SQLException {
ResultSetHandler h = new ColumnListHandler(2);
List results = (List) h.handle(this.rs);
assertNotNull(results);
assertEquals(ROWS, results.size());
assertEquals("2", results.get(0));
assertEquals("5", results.get(1));
}
public void testColumnNameHandle() throws SQLException {
ResultSetHandler h = new ColumnListHandler("Three");
List results = (List) h.handle(this.rs);
assertNotNull(results);
assertEquals(ROWS, results.size());
assertEquals("3", results.get(0));
assertEquals("6", results.get(1));
}
public void testEmptyResultSetHandle() throws SQLException {
ResultSetHandler h = new ColumnListHandler();
List results = (List) h.handle(this.emptyResultSet);
assertNotNull(results);
assertTrue(results.isEmpty());
}
}
1.1
jakarta-commons/dbutils/src/java/org/apache/commons/dbutils/handlers/ColumnListHandler.java
Index: ColumnListHandler.java
===================================================================
/*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.dbutils.handlers;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.dbutils.ResultSetHandler;
/**
* <code>ResultSetHandler</code> implementation that converts one
* <code>ResultSet</code> column into a <code>List</code> of
* <code>Object</code>s. This class is thread safe.
*
* @see ResultSetHandler
* @since DbUtils 1.1
*/
public class ColumnListHandler implements ResultSetHandler {
/**
* The column number to retrieve.
*/
private int columnIndex = 1;
/**
* The column name to retrieve. Either columnName or columnIndex
* will be used but never both.
*/
private String columnName = null;
/**
* Creates a new instance of ColumnListHandler. The first column of each
* row will be returned from <code>handle()</code>.
*/
public ColumnListHandler() {
super();
}
/**
* Creates a new instance of ColumnListHandler.
*
* @param columnIndex The index of the column to retrieve from the
* <code>ResultSet</code>.
*/
public ColumnListHandler(int columnIndex) {
this.columnIndex = columnIndex;
}
/**
* Creates a new instance of ColumnListHandler.
*
* @param columnName The name of the column to retrieve from the
* <code>ResultSet</code>.
*/
public ColumnListHandler(String columnName) {
this.columnName = columnName;
}
/**
* Returns one <code>ResultSet</code> column as a <code>List</code> of
* <code>Object</code>s. The elements are added to the <code>List</code> via
* the <code>ResultSet.getObject()</code> method.
*
* @return A <code>List</code> of <code>Object</code>s, never
* <code>null</code>.
*
* @throws SQLException
*
* @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet)
*/
public Object handle(ResultSet rs) throws SQLException {
List result = new ArrayList();
while (rs.next()) {
if (this.columnName == null) {
result.add(rs.getObject(this.columnIndex));
} else {
result.add(rs.getObject(this.columnName));
}
}
return result;
}
}
1.10 +18 -9 jakarta-commons/dbutils/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/jakarta-commons/dbutils/project.xml,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- project.xml 28 Feb 2004 00:36:26 -0000 1.9
+++ project.xml 9 Mar 2004 03:05:51 -0000 1.10
@@ -30,15 +30,6 @@
<developers>
<developer>
- <name>Henri Yandell</name>
- <id>bayard</id>
- <email>[EMAIL PROTECTED]</email>
- <organization></organization>
- <roles>
- <role>Java Developer</role>
- </roles>
- </developer>
- <developer>
<name>Juozas Baliuka</name>
<id>baliuka</id>
<email>[EMAIL PROTECTED]</email>
@@ -74,9 +65,27 @@
<role>Java Developer</role>
</roles>
</developer>
+ <developer>
+ <name>Henri Yandell</name>
+ <id>bayard</id>
+ <email>[EMAIL PROTECTED]</email>
+ <organization></organization>
+ <roles>
+ <role>Java Developer</role>
+ </roles>
+ </developer>
</developers>
<contributors>
+ <contributor>
+ <name>Péter Bagyinszki</name>
+ <id></id>
+ <email></email>
+ <organization></organization>
+ <roles>
+ <role>Java Developer</role>
+ </roles>
+ </contributor>
<contributor>
<name>Corby Page</name>
<id></id>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]