You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by th...@apache.org on 2017/07/07 02:05:37 UTC
[02/50] commons-dbutils git commit: DBUTILS-114: Order of columns not
retained in BasicRowProcessor with HashMap. Thanks to Michael Osipov.
DBUTILS-114: Order of columns not retained in BasicRowProcessor with HashMap. Thanks to Michael Osipov.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/dbutils/trunk@1611088 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/commons-dbutils/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-dbutils/commit/c8c9329c
Tree: http://git-wip-us.apache.org/repos/asf/commons-dbutils/tree/c8c9329c
Diff: http://git-wip-us.apache.org/repos/asf/commons-dbutils/diff/c8c9329c
Branch: refs/heads/master
Commit: c8c9329c518186865a2d279a58b53e291086a280
Parents: 5d61f56
Author: Benedikt Ritter <br...@apache.org>
Authored: Wed Jul 16 16:55:17 2014 +0000
Committer: Benedikt Ritter <br...@apache.org>
Committed: Wed Jul 16 16:55:17 2014 +0000
----------------------------------------------------------------------
src/changes/changes.xml | 3 +++
.../commons/dbutils/BasicRowProcessor.java | 22 +++++++++++++-------
.../commons/dbutils/BasicRowProcessorTest.java | 21 +++++++++++++++++++
3 files changed, 38 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/c8c9329c/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 53bf58a..b9d5337 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -44,6 +44,9 @@ The <action> type attribute can be add,update,fix,remove.
</properties>
<body>
<release version="1.6" date="TBA" description="Bugfixes and addition of insert methods">
+ <action dev="britter" type="fix" issue="DBUTILS-114" due-to="Michael Osipov">
+ Order of columns not retained in BasicRowProcessor with HashMap
+ </action>
<action dev="britter" type="fix" issue="DBUTILS-118" due-to="Feysal Rujbally, Daniele Cremonini">
BeanProcessor not returning nanoseconds
</action>
http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/c8c9329c/src/main/java/org/apache/commons/dbutils/BasicRowProcessor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/dbutils/BasicRowProcessor.java b/src/main/java/org/apache/commons/dbutils/BasicRowProcessor.java
index 4f4452a..7508140 100644
--- a/src/main/java/org/apache/commons/dbutils/BasicRowProcessor.java
+++ b/src/main/java/org/apache/commons/dbutils/BasicRowProcessor.java
@@ -20,6 +20,7 @@ import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -140,14 +141,19 @@ public class BasicRowProcessor implements RowProcessor {
}
/**
- * Convert a <code>ResultSet</code> row into a <code>Map</code>. This
- * implementation returns a <code>Map</code> with case insensitive column
- * names as keys. Calls to <code>map.get("COL")</code> and
- * <code>map.get("col")</code> return the same value.
- * @see org.apache.commons.dbutils.RowProcessor#toMap(java.sql.ResultSet)
+ * Convert a <code>ResultSet</code> row into a <code>Map</code>.
+ *
+ * <p>
+ * This implementation returns a <code>Map</code> with case insensitive column names as keys. Calls to
+ * <code>map.get("COL")</code> and <code>map.get("col")</code> return the same value. Furthermore this implementation
+ * will return an ordered map, that preserves the ordering of the columns in the ResultSet, so that iterating over
+ * the entry set of the returned map will return the first column of the ResultSet, then the second and so forth.
+ * </p>
+ *
* @param rs ResultSet that supplies the map data
- * @throws SQLException if a database access error occurs
* @return the newly created Map
+ * @throws SQLException if a database access error occurs
+ * @see org.apache.commons.dbutils.RowProcessor#toMap(java.sql.ResultSet)
*/
@Override
public Map<String, Object> toMap(ResultSet rs) throws SQLException {
@@ -176,12 +182,12 @@ public class BasicRowProcessor implements RowProcessor {
* achieve the case insensitive lookup.
*
* <p>Note: This implementation does not allow <tt>null</tt>
- * for key, whereas {@link HashMap} does, because of the code:
+ * for key, whereas {@link LinkedHashMap} does, because of the code:
* <pre>
* key.toString().toLowerCase()
* </pre>
*/
- private static class CaseInsensitiveHashMap extends HashMap<String, Object> {
+ private static class CaseInsensitiveHashMap extends LinkedHashMap<String, Object> {
/**
* The internal mapping from lowercase keys to the real keys.
*
http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/c8c9329c/src/test/java/org/apache/commons/dbutils/BasicRowProcessorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/dbutils/BasicRowProcessorTest.java b/src/test/java/org/apache/commons/dbutils/BasicRowProcessorTest.java
index 55cb80f..7c701cd 100644
--- a/src/test/java/org/apache/commons/dbutils/BasicRowProcessorTest.java
+++ b/src/test/java/org/apache/commons/dbutils/BasicRowProcessorTest.java
@@ -20,6 +20,7 @@ import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -137,4 +138,24 @@ public class BasicRowProcessorTest extends BaseTestCase {
assertFalse(this.rs.next());
}
+ public void testToMapOrdering() throws SQLException {
+
+ assertTrue(this.rs.next());
+ Map<String, Object> m = processor.toMap(this.rs);
+
+ Iterator<String> itr = m.keySet().iterator();
+ assertEquals("one", itr.next());
+ assertEquals("two", itr.next());
+ assertEquals("three", itr.next());
+ assertEquals("notInBean", itr.next());
+ assertEquals("intTest", itr.next());
+ assertEquals("integerTest", itr.next());
+ assertEquals("nullObjectTest", itr.next());
+ assertEquals("nullPrimitiveTest", itr.next());
+ assertEquals("notDate", itr.next());
+ assertEquals("columnProcessorDoubleTest", itr.next());
+
+ assertFalse(itr.hasNext());
+ }
+
}