use of org.apache.cayenne.query.UpdateBatchQuery in project cayenne by apache.
the class UpdateBatchTranslatorIT method testConstructor.
@Test
public void testConstructor() {
DbAdapter adapter = objectFactory.newInstance(DbAdapter.class, JdbcAdapter.class.getName());
UpdateBatchQuery query = mock(UpdateBatchQuery.class);
UpdateBatchTranslator builder = new UpdateBatchTranslator(query, adapter);
assertSame(adapter, builder.context.getAdapter());
assertSame(query, builder.context.getQuery());
}
use of org.apache.cayenne.query.UpdateBatchQuery in project cayenne by apache.
the class UpdateBatchTranslatorIT method testCreateSqlStringWithIdentifiersQuote.
@Test
public void testCreateSqlStringWithIdentifiersQuote() {
DbEntity entity = runtime.getDataDomain().getEntityResolver().getObjEntity(SimpleLockingTestEntity.class).getDbEntity();
try {
entity.getDataMap().setQuotingSQLIdentifiers(true);
List<DbAttribute> idAttributes = Collections.singletonList(entity.getAttribute("LOCKING_TEST_ID"));
List<DbAttribute> updatedAttributes = Collections.singletonList(entity.getAttribute("DESCRIPTION"));
UpdateBatchQuery updateQuery = new UpdateBatchQuery(entity, idAttributes, updatedAttributes, Collections.emptySet(), 1);
JdbcAdapter adapter = (JdbcAdapter) this.adapter;
UpdateBatchTranslator builder = new UpdateBatchTranslator(updateQuery, adapter);
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);
}
}
use of org.apache.cayenne.query.UpdateBatchQuery in project cayenne by apache.
the class UpdateBatchTranslatorIT method testCreateSqlStringWithNullsWithIdentifiersQuote.
@Test
public void testCreateSqlStringWithNullsWithIdentifiersQuote() throws Exception {
DbEntity entity = runtime.getDataDomain().getEntityResolver().getObjEntity(SimpleLockingTestEntity.class).getDbEntity();
try {
entity.getDataMap().setQuotingSQLIdentifiers(true);
List idAttributes = Arrays.asList(entity.getAttribute("LOCKING_TEST_ID"), entity.getAttribute("NAME"));
List updatedAttributes = Collections.singletonList(entity.getAttribute("DESCRIPTION"));
Collection nullAttributes = Collections.singleton("NAME");
UpdateBatchQuery updateQuery = new UpdateBatchQuery(entity, idAttributes, updatedAttributes, nullAttributes, 1);
JdbcAdapter adapter = (JdbcAdapter) this.adapter;
UpdateBatchTranslator builder = new UpdateBatchTranslator(updateQuery, adapter, null);
String generatedSql = builder.getSql();
assertNotNull(generatedSql);
String charStart = unitAdapter.getIdentifiersStartQuote();
String charEnd = unitAdapter.getIdentifiersEndQuote();
assertEquals("UPDATE " + charStart + entity.getName() + charEnd + " SET " + charStart + "DESCRIPTION" + charEnd + " = ? WHERE " + charStart + "LOCKING_TEST_ID" + charEnd + " = ? AND " + charStart + "NAME" + charEnd + " IS NULL", generatedSql);
} finally {
entity.getDataMap().setQuotingSQLIdentifiers(false);
}
}
use of org.apache.cayenne.query.UpdateBatchQuery in project cayenne by apache.
the class UpdateBatchTranslatorIT method testCreateSqlString.
@Test
public void testCreateSqlString() throws Exception {
DbEntity entity = runtime.getDataDomain().getEntityResolver().getObjEntity(SimpleLockingTestEntity.class).getDbEntity();
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);
DbAdapter adapter = objectFactory.newInstance(DbAdapter.class, JdbcAdapter.class.getName());
UpdateBatchTranslator builder = new UpdateBatchTranslator(updateQuery, adapter, null);
String generatedSql = builder.getSql();
assertNotNull(generatedSql);
assertEquals("UPDATE " + entity.getName() + " SET DESCRIPTION = ? WHERE LOCKING_TEST_ID = ?", generatedSql);
}
Aggregations