use of org.apache.cayenne.dba.JdbcAdapter 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.dba.JdbcAdapter in project cayenne by apache.
the class DataNodeIT method testAdapter.
@Test
public void testAdapter() throws Exception {
DataNode node = new DataNode();
assertNull(node.getAdapter());
JdbcAdapter a1 = objectFactory.newInstance(JdbcAdapter.class, JdbcAdapter.class.getName());
node.setAdapter(a1);
assertSame(a1, node.getAdapter());
JdbcAdapter a2 = objectFactory.newInstance(JdbcAdapter.class, JdbcAdapter.class.getName());
node.setAdapter(a2);
assertSame(a2, node.getAdapter());
}
use of org.apache.cayenne.dba.JdbcAdapter in project cayenne by apache.
the class DataContextExtrasIT method testCommitChangesError.
@Test
public void testCommitChangesError() {
DataDomain domain = context.getParentDataDomain();
// setup mockup PK generator that will blow on PK request
// to emulate an exception
JdbcAdapter jdbcAdapter = objectFactory.newInstance(JdbcAdapter.class, JdbcAdapter.class.getName());
PkGenerator newGenerator = new JdbcPkGenerator(jdbcAdapter) {
@Override
public Object generatePk(DataNode node, DbAttribute pk) throws Exception {
throw new CayenneRuntimeException("Intentional");
}
};
PkGenerator oldGenerator = domain.getDataNodes().iterator().next().getAdapter().getPkGenerator();
JdbcAdapter adapter = (JdbcAdapter) domain.getDataNodes().iterator().next().getAdapter();
adapter.setPkGenerator(newGenerator);
try {
Artist newArtist = context.newObject(Artist.class);
newArtist.setArtistName("aaa");
context.commitChanges();
fail("Exception expected but not thrown due to missing PK generation routine.");
} catch (CayenneRuntimeException ex) {
// exception expected
} finally {
adapter.setPkGenerator(oldGenerator);
}
}
use of org.apache.cayenne.dba.JdbcAdapter in project cayenne by apache.
the class BatchActionGeneratedIT method testHasGeneratedKeys1.
@Test
public void testHasGeneratedKeys1() throws Exception {
EntityResolver resolver = runtime.getChannel().getEntityResolver();
// test with adapter that supports keys
JdbcAdapter adapter = buildAdapter(true);
InsertBatchQuery batch1 = new InsertBatchQuery(resolver.getObjEntity(GeneratedColumnTestEntity.class).getDbEntity(), 5);
DataNode node = new DataNode();
node.setAdapter(adapter);
node.setEntityResolver(resolver);
node.setRowReaderFactory(mock(RowReaderFactory.class));
assertTrue(new BatchAction(batch1, node, false).hasGeneratedKeys());
}
use of org.apache.cayenne.dba.JdbcAdapter in project cayenne by apache.
the class BatchActionGeneratedIT method buildAdapter.
JdbcAdapter buildAdapter(boolean supportGeneratedKeys) {
JdbcAdapter adapter = objectFactory.newInstance(JdbcAdapter.class, JdbcAdapter.class.getName());
adapter.setSupportsGeneratedKeys(supportGeneratedKeys);
return adapter;
}
Aggregations