use of org.apache.cayenne.query.UpdateBatchQuery in project cayenne by apache.
the class OracleAdapter method updatesLOBColumns.
/**
* Utility method that returns <code>true</code> if the query will update at
* least one BLOB or CLOB DbAttribute.
*
* @since 1.2
*/
static boolean updatesLOBColumns(BatchQuery query) {
boolean isInsert = query instanceof InsertBatchQuery;
boolean isUpdate = query instanceof UpdateBatchQuery;
if (!isInsert && !isUpdate) {
return false;
}
List<DbAttribute> updatedAttributes = (isInsert) ? query.getDbAttributes() : ((UpdateBatchQuery) query).getUpdatedAttributes();
for (DbAttribute attr : updatedAttributes) {
int type = attr.getType();
if (type == Types.CLOB || type == Types.BLOB) {
return true;
}
}
return false;
}
use of org.apache.cayenne.query.UpdateBatchQuery 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);
}
}
use of org.apache.cayenne.query.UpdateBatchQuery in project cayenne by apache.
the class UpdateBatchTranslatorIT method testCreateSqlStringWithNulls.
@Test
public void testCreateSqlStringWithNulls() throws Exception {
DbEntity entity = runtime.getDataDomain().getEntityResolver().getObjEntity(SimpleLockingTestEntity.class).getDbEntity();
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);
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 = ? AND NAME IS NULL", generatedSql);
}
use of org.apache.cayenne.query.UpdateBatchQuery in project cayenne by apache.
the class UpdateBatchTranslatorIT method testCreateSqlStringWithNullsWithIdentifiersQuote.
@Test
public void testCreateSqlStringWithNullsWithIdentifiersQuote() {
DbEntity entity = runtime.getDataDomain().getEntityResolver().getObjEntity(SimpleLockingTestEntity.class).getDbEntity();
try {
entity.getDataMap().setQuotingSQLIdentifiers(true);
List<DbAttribute> idAttributes = Arrays.asList(entity.getAttribute("LOCKING_TEST_ID"), entity.getAttribute("NAME"));
List<DbAttribute> updatedAttributes = Collections.singletonList(entity.getAttribute("DESCRIPTION"));
Collection<String> nullAttributes = Collections.singleton("NAME");
UpdateBatchQuery updateQuery = new UpdateBatchQuery(entity, idAttributes, updatedAttributes, nullAttributes, 1);
JdbcAdapter adapter = (JdbcAdapter) this.adapter;
UpdateBatchTranslator builder = new UpdateBatchTranslator(updateQuery, adapter);
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 testCreateSqlStringWithNulls.
@Test
public void testCreateSqlStringWithNulls() {
DbEntity entity = runtime.getDataDomain().getEntityResolver().getObjEntity(SimpleLockingTestEntity.class).getDbEntity();
List<DbAttribute> idAttributes = Arrays.asList(entity.getAttribute("LOCKING_TEST_ID"), entity.getAttribute("NAME"));
List<DbAttribute> updatedAttributes = Collections.singletonList(entity.getAttribute("DESCRIPTION"));
Collection<String> nullAttributes = Collections.singleton("NAME");
UpdateBatchQuery updateQuery = new UpdateBatchQuery(entity, idAttributes, updatedAttributes, nullAttributes, 1);
DbAdapter adapter = objectFactory.newInstance(DbAdapter.class, JdbcAdapter.class.getName());
UpdateBatchTranslator builder = new UpdateBatchTranslator(updateQuery, adapter);
String generatedSql = builder.getSql();
assertNotNull(generatedSql);
assertEquals("UPDATE " + entity.getName() + " SET DESCRIPTION = ? WHERE ( LOCKING_TEST_ID = ? ) AND ( NAME IS NULL )", generatedSql);
}
Aggregations