You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by qi...@apache.org on 2008/06/06 04:04:38 UTC
svn commit: r663801 - in
/harmony/enhanced/classlib/branches/java6/modules/sql/src:
main/java/org/apache/harmony/sql/internal/rowset/SyncResolverImpl.java
test/java/org/apache/harmony/sql/tests/internal/rowset/SyncResolverTest.java
Author: qiuxx
Date: Thu Jun 5 19:04:37 2008
New Revision: 663801
URL: http://svn.apache.org/viewvc?rev=663801&view=rev
Log:
Apply for HARMONY-5864, ( [java6][classlib][sql][rowset] - implements java6 new API in SyncResolver)
Modified:
harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/SyncResolverImpl.java
harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/SyncResolverTest.java
Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/SyncResolverImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/SyncResolverImpl.java?rev=663801&r1=663800&r2=663801&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/SyncResolverImpl.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/SyncResolverImpl.java Thu Jun 5 19:04:37 2008
@@ -29,6 +29,7 @@
import java.sql.ResultSetMetaData;
import java.sql.RowId;
import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Statement;
@@ -42,7 +43,6 @@
import javax.sql.rowset.BaseRowSet;
import javax.sql.rowset.spi.SyncResolver;
-import org.apache.harmony.luni.util.NotImplementedException;
import org.apache.harmony.sql.internal.nls.Messages;
/**
@@ -141,14 +141,13 @@
}
public void setResolvedValue(int index, Object obj) throws SQLException {
- // TODO not yet implemented
- throw new NotImplementedException();
-
+ // Follow RI throw SQLException
+ throw new SQLException();
}
public void setResolvedValue(String columnName, Object obj)
throws SQLException {
- setResolvedValue(getIndexByName(columnName), obj);
+ // Follow RI do thing
}
public int getRow() throws SQLException {
@@ -718,283 +717,234 @@
throw new UnsupportedOperationException();
}
- public int getHoldability() throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
- return 0;
+ public int getHoldability() throws SQLException {
+ throw new UnsupportedOperationException();
}
- public Reader getNCharacterStream(int columnIndex) throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
- return null;
+ public Reader getNCharacterStream(int columnIndex) throws SQLException {
+ throw new UnsupportedOperationException();
}
- public Reader getNCharacterStream(String columnLabel) throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
- return null;
+ public Reader getNCharacterStream(String columnLabel) throws SQLException {
+ throw new UnsupportedOperationException();
}
- public NClob getNClob(int columnIndex) throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
- return null;
+ public NClob getNClob(int columnIndex) throws SQLException {
+ throw new UnsupportedOperationException();
}
- public NClob getNClob(String columnLabel) throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
- return null;
+ public NClob getNClob(String columnLabel) throws SQLException {
+ throw new UnsupportedOperationException();
}
- public String getNString(int columnIndex) throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
- return null;
+ public String getNString(int columnIndex) throws SQLException {
+ throw new UnsupportedOperationException();
}
- public String getNString(String columnLabel) throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
- return null;
+ public String getNString(String columnLabel) throws SQLException {
+ throw new UnsupportedOperationException();
}
- public RowId getRowId(int columnIndex) throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
- return null;
+ public RowId getRowId(int columnIndex) throws SQLException {
+ throw new UnsupportedOperationException();
}
- public RowId getRowId(String columnLabel) throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
- return null;
+ public RowId getRowId(String columnLabel) throws SQLException {
+ throw new UnsupportedOperationException();
}
- public SQLXML getSQLXML(int columnIndex) throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
- return null;
+ public SQLXML getSQLXML(int columnIndex) throws SQLException {
+ throw new UnsupportedOperationException();
}
- public SQLXML getSQLXML(String columnLabel) throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
- return null;
+ public SQLXML getSQLXML(String columnLabel) throws SQLException {
+ throw new UnsupportedOperationException();
}
- public boolean isClosed() throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
- return false;
+ public boolean isClosed() throws SQLException {
+ throw new UnsupportedOperationException();
}
public void updateAsciiStream(int columnIndex, InputStream x, long length)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ throws SQLException {
+ // Follow RI. Do nothing.
}
public void updateAsciiStream(String columnLabel, InputStream x, long length)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ throws SQLException {
+ // Follow RI. Do nothing.
}
public void updateAsciiStream(int columnIndex, InputStream x)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ throws SQLException {
+ throw new SQLFeatureNotSupportedException();
}
public void updateAsciiStream(String columnLabel, InputStream x)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ throws SQLException {
+ // Follow RI. Do nothing.
}
public void updateBinaryStream(int columnIndex, InputStream x, long length)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ throws SQLException {
+ // Follow RI. Do nothing.
}
public void updateBinaryStream(String columnLabel, InputStream x,
- long length) throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ long length) throws SQLException {
+ // Follow RI. Do nothing.
}
public void updateBinaryStream(int columnIndex, InputStream x)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ throws SQLException {
+ throw new SQLFeatureNotSupportedException();
}
public void updateBinaryStream(String columnLabel, InputStream x)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ throws SQLException {
+ throw new SQLFeatureNotSupportedException();
}
public void updateBlob(int columnIndex, InputStream inputStream, long length)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ throws SQLException {
+ throw new SQLFeatureNotSupportedException();
}
public void updateBlob(String columnLabel, InputStream inputStream,
- long length) throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ long length) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
}
public void updateBlob(int columnIndex, InputStream inputStream)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ throws SQLException {
+ throw new SQLFeatureNotSupportedException();
}
public void updateBlob(String columnLabel, InputStream inputStream)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ throws SQLException {
+ throw new SQLFeatureNotSupportedException();
}
public void updateCharacterStream(int columnIndex, Reader x, long length)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ throws SQLException {
+ throw new SQLFeatureNotSupportedException();
}
public void updateCharacterStream(String columnLabel, Reader reader,
- long length) throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ long length) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
}
public void updateCharacterStream(int columnIndex, Reader x)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ throws SQLException {
+ throw new SQLFeatureNotSupportedException();
}
public void updateCharacterStream(String columnLabel, Reader reader)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ throws SQLException {
+ throw new SQLFeatureNotSupportedException();
}
public void updateClob(int columnIndex, Reader reader, long length)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ throws SQLException {
+ throw new SQLFeatureNotSupportedException();
}
public void updateClob(String columnLabel, Reader reader, long length)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ throws SQLException {
+ throw new SQLFeatureNotSupportedException();
}
- public void updateClob(int columnIndex, Reader reader) throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ public void updateClob(int columnIndex, Reader reader) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
}
public void updateClob(String columnLabel, Reader reader)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ throws SQLException {
+ throw new SQLFeatureNotSupportedException();
}
public void updateNCharacterStream(int columnIndex, Reader x, long length)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ throws SQLException {
+ throw new UnsupportedOperationException();
}
public void updateNCharacterStream(String columnLabel, Reader reader,
- long length) throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ long length) throws SQLException {
+ throw new UnsupportedOperationException();
}
public void updateNCharacterStream(int columnIndex, Reader x)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ throws SQLException {
+ throw new SQLFeatureNotSupportedException();
}
public void updateNCharacterStream(String columnLabel, Reader reader)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ throws SQLException {
+ throw new SQLFeatureNotSupportedException();
}
- public void updateNClob(int columnIndex, NClob clob) throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ public void updateNClob(int columnIndex, NClob nClob) throws SQLException {
+ throw new UnsupportedOperationException();
}
- public void updateNClob(String columnLabel, NClob clob) throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ public void updateNClob(String columnLabel, NClob nClob)
+ throws SQLException {
+ throw new UnsupportedOperationException();
}
public void updateNClob(int columnIndex, Reader reader, long length)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ throws SQLException {
+ throw new SQLFeatureNotSupportedException();
}
public void updateNClob(String columnLabel, Reader reader, long length)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ throws SQLException {
+ throw new SQLFeatureNotSupportedException();
}
- public void updateNClob(int columnIndex, Reader reader) throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ public void updateNClob(int columnIndex, Reader reader) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
}
public void updateNClob(String columnLabel, Reader reader)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ throws SQLException {
+ throw new SQLFeatureNotSupportedException();
}
- public void updateNString(int columnIndex, String string)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ public void updateNString(int columnIndex, String nString)
+ throws SQLException {
+ throw new UnsupportedOperationException();
}
- public void updateNString(String columnLabel, String string)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ public void updateNString(String columnLabel, String nString)
+ throws SQLException {
+ throw new UnsupportedOperationException();
}
- public void updateRowId(int columnIndex, RowId x) throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ public void updateRowId(int columnIndex, RowId x) throws SQLException {
+ throw new UnsupportedOperationException();
}
- public void updateRowId(String columnLabel, RowId x) throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ public void updateRowId(String columnLabel, RowId x) throws SQLException {
+ throw new UnsupportedOperationException();
}
public void updateSQLXML(int columnIndex, SQLXML xmlObject)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ throws SQLException {
+ throw new UnsupportedOperationException();
}
public void updateSQLXML(String columnLabel, SQLXML xmlObject)
- throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
-
+ throws SQLException {
+ throw new UnsupportedOperationException();
}
- public boolean isWrapperFor(Class<?> iface) throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
+ public boolean isWrapperFor(Class<?> iface) throws SQLException {
return false;
}
- public <T> T unwrap(Class<T> iface) throws SQLException, NotImplementedException {
- // TODO Auto-generated method stub
+ public <T> T unwrap(Class<T> iface) throws SQLException {
return null;
}
Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/SyncResolverTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/SyncResolverTest.java?rev=663801&r1=663800&r2=663801&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/SyncResolverTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/SyncResolverTest.java Thu Jun 5 19:04:37 2008
@@ -17,7 +17,15 @@
package org.apache.harmony.sql.tests.internal.rowset;
+import java.io.StringBufferInputStream;
+import java.io.StringReader;
+import java.math.BigDecimal;
+import java.sql.Date;
+import java.sql.PreparedStatement;
import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.sql.Time;
+import java.sql.Timestamp;
import javax.sql.RowSetMetaData;
import javax.sql.rowset.CachedRowSet;
@@ -27,6 +35,9 @@
import org.apache.harmony.sql.internal.rowset.CachedRow;
import org.apache.harmony.sql.internal.rowset.SyncResolverImpl;
+import org.apache.harmony.sql.tests.javax.sql.rowset.MockBlob;
+import org.apache.harmony.sql.tests.javax.sql.rowset.MockClob;
+import org.apache.harmony.sql.tests.javax.sql.rowset.MockNClob;
public class SyncResolverTest extends CachedRowSetTestCase {
@Override
@@ -265,6 +276,922 @@
} catch (UnsupportedOperationException e) {
// expected
}
+
+ try {
+ resolver.getHoldability();
+ fail("Should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ resolver.getNCharacterStream(100);
+ fail("Should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ resolver.getNClob(100);
+ fail("Should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ resolver.getNString(100);
+ fail("Should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ resolver.getRowId(100);
+ fail("Should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ resolver.getSQLXML(100);
+ fail("Should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ resolver.isClosed();
+ fail("Should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ resolver.updateAsciiStream(100, null, 100L);
+ resolver.updateAsciiStream("not exist", null, 100L);
+
+ try {
+ resolver.updateAsciiStream(100, null);
+ fail("Should throw SQLFeatureNotSupportedException");
+ } catch (SQLFeatureNotSupportedException e) {
+ // expected
+ }
+
+ resolver.updateBinaryStream(100, null, 100L);
+ resolver.updateBinaryStream("not exist", null, 100L);
+
+ try {
+ resolver.updateBinaryStream(100, null);
+ fail("Should throw SQLFeatureNotSupportedException");
+ } catch (SQLFeatureNotSupportedException e) {
+ // expected
+ }
+
+ try {
+ resolver.updateBlob(100, null, 100L);
+ fail("Should throw SQLFeatureNotSupportedException");
+ } catch (SQLFeatureNotSupportedException e) {
+ // expected
+ }
+
+ try {
+ resolver.updateBlob(100, new StringBufferInputStream("test"));
+ fail("Should throw SQLFeatureNotSupportedException");
+ } catch (SQLFeatureNotSupportedException e) {
+ // expected
+ }
+ try {
+ resolver.updateCharacterStream(100, null, 100L);
+ fail("Should throw SQLFeatureNotSupportedException");
+ } catch (SQLFeatureNotSupportedException e) {
+ // expected
+ }
+ try {
+ resolver.updateCharacterStream("not", null, 100L);
+ fail("Should throw SQLFeatureNotSupportedException");
+ } catch (SQLFeatureNotSupportedException e) {
+ // expected
+ }
+ try {
+ resolver.updateCharacterStream(100, null, 100);
+ fail("Should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateCharacterStream("not", null, 100);
+ fail("Should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ resolver.updateCharacterStream(100, null);
+ fail("Should throw SQLFeatureNotSupportedException");
+ } catch (SQLFeatureNotSupportedException e) {
+ // expected
+ }
+ try {
+ resolver.updateCharacterStream("not", null);
+ fail("Should throw SQLFeatureNotSupportedException");
+ } catch (SQLFeatureNotSupportedException e) {
+ // expected
+ }
+
+ try {
+ resolver.updateClob(100, null, 100L);
+ fail("Should throw SQLFeatureNotSupportedException");
+ } catch (SQLFeatureNotSupportedException e) {
+ // expected
+ }
+ try {
+ resolver.updateClob("not", null, 100L);
+ fail("Should throw SQLFeatureNotSupportedException");
+ } catch (SQLFeatureNotSupportedException e) {
+ // expected
+ }
+
+ try {
+ resolver.updateClob(100, new StringReader("test"));
+ fail("Should throw SQLFeatureNotSupportedException");
+ } catch (SQLFeatureNotSupportedException e) {
+ // expected
+ }
+ try {
+ resolver.updateClob("not", new StringReader("test"));
+ fail("Should throw SQLFeatureNotSupportedException");
+ } catch (SQLFeatureNotSupportedException e) {
+ // expected
+ }
+
+ try {
+ resolver.updateNCharacterStream(100, null, 100L);
+ fail("Should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateNCharacterStream("not", null, 100L);
+ fail("Should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ resolver.updateNCharacterStream(100, null);
+ fail("Should throw SQLFeatureNotSupportedException");
+ } catch (SQLFeatureNotSupportedException e) {
+ // expected
+ }
+ try {
+ resolver.updateNCharacterStream("not", null);
+ fail("Should throw SQLFeatureNotSupportedException");
+ } catch (SQLFeatureNotSupportedException e) {
+ // expected
+ }
+
+ try {
+ resolver.updateNClob(2, new StringReader("readstr"));
+ fail("should throw SQLFeatureNotSupportedException");
+ } catch (SQLFeatureNotSupportedException e) {
+ // expected
+ }
+ try {
+ resolver.updateNClob("not", new StringReader("readstr"));
+ fail("should throw SQLFeatureNotSupportedException");
+ } catch (SQLFeatureNotSupportedException e) {
+ // expected
+ }
+ try {
+ resolver.updateNClob(100, new StringReader("readstr"), 1000L);
+ fail("should throw SQLFeatureNotSupportedException");
+ } catch (SQLFeatureNotSupportedException e) {
+ // expected
+ }
+ try {
+ resolver.updateNClob("not", new StringReader("readstr"), 1000L);
+ fail("should throw SQLFeatureNotSupportedException");
+ } catch (SQLFeatureNotSupportedException e) {
+ // expected
+ }
+
+ try {
+ resolver.updateNString(100, "test");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateNString("not", "test");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ resolver.updateRowId(100, null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateRowId("not", null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ resolver.updateSQLXML(100, null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateSQLXML("not", null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ resolver.afterLast();
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.beforeFirst();
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.first();
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getArray("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getArray(100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getAsciiStream("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getAsciiStream(100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getBigDecimal(100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getBigDecimal("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getBigDecimal(100, 100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getBigDecimal("not", 100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getBinaryStream(100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getBinaryStream("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getBlob(100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getBlob("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getBoolean(100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getBoolean("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getByte(100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getByte("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getBytes(100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getBytes("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ // //////
+ try {
+ resolver.getCharacterStream(100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getCharacterStream("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getClob(100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getClob("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getDate(100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getDate("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getDate(100, null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getDate("not", null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getDouble(100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getDouble("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getFloat(100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getFloat("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getInt(100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getInt("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getLong(100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getLong("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getNCharacterStream("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getNClob("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getNString("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getObject("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getObject(100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getObject("not", null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getObject(100, null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getRef("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getRef(100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getRowId("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getSQLXML("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getShort("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getShort(100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getString("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getTime(100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getTime("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getTime(100, null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getTime("not", null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getTimestamp(100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getTimestamp("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getTimestamp(100, null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getTimestamp("not", null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getURL(100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getURL("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getUnicodeStream(100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.getUnicodeStream("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.last();
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ resolver.updateArray(100, null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateArray("not", null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ resolver.updateAsciiStream("not", null);
+ try {
+ resolver.updateAsciiStream("not", null, 100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateAsciiStream(100, null, 100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateBigDecimal(100, null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateBigDecimal("not", null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateBinaryStream("not", null);
+ fail("should throw SQLFeatureNotSupportedException");
+ } catch (SQLFeatureNotSupportedException e) {
+ // expected
+ }
+ try {
+ resolver.updateBinaryStream("not", null, 100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateBinaryStream(100, null, 100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateBlob("not", new StringBufferInputStream("test"));
+ fail("should throw SQLFeatureNotSupportedException");
+ } catch (SQLFeatureNotSupportedException e) {
+ // expected
+ }
+ try {
+ resolver.updateBlob("not", new StringBufferInputStream("test"),
+ 100L);
+ fail("should throw SQLFeatureNotSupportedException");
+ } catch (SQLFeatureNotSupportedException e) {
+ // expected
+ }
+ try {
+ resolver.updateBoolean(100, false);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateBoolean("not", false);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ byte aByte = 0;
+ try {
+ resolver.updateByte(100, aByte);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateByte("not", aByte);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateBytes(100, null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateBytes("not", null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateDate(100, null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateDate("not", null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateDouble(100, 0);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateDouble("not", 0);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateFloat(100, 0);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateFloat("not", 0);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateInt(100, 0);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateInt("not", 0);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateLong(100, 0);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateLong("not", 0);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateNull(100);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateNull("not");
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateObject(100, null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateObject("not", null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateObject(100, null, 10);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateObject("not", null, 10);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateRef(100, null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateRef("not", null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ short aShort = 0;
+ try {
+ resolver.updateShort(100, aShort);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateShort("not", aShort);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateString("not", null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateTime("not", null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateTime(100, null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateTimestamp("not", null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateTimestamp(100, null);
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ resolver.updateBlob(100, new MockBlob());
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateBlob("not", new MockBlob());
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateClob(100, new MockClob());
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateClob("not", new MockClob());
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateNClob(100, new MockNClob());
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ resolver.updateNClob("not", new MockNClob());
+ fail("should throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
}
public void testGetConflictValue() throws Exception {
@@ -390,4 +1317,528 @@
}
}
+
+ public void testAcceptChanges_InsertException_Two() throws Exception {
+ /*
+ * Insert a new row. The new row's primary key has existed. Therefore,
+ * it should throw SyncProviderException.
+ */
+ crset = newNoInitialInstance();
+ crset.populate(st.executeQuery("select * from USER_INFO"));
+ crset.setTableName("USER_INFO");
+ crset.moveToInsertRow();
+ crset.updateInt(1, 4); // The ID valued 4 has existed in db.
+ crset.updateString(2, "test5");
+ crset.updateBigDecimal(4, new BigDecimal(12));
+ crset.updateTimestamp(12, new Timestamp(874532105));
+ crset.insertRow();
+ crset.moveToCurrentRow();
+ try {
+ crset.acceptChanges(conn);
+ fail("should throw SyncProviderException");
+ } catch (SyncProviderException e) {
+ SyncResolver resolver = e.getSyncResolver();
+ assertEquals(0, resolver.getRow());
+ assertTrue(resolver.nextConflict());
+ assertEquals(1, resolver.getRow());
+ assertEquals(SyncResolver.INSERT_ROW_CONFLICT, resolver.getStatus());
+ for (int i = 1; i <= crset.getMetaData().getColumnCount(); i++) {
+ assertNull(resolver.getConflictValue(i));
+ try {
+ resolver.setResolvedValue(i, null);
+ fail("should throw SQLException");
+ } catch (SQLException ex) {
+ // expected
+ }
+ }
+ assertFalse(resolver.nextConflict());
+ }
+ }
+
+ public void testAcceptChanges_InsertException_Three() throws Exception {
+ /*
+ * Insert a new row. Before inserting the new row, another new row which
+ * has the same data is inserted into the DB. However, the current
+ * CachedRowSet doesn't know it.
+ */
+ crset = newNoInitialInstance();
+ crset.populate(st.executeQuery("select * from USER_INFO"));
+ String insertSQL = "INSERT INTO USER_INFO(ID, NAME, BIGINT_T, NUMERIC_T,DECIMAL_T, SMALLINT_T, "
+ + "FLOAT_T, REAL_T, DOUBLE_T, DATE_T, TIME_T, TIMESTAMP_T) VALUES(?, ?, ?, ?, ?, ?,"
+ + "?, ?, ?, ?, ?, ? )";
+ PreparedStatement preStmt = conn.prepareStatement(insertSQL);
+ preStmt.setInt(1, 80);
+ preStmt.setString(2, "test" + 80);
+ preStmt.setLong(3, 444423L);
+ preStmt.setBigDecimal(4, new BigDecimal(12));
+ preStmt.setBigDecimal(5, new BigDecimal(23));
+ preStmt.setInt(6, 41);
+ preStmt.setFloat(7, 4.8F);
+ preStmt.setFloat(8, 4.888F);
+ preStmt.setDouble(9, 4.9999);
+ preStmt.setDate(10, new Date(965324512));
+ preStmt.setTime(11, new Time(452368512));
+ preStmt.setTimestamp(12, new Timestamp(874532105));
+ preStmt.executeUpdate();
+ if (preStmt != null) {
+ preStmt.close();
+ }
+ // check the new row in DB
+ rs = st.executeQuery("select COUNT(*) from USER_INFO where ID = 80");
+ assertTrue(rs.next());
+ assertEquals(1, rs.getInt(1));
+
+ // now call CachedRowSet.insertRow()
+ crset.setTableName("USER_INFO");
+ assertTrue(crset.absolute(3));
+ crset.moveToInsertRow();
+ crset.updateInt(1, 80);
+ crset.updateString(2, "test" + 80);
+ crset.updateLong(3, 444423L);
+ crset.updateBigDecimal(4, new BigDecimal(12));
+ crset.updateBigDecimal(5, new BigDecimal(23));
+ crset.updateInt(6, 41);
+ crset.updateFloat(7, 4.8F);
+ crset.updateFloat(8, 4.888F);
+ crset.updateDouble(9, 4.9999);
+ crset.updateDate(10, new Date(965324512));
+ crset.updateTime(11, new Time(452368512));
+ crset.updateTimestamp(12, new Timestamp(874532105));
+ crset.insertRow();
+ crset.moveToCurrentRow();
+ try {
+ crset.acceptChanges(conn);
+ fail("should throw SyncProviderException");
+ } catch (SyncProviderException e) {
+ SyncResolver resolver = e.getSyncResolver();
+ assertEquals(0, resolver.getRow());
+ assertTrue(resolver.nextConflict());
+ assertEquals(4, resolver.getRow());
+ assertEquals(SyncResolver.INSERT_ROW_CONFLICT, resolver.getStatus());
+ for (int i = 1; i <= crset.getMetaData().getColumnCount(); i++) {
+ assertNull(resolver.getConflictValue(i));
+ try {
+ resolver.setResolvedValue(i, null);
+ fail("should throw SQLException");
+ } catch (SQLException ex) {
+ // expected
+ }
+ }
+ assertFalse(resolver.nextConflict());
+ }
+ }
+
+ public void testAcceptChanges_DeleteException_One() throws Exception {
+ /*
+ * Delete a row which has been deleted from database
+ */
+ int result = st.executeUpdate("delete from USER_INFO where ID = 3");
+ assertEquals(1, result);
+ // move to the third row which doesn't exist in database
+ assertTrue(crset.absolute(3));
+ assertEquals(3, crset.getInt(1));
+ crset.deleteRow();
+ assertFalse(crset.getShowDeleted());
+ try {
+ crset.acceptChanges(conn);
+ fail("should throw SyncProviderException");
+ } catch (SyncProviderException e) {
+ SyncResolver resolver = e.getSyncResolver();
+ assertEquals(0, resolver.getRow());
+ assertTrue(resolver.nextConflict());
+ if ("true".equals(System.getProperty("Testing Harmony"))) {
+ assertEquals(3, resolver.getRow());
+ } else {
+ assertEquals(0, resolver.getRow());
+ }
+ assertEquals(SyncResolver.DELETE_ROW_CONFLICT, resolver.getStatus());
+ for (int i = 1; i <= DEFAULT_COLUMN_COUNT; ++i) {
+ assertNull(resolver.getConflictValue(i));
+ try {
+ resolver.setResolvedValue(i, null);
+ fail("should throw SQLException");
+ } catch (SQLException ex) {
+ // expected
+ }
+ }
+ assertFalse(resolver.nextConflict());
+ }
+
+ assertEquals(0, crset.getRow());
+ try {
+ crset.getObject(1);
+ fail("should throw SQLException");
+ } catch (SQLException e) {
+ // expected
+ }
+
+ // check database
+ rs = st.executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE ID = 3");
+ assertTrue(rs.next());
+ assertEquals(0, rs.getInt(1));
+
+ // check CachedRowSet
+ assertFalse(crset.getShowDeleted());
+ crset.beforeFirst();
+ assertTrue(crset.absolute(3));
+ assertEquals(4, crset.getInt(1));
+ assertFalse(crset.next());
+
+ crset.setShowDeleted(true);
+ assertTrue(crset.absolute(3));
+ assertTrue(crset.rowDeleted());
+ assertEquals(3, crset.getInt(1));
+ }
+
+ public void testAcceptChanges_DeleteException_Two() throws Exception {
+ /*
+ * Delete a row which has been updated in database
+ */
+ crset = newNoInitialInstance();
+ crset.setCommand("SELECT * FROM USER_INFO");
+ crset.setUrl(DERBY_URL);
+ crset.execute();
+
+ int result = st
+ .executeUpdate("update USER_INFO set NAME = 'update44' where ID = 4");
+ assertEquals(1, result);
+ // move to the updated row
+ crset.absolute(4);
+ assertEquals(4, crset.getInt(1));
+ assertEquals("test4", crset.getString(2));
+ crset.deleteRow();
+ assertFalse(crset.getShowDeleted());
+ try {
+ crset.acceptChanges(conn);
+ fail("should throw SyncProviderException");
+ } catch (SyncProviderException e) {
+ SyncResolver resolver = e.getSyncResolver();
+ assertEquals(0, resolver.getRow());
+ assertTrue(resolver.nextConflict());
+ assertEquals(SyncResolver.DELETE_ROW_CONFLICT, resolver.getStatus());
+ if ("true".equals(System.getProperty("Testing Harmony"))) {
+ assertEquals(4, resolver.getRow());
+ assertNull(resolver.getConflictValue(1));
+ } else {
+ assertEquals(0, resolver.getRow());
+ try {
+ resolver.getConflictValue(1);
+ fail("should throw SQLException");
+ } catch (SQLException ex) {
+ // expected
+ }
+ }
+ assertFalse(resolver.nextConflict());
+ }
+
+ // check database
+ rs = st.executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE ID = 4");
+ assertTrue(rs.next());
+ assertEquals(1, rs.getInt(1));
+
+ // check CachedRowSet
+ assertFalse(crset.getShowDeleted());
+ crset.beforeFirst();
+ assertFalse(crset.absolute(4));
+
+ crset.setShowDeleted(true);
+ assertTrue(crset.absolute(4));
+ assertEquals(4, crset.getInt(1));
+ assertTrue(crset.rowDeleted());
+ }
+
+ public void testAcceptChanges_UpdateException_One() throws Exception {
+ /*
+ * Update a row which has been deleted from database
+ */
+ int result = st.executeUpdate("delete from USER_INFO where ID = 3");
+ assertEquals(1, result);
+ // move to the third row which doesn't exist in database
+ assertTrue(crset.absolute(3));
+ assertEquals(3, crset.getInt(1));
+ crset.updateString(2, "update33");
+ crset.updateRow();
+ try {
+ crset.acceptChanges(conn);
+ fail("should throw SyncProviderException");
+ } catch (SyncProviderException e) {
+ SyncResolver resolver = e.getSyncResolver();
+ assertEquals(0, resolver.getRow());
+
+ try {
+ resolver.getConflictValue(1);
+ fail("Should throw SQLException");
+ } catch (SQLException ex) {
+ // expected, Invalid cursor position
+ }
+
+ assertTrue(resolver.nextConflict());
+ assertEquals(3, resolver.getRow());
+ assertEquals(SyncResolver.UPDATE_ROW_CONFLICT, resolver.getStatus());
+
+ for (int i = 1; i <= DEFAULT_COLUMN_COUNT; ++i) {
+ assertNull(resolver.getConflictValue(i));
+ try {
+ resolver.setResolvedValue(i, null);
+ fail("should throw SQLException");
+ } catch (SQLException ex) {
+ // expected
+ }
+ }
+ assertFalse(resolver.nextConflict());
+ }
+ }
+
+ public void testAcceptChanges_UpdateException_Two() throws Exception {
+ /*
+ * Update a row which has been updated in database
+ */
+ crset = newNoInitialInstance();
+ crset.populate(st.executeQuery("select * from USER_INFO"));
+ int result = st
+ .executeUpdate("update USER_INFO set NAME = 'update44' where ID = 4");
+ assertEquals(1, result);
+
+ // move to the updated row
+ assertTrue(crset.absolute(4));
+ assertEquals(4, crset.getInt(1));
+ assertEquals("test4", crset.getString(2));
+ crset.updateString(2, "change4");
+ crset.updateRow();
+ try {
+ crset.acceptChanges(conn);
+ fail("should throw SyncProviderException");
+ } catch (SyncProviderException e) {
+ SyncResolver resolver = e.getSyncResolver();
+ assertEquals(0, resolver.getRow());
+ assertTrue(resolver.nextConflict());
+ assertEquals(4, resolver.getRow());
+ assertEquals(SyncResolver.UPDATE_ROW_CONFLICT, resolver.getStatus());
+
+ if ("true".equals(System.getProperty("Testing Harmony"))) {
+ resolver.getConflictValue(1);
+ } else {
+ try {
+ resolver.getConflictValue(1);
+ fail("should throw SQLException");
+ } catch (SQLException ex) {
+ // TODO RI throw SQLException here, maybe RI's bug
+ }
+ }
+ assertFalse(resolver.nextConflict());
+ }
+ }
+
+ public void testAcceptChanges_UpdateException_Three() throws Exception {
+ /*
+ * Update a row in which one column's value is out of range
+ */
+ crset = newNoInitialInstance();
+ crset.populate(st.executeQuery("select * from USER_INFO"));
+ assertEquals(4, crset.size());
+ assertTrue(crset.absolute(4));
+ assertEquals(4, crset.getInt(1));
+ crset.updateString(2, "update4");
+ crset.updateLong(3, 555555L);
+ crset.updateInt(4, 200000); // 200000 exceeds the NUMERIC's range
+ crset.updateBigDecimal(5, new BigDecimal(23));
+ crset.updateFloat(8, 4.888F);
+ crset.updateRow();
+ try {
+ crset.acceptChanges(conn);
+ fail("should throw SyncProviderException");
+ } catch (SyncProviderException e) {
+ SyncResolver resolver = e.getSyncResolver();
+ assertEquals(0, resolver.getRow());
+ assertTrue(resolver.nextConflict());
+ assertEquals(4, resolver.getRow());
+ assertEquals(SyncResolver.UPDATE_ROW_CONFLICT, resolver.getStatus());
+
+ for (int i = 1; i <= DEFAULT_COLUMN_COUNT; ++i) {
+ assertNull(resolver.getConflictValue(i));
+ try {
+ resolver.setResolvedValue(i, null);
+ fail("should throw SQLException");
+ } catch (SQLException ex) {
+ // expected
+ }
+ }
+ assertFalse(resolver.nextConflict());
+ }
+ }
+
+ public void testAcceptChanges_MultiConflicts() throws Exception {
+ /*
+ * Update a row in which one column's value is out of range
+ */
+ assertTrue(crset.absolute(3));
+ assertEquals(3, crset.getInt(1));
+ crset.updateString(2, "update4");
+ crset.updateLong(3, 555555L);
+ crset.updateInt(4, 200000); // 200000 exceeds the NUMERIC's range
+ crset.updateBigDecimal(5, new BigDecimal(23));
+ crset.updateFloat(8, 4.888F);
+ crset.updateRow();
+
+ /*
+ * Delete a row which has been deleted from database
+ */
+ int result = st.executeUpdate("delete from USER_INFO where ID = 1");
+ assertEquals(1, result);
+ // move to the first row which doesn't exist in database
+ assertTrue(crset.absolute(1));
+ assertEquals(1, crset.getInt(1));
+ crset.deleteRow();
+
+ /*
+ * Insert a new row. One given column's value exceeds the max range.
+ */
+ assertTrue(crset.last());
+ crset.setTableName("USER_INFO");
+ crset.moveToInsertRow();
+ crset.updateInt(1, 5);
+ crset.updateString(2, "test5");
+ crset.updateLong(3, 555555L);
+ crset.updateInt(4, 200000); // 200000 exceeds the NUMERIC's range
+ crset.updateBigDecimal(5, new BigDecimal(23));
+ crset.updateFloat(8, 4.888F);
+ crset.insertRow();
+ crset.moveToCurrentRow();
+
+ try {
+ crset.acceptChanges(conn);
+ fail("should throw SyncProviderException");
+ } catch (SyncProviderException e) {
+ SyncResolver resolver = e.getSyncResolver();
+ assertEquals(0, resolver.getRow());
+
+ try {
+ resolver.getConflictValue(1);
+ fail("should throw SQLException");
+ } catch (SQLException ex) {
+ // expected
+ }
+
+ assertTrue(resolver.nextConflict());
+ assertEquals(SyncResolver.DELETE_ROW_CONFLICT, resolver.getStatus());
+ if ("true".equals(System.getProperty("Testing Harmony"))) {
+ assertEquals(1, resolver.getRow());
+ } else {
+ assertEquals(0, resolver.getRow());
+ }
+ for (int i = 1; i <= DEFAULT_COLUMN_COUNT; ++i) {
+ assertNull(resolver.getConflictValue(i));
+ }
+
+ assertTrue(resolver.nextConflict());
+ assertEquals(SyncResolver.UPDATE_ROW_CONFLICT, resolver.getStatus());
+ assertEquals(3, resolver.getRow());
+ for (int i = 1; i <= DEFAULT_COLUMN_COUNT; ++i) {
+ assertNull(resolver.getConflictValue(i));
+ }
+
+ assertTrue(resolver.nextConflict());
+ assertEquals(SyncResolver.INSERT_ROW_CONFLICT, resolver.getStatus());
+ assertEquals(5, resolver.getRow());
+ for (int i = 1; i <= DEFAULT_COLUMN_COUNT; ++i) {
+ assertNull(resolver.getConflictValue(i));
+ }
+
+ assertFalse(resolver.nextConflict());
+ }
+ }
+
+ public void testSetResolvedValue_ILObject() throws Exception {
+
+ /*
+ * Insert a new row. The new row's primary key has existed. Therefore,
+ * it should throw SyncProviderException.
+ */
+ crset = newNoInitialInstance();
+ crset.populate(st.executeQuery("select * from USER_INFO"));
+ crset.setTableName("USER_INFO");
+ crset.moveToInsertRow();
+ crset.updateInt(1, 4); // The ID valued 4 has existed in db.
+ crset.updateString(2, "test5");
+ crset.updateBigDecimal(4, new BigDecimal(12));
+ crset.updateTimestamp(12, new Timestamp(874532105));
+ crset.insertRow();
+ crset.moveToCurrentRow();
+ try {
+ crset.acceptChanges(conn);
+ fail("should throw SyncProviderException");
+ } catch (SyncProviderException e) {
+ SyncResolver resolver = e.getSyncResolver();
+
+ // before call nextConflict
+ try {
+ resolver.setResolvedValue(1, 1);
+ fail("Should throw SQLException");
+ } catch (SQLException ex) {
+ // expected, Invalid cursor position
+ }
+
+ try {
+ resolver.setResolvedValue(-1, 1);
+ fail("Should throw SQLException");
+ } catch (SQLException ex) {
+ // expected, Invalid column index
+ }
+
+ assertTrue(resolver.nextConflict());
+
+ try {
+ resolver.setResolvedValue(-1, 10);
+ fail("Should throw SQLException");
+ } catch (SQLException ex) {
+ // expected
+ }
+
+ for (int i = 1; i <= DEFAULT_COLUMN_COUNT; ++i) {
+ try {
+ resolver.setResolvedValue(i, i);
+ fail("Should throw SQLException");
+ } catch (SQLException ex) {
+ // expected
+ }
+ }
+ }
+ }
+
+ public void testSetResolvedValue_LStringLObject() throws Exception {
+ /*
+ * Insert a new row. The new row's primary key has existed. Therefore,
+ * it should throw SyncProviderException.
+ */
+ crset = newNoInitialInstance();
+ crset.populate(st.executeQuery("select * from USER_INFO"));
+ crset.setTableName("USER_INFO");
+ crset.moveToInsertRow();
+ crset.updateInt(1, 4); // The ID valued 4 has existed in db.
+ crset.updateString(2, "test5");
+ crset.updateBigDecimal(4, new BigDecimal(12));
+ crset.updateTimestamp(12, new Timestamp(874532105));
+ crset.insertRow();
+ crset.moveToCurrentRow();
+ try {
+ crset.acceptChanges(conn);
+ fail("should throw SyncProviderException");
+ } catch (SyncProviderException e) {
+ SyncResolver resolver = e.getSyncResolver();
+
+ // before call nextConflict
+ resolver.setResolvedValue(null, 1);
+ resolver.setResolvedValue("ID", 1);
+ resolver.setResolvedValue("not exist", 1);
+
+ assertTrue(resolver.nextConflict());
+
+ resolver.setResolvedValue(null, 1);
+ resolver.setResolvedValue("ID", 1);
+ assertNull(resolver.getConflictValue("ID"));
+ resolver.setResolvedValue("NAME", "hello");
+ assertNull(resolver.getConflictValue("NAME"));
+ resolver.setResolvedValue("not exist", 1);
+ }
+ }
}