Search in sources :

Example 11 with JdbcAdapter

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());
}
Also used : JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter) InsertBatchQuery(org.apache.cayenne.query.InsertBatchQuery) DataNode(org.apache.cayenne.access.DataNode) RowReaderFactory(org.apache.cayenne.access.jdbc.reader.RowReaderFactory) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 12 with JdbcAdapter

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());
}
Also used : JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter) InsertBatchQuery(org.apache.cayenne.query.InsertBatchQuery) DataNode(org.apache.cayenne.access.DataNode) RowReaderFactory(org.apache.cayenne.access.jdbc.reader.RowReaderFactory) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 13 with JdbcAdapter

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;
}
Also used : JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter)

Example 14 with JdbcAdapter

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);
    }
}
Also used : JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter) DbEntity(org.apache.cayenne.map.DbEntity) DeleteBatchQuery(org.apache.cayenne.query.DeleteBatchQuery) SimpleLockingTestEntity(org.apache.cayenne.testdo.locking.SimpleLockingTestEntity) DbAttribute(org.apache.cayenne.map.DbAttribute) Test(org.junit.Test)

Example 15 with JdbcAdapter

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);
    }
}
Also used : JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter) DbEntity(org.apache.cayenne.map.DbEntity) InsertBatchQuery(org.apache.cayenne.query.InsertBatchQuery) SimpleLockingTestEntity(org.apache.cayenne.testdo.locking.SimpleLockingTestEntity) Test(org.junit.Test)

Aggregations

JdbcAdapter (org.apache.cayenne.dba.JdbcAdapter)18 Test (org.junit.Test)15 DbEntity (org.apache.cayenne.map.DbEntity)9 SimpleLockingTestEntity (org.apache.cayenne.testdo.locking.SimpleLockingTestEntity)7 DataNode (org.apache.cayenne.access.DataNode)6 RowReaderFactory (org.apache.cayenne.access.jdbc.reader.RowReaderFactory)6 DbAttribute (org.apache.cayenne.map.DbAttribute)6 EntityResolver (org.apache.cayenne.map.EntityResolver)6 DeleteBatchQuery (org.apache.cayenne.query.DeleteBatchQuery)5 InsertBatchQuery (org.apache.cayenne.query.InsertBatchQuery)5 PreparedStatementResultSetHandler (com.mockrunner.jdbc.PreparedStatementResultSetHandler)2 MockConnection (com.mockrunner.mock.jdbc.MockConnection)2 HashMap (java.util.HashMap)2 List (java.util.List)2 MockOperationObserver (org.apache.cayenne.access.MockOperationObserver)2 DeleteBatchTranslator (org.apache.cayenne.access.translator.batch.DeleteBatchTranslator)2 UpdateBatchQuery (org.apache.cayenne.query.UpdateBatchQuery)2 SoftDelete (org.apache.cayenne.testdo.soft_delete.SoftDelete)2 Collection (java.util.Collection)1 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)1