Search in sources :

Example 1 with SoftDelete

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);
    }
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) DbEntity(org.apache.cayenne.map.DbEntity) SoftDelete(org.apache.cayenne.testdo.soft_delete.SoftDelete) Expression(org.apache.cayenne.exp.Expression) BatchTranslatorFactory(org.apache.cayenne.access.translator.batch.BatchTranslatorFactory) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) Test(org.junit.Test)

Example 2 with SoftDelete

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);
    }
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) DbEntity(org.apache.cayenne.map.DbEntity) SoftDelete(org.apache.cayenne.testdo.soft_delete.SoftDelete) Expression(org.apache.cayenne.exp.Expression) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) Test(org.junit.Test)

Aggregations

Expression (org.apache.cayenne.exp.Expression)2 DbEntity (org.apache.cayenne.map.DbEntity)2 SQLTemplate (org.apache.cayenne.query.SQLTemplate)2 ParallelTestContainer (org.apache.cayenne.test.parallel.ParallelTestContainer)2 SoftDelete (org.apache.cayenne.testdo.soft_delete.SoftDelete)2 Test (org.junit.Test)2 BatchTranslatorFactory (org.apache.cayenne.access.translator.batch.BatchTranslatorFactory)1