commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dfabul...@apache.org
Subject svn commit: r833753 - in /commons/proper/dbutils/trunk/src: java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSet.java test/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSetTest.java
Date Sat, 07 Nov 2009 20:26:37 GMT
Author: dfabulich
Date: Sat Nov  7 20:26:36 2009
New Revision: 833753

URL: http://svn.apache.org/viewvc?rev=833753&view=rev
Log:
[DBUTILS-63] SqlNullCheckedResultSet exposes internal representation

Modified:
    commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSet.java
    commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSetTest.java

Modified: commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSet.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSet.java?rev=833753&r1=833752&r2=833753&view=diff
==============================================================================
--- commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSet.java
(original)
+++ commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSet.java
Sat Nov  7 20:26:36 2009
@@ -29,6 +29,7 @@
 import java.sql.ResultSet;
 import java.sql.Time;
 import java.sql.Timestamp;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -212,7 +213,7 @@
      * @return the value
      */
     public byte[] getNullBytes() {
-        return this.nullBytes;
+        return this.nullBytes == null ? null : Arrays.copyOf(this.nullBytes, this.nullBytes.length);
     }
 
     /**
@@ -444,7 +445,7 @@
      * @param nullBytes the value
      */
     public void setNullBytes(byte[] nullBytes) {
-        this.nullBytes = nullBytes;
+        this.nullBytes = Arrays.copyOf(nullBytes, nullBytes.length);
     }
 
     /**

Modified: commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSetTest.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSetTest.java?rev=833753&r1=833752&r2=833753&view=diff
==============================================================================
--- commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSetTest.java
(original)
+++ commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSetTest.java
Sat Nov  7 20:26:36 2009
@@ -34,6 +34,7 @@
 import java.sql.SQLException;
 import java.sql.Time;
 import java.sql.Timestamp;
+import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Map;
 
@@ -188,11 +189,23 @@
         }
         rs2.setNullBytes(b);
         assertNotNull(rs.getBytes(1));
-        assertEquals(b, rs.getBytes(1));
+        assertArrayEquals(b, rs.getBytes(1));
         assertNotNull(rs.getBytes("column"));
-        assertEquals(b, rs.getBytes("column"));
+        assertArrayEquals(b, rs.getBytes("column"));
 
     }
+    
+    private static void assertArrayEquals(byte[] expected, byte[] actual) {
+    	if (expected == actual) return;
+    	if (expected.length != actual.length) {
+    		failNotEquals(null, Arrays.toString(expected), Arrays.toString(actual));
+    	}
+    	for (int i = 0; i < expected.length; i++) {
+    		byte expectedItem = expected[i];
+    		byte actualItem = actual[i];
+    		assertEquals("Array not equal at index " + i, expectedItem, actualItem);
+    	}
+    }
 
     /**
      * Tests the getCharacterStream implementation.
@@ -593,9 +606,9 @@
         }
         rs2.setNullBytes(b);
         assertNotNull(rs.getBytes(1));
-        assertEquals(b, rs.getBytes(1));
+        assertArrayEquals(b, rs.getBytes(1));
         assertNotNull(rs.getBytes("column"));
-        assertEquals(b, rs.getBytes("column"));
+        assertArrayEquals(b, rs.getBytes("column"));
 
     }
 



Mime
View raw message