harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r636705 - in /harmony/enhanced/classlib/trunk/modules/sql/src: main/java/org/apache/harmony/sql/internal/nls/ main/java/org/apache/harmony/sql/internal/rowset/ test/java/org/apache/harmony/sql/tests/internal/rowset/
Date Thu, 13 Mar 2008 10:44:23 GMT
Author: tonywu
Date: Thu Mar 13 03:44:18 2008
New Revision: 636705

URL: http://svn.apache.org/viewvc?rev=636705&view=rev
Log:
Apply patch for HARMONY-5603 ([classlib][sql][rowset] implements release(), close(), commit() and rollback() in CachedRowsetImpl)

Added:
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetTransactionTest.java   (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetMatchColumnTest.java

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties?rev=636705&r1=636704&r2=636705&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties Thu Mar 13 03:44:18 2008
@@ -75,3 +75,5 @@
 rowset.12=Match columns should not be empty or null string
 rowset.13=Set Match columns before getting them
 rowset.14=Positioned updates not supported
+rowset.15=Columns being unset are not the same as set
+rowset.16=Not a valid command

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java?rev=636705&r1=636704&r2=636705&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java Thu Mar 13 03:44:18 2008
@@ -118,7 +118,6 @@
 
     private SyncProvider syncProvider;
 
-    // TODO where is it initialized
     private CachedRowSetImpl originalResultSet;
 
     private SQLWarning sqlwarn;
@@ -131,6 +130,10 @@
 
     private String cursorName;
 
+    private boolean isLastColNull;
+
+    private Connection conn;
+
     private static Map<Integer, Class> TYPE_MAPPING = initialTypeMapping();
 
     public static final String PROVIDER_ID = "Apache Harmony HYOptimisticProvider"; //$NON-NLS-1$
@@ -211,12 +214,19 @@
             currentConn = getConnection();
             acceptChanges(currentConn);
         } catch (SQLException e) {
+            try {
+                currentConn.rollback();
+            } catch (SQLException ex) {
+                // ignore
+            }
             SyncProviderException ex = new SyncProviderException();
             ex.initCause(e);
             throw ex;
         } finally {
+            conn = null;
             if (currentConn != null) {
                 try {
+                    currentConn.commit();
                     currentConn.close();
                 } catch (SQLException ex) {
                     SyncProviderException spe = new SyncProviderException();
@@ -233,7 +243,9 @@
             throw new SyncProviderException(Messages.getString("rowset.11")); //$NON-NLS-1$
         }
 
+        conn = con;
         try {
+            conn.setAutoCommit(false);
             CachedRowSetWriter rowSetWriter = (CachedRowSetWriter) syncProvider
                     .getRowSetWriter();
             rowSetWriter.setConnection(con);
@@ -333,7 +345,10 @@
     }
 
     public void commit() throws SQLException {
-        getConnection().commit();
+        if (conn == null) {
+            throw new NullPointerException();
+        }
+        conn.commit();
     }
 
     public CachedRowSet createCopy() throws SQLException {
@@ -438,10 +453,13 @@
         output.currentRow = null;
         output.currentRowIndex = 0;
         output.insertRow = null;
+        output.isCursorOnInsert = false;
+        output.isLastColNull = false;
         output.nextPageRowIndex = -1;
         output.rememberedCursorPosition = 0;
         output.rows = new ArrayList<CachedRow>();
         output.sqlwarn = null;
+        output.deletedRowCount = 0;
 
         return output;
     }
@@ -460,13 +478,13 @@
     }
 
     public void execute(Connection conn) throws SQLException {
-        // TODO ensure the getConnection can works!
         String localCommand = getCommand();
         if (localCommand == null || getParams() == null) {
-            // TODO add error messages
-            throw new SQLException();
+            // rowset.16=Not a valid command
+            throw new SQLException(Messages.getString("rowset.16"));
         }
 
+        this.conn = conn;
         PreparedStatement ps = conn.prepareStatement(localCommand);
         Object[] params = getParams();
         for (int i = 0; i < params.length; i++)
@@ -807,7 +825,8 @@
     }
 
     public void release() throws SQLException {
-        throw new NotImplementedException();
+        // TODO send a rowSetChanged event to all listeners
+        rows = new ArrayList<CachedRow>();
     }
 
     public void restoreOriginal() throws SQLException {
@@ -834,11 +853,17 @@
     }
 
     public void rollback() throws SQLException {
-        throw new NotImplementedException();
+        if (conn == null) {
+            throw new NullPointerException();
+        }
+        conn.rollback();
     }
 
     public void rollback(Savepoint s) throws SQLException {
-        throw new NotImplementedException();
+        if (conn == null) {
+            throw new NullPointerException();
+        }
+        conn.rollback(s);
     }
 
     public void rowSetPopulated(RowSetEvent event, int numRows)
@@ -989,7 +1014,8 @@
     }
 
     public int[] getMatchColumnIndexes() throws SQLException {
-        if (matchColumnIndexes == null) {
+        if (matchColumnIndexes == null || matchColumnIndexes.length == 0
+                || matchColumnIndexes[0] == -1) {
             // rowset.13=Set Match columns before getting them
             throw new SQLException(Messages.getString("rowset.13")); //$NON-NLS-1$
         }
@@ -998,7 +1024,8 @@
     }
 
     public String[] getMatchColumnNames() throws SQLException {
-        if (matchColumnNames == null) {
+        if (matchColumnNames == null || matchColumnNames.length == 0
+                || matchColumnNames[0] == null) {
             // rowset.13=Set Match columns before getting them
             throw new SQLException(Messages.getString("rowset.13")); //$NON-NLS-1$
         }
@@ -1098,19 +1125,69 @@
     }
 
     public void unsetMatchColumn(int columnIdx) throws SQLException {
-        throw new NotImplementedException();
+
+        if (matchColumnIndexes == null || matchColumnIndexes.length == 0
+                || matchColumnIndexes[0] != columnIdx) {
+            throw new SQLException(Messages.getString("rowset.15")); //$NON-NLS-1$
+        }
+
+        matchColumnIndexes[0] = -1;
     }
 
     public void unsetMatchColumn(int[] columnIdxes) throws SQLException {
-        throw new NotImplementedException();
+        if (columnIdxes == null) {
+            throw new NullPointerException();
+        }
+
+        if (columnIdxes.length == 0) {
+            return;
+        }
+
+        if (matchColumnIndexes == null
+                || matchColumnIndexes.length < columnIdxes.length) {
+            throw new SQLException(Messages.getString("rowset.15")); //$NON-NLS-1$
+        }
+
+        for (int i = 0; i < columnIdxes.length; i++) {
+            if (matchColumnIndexes[i] != columnIdxes[i]) {
+                throw new SQLException(Messages.getString("rowset.15")); //$NON-NLS-1$    
+            }
+        }
+
+        Arrays.fill(matchColumnIndexes, 0, columnIdxes.length, -1);
     }
 
     public void unsetMatchColumn(String columnName) throws SQLException {
-        throw new NotImplementedException();
+        if (matchColumnNames == null || matchColumnNames.length == 0
+                || !matchColumnNames[0].equals(columnName)) {
+            throw new SQLException(Messages.getString("rowset.15")); //$NON-NLS-1$
+        }
+
+        matchColumnNames[0] = null;
+
     }
 
     public void unsetMatchColumn(String[] columnName) throws SQLException {
-        throw new NotImplementedException();
+        if (columnName == null) {
+            throw new NullPointerException();
+        }
+
+        if (columnName.length == 0) {
+            return;
+        }
+
+        if (matchColumnNames == null
+                || matchColumnNames.length < columnName.length) {
+            throw new SQLException(Messages.getString("rowset.15")); //$NON-NLS-1$
+        }
+
+        for (int i = 0; i < columnName.length; i++) {
+            if (matchColumnNames[i] != columnName[i]) {
+                throw new SQLException(Messages.getString("rowset.15")); //$NON-NLS-1$    
+            }
+        }
+
+        Arrays.fill(matchColumnNames, 0, columnName.length, null);
     }
 
     public boolean absolute(int row) throws SQLException {
@@ -1190,15 +1267,21 @@
     }
 
     public void close() throws SQLException {
+        String username = getUsername();
+        String password = getPassword();
+        initialProperties();
+        setUsername(username);
+        setPassword(password);
 
-        // TODO need more concerns!
-        if (rows != null) {
-            rows.clear();
-        }
+        rows = new ArrayList<CachedRow>();
         currentRowIndex = 0;
         currentRow = null;
-        meta = null;
-
+        deletedRowCount = 0;
+        isCursorOnInsert = false;
+        isLastColNull = false;
+        matchColumnNames = null;
+        matchColumnIndexes = null;
+        conn = null;
     }
 
     public void deleteRow() throws SQLException {
@@ -1300,8 +1383,10 @@
     public Array getArray(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
+            isLastColNull = true;
             return null;
         }
+        isLastColNull = false;
         try {
             return (Array) obj;
         } catch (ClassCastException e) {
@@ -1325,8 +1410,10 @@
     public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
+            isLastColNull = true;
             return null;
         }
+        isLastColNull = false;
         try {
             return new BigDecimal(obj.toString());
         } catch (NumberFormatException e) {
@@ -1360,8 +1447,10 @@
     public Blob getBlob(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
+            isLastColNull = true;
             return null;
         }
+        isLastColNull = false;
         try {
             return (Blob) obj;
         } catch (ClassCastException e) {
@@ -1377,8 +1466,10 @@
     public boolean getBoolean(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
+            isLastColNull = true;
             return false;
         }
+        isLastColNull = false;
         try {
             return Boolean.parseBoolean(obj.toString());
         } catch (Exception e) {
@@ -1394,8 +1485,10 @@
     public byte getByte(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
+            isLastColNull = true;
             return 0;
         }
+        isLastColNull = false;
         try {
             return Byte.parseByte(obj.toString());
         } catch (NumberFormatException e) {
@@ -1410,8 +1503,11 @@
 
     public byte[] getBytes(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
-        if (obj == null)
+        if (obj == null) {
+            isLastColNull = true;
             return null;
+        }
+        isLastColNull = false;
         try {
             return (byte[]) obj;
         } catch (ClassCastException e) {
@@ -1435,8 +1531,10 @@
     public Clob getClob(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
+            isLastColNull = true;
             return null;
         }
+        isLastColNull = false;
         try {
             return (Clob) obj;
         } catch (ClassCastException e) {
@@ -1463,8 +1561,10 @@
     public Date getDate(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
+            isLastColNull = true;
             return null;
         }
+        isLastColNull = false;
         try {
             if (obj instanceof Date) {
                 return (Date) obj;
@@ -1494,8 +1594,10 @@
     public double getDouble(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
+            isLastColNull = true;
             return 0;
         }
+        isLastColNull = false;
         try {
             return Double.parseDouble(obj.toString());
         } catch (NumberFormatException e) {
@@ -1511,8 +1613,10 @@
     public float getFloat(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
+            isLastColNull = true;
             return 0;
         }
+        isLastColNull = false;
         try {
             return Float.parseFloat(obj.toString());
         } catch (NumberFormatException e) {
@@ -1528,8 +1632,10 @@
     public int getInt(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
+            isLastColNull = true;
             return 0;
         }
+        isLastColNull = false;
         try {
             return Integer.parseInt(obj.toString());
         } catch (NumberFormatException e) {
@@ -1545,8 +1651,10 @@
     public long getLong(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
+            isLastColNull = true;
             return 0;
         }
+        isLastColNull = false;
         try {
             return Long.parseLong(obj.toString());
         } catch (NumberFormatException e) {
@@ -1572,7 +1680,13 @@
             // sql.27=Invalid column index :{0}
             throw new SQLException(Messages.getString("sql.27", columnIndex));
         }
-        return currentRow.getObject(columnIndex);
+        Object obj = currentRow.getObject(columnIndex);
+        if (obj == null) {
+            isLastColNull = true;
+        } else {
+            isLastColNull = false;
+        }
+        return obj;
     }
 
     public Object getObject(int columnIndex, Map<String, Class<?>> map)
@@ -1592,8 +1706,10 @@
     public Ref getRef(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
+            isLastColNull = true;
             return null;
         }
+        isLastColNull = false;
         try {
             return (Ref) obj;
         } catch (Exception e) {
@@ -1634,8 +1750,10 @@
     public short getShort(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
+            isLastColNull = true;
             return 0;
         }
+        isLastColNull = false;
         try {
             return Short.parseShort(obj.toString());
         } catch (NumberFormatException e) {
@@ -1649,15 +1767,17 @@
     }
 
     public Statement getStatement() throws SQLException {
-        throw new NotImplementedException();
+        return null;
     }
 
     // columnIndex: from 1 rather than 0
     public String getString(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
+            isLastColNull = true;
             return null;
         }
+        isLastColNull = false;
         try {
             return obj.toString();
         } catch (Exception e) {
@@ -1681,8 +1801,10 @@
     public Time getTime(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
+            isLastColNull = true;
             return null;
         }
+        isLastColNull = false;
         try {
             if (obj instanceof Time) {
                 return (Time) obj;
@@ -1712,8 +1834,10 @@
     public Timestamp getTimestamp(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
+            isLastColNull = true;
             return null;
         }
+        isLastColNull = false;
         try {
             if (obj instanceof Date) {
                 return new Timestamp(((Date) obj).getTime());
@@ -1744,8 +1868,10 @@
     public java.net.URL getURL(int columnIndex) throws SQLException {
         Object obj = getObject(columnIndex);
         if (obj == null) {
+            isLastColNull = true;
             return null;
         }
+        isLastColNull = false;
         try {
             return (java.net.URL) obj;
         } catch (Exception e) {
@@ -2426,12 +2552,12 @@
     }
 
     public boolean wasNull() throws SQLException {
-        // return (currentColumn instanceof Types(Types.NULL));
-        throw new NotImplementedException();
+        return isLastColNull;
     }
 
     public void execute() throws SQLException {
         execute(getConnection());
+        conn = null;
     }
 
     public Connection getConnection() throws SQLException {

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java?rev=636705&r1=636704&r2=636705&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java Thu Mar 13 03:44:18 2008
@@ -2500,9 +2500,7 @@
         }
 
         rs = st.executeQuery("select * from USER_INFO");
-        System.out.println("rs 1: " + rs.getCursorName());
         assertTrue(rs.next());
-        System.out.println("rs 2: " + rs.getCursorName());
         rs = st.executeQuery("select * from USER_INFO");
         noInitialCrset.populate(rs);
 
@@ -2519,6 +2517,52 @@
                 fail("should throw SQLException");
             } catch (SQLException e) {
                 // expected
+            }
+        }
+    }
+
+    public void testGetStatement() throws Exception {
+        noInitialCrset = newNoInitialInstance();
+        assertNull(noInitialCrset.getStatement());
+
+        rs = st.executeQuery("select * from USER_INFO");
+        assertNotNull(rs.getStatement());
+        noInitialCrset.populate(rs);
+        assertNull(noInitialCrset.getStatement());
+
+        noInitialCrset.setUrl(DERBY_URL);
+        assertNull(noInitialCrset.getStatement());
+    }
+
+    public void testWasNull() throws Exception {
+        noInitialCrset = newNoInitialInstance();
+        assertFalse(noInitialCrset.wasNull());
+
+        rs = st.executeQuery("select * from USER_INFO");
+        noInitialCrset.populate(rs);
+        assertFalse(noInitialCrset.wasNull());
+
+        assertTrue(noInitialCrset.next());
+        assertFalse(noInitialCrset.wasNull());
+        assertNull(noInitialCrset.getObject(3));
+        assertTrue(noInitialCrset.wasNull());
+
+        assertNotNull(noInitialCrset.getObject(1));
+        assertFalse(noInitialCrset.wasNull());
+
+        assertNull(noInitialCrset.getObject(5));
+        assertTrue(noInitialCrset.wasNull());
+
+        assertTrue(noInitialCrset.absolute(3));
+        noInitialCrset.updateString(2, "x");
+        assertTrue(noInitialCrset.wasNull());
+
+        assertTrue(noInitialCrset.first());
+        for (int i = 1; i <= DEFAULT_COLUMN_COUNT; i++) {
+            if (noInitialCrset.getObject(i) == null) {
+                assertTrue(noInitialCrset.wasNull());
+            } else {
+                assertFalse(noInitialCrset.wasNull());
             }
         }
     }

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetMatchColumnTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetMatchColumnTest.java?rev=636705&r1=636704&r2=636705&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetMatchColumnTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetMatchColumnTest.java Thu Mar 13 03:44:18 2008
@@ -457,4 +457,749 @@
 
     }
 
+    public void testUnsetMatchColumn_Index_Unpopulate() throws Exception {
+        int[] indexes = null;
+        try {
+            noInitialCrset.unsetMatchColumn(indexes);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        indexes = new int[0];
+
+        noInitialCrset.unsetMatchColumn(indexes);
+
+        indexes = new int[] { 1, 2, 3 };
+        try {
+            noInitialCrset.unsetMatchColumn(indexes);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+
+        try {
+            noInitialCrset.unsetMatchColumn(-2);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+
+        try {
+            noInitialCrset.unsetMatchColumn(0);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+
+        noInitialCrset.setMatchColumn(1);
+        try {
+            noInitialCrset.unsetMatchColumn(2);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+
+        noInitialCrset.unsetMatchColumn(1);
+
+        try {
+            noInitialCrset.getMatchColumnIndexes();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Set Match columns before getting them
+        }
+
+        noInitialCrset.setMatchColumn(new int[] { 1, 2, 3 });
+
+        try {
+            noInitialCrset.unsetMatchColumn(2);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+        try {
+            noInitialCrset.unsetMatchColumn(3);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+
+        noInitialCrset.unsetMatchColumn(1);
+
+        try {
+            noInitialCrset.getMatchColumnIndexes();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Set Match columns before getting them
+        }
+
+        noInitialCrset.setMatchColumn(4);
+        indexes = noInitialCrset.getMatchColumnIndexes();
+        assertNotNull(indexes);
+        assertEquals(13, indexes.length);
+        assertEquals(4, indexes[0]);
+        assertEquals(2, indexes[1]);
+        assertEquals(3, indexes[2]);
+        for (int i = 3; i < indexes.length; i++) {
+            assertEquals(-1, indexes[i]);
+        }
+
+        try {
+            noInitialCrset.unsetMatchColumn(2);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+        try {
+            noInitialCrset.unsetMatchColumn(3);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+
+        noInitialCrset.setMatchColumn(new int[] { 5, 6 });
+        try {
+            noInitialCrset.unsetMatchColumn(2);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+        try {
+            noInitialCrset.unsetMatchColumn(3);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+        try {
+            noInitialCrset.unsetMatchColumn(4);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+        try {
+            noInitialCrset.unsetMatchColumn(6);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+
+        noInitialCrset.unsetMatchColumn(5);
+
+        try {
+            noInitialCrset.getMatchColumnIndexes();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Set Match columns before getting them
+        }
+
+        noInitialCrset.setMatchColumn(7);
+        indexes = noInitialCrset.getMatchColumnIndexes();
+        assertNotNull(indexes);
+        assertEquals(15, indexes.length);
+        assertEquals(7, indexes[0]);
+        assertEquals(6, indexes[1]);
+        assertEquals(4, indexes[2]);
+        assertEquals(2, indexes[3]);
+        assertEquals(3, indexes[4]);
+
+        for (int i = 6; i < indexes.length; i++) {
+            assertEquals(-1, indexes[i]);
+        }
+
+        noInitialCrset.unsetMatchColumn(new int[] { 7, 6 });
+        try {
+            noInitialCrset.getMatchColumnIndexes();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Set Match columns before getting them
+        }
+
+        noInitialCrset.setMatchColumn(new int[] { 7, 6 });
+        indexes = noInitialCrset.getMatchColumnIndexes();
+
+        assertNotNull(indexes);
+        assertEquals(17, indexes.length);
+        assertEquals(7, indexes[0]);
+        assertEquals(6, indexes[1]);
+        assertEquals(-1, indexes[2]);
+        assertEquals(-1, indexes[3]);
+        assertEquals(4, indexes[4]);
+        assertEquals(2, indexes[5]);
+        assertEquals(3, indexes[6]);
+    }
+
+    public void testUnsetMatchColumn_Index() throws Exception {
+        int[] indexes = null;
+        try {
+            crset.unsetMatchColumn(indexes);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        indexes = new int[0];
+
+        crset.unsetMatchColumn(indexes);
+
+        indexes = new int[] { 1, 2, 3 };
+        try {
+            crset.unsetMatchColumn(indexes);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+
+        try {
+            crset.unsetMatchColumn(-2);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+
+        try {
+            crset.unsetMatchColumn(0);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+
+        crset.setMatchColumn(1);
+        try {
+            crset.unsetMatchColumn(2);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+
+        crset.unsetMatchColumn(1);
+
+        try {
+            indexes = crset.getMatchColumnIndexes();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Set Match columns before getting them
+        }
+
+        crset.setMatchColumn(new int[] { 1, 2, 3 });
+
+        try {
+            crset.unsetMatchColumn(2);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+        try {
+            crset.unsetMatchColumn(3);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+
+        crset.unsetMatchColumn(1);
+
+        try {
+            crset.getMatchColumnIndexes();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Set Match columns before getting them
+        }
+
+        crset.setMatchColumn(4);
+        indexes = crset.getMatchColumnIndexes();
+        assertNotNull(indexes);
+        assertEquals(13, indexes.length);
+        assertEquals(4, indexes[0]);
+        assertEquals(2, indexes[1]);
+        assertEquals(3, indexes[2]);
+        for (int i = 3; i < indexes.length; i++) {
+            assertEquals(-1, indexes[i]);
+        }
+
+        try {
+            crset.unsetMatchColumn(2);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+        try {
+            crset.unsetMatchColumn(3);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+
+        crset.setMatchColumn(new int[] { 5, 6 });
+        try {
+            crset.unsetMatchColumn(2);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+        try {
+            crset.unsetMatchColumn(3);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+        try {
+            crset.unsetMatchColumn(4);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+        try {
+            crset.unsetMatchColumn(6);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+
+        crset.unsetMatchColumn(5);
+
+        try {
+            crset.getMatchColumnIndexes();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Set Match columns before getting them
+        }
+
+        crset.setMatchColumn(7);
+        indexes = crset.getMatchColumnIndexes();
+        assertNotNull(indexes);
+        assertEquals(15, indexes.length);
+        assertEquals(7, indexes[0]);
+        assertEquals(6, indexes[1]);
+        assertEquals(4, indexes[2]);
+        assertEquals(2, indexes[3]);
+        assertEquals(3, indexes[4]);
+
+        for (int i = 6; i < indexes.length; i++) {
+            assertEquals(-1, indexes[i]);
+        }
+
+        crset.unsetMatchColumn(new int[] { 7, 6 });
+        try {
+            crset.getMatchColumnIndexes();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Set Match columns before getting them
+        }
+
+        crset.setMatchColumn(new int[] { 7, 6 });
+        indexes = crset.getMatchColumnIndexes();
+
+        assertNotNull(indexes);
+        assertEquals(17, indexes.length);
+        assertEquals(7, indexes[0]);
+        assertEquals(6, indexes[1]);
+        assertEquals(-1, indexes[2]);
+        assertEquals(-1, indexes[3]);
+        assertEquals(4, indexes[4]);
+        assertEquals(2, indexes[5]);
+        assertEquals(3, indexes[6]);
+
+        crset.unsetMatchColumn(new int[] { 7, 6, -1, -1, 4, 2, 3 });
+        try {
+            indexes = crset.getMatchColumnIndexes();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Set Match columns before getting them
+        }
+    }
+
+    public void testUnsetMatchColumn_Name_Unpopulate() throws Exception {
+        String[] names = null;
+        try {
+            noInitialCrset.unsetMatchColumn(names);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        names = new String[0];
+
+        noInitialCrset.unsetMatchColumn(names);
+
+        names = new String[] { "1", "2", "3" };
+        try {
+            noInitialCrset.unsetMatchColumn(names);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+
+        /*
+         * TODO behavior of unsetMatchColumn(String) is not the same with
+         * unsetMatchColumn(int) in RI, we think throw SQLException is more
+         * reasonable
+         */
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            try {
+                noInitialCrset.unsetMatchColumn("");
+                fail("Should throw SQLException");
+            } catch (SQLException e) {
+                // expected, Columns being unset are not the same as set
+            }
+            try {
+                noInitialCrset.unsetMatchColumn("0");
+                fail("Should throw SQLException");
+            } catch (SQLException e) {
+                // expected, Columns being unset are not the same as set
+            }
+        } else {
+            try {
+                noInitialCrset.unsetMatchColumn("");
+                fail("Should throw NullPointerException");
+            } catch (NullPointerException e) {
+                // expected
+            }
+
+            try {
+                noInitialCrset.unsetMatchColumn("0");
+                fail("Should throw NullPointerException");
+            } catch (NullPointerException e) {
+                // expected
+            }
+
+        }
+
+        noInitialCrset.setMatchColumn("1");
+        try {
+            noInitialCrset.unsetMatchColumn("2");
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+
+        noInitialCrset.unsetMatchColumn("1");
+
+        try {
+            noInitialCrset.getMatchColumnNames();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Set Match columns before getting them
+        }
+
+        noInitialCrset.setMatchColumn(new String[] { "1", "2", "3" });
+
+        try {
+            noInitialCrset.unsetMatchColumn("2");
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+        try {
+            noInitialCrset.unsetMatchColumn("3");
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+
+        noInitialCrset.unsetMatchColumn("1");
+
+        try {
+            noInitialCrset.getMatchColumnNames();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Set Match columns before getting them
+        }
+
+        noInitialCrset.setMatchColumn("4");
+        names = noInitialCrset.getMatchColumnNames();
+        assertNotNull(names);
+        assertEquals(13, names.length);
+        assertEquals("4", names[0]);
+        assertEquals("2", names[1]);
+        assertEquals("3", names[2]);
+        for (int i = 3; i < names.length; i++) {
+            assertNull(names[i]);
+        }
+
+        try {
+            noInitialCrset.unsetMatchColumn("2");
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+        try {
+            noInitialCrset.unsetMatchColumn("3");
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+
+        noInitialCrset.setMatchColumn(new String[] { "5", "6" });
+        try {
+            noInitialCrset.unsetMatchColumn("2");
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+        try {
+            noInitialCrset.unsetMatchColumn("3");
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+        try {
+            noInitialCrset.unsetMatchColumn("4");
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+        try {
+            noInitialCrset.unsetMatchColumn("6");
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+
+        noInitialCrset.unsetMatchColumn("5");
+
+        try {
+            noInitialCrset.getMatchColumnNames();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Set Match columns before getting them
+        }
+
+        noInitialCrset.setMatchColumn("7");
+        names = noInitialCrset.getMatchColumnNames();
+        assertNotNull(names);
+        assertEquals(15, names.length);
+        assertEquals("7", names[0]);
+        assertEquals("6", names[1]);
+        assertEquals("4", names[2]);
+        assertEquals("2", names[3]);
+        assertEquals("3", names[4]);
+
+        for (int i = 6; i < names.length; i++) {
+            assertNull(names[i]);
+        }
+
+        noInitialCrset.unsetMatchColumn(new String[] { "7", "6" });
+        try {
+            noInitialCrset.getMatchColumnNames();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Set Match columns before getting them
+        }
+
+        noInitialCrset.setMatchColumn(new String[] { "7", "6" });
+        names = noInitialCrset.getMatchColumnNames();
+
+        assertNotNull(names);
+        assertEquals(17, names.length);
+        assertEquals("7", names[0]);
+        assertEquals("6", names[1]);
+        assertNull(names[2]);
+        assertNull(names[3]);
+        assertEquals("4", names[4]);
+        assertEquals("2", names[5]);
+        assertEquals("3", names[6]);
+    }
+
+    public void testUnsetMatchColumn_Name() throws Exception {
+        String[] names = null;
+        try {
+            crset.unsetMatchColumn(names);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        names = new String[0];
+
+        crset.unsetMatchColumn(names);
+
+        names = new String[] { "1", "2", "3" };
+        try {
+            crset.unsetMatchColumn(names);
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+
+        /*
+         * TODO behavior of unsetMatchColumn(String) is not the same with
+         * unsetMatchColumn(int) in RI, we think throw SQLException is more
+         * reasonable
+         */
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            try {
+                crset.unsetMatchColumn("");
+                fail("Should throw SQLException");
+            } catch (SQLException e) {
+                // expected, Columns being unset are not the same as set
+            }
+            try {
+                crset.unsetMatchColumn("0");
+                fail("Should throw SQLException");
+            } catch (SQLException e) {
+                // expected, Columns being unset are not the same as set
+            }
+        } else {
+            try {
+                crset.unsetMatchColumn("");
+                fail("Should throw NullPointerException");
+            } catch (NullPointerException e) {
+                // expected
+            }
+
+            try {
+                crset.unsetMatchColumn("0");
+                fail("Should throw NullPointerException");
+            } catch (NullPointerException e) {
+                // expected
+            }
+
+        }
+
+        crset.setMatchColumn("1");
+        try {
+            crset.unsetMatchColumn("2");
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+
+        crset.unsetMatchColumn("1");
+
+        try {
+            crset.getMatchColumnNames();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Set Match columns before getting them
+        }
+
+        crset.setMatchColumn(new String[] { "1", "2", "3" });
+
+        try {
+            crset.unsetMatchColumn("2");
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+        try {
+            crset.unsetMatchColumn("3");
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+
+        crset.unsetMatchColumn("1");
+
+        try {
+            crset.getMatchColumnNames();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Set Match columns before getting them
+        }
+
+        crset.setMatchColumn("4");
+        names = crset.getMatchColumnNames();
+        assertNotNull(names);
+        assertEquals(13, names.length);
+        assertEquals("4", names[0]);
+        assertEquals("2", names[1]);
+        assertEquals("3", names[2]);
+        for (int i = 3; i < names.length; i++) {
+            assertNull(names[i]);
+        }
+
+        try {
+            crset.unsetMatchColumn("2");
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+        try {
+            crset.unsetMatchColumn("3");
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+
+        crset.setMatchColumn(new String[] { "5", "6" });
+        try {
+            crset.unsetMatchColumn("2");
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+        try {
+            crset.unsetMatchColumn("3");
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+        try {
+            crset.unsetMatchColumn("4");
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+        try {
+            crset.unsetMatchColumn("6");
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+
+        crset.unsetMatchColumn("5");
+
+        try {
+            crset.getMatchColumnNames();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Set Match columns before getting them
+        }
+
+        crset.setMatchColumn("7");
+        names = crset.getMatchColumnNames();
+        assertNotNull(names);
+        assertEquals(15, names.length);
+        assertEquals("7", names[0]);
+        assertEquals("6", names[1]);
+        assertEquals("4", names[2]);
+        assertEquals("2", names[3]);
+        assertEquals("3", names[4]);
+
+        for (int i = 6; i < names.length; i++) {
+            assertNull(names[i]);
+        }
+
+        crset.unsetMatchColumn(new String[] { "7", "6" });
+        try {
+            crset.getMatchColumnNames();
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Set Match columns before getting them
+        }
+
+        crset.setMatchColumn(new String[] { "7", "6" });
+        names = crset.getMatchColumnNames();
+
+        assertNotNull(names);
+        assertEquals(17, names.length);
+        assertEquals("7", names[0]);
+        assertEquals("6", names[1]);
+        assertNull(names[2]);
+        assertNull(names[3]);
+        assertEquals("4", names[4]);
+        assertEquals("2", names[5]);
+        assertEquals("3", names[6]);
+
+        crset = newNoInitialInstance();
+
+        // test whether column name is case sensitive
+        crset.setMatchColumn("TesT");
+        assertEquals("TesT", crset.getMatchColumnNames()[0]);
+        try {
+            crset.unsetMatchColumn("test");
+            fail("Should throw SQLException");
+        } catch (SQLException e) {
+            // expected, Columns being unset are not the same as set
+        }
+    }
 }

Added: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetTransactionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetTransactionTest.java?rev=636705&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetTransactionTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetTransactionTest.java Thu Mar 13 03:44:18 2008
@@ -0,0 +1,433 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.harmony.sql.tests.internal.rowset;
+
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.util.Arrays;
+import java.util.HashMap;
+
+import javax.sql.rowset.CachedRowSet;
+import javax.sql.rowset.spi.SyncProviderException;
+
+public class CachedRowSetTransactionTest extends CachedRowSetTestCase {
+
+    public void testRelease() throws Exception {
+        noInitialCrset = newNoInitialInstance();
+        noInitialCrset.release();
+
+        crset.setCommand("testCommand");
+        assertEquals(DERBY_URL, crset.getUrl());
+        crset.setDataSourceName("testDataSourceName");
+        assertNull(crset.getUrl());
+        crset.setFetchDirection(ResultSet.FETCH_REVERSE);
+        crset.setMaxFieldSize(100);
+        crset.setMaxRows(10);
+        crset.setPageSize(10);
+        crset.setPassword("passwo");
+        crset.setQueryTimeout(100);
+        crset.setTableName("testTable");
+        crset.setTransactionIsolation(ResultSet.HOLD_CURSORS_OVER_COMMIT);
+        crset.setType(ResultSet.TYPE_SCROLL_SENSITIVE);
+        HashMap<String, Class<?>> map = new HashMap<String, Class<?>>();
+        crset.setTypeMap(map);
+        crset.setUsername("testUserName");
+        crset.setEscapeProcessing(false);
+        crset.setKeyColumns(new int[] { 1 });
+
+        assertTrue(crset.absolute(1));
+        crset.updateString(2, "update2");
+
+        crset.release();
+
+        assertEquals("testCommand", crset.getCommand());
+        assertEquals("testDataSourceName", crset.getDataSourceName());
+        assertEquals(ResultSet.FETCH_REVERSE, crset.getFetchDirection());
+        assertEquals(100, crset.getMaxFieldSize());
+        assertEquals(10, crset.getMaxRows());
+        assertEquals(10, crset.getPageSize());
+        assertEquals("passwo", crset.getPassword());
+        assertEquals(100, crset.getQueryTimeout());
+        assertEquals("testTable", crset.getTableName());
+        assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, crset
+                .getTransactionIsolation());
+        assertEquals(ResultSet.TYPE_SCROLL_SENSITIVE, crset.getType());
+        assertEquals(map, crset.getTypeMap());
+        assertEquals("testUserName", crset.getUsername());
+        assertFalse(crset.getEscapeProcessing());
+        assertTrue(Arrays.equals(new int[] { 1 }, crset.getKeyColumns()));
+
+        assertFalse(crset.next());
+        assertEquals(0, crset.size());
+
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        crset.populate(rs);
+
+        assertTrue(crset.first());
+        int index = 1;
+        while (crset.next()) {
+            index++;
+            assertEquals(index, crset.getInt(1));
+        }
+        assertEquals(4, index);
+    }
+
+    public void testClose() throws Exception {
+        noInitialCrset = newNoInitialInstance();
+        noInitialCrset.close();
+
+        crset.setCommand("testCommand");
+        assertEquals(DERBY_URL, crset.getUrl());
+        crset.setDataSourceName("testDataSourceName");
+        assertNull(crset.getUrl());
+        crset.setFetchDirection(ResultSet.FETCH_REVERSE);
+        crset.setMaxFieldSize(100);
+        crset.setMaxRows(10);
+        crset.setPageSize(10);
+        crset.setPassword("passwo");
+        crset.setQueryTimeout(100);
+        crset.setTableName("testTable");
+        crset.setTransactionIsolation(ResultSet.HOLD_CURSORS_OVER_COMMIT);
+        crset.setType(ResultSet.TYPE_SCROLL_SENSITIVE);
+        HashMap<String, Class<?>> map = new HashMap<String, Class<?>>();
+        crset.setTypeMap(map);
+        crset.setUsername("testUserName");
+        crset.setEscapeProcessing(false);
+        crset.setKeyColumns(new int[] { 1 });
+        ResultSetMetaData rsmd = crset.getMetaData();
+
+        crset.close();
+
+        assertEquals(rsmd, crset.getMetaData());
+        assertEquals("testCommand", crset.getCommand());
+        assertEquals(ResultSet.CONCUR_UPDATABLE, crset.getConcurrency());
+        assertEquals("testDataSourceName", crset.getDataSourceName());
+        assertEquals(ResultSet.FETCH_REVERSE, crset.getFetchDirection());
+        assertEquals(0, crset.getFetchSize());
+        assertEquals(0, crset.getMaxFieldSize());
+        assertEquals(0, crset.getMaxRows());
+        assertEquals(10, crset.getPageSize());
+        assertEquals("passwo", crset.getPassword());
+        assertEquals(0, crset.getQueryTimeout());
+        assertEquals("testTable", crset.getTableName());
+        assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, crset
+                .getTransactionIsolation());
+        assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE, crset.getType());
+        assertNull(crset.getTypeMap());
+        assertNull(crset.getUrl());
+        assertEquals("testUserName", crset.getUsername());
+        assertTrue(crset.getEscapeProcessing());
+        assertTrue(Arrays.equals(new int[] { 1 }, crset.getKeyColumns()));
+    }
+
+    public void testCommit() throws Exception {
+        noInitialCrset = newNoInitialInstance();
+        try {
+            noInitialCrset.commit();
+            fail("should throw exception");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        noInitialCrset.populate(rs);
+
+        try {
+            noInitialCrset.commit();
+            fail("should throw exception");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        /*
+         * test when call execute()
+         */
+        noInitialCrset = newNoInitialInstance();
+        noInitialCrset.setCommand("SELECT * FROM USER_INFO");
+        noInitialCrset.setUrl(DERBY_URL);
+        noInitialCrset.execute();
+        try {
+            noInitialCrset.commit();
+            fail("should throw exception");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        assertTrue(CachedRowSet.COMMIT_ON_ACCEPT_CHANGES);
+        noInitialCrset = newNoInitialInstance();
+        noInitialCrset.setCommand("SELECT * FROM USER_INFO");
+        assertTrue(conn.getAutoCommit());
+        noInitialCrset.execute(conn);
+        noInitialCrset.commit();
+
+        /*
+         * test when call acceptChanges()
+         */
+        noInitialCrset = newNoInitialInstance();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        noInitialCrset.populate(rs);
+        noInitialCrset.setUrl(DERBY_URL);
+
+        noInitialCrset.acceptChanges();
+        try {
+            noInitialCrset.commit();
+            fail("should throw exception");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        noInitialCrset = newNoInitialInstance();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        noInitialCrset.populate(rs);
+        noInitialCrset.acceptChanges(conn);
+        noInitialCrset.commit();
+    }
+
+    public void testRollback() throws Exception {
+        noInitialCrset = newNoInitialInstance();
+        try {
+            noInitialCrset.rollback();
+            fail("should throw exception");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        noInitialCrset.populate(rs);
+
+        try {
+            noInitialCrset.rollback();
+            fail("should throw exception");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        /*
+         * test when call execute()
+         */
+        noInitialCrset = newNoInitialInstance();
+        noInitialCrset.setCommand("SELECT * FROM USER_INFO");
+        noInitialCrset.setUrl(DERBY_URL);
+        noInitialCrset.execute();
+        try {
+            noInitialCrset.rollback();
+            fail("should throw exception");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        assertTrue(CachedRowSet.COMMIT_ON_ACCEPT_CHANGES);
+        noInitialCrset = newNoInitialInstance();
+        noInitialCrset.setCommand("SELECT * FROM USER_INFO");
+        assertTrue(conn.getAutoCommit());
+        noInitialCrset.execute(conn);
+        noInitialCrset.rollback();
+
+        /*
+         * test when call acceptChanges()
+         */
+        noInitialCrset = newNoInitialInstance();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        noInitialCrset.populate(rs);
+        noInitialCrset.setUrl(DERBY_URL);
+
+        noInitialCrset.acceptChanges();
+        try {
+            noInitialCrset.rollback();
+            fail("should throw exception");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        noInitialCrset = newNoInitialInstance();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        noInitialCrset.populate(rs);
+        noInitialCrset.acceptChanges(conn);
+        noInitialCrset.rollback();
+    }
+
+    public void testAcceptChanges_UpdateException() throws Exception {
+        assertTrue(crset.absolute(3));
+        crset.updateString(2, "update3");
+        crset.updateRow();
+
+        assertTrue(crset.next());
+        crset.updateString(2, "abcccccccccccccc"); // out of range
+        crset.updateRow();
+
+        try {
+            crset.acceptChanges(conn);
+            fail("should throw exception");
+        } catch (SyncProviderException e) {
+            // expected
+        }
+
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        int index = 0;
+        while (rs.next()) {
+            index++;
+            if (index == 3) {
+                assertEquals("update3", rs.getString(2));
+            }
+        }
+        assertEquals(4, index);
+
+        assertFalse(conn.getAutoCommit());
+        crset.rollback();
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        index = 0;
+        while (rs.next()) {
+            index++;
+            if (index == 3) {
+                assertEquals("test3", rs.getString(2));
+            }
+        }
+        assertEquals(4, index);
+
+        crset.beforeFirst();
+        index = 0;
+        while (crset.next()) {
+            index++;
+            if (index == 3) {
+                assertEquals("update3", crset.getString(2));
+            } else if (index == 4) {
+                assertEquals("abcccccccccccccc", crset.getString(2));
+            }
+        }
+        assertEquals(4, index);
+
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            try {
+                crset.acceptChanges();
+                fail("should throw exception");
+            } catch (SyncProviderException e) {
+                // expected
+            }
+
+            // check db
+            rs = st.executeQuery("SELECT * FROM USER_INFO");
+            index = 0;
+            while (rs.next()) {
+                index++;
+                if (index == 3) {
+                    assertEquals("test3", rs.getString(2));
+                }
+            }
+            assertEquals(4, index);
+        }
+    }
+
+    public void testAcceptChanges_InsertException() throws Exception {
+        assertTrue(crset.absolute(4));
+        crset.updateString(2, "update4");
+        crset.updateRow();
+
+        /*
+         * Insert two rows. The second would throw exception
+         */
+        crset.moveToInsertRow();
+        crset.updateInt(1, 5);
+        crset.updateString(2, "insert5");
+        crset.insertRow();
+        crset.updateInt(1, 6);
+        crset.updateString(2, "insert66666666666"); // out of range
+        crset.insertRow();
+        crset.moveToCurrentRow();
+
+        assertTrue(conn.getAutoCommit());
+        try {
+            crset.acceptChanges(conn);
+            fail("should throw exception");
+        } catch (SyncProviderException e) {
+            // expected
+        }
+        assertFalse(conn.getAutoCommit());
+
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        int index = 0;
+        while (rs.next()) {
+            index++;
+            if (index == 4) {
+                assertEquals("update4", rs.getString(2));
+            } else if (index == 5) {
+                assertEquals("insert5", rs.getString(2));
+            }
+        }
+        assertEquals(5, index);
+
+        crset.rollback();
+        assertFalse(conn.getAutoCommit());
+        rs = st.executeQuery("SELECT * FROM USER_INFO");
+        index = 0;
+        while (rs.next()) {
+            index++;
+            if (index == 4) {
+                assertEquals("test4", rs.getString(2));
+            }
+        }
+        assertEquals(4, index);
+
+        crset.beforeFirst();
+        index = 0;
+
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            while (crset.next()) {
+                index++;
+                if (index == 4) {
+                    assertEquals("update4", crset.getString(2));
+                } else if (index == 5) {
+                    assertEquals("insert5", crset.getString(2));
+                } else if (index == 6) {
+                    assertEquals("insert66666666666", crset.getString(2));
+                }
+            }
+        } else {
+            while (crset.next()) {
+                index++;
+                if (index == 4) {
+                    assertEquals("update4", crset.getString(2));
+                } else if (index == 5) {
+                    assertEquals("insert66666666666", crset.getString(2));
+                } else if (index == 6) {
+                    assertEquals("insert5", crset.getString(2));
+                }
+            }
+        }
+        assertEquals(6, index);
+
+        if ("true".equals(System.getProperty("Testing Harmony"))) {
+            try {
+                crset.acceptChanges();
+                fail("should throw exception");
+            } catch (SyncProviderException e) {
+                // expected
+            }
+
+            // check db
+            rs = st.executeQuery("SELECT * FROM USER_INFO");
+            index = 0;
+            while (rs.next()) {
+                index++;
+                if (index == 4) {
+                    assertEquals("test4", rs.getString(2));
+                }
+            }
+            assertEquals(4, index);
+        }
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetTransactionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message