本文整理汇总了Java中javax.sql.rowset.spi.SyncResolver类的典型用法代码示例。如果您正苦于以下问题:Java SyncResolver类的具体用法?Java SyncResolver怎么用?Java SyncResolver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SyncResolver类属于javax.sql.rowset.spi包,在下文中一共展示了SyncResolver类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testNextPreviousConflict
import javax.sql.rowset.spi.SyncResolver; //导入依赖的package包/类
public void testNextPreviousConflict() throws Exception {
RowSetMetaData metadata = new RowSetMetaDataImpl();
metadata.setColumnCount(DEFAULT_COLUMN_COUNT);
SyncResolverImpl resolver = new SyncResolverImpl(metadata);
resolver.addConflictRow(
new CachedRow(new Object[DEFAULT_COLUMN_COUNT]), 1,
SyncResolver.INSERT_ROW_CONFLICT);
resolver.addConflictRow(
new CachedRow(new Object[DEFAULT_COLUMN_COUNT]), 2,
SyncResolver.INSERT_ROW_CONFLICT);
assertTrue(resolver.nextConflict());
assertTrue(resolver.nextConflict());
assertFalse(resolver.nextConflict());
assertFalse(resolver.nextConflict());
assertTrue(resolver.previousConflict());
assertTrue(resolver.previousConflict());
assertFalse(resolver.previousConflict());
assertFalse(resolver.previousConflict());
}
开发者ID:shannah,项目名称:cn1,代码行数:25,代码来源:SyncResolverTest.java
示例2: test_constructor_Ljavax_sql_rowset_spi_SyncResolver
import javax.sql.rowset.spi.SyncResolver; //导入依赖的package包/类
/**
* @add tests
* {@link javax.sql.rowset.spi.SyncProviderException#SyncProviderException(javax.sql.rowset.spi.SyncResolver)}
*/
public void test_constructor_Ljavax_sql_rowset_spi_SyncResolver() {
try {
new SyncProviderException((SyncResolver) null);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
}
开发者ID:shannah,项目名称:cn1,代码行数:13,代码来源:SyncProviderExceptionTest.java
示例3: testAcceptChanges_InsertException_Two
import javax.sql.rowset.spi.SyncResolver; //导入依赖的package包/类
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());
}
}
开发者ID:shannah,项目名称:cn1,代码行数:37,代码来源:SyncResolverTest.java
示例4: testAcceptChanges_UpdateException_Two
import javax.sql.rowset.spi.SyncResolver; //导入依赖的package包/类
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());
}
}
开发者ID:shannah,项目名称:cn1,代码行数:40,代码来源:SyncResolverTest.java
示例5: testAcceptChanges_UpdateException_Three
import javax.sql.rowset.spi.SyncResolver; //导入依赖的package包/类
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());
}
}
开发者ID:shannah,项目名称:cn1,代码行数:38,代码来源:SyncResolverTest.java
示例6: testSetResolvedValue_LStringLObject
import javax.sql.rowset.spi.SyncResolver; //导入依赖的package包/类
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);
}
}
开发者ID:shannah,项目名称:cn1,代码行数:37,代码来源:SyncResolverTest.java
示例7: testAcceptChanges_InsertException_Three
import javax.sql.rowset.spi.SyncResolver; //导入依赖的package包/类
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());
}
}
开发者ID:shannah,项目名称:cn1,代码行数:73,代码来源:SyncResolverTest.java
示例8: testAcceptChanges_DeleteException_Two
import javax.sql.rowset.spi.SyncResolver; //导入依赖的package包/类
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());
}
开发者ID:shannah,项目名称:cn1,代码行数:57,代码来源:SyncResolverTest.java
示例9: testAcceptChanges_MultiConflicts
import javax.sql.rowset.spi.SyncResolver; //导入依赖的package包/类
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());
}
}
开发者ID:shannah,项目名称:cn1,代码行数:81,代码来源:SyncResolverTest.java
示例10: testCreateCopy2
import javax.sql.rowset.spi.SyncResolver; //导入依赖的package包/类
public void testCreateCopy2() throws Exception {
CachedRowSet copy = crset.createCopy();
copy.absolute(3);
crset.absolute(3);
copy.updateString(2, "updated");
assertEquals("updated", copy.getString(2));
assertEquals("test3", crset.getString(2));
copy.updateRow();
copy.acceptChanges();
assertEquals("updated", copy.getString(2));
assertEquals("test3", crset.getString(2));
crset.updateString(2, "again");
assertEquals("updated", copy.getString(2));
assertEquals("again", crset.getString(2));
crset.updateRow();
try {
/*
* seems ri doesn't release lock when exception throw from
* acceptChanges(), which will cause test case block at insertData()
* when next test case setUp, so we must pass current connection to
* it, and all resource would be released after connection closed.
*/
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) {
// all values are null
assertNull(resolver.getConflictValue(i));
}
assertFalse(resolver.nextConflict());
}
assertEquals("updated", copy.getString(2));
crset.absolute(3);
// data doesn't change
assertEquals("again", crset.getString(2));
}
开发者ID:shannah,项目名称:cn1,代码行数:62,代码来源:CachedRowSetImplTest.java
注:本文中的javax.sql.rowset.spi.SyncResolver类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论