Search in sources :

Example 11 with DbAdapter

use of org.apache.cayenne.dba.DbAdapter in project cayenne by apache.

the class DeleteBatchTranslatorIT method testCreateSqlString.

@Test
public void testCreateSqlString() throws Exception {
    DbEntity entity = runtime.getDataDomain().getEntityResolver().getObjEntity(SimpleLockingTestEntity.class).getDbEntity();
    List<DbAttribute> idAttributes = Collections.singletonList(entity.getAttribute("LOCKING_TEST_ID"));
    DeleteBatchQuery deleteQuery = new DeleteBatchQuery(entity, idAttributes, Collections.<String>emptySet(), 1);
    DbAdapter adapter = objectFactory.newInstance(DbAdapter.class, JdbcAdapter.class.getName());
    DeleteBatchTranslator builder = new DeleteBatchTranslator(deleteQuery, adapter, null);
    String generatedSql = builder.getSql();
    assertNotNull(generatedSql);
    assertEquals("DELETE FROM " + entity.getName() + " WHERE LOCKING_TEST_ID = ?", generatedSql);
}
Also used : JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter) DbEntity(org.apache.cayenne.map.DbEntity) UnitDbAdapter(org.apache.cayenne.unit.UnitDbAdapter) DbAdapter(org.apache.cayenne.dba.DbAdapter) DeleteBatchQuery(org.apache.cayenne.query.DeleteBatchQuery) SimpleLockingTestEntity(org.apache.cayenne.testdo.locking.SimpleLockingTestEntity) DbAttribute(org.apache.cayenne.map.DbAttribute) Test(org.junit.Test)

Example 12 with DbAdapter

use of org.apache.cayenne.dba.DbAdapter in project cayenne by apache.

the class DeleteBatchTranslatorIT method testCreateSqlStringWithNulls.

@Test
public void testCreateSqlStringWithNulls() throws Exception {
    DbEntity entity = runtime.getDataDomain().getEntityResolver().getObjEntity(SimpleLockingTestEntity.class).getDbEntity();
    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);
    DbAdapter adapter = objectFactory.newInstance(DbAdapter.class, JdbcAdapter.class.getName());
    DeleteBatchTranslator builder = new DeleteBatchTranslator(deleteQuery, adapter, null);
    String generatedSql = builder.getSql();
    assertNotNull(generatedSql);
    assertEquals("DELETE FROM " + entity.getName() + " WHERE LOCKING_TEST_ID = ? AND NAME IS NULL", generatedSql);
}
Also used : JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter) DbEntity(org.apache.cayenne.map.DbEntity) UnitDbAdapter(org.apache.cayenne.unit.UnitDbAdapter) DbAdapter(org.apache.cayenne.dba.DbAdapter) DeleteBatchQuery(org.apache.cayenne.query.DeleteBatchQuery) SimpleLockingTestEntity(org.apache.cayenne.testdo.locking.SimpleLockingTestEntity) DbAttribute(org.apache.cayenne.map.DbAttribute) Test(org.junit.Test)

Example 13 with DbAdapter

use of org.apache.cayenne.dba.DbAdapter in project cayenne by apache.

the class DeleteBatchTranslatorIT method testConstructor.

@Test
public void testConstructor() throws Exception {
    DbAdapter adapter = objectFactory.newInstance(DbAdapter.class, JdbcAdapter.class.getName());
    DeleteBatchTranslator builder = new DeleteBatchTranslator(mock(DeleteBatchQuery.class), adapter, null);
    assertSame(adapter, builder.adapter);
}
Also used : JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter) UnitDbAdapter(org.apache.cayenne.unit.UnitDbAdapter) DbAdapter(org.apache.cayenne.dba.DbAdapter) DeleteBatchQuery(org.apache.cayenne.query.DeleteBatchQuery) Test(org.junit.Test)

Example 14 with DbAdapter

use of org.apache.cayenne.dba.DbAdapter in project cayenne by apache.

the class InsertBatchTranslatorIT method testCreateSqlString.

@Test
public void testCreateSqlString() throws Exception {
    DbEntity entity = runtime.getDataDomain().getEntityResolver().getObjEntity(SimpleLockingTestEntity.class).getDbEntity();
    DbAdapter adapter = objectFactory.newInstance(DbAdapter.class, JdbcAdapter.class.getName());
    InsertBatchQuery insertQuery = new InsertBatchQuery(entity, 1);
    InsertBatchTranslator builder = new InsertBatchTranslator(insertQuery, adapter);
    String generatedSql = builder.getSql();
    assertNotNull(generatedSql);
    assertEquals("INSERT INTO " + entity.getName() + " (DESCRIPTION, INT_COLUMN_NOTNULL, INT_COLUMN_NULL, LOCKING_TEST_ID, NAME) VALUES (?, ?, ?, ?, ?)", generatedSql);
}
Also used : JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter) DbEntity(org.apache.cayenne.map.DbEntity) UnitDbAdapter(org.apache.cayenne.unit.UnitDbAdapter) DbAdapter(org.apache.cayenne.dba.DbAdapter) InsertBatchQuery(org.apache.cayenne.query.InsertBatchQuery) SimpleLockingTestEntity(org.apache.cayenne.testdo.locking.SimpleLockingTestEntity) Test(org.junit.Test)

Example 15 with DbAdapter

use of org.apache.cayenne.dba.DbAdapter in project cayenne by apache.

the class UpdateBatchTranslatorIT method testCreateSqlString.

@Test
public void testCreateSqlString() throws Exception {
    DbEntity entity = runtime.getDataDomain().getEntityResolver().getObjEntity(SimpleLockingTestEntity.class).getDbEntity();
    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);
    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 = ?", generatedSql);
}
Also used : JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter) DbEntity(org.apache.cayenne.map.DbEntity) UnitDbAdapter(org.apache.cayenne.unit.UnitDbAdapter) DbAdapter(org.apache.cayenne.dba.DbAdapter) UpdateBatchQuery(org.apache.cayenne.query.UpdateBatchQuery) SimpleLockingTestEntity(org.apache.cayenne.testdo.locking.SimpleLockingTestEntity) List(java.util.List) Test(org.junit.Test)

Aggregations

DbAdapter (org.apache.cayenne.dba.DbAdapter)44 Test (org.junit.Test)17 DbEntity (org.apache.cayenne.map.DbEntity)16 JdbcAdapter (org.apache.cayenne.dba.JdbcAdapter)11 QuotingStrategy (org.apache.cayenne.dba.QuotingStrategy)11 UnitDbAdapter (org.apache.cayenne.unit.UnitDbAdapter)10 Injector (org.apache.cayenne.di.Injector)8 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)7 List (java.util.List)6 AdhocObjectFactory (org.apache.cayenne.di.AdhocObjectFactory)6 JdbcEventLogger (org.apache.cayenne.log.JdbcEventLogger)6 ArrayList (java.util.ArrayList)5 DbAttributeBinding (org.apache.cayenne.access.translator.DbAttributeBinding)5 AutoAdapter (org.apache.cayenne.dba.AutoAdapter)5 DataMap (org.apache.cayenne.map.DataMap)5 BatchQueryRow (org.apache.cayenne.query.BatchQueryRow)5 SimpleLockingTestEntity (org.apache.cayenne.testdo.locking.SimpleLockingTestEntity)5 MockConnection (com.mockrunner.mock.jdbc.MockConnection)4 MockDataSource (com.mockrunner.mock.jdbc.MockDataSource)4 DatabaseMetaData (java.sql.DatabaseMetaData)4