use of org.apache.cayenne.dba.JdbcAdapter in project cayenne by apache.
the class BatchActionIT method testHasGeneratedKeys1.
@Test
public void testHasGeneratedKeys1() throws Exception {
EntityResolver resolver = runtime.getChannel().getEntityResolver();
// test with adapter that supports keys
JdbcAdapter adapter = buildAdapter(true);
DataNode node = new DataNode();
node.setAdapter(adapter);
node.setEntityResolver(resolver);
node.setRowReaderFactory(mock(RowReaderFactory.class));
InsertBatchQuery batch2 = new InsertBatchQuery(resolver.getObjEntity(Artist.class).getDbEntity(), 5);
assertFalse(new BatchAction(batch2, node, false).hasGeneratedKeys());
}
use of org.apache.cayenne.dba.JdbcAdapter in project cayenne by apache.
the class BatchActionIT method testHasGeneratedKeys2.
@Test
public void testHasGeneratedKeys2() throws Exception {
EntityResolver resolver = runtime.getChannel().getEntityResolver();
// test with adapter that does not support keys...
JdbcAdapter adapter = buildAdapter(false);
DataNode node = new DataNode();
node.setAdapter(adapter);
node.setEntityResolver(resolver);
node.setRowReaderFactory(mock(RowReaderFactory.class));
InsertBatchQuery batch2 = new InsertBatchQuery(resolver.getObjEntity(Artist.class).getDbEntity(), 5);
assertFalse(new BatchAction(batch2, node, false).hasGeneratedKeys());
}
use of org.apache.cayenne.dba.JdbcAdapter in project cayenne by apache.
the class BatchActionLockingIT method buildAdapter.
JdbcAdapter buildAdapter(boolean supportGeneratedKeys) {
JdbcAdapter adapter = objectFactory.newInstance(JdbcAdapter.class, JdbcAdapter.class.getName());
adapter.setSupportsGeneratedKeys(supportGeneratedKeys);
injector.injectMembers(adapter);
return adapter;
}
use of org.apache.cayenne.dba.JdbcAdapter in project cayenne by apache.
the class DeleteBatchTranslatorIT method testCreateSqlStringWithNullsWithIdentifiersQuote.
@Test
public void testCreateSqlStringWithNullsWithIdentifiersQuote() throws Exception {
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"));
Collection<String> nullAttributes = Collections.singleton("NAME");
DeleteBatchQuery deleteQuery = new DeleteBatchQuery(entity, idAttributes, nullAttributes, 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 + " = ? AND " + charStart + "NAME" + charEnd + " IS NULL", generatedSql);
} finally {
entity.getDataMap().setQuotingSQLIdentifiers(false);
}
}
use of org.apache.cayenne.dba.JdbcAdapter 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);
}
}
Aggregations