public void testUpdate() throws Exception {
final DbEntity entity = context.getEntityResolver().lookupObjEntity(
SoftTest.class).getDbEntity();
JdbcAdapter adapter = (JdbcAdapter) this.adapter;
BatchQueryBuilderFactory oldFactory = adapter.getBatchQueryBuilderFactory();
try {
adapter.setBatchQueryBuilderFactory(new SoftDeleteQueryBuilderFactory());
final SoftTest test = context.newObject(SoftTest.class);
test.setName("SoftDeleteBatchQueryBuilderTest");
context.commitChanges();
final SelectQuery query = new SelectQuery(SoftTest.class);
new ThreadedTestHelper() {
@Override
protected void assertResult() throws Exception {
query
.setQualifier(ExpressionFactory.matchExp("name", test
.getName()));
assertEquals(1, context.performQuery(query).size());
query.andQualifier(ExpressionFactory.matchDbExp("DELETED", true));
assertEquals(0, context.performQuery(query).size());
}
}.assertWithTimeout(200);
context.deleteObjects(test);
assertEquals(test.getPersistenceState(), PersistenceState.DELETED);
context.commitChanges();
new ThreadedTestHelper() {
@Override
protected void assertResult() throws Exception {
query
.setQualifier(ExpressionFactory.matchExp("name", test
.getName()));
assertEquals(0, context.performQuery(query).size());
SQLTemplate template = new SQLTemplate(
entity,
"SELECT * FROM SOFT_TEST");
template.setFetchingDataRows(true);
assertEquals(1, context.performQuery(template).size());
}
}.assertWithTimeout(200);
}
finally {
context.performQuery(new SQLTemplate(entity, "DELETE FROM SOFT_TEST"));
adapter.setBatchQueryBuilderFactory(oldFactory);
}
}