
| Key: |
DBUTILS-16
|
| Type: |
Improvement
|
| Status: |
Closed
|
| Resolution: |
Fixed
|
| Priority: |
Minor
|
| Assignee: |
Unassigned
|
| Reporter: |
Mikhail Krivoshein
|
| Votes: |
0
|
| Watchers: |
0
|
|
If you were logged in you would be able to see more operations.
|
|
|
|
File Attachments:
|
|
|
Environment:
|
Operating System: All
Platform: All
Operating System: All
Platform: All
|
|
| Bugzilla Id: |
29392
|
| Resolution Date: |
03/Nov/06 08:20 PM
|
Index: ArrayListHandler.java
===================================================================
RCS file: /home/cvspublic/jakarta-
commons/dbutils/src/java/org/apache/commons/dbutils/handlers/ArrayListHandler.ja
va,v
retrieving revision 1.4
diff -u -r1.4 ArrayListHandler.java
— ArrayListHandler.java 28 Feb 2004 00:12:22 -0000 1.4
+++ ArrayListHandler.java 4 Jun 2004 13:24:00 -0000
@@ -1,82 +1,68 @@
/*
- Copyright 2003-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

- *
+ *
+ * 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.
+ * 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;
import org.apache.commons.dbutils.RowProcessor;
/**
- * <code>ResultSetHandler</code> implementation that converts the
- * <code>ResultSet</code> into a <code>List</code> of <code>Object[]</code>s.
- * This class is thread safe.
+ * <code>ResultSetHandler</code> implementation that converts the
<code>ResultSet</code>
+ * into a <code>List</code> of <code>Object[]</code>s. This class is
+ * thread safe.
- @see ResultSetHandler
*/
-public class ArrayListHandler implements ResultSetHandler {
-
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.RowProcessor;
/**
@@ -30,7 +27,7 @@
- @see ResultSetHandler
*/
-public class MapListHandler implements ResultSetHandler {
+public class MapListHandler extends ResultSetRowProcessor {
/**
* The RowProcessor implementation to use when converting rows
@@ -58,24 +55,16 @@
}
/**
- * Converts the <code>ResultSet</code> rows into a <code>List</code> of
- * <code>Map</code> objects.
+ * Converts the <code>ResultSet</code> row into a <code>Map</code> object.
- * @return A <code>List</code> of <code>Map</code>s, never null.
+ * @return A <code>Map</code>, never null.
- * @see org.apache.commons.dbutils.ResultSetHandler#handle
(java.sql.ResultSet)
+ * @see org.apache.commons.dbutils.handlers.ResultSetRowProcessor#handle
(ResultSet)
*/
- public Object handle(ResultSet rs) throws SQLException {
-
- List results = new ArrayList();
-
- while (rs.next()) {
- results.add(this.convert.toMap(rs));
- }
-
- return results;
- }
+ protected Object handleRow(ResultSet rs) throws SQLException {
+ return this.convert.toMap(rs);
+ }
}
Index: src/java/org/apache/commons/dbutils/handlers/ResultSetRowProcessor.java
===================================================================
RCS file:
src/java/org/apache/commons/dbutils/handlers/ResultSetRowProcessor.java
diff -N src/java/org/apache/commons/dbutils/handlers/ResultSetRowProcessor.java
— /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/java/org/apache/commons/dbutils/handlers/ResultSetRowProcessor.java
1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2003-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;
+
+/**
+ * Abstract class that simplify development of <code>ResultSetHandler</code>
+ * classes that convert <code>ResultSet</code> into <code>List</code>.
+ */
+public abstract class ResultSetRowProcessor implements ResultSetHandler {
+ /**
+ * Whole <code>ResultSet</code> handler. It produce <code>List</code> as
+ * result. To convert individual rows into Java objects it uses
<code>handleRow(ResultSet)</code>
+ * method.
+ *
+ * @see #handleRow(ResultSet)
+ */
+ public Object handle(ResultSet rs) throws SQLException {
+ List rows = new ArrayList();
+ while (rs.next()) {
+ rows.add(this.handleRow(rs));
+ }
+ return rows;
+ }
+
+ /**
+ * Row handler. Method converts current row into some Java object.
+ *
+ * @param rs <code>ResultSet</code> to process.
+ * @return row processing result
+ * @throws SQLException error occurs
+ */
+ protected abstract Object handleRow(ResultSet rs) throws SQLException;
+}
|
|
Description
|
Index: ArrayListHandler.java
===================================================================
RCS file: /home/cvspublic/jakarta-
commons/dbutils/src/java/org/apache/commons/dbutils/handlers/ArrayListHandler.ja
va,v
retrieving revision 1.4
diff -u -r1.4 ArrayListHandler.java
— ArrayListHandler.java 28 Feb 2004 00:12:22 -0000 1.4
+++ ArrayListHandler.java 4 Jun 2004 13:24:00 -0000
@@ -1,82 +1,68 @@
/*
- Copyright 2003-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

- *
+ *
+ * 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.
+ * 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;
import org.apache.commons.dbutils.RowProcessor;
/**
- * <code>ResultSetHandler</code> implementation that converts the
- * <code>ResultSet</code> into a <code>List</code> of <code>Object[]</code>s.
- * This class is thread safe.
+ * <code>ResultSetHandler</code> implementation that converts the
<code>ResultSet</code>
+ * into a <code>List</code> of <code>Object[]</code>s. This class is
+ * thread safe.
- @see ResultSetHandler
*/
-public class ArrayListHandler implements ResultSetHandler {
-
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.RowProcessor;
/**
@@ -30,7 +27,7 @@
- @see ResultSetHandler
*/
-public class MapListHandler implements ResultSetHandler {
+public class MapListHandler extends ResultSetRowProcessor {
/**
* The RowProcessor implementation to use when converting rows
@@ -58,24 +55,16 @@
}
/**
- * Converts the <code>ResultSet</code> rows into a <code>List</code> of
- * <code>Map</code> objects.
+ * Converts the <code>ResultSet</code> row into a <code>Map</code> object.
- * @return A <code>List</code> of <code>Map</code>s, never null.
+ * @return A <code>Map</code>, never null.
- * @see org.apache.commons.dbutils.ResultSetHandler#handle
(java.sql.ResultSet)
+ * @see org.apache.commons.dbutils.handlers.ResultSetRowProcessor#handle
(ResultSet)
*/
- public Object handle(ResultSet rs) throws SQLException {
-
- List results = new ArrayList();
-
- while (rs.next()) {
- results.add(this.convert.toMap(rs));
- }
-
- return results;
- }
+ protected Object handleRow(ResultSet rs) throws SQLException {
+ return this.convert.toMap(rs);
+ }
}
Index: src/java/org/apache/commons/dbutils/handlers/ResultSetRowProcessor.java
===================================================================
RCS file:
src/java/org/apache/commons/dbutils/handlers/ResultSetRowProcessor.java
diff -N src/java/org/apache/commons/dbutils/handlers/ResultSetRowProcessor.java
— /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/java/org/apache/commons/dbutils/handlers/ResultSetRowProcessor.java
1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2003-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;
+
+/**
+ * Abstract class that simplify development of <code>ResultSetHandler</code>
+ * classes that convert <code>ResultSet</code> into <code>List</code>.
+ */
+public abstract class ResultSetRowProcessor implements ResultSetHandler {
+ /**
+ * Whole <code>ResultSet</code> handler. It produce <code>List</code> as
+ * result. To convert individual rows into Java objects it uses
<code>handleRow(ResultSet)</code>
+ * method.
+ *
+ * @see #handleRow(ResultSet)
+ */
+ public Object handle(ResultSet rs) throws SQLException {
+ List rows = new ArrayList();
+ while (rs.next()) {
+ rows.add(this.handleRow(rs));
+ }
+ return rows;
+ }
+
+ /**
+ * Row handler. Method converts current row into some Java object.
+ *
+ * @param rs <code>ResultSet</code> to process.
+ * @return row processing result
+ * @throws SQLException error occurs
+ */
+ protected abstract Object handleRow(ResultSet rs) throws SQLException;
+} |
Show » |
|
file including the license. I will apply a patch that just touches the lines
necessary to make the change.