Search in sources :

Example 21 with UpdateBatchQuery

use of org.apache.cayenne.query.UpdateBatchQuery in project cayenne by apache.

the class UpdateBatchTranslatorIT method testConstructor.

@Test
public void testConstructor() {
    DbAdapter adapter = objectFactory.newInstance(DbAdapter.class, JdbcAdapter.class.getName());
    UpdateBatchQuery query = mock(UpdateBatchQuery.class);
    UpdateBatchTranslator builder = new UpdateBatchTranslator(query, adapter);
    assertSame(adapter, builder.context.getAdapter());
    assertSame(query, builder.context.getQuery());
}
Also used : JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter) UnitDbAdapter(org.apache.cayenne.unit.UnitDbAdapter) DbAdapter(org.apache.cayenne.dba.DbAdapter) UpdateBatchQuery(org.apache.cayenne.query.UpdateBatchQuery) Test(org.junit.Test)

Example 22 with UpdateBatchQuery

use of org.apache.cayenne.query.UpdateBatchQuery in project cayenne by apache.

the class UpdateBatchTranslatorIT method testCreateSqlStringWithIdentifiersQuote.

@Test
public void testCreateSqlStringWithIdentifiersQuote() {
    DbEntity entity = runtime.getDataDomain().getEntityResolver().getObjEntity(SimpleLockingTestEntity.class).getDbEntity();
    try {
        entity.getDataMap().setQuotingSQLIdentifiers(true);
        List<DbAttribute> idAttributes = Collections.singletonList(entity.getAttribute("LOCKING_TEST_ID"));
        List<DbAttribute> updatedAttributes = Collections.singletonList(entity.getAttribute("DESCRIPTION"));
        UpdateBatchQuery updateQuery = new UpdateBatchQuery(entity, idAttributes, updatedAttributes, Collections.emptySet(), 1);
        JdbcAdapter adapter = (JdbcAdapter) this.adapter;
        UpdateBatchTranslator builder = new UpdateBatchTranslator(updateQuery, adapter);
        String generatedSql = builder.getSql();
        String charStart = unitAdapter.getIdentifiersStartQuote();
        String charEnd = unitAdapter.getIdentifiersEndQuote();
        assertNotNull(generatedSql);
        assertEquals("UPDATE " + charStart + entity.getName() + charEnd + " SET " + charStart + "DESCRIPTION" + charEnd + " = ? WHERE " + charStart + "LOCKING_TEST_ID" + charEnd + " = ?", generatedSql);
    } finally {
        entity.getDataMap().setQuotingSQLIdentifiers(false);
    }
}
Also used : JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter) DbEntity(org.apache.cayenne.map.DbEntity) UpdateBatchQuery(org.apache.cayenne.query.UpdateBatchQuery) SimpleLockingTestEntity(org.apache.cayenne.testdo.locking.SimpleLockingTestEntity) DbAttribute(org.apache.cayenne.map.DbAttribute) Test(org.junit.Test)

Example 23 with UpdateBatchQuery

use of org.apache.cayenne.query.UpdateBatchQuery 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);
    }
}
Also used : JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter) DbEntity(org.apache.cayenne.map.DbEntity) UpdateBatchQuery(org.apache.cayenne.query.UpdateBatchQuery) SimpleLockingTestEntity(org.apache.cayenne.testdo.locking.SimpleLockingTestEntity) Collection(java.util.Collection) List(java.util.List) Test(org.junit.Test)

Example 24 with UpdateBatchQuery

use of org.apache.cayenne.query.UpdateBatchQuery 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

UpdateBatchQuery (org.apache.cayenne.query.UpdateBatchQuery)24 DbAttribute (org.apache.cayenne.map.DbAttribute)18 DbEntity (org.apache.cayenne.map.DbEntity)10 Test (org.junit.Test)10 JdbcAdapter (org.apache.cayenne.dba.JdbcAdapter)9 SimpleLockingTestEntity (org.apache.cayenne.testdo.locking.SimpleLockingTestEntity)8 List (java.util.List)5 DbAdapter (org.apache.cayenne.dba.DbAdapter)5 UnitDbAdapter (org.apache.cayenne.unit.UnitDbAdapter)5 DbAttributeBinding (org.apache.cayenne.access.translator.DbAttributeBinding)3 QuotingStrategy (org.apache.cayenne.dba.QuotingStrategy)3 Collection (java.util.Collection)2 ExtendedType (org.apache.cayenne.access.types.ExtendedType)2 InsertBatchQuery (org.apache.cayenne.query.InsertBatchQuery)2 PreparedStatement (java.sql.PreparedStatement)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Set (java.util.Set)1