use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.
the class DeleteBatchTranslatorIT method testCreateSqlString.
@Test
public void testCreateSqlString() throws Exception {
DbEntity entity = runtime.getDataDomain().getEntityResolver().getObjEntity(SimpleLockingTestEntity.class).getDbEntity();
List<DbAttribute> idAttributes = Collections.singletonList(entity.getAttribute("LOCKING_TEST_ID"));
DeleteBatchQuery deleteQuery = new DeleteBatchQuery(entity, idAttributes, Collections.<String>emptySet(), 1);
DbAdapter adapter = objectFactory.newInstance(DbAdapter.class, JdbcAdapter.class.getName());
DeleteBatchTranslator builder = new DeleteBatchTranslator(deleteQuery, adapter, null);
String generatedSql = builder.getSql();
assertNotNull(generatedSql);
assertEquals("DELETE FROM " + entity.getName() + " WHERE LOCKING_TEST_ID = ?", generatedSql);
}
use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.
the class DeleteBatchTranslatorIT method testCreateSqlStringWithNulls.
@Test
public void testCreateSqlStringWithNulls() throws Exception {
DbEntity entity = runtime.getDataDomain().getEntityResolver().getObjEntity(SimpleLockingTestEntity.class).getDbEntity();
List<DbAttribute> idAttributes = Arrays.asList(entity.getAttribute("LOCKING_TEST_ID"), entity.getAttribute("NAME"));
Collection<String> nullAttributes = Collections.singleton("NAME");
DeleteBatchQuery deleteQuery = new DeleteBatchQuery(entity, idAttributes, nullAttributes, 1);
DbAdapter adapter = objectFactory.newInstance(DbAdapter.class, JdbcAdapter.class.getName());
DeleteBatchTranslator builder = new DeleteBatchTranslator(deleteQuery, adapter, null);
String generatedSql = builder.getSql();
assertNotNull(generatedSql);
assertEquals("DELETE FROM " + entity.getName() + " WHERE LOCKING_TEST_ID = ? AND NAME IS NULL", generatedSql);
}
use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.
the class DeleteBatchTranslatorIT method testCreateSqlStringWithIdentifiersQuote.
@Test
public void testCreateSqlStringWithIdentifiersQuote() throws Exception {
DbEntity entity = runtime.getDataDomain().getEntityResolver().getObjEntity(SimpleLockingTestEntity.class).getDbEntity();
try {
entity.getDataMap().setQuotingSQLIdentifiers(true);
List<DbAttribute> idAttributes = Collections.singletonList(entity.getAttribute("LOCKING_TEST_ID"));
DeleteBatchQuery deleteQuery = new DeleteBatchQuery(entity, idAttributes, Collections.<String>emptySet(), 1);
JdbcAdapter adapter = (JdbcAdapter) this.adapter;
DeleteBatchTranslator builder = new DeleteBatchTranslator(deleteQuery, adapter, null);
String generatedSql = builder.getSql();
String charStart = unitAdapter.getIdentifiersStartQuote();
String charEnd = unitAdapter.getIdentifiersEndQuote();
assertNotNull(generatedSql);
assertEquals("DELETE FROM " + charStart + entity.getName() + charEnd + " WHERE " + charStart + "LOCKING_TEST_ID" + charEnd + " = ?", generatedSql);
} finally {
entity.getDataMap().setQuotingSQLIdentifiers(false);
}
}
use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.
the class SoftDeleteBatchTranslatorIT method testCreateSqlString.
@Test
public void testCreateSqlString() throws Exception {
DbEntity entity = context.getEntityResolver().getObjEntity(SoftDelete.class).getDbEntity();
List<DbAttribute> idAttributes = Collections.singletonList(entity.getAttribute("ID"));
DeleteBatchQuery deleteQuery = new DeleteBatchQuery(entity, idAttributes, Collections.<String>emptySet(), 1);
DeleteBatchTranslator builder = createTranslator(deleteQuery);
String generatedSql = builder.getSql();
assertNotNull(generatedSql);
assertEquals("UPDATE " + entity.getName() + " SET DELETED = ? WHERE ID = ?", generatedSql);
}
use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.
the class SoftDeleteBatchTranslatorIT method testCreateSqlStringWithNulls.
@Test
public void testCreateSqlStringWithNulls() throws Exception {
DbEntity entity = context.getEntityResolver().getObjEntity(SoftDelete.class).getDbEntity();
List<DbAttribute> idAttributes = Arrays.asList(entity.getAttribute("ID"), entity.getAttribute("NAME"));
Collection<String> nullAttributes = Collections.singleton("NAME");
DeleteBatchQuery deleteQuery = new DeleteBatchQuery(entity, idAttributes, nullAttributes, 1);
DeleteBatchTranslator builder = createTranslator(deleteQuery);
String generatedSql = builder.getSql();
assertNotNull(generatedSql);
assertEquals("UPDATE " + entity.getName() + " SET DELETED = ? WHERE ID = ? AND NAME IS NULL", generatedSql);
}
Aggregations