use of org.apache.cayenne.query.InsertBatchQuery 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.InsertBatchQuery in project cayenne by apache.
the class InsertBatchTranslatorIT method testCreateSqlStringWithIdentifiersQuote.
@Test
public void testCreateSqlStringWithIdentifiersQuote() throws Exception {
DbEntity entity = runtime.getDataDomain().getEntityResolver().getObjEntity(SimpleLockingTestEntity.class).getDbEntity();
try {
entity.getDataMap().setQuotingSQLIdentifiers(true);
JdbcAdapter adapter = (JdbcAdapter) this.adapter;
InsertBatchQuery insertQuery = new InsertBatchQuery(entity, 1);
InsertBatchTranslator builder = new InsertBatchTranslator(insertQuery, adapter);
String generatedSql = builder.getSql();
String charStart = unitAdapter.getIdentifiersStartQuote();
String charEnd = unitAdapter.getIdentifiersEndQuote();
assertNotNull(generatedSql);
assertEquals("INSERT INTO " + charStart + entity.getName() + charEnd + " (" + charStart + "DESCRIPTION" + charEnd + ", " + charStart + "INT_COLUMN_NOTNULL" + charEnd + ", " + charStart + "INT_COLUMN_NULL" + charEnd + ", " + charStart + "LOCKING_TEST_ID" + charEnd + ", " + charStart + "NAME" + charEnd + ") VALUES (?, ?, ?, ?, ?)", generatedSql);
} finally {
entity.getDataMap().setQuotingSQLIdentifiers(false);
}
}
use of org.apache.cayenne.query.InsertBatchQuery in project cayenne by apache.
the class OracleAdapterIT method testUpdatesLOBColumns.
@Test
public void testUpdatesLOBColumns() throws Exception {
DataMap map = runtime.getDataDomain().getDataMap("lob");
assertTrue(OracleAdapter.updatesLOBColumns(new InsertBatchQuery(map.getDbEntity("BLOB_TEST"), 1)));
assertTrue(OracleAdapter.updatesLOBColumns(new InsertBatchQuery(map.getDbEntity("CLOB_TEST"), 1)));
assertFalse(OracleAdapter.updatesLOBColumns(new InsertBatchQuery(map.getDbEntity("TEST"), 1)));
}
use of org.apache.cayenne.query.InsertBatchQuery in project cayenne by apache.
the class InsertBatchTranslator method getSql.
@Override
public String getSql() {
InsertBatchQuery query = context.getQuery();
InsertBuilder insertBuilder = SQLBuilder.insert(context.getRootDbEntity());
for (DbAttribute attribute : query.getDbAttributes()) {
// skip generated attributes, if needed
if (excludeInBatch(attribute)) {
continue;
}
insertBuilder.column(SQLBuilder.column(attribute.getName()).attribute(attribute)).value(SQLBuilder.value(1).attribute(attribute));
}
return doTranslate(insertBuilder);
}
use of org.apache.cayenne.query.InsertBatchQuery in project cayenne by apache.
the class InsertBatchTranslator method updateBindings.
@Override
public DbAttributeBinding[] updateBindings(BatchQueryRow row) {
InsertBatchQuery query = context.getQuery();
int i = 0;
int j = 0;
for (DbAttribute attribute : query.getDbAttributes()) {
if (excludeInBatch(attribute)) {
i++;
continue;
}
Object value = row.getValue(i++);
ExtendedType<?> extendedType = value != null ? context.getAdapter().getExtendedTypes().getRegisteredType(value.getClass()) : context.getAdapter().getExtendedTypes().getDefaultType();
bindings[j].include(++j, value, extendedType);
}
return bindings;
}
Aggregations