use of org.apache.cayenne.testdo.soft_delete.SoftDelete in project cayenne by apache.
the class SoftDeleteBatchTranslatorIT method testUpdate.
@Test
public void testUpdate() throws Exception {
final DbEntity entity = context.getEntityResolver().getObjEntity(SoftDelete.class).getDbEntity();
BatchTranslatorFactory oldFactory = dataNode.getBatchTranslatorFactory();
try {
dataNode.setBatchTranslatorFactory(new SoftDeleteTranslatorFactory());
final SoftDelete test = context.newObject(SoftDelete.class);
test.setName("SoftDeleteBatchQueryBuilderTest");
context.commitChanges();
new ParallelTestContainer() {
@Override
protected void assertResult() {
Expression exp = ExpressionFactory.matchExp("name", test.getName());
assertEquals(1, ObjectSelect.query(SoftDelete.class, exp).selectCount(context));
exp = ExpressionFactory.matchDbExp("DELETED", true);
assertEquals(0, ObjectSelect.query(SoftDelete.class, exp).selectCount(context));
}
}.runTest(200);
context.deleteObjects(test);
assertEquals(test.getPersistenceState(), PersistenceState.DELETED);
context.commitChanges();
new ParallelTestContainer() {
@Override
protected void assertResult() {
Expression exp = ExpressionFactory.matchExp("name", test.getName());
assertEquals(0, ObjectSelect.query(SoftDelete.class, exp).selectCount(context));
SQLTemplate template = new SQLTemplate(entity, "SELECT * FROM SOFT_DELETE");
template.setFetchingDataRows(true);
assertEquals(1, context.performQuery(template).size());
}
}.runTest(200);
} finally {
context.performQuery(new SQLTemplate(entity, "DELETE FROM SOFT_DELETE"));
dataNode.setBatchTranslatorFactory(oldFactory);
}
}
use of org.apache.cayenne.testdo.soft_delete.SoftDelete in project cayenne by apache.
the class SoftDeleteBatchTranslatorIT method testUpdate.
@Test
public void testUpdate() throws Exception {
final DbEntity entity = context.getEntityResolver().getObjEntity(SoftDelete.class).getDbEntity();
BatchTranslatorFactory oldFactory = dataNode.getBatchTranslatorFactory();
try {
dataNode.setBatchTranslatorFactory(new SoftDeleteTranslatorFactory());
final SoftDelete test = context.newObject(SoftDelete.class);
test.setName("SoftDeleteBatchQueryBuilderTest");
context.commitChanges();
new ParallelTestContainer() {
@Override
protected void assertResult() {
Expression exp = ExpressionFactory.matchExp("name", test.getName());
assertEquals(1, ObjectSelect.query(SoftDelete.class, exp).selectCount(context));
exp = ExpressionFactory.matchDbExp("DELETED", true);
assertEquals(0, ObjectSelect.query(SoftDelete.class, exp).selectCount(context));
}
}.runTest(200);
context.deleteObjects(test);
assertEquals(test.getPersistenceState(), PersistenceState.DELETED);
context.commitChanges();
new ParallelTestContainer() {
@Override
protected void assertResult() {
Expression exp = ExpressionFactory.matchExp("name", test.getName());
assertEquals(0, ObjectSelect.query(SoftDelete.class, exp).selectCount(context));
SQLTemplate template = new SQLTemplate(entity, "SELECT * FROM SOFT_DELETE");
template.setFetchingDataRows(true);
assertEquals(1, context.performQuery(template).size());
}
}.runTest(200);
} finally {
context.performQuery(new SQLTemplate(entity, "DELETE FROM SOFT_DELETE"));
dataNode.setBatchTranslatorFactory(oldFactory);
}
}
Aggregations