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, Invalid cursor position
}
assertTrue(resolver.nextConflict());
assertEquals(1, resolver.getRow());
assertEquals(SyncResolver.INSERT_ROW_CONFLICT, resolver.getStatus());
for (int i = 1; i <= DEFAULT_COLUMN_COUNT; ++i) {
// all values are null
assertNull(resolver.getConflictValue(i));
}
assertFalse(resolver.nextConflict());
}
/*
* Insert a new row. The new row's primary key has existed. Therefore,
* it should throw SyncProviderException.
*/
crset = newNoInitialInstance();
rs = st.executeQuery("select * from USER_INFO");
crset.populate(rs);
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());
try {
resolver.getConflictValue(1);
fail("Should throw SQLException");
} catch (SQLException ex) {
// expected, Invalid cursor position
}
assertTrue(resolver.nextConflict());
assertEquals(1, resolver.getRow());
assertEquals(SyncResolver.INSERT_ROW_CONFLICT, resolver.getStatus());
for (int i = 1; i <= DEFAULT_COLUMN_COUNT; ++i) {
// all values are null
assertNull(resolver.getConflictValue(i));
}
assertFalse(resolver.nextConflict());
}
/*
* 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. In this situation, it should throw
* SyncProviderException.
*/
crset = newNoInitialInstance();
rs = st.executeQuery("select * from USER_INFO");
crset.populate(rs);
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 * from USER_INFO where ID = 80");
assertTrue(rs.next());
assertEquals(80, rs.getInt(1));
assertEquals("test80", rs.getString(2));
// now call CachedRowSet.insertRow()
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());
try {
resolver.getConflictValue(1);
fail("Should throw SQLException");
} catch (SQLException ex) {
// expected, Invalid cursor position
}
assertTrue(resolver.nextConflict());
assertEquals(1, resolver.getRow());
assertEquals(SyncResolver.INSERT_ROW_CONFLICT, resolver.getStatus());
for (int i = 1; i <= DEFAULT_COLUMN_COUNT; ++i) {
// all values are null
assertNull(resolver.getConflictValue(i));
}
assertFalse(resolver.nextConflict());
}
}