use of org.apache.cayenne.dba.JdbcAdapter 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();
JdbcAdapter adapter = (JdbcAdapter) this.adapter;
BatchTranslatorFactory oldFactory = dataNode.getBatchTranslatorFactory();
try {
dataNode.setBatchTranslatorFactory(new SoftDeleteTranslatorFactory());
final SoftDelete test = context.newObject(SoftDelete.class);
test.setName("SoftDeleteBatchQueryBuilderTest");
context.commitChanges();
final SelectQuery query = new SelectQuery(SoftDelete.class);
new ParallelTestContainer() {
@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());
}
}.runTest(200);
context.deleteObjects(test);
assertEquals(test.getPersistenceState(), PersistenceState.DELETED);
context.commitChanges();
new ParallelTestContainer() {
@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_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.dba.JdbcAdapter in project cayenne by apache.
the class SoftDeleteBatchTranslatorIT method testCreateSqlStringWithIdentifiersQuote.
@Test
public void testCreateSqlStringWithIdentifiersQuote() throws Exception {
DbEntity entity = context.getEntityResolver().getObjEntity(SoftDelete.class).getDbEntity();
try {
entity.getDataMap().setQuotingSQLIdentifiers(true);
List<DbAttribute> idAttributes = Collections.singletonList(entity.getAttribute("ID"));
DeleteBatchQuery deleteQuery = new DeleteBatchQuery(entity, idAttributes, Collections.<String>emptySet(), 1);
JdbcAdapter adapter = (JdbcAdapter) this.adapter;
DeleteBatchTranslator builder = createTranslator(deleteQuery, adapter);
String generatedSql = builder.getSql();
String charStart = unitAdapter.getIdentifiersStartQuote();
String charEnd = unitAdapter.getIdentifiersEndQuote();
assertNotNull(generatedSql);
assertEquals("UPDATE " + charStart + entity.getName() + charEnd + " SET " + charStart + "DELETED" + charEnd + " = ? WHERE " + charStart + "ID" + charEnd + " = ?", generatedSql);
} finally {
entity.getDataMap().setQuotingSQLIdentifiers(false);
}
}
use of org.apache.cayenne.dba.JdbcAdapter in project cayenne by apache.
the class UpdateBatchTranslatorIT method testCreateSqlStringWithIdentifiersQuote.
@Test
public void testCreateSqlStringWithIdentifiersQuote() throws Exception {
DbEntity entity = runtime.getDataDomain().getEntityResolver().getObjEntity(SimpleLockingTestEntity.class).getDbEntity();
try {
entity.getDataMap().setQuotingSQLIdentifiers(true);
List idAttributes = Collections.singletonList(entity.getAttribute("LOCKING_TEST_ID"));
List updatedAttributes = Collections.singletonList(entity.getAttribute("DESCRIPTION"));
UpdateBatchQuery updateQuery = new UpdateBatchQuery(entity, idAttributes, updatedAttributes, Collections.<String>emptySet(), 1);
JdbcAdapter adapter = (JdbcAdapter) this.adapter;
UpdateBatchTranslator builder = new UpdateBatchTranslator(updateQuery, adapter, null);
String generatedSql = builder.getSql();
String charStart = unitAdapter.getIdentifiersStartQuote();
String charEnd = unitAdapter.getIdentifiersEndQuote();
assertNotNull(generatedSql);
assertEquals("UPDATE " + charStart + entity.getName() + charEnd + " SET " + charStart + "DESCRIPTION" + charEnd + " = ? WHERE " + charStart + "LOCKING_TEST_ID" + charEnd + " = ?", generatedSql);
} finally {
entity.getDataMap().setQuotingSQLIdentifiers(false);
}
}
Aggregations