Search in sources :

Example 71 with DbAttribute

use of org.apache.cayenne.map.DbAttribute 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 72 with DbAttribute

use of org.apache.cayenne.map.DbAttribute 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 73 with DbAttribute

use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.

the class DeleteBatchTranslatorIT method testCreateSqlStringWithIdentifiersQuote.

@Test
public void testCreateSqlStringWithIdentifiersQuote() throws Exception {
    DbEntity entity = runtime.getDataDomain().getEntityResolver().getObjEntity(SimpleLockingTestEntity.class).getDbEntity();
    try {
        entity.getDataMap().setQuotingSQLIdentifiers(true);
        List<DbAttribute> idAttributes = Collections.singletonList(entity.getAttribute("LOCKING_TEST_ID"));
        DeleteBatchQuery deleteQuery = new DeleteBatchQuery(entity, idAttributes, Collections.<String>emptySet(), 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 + " = ?", 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 74 with DbAttribute

use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.

the class SoftDeleteBatchTranslatorIT method testCreateSqlString.

@Test
public void testCreateSqlString() throws Exception {
    DbEntity entity = context.getEntityResolver().getObjEntity(SoftDelete.class).getDbEntity();
    List<DbAttribute> idAttributes = Collections.singletonList(entity.getAttribute("ID"));
    DeleteBatchQuery deleteQuery = new DeleteBatchQuery(entity, idAttributes, Collections.<String>emptySet(), 1);
    DeleteBatchTranslator builder = createTranslator(deleteQuery);
    String generatedSql = builder.getSql();
    assertNotNull(generatedSql);
    assertEquals("UPDATE " + entity.getName() + " SET DELETED = ? WHERE ID = ?", generatedSql);
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) SoftDelete(org.apache.cayenne.testdo.soft_delete.SoftDelete) DeleteBatchQuery(org.apache.cayenne.query.DeleteBatchQuery) DbAttribute(org.apache.cayenne.map.DbAttribute) Test(org.junit.Test)

Example 75 with DbAttribute

use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.

the class SoftDeleteBatchTranslatorIT method testCreateSqlStringWithNulls.

@Test
public void testCreateSqlStringWithNulls() throws Exception {
    DbEntity entity = context.getEntityResolver().getObjEntity(SoftDelete.class).getDbEntity();
    List<DbAttribute> idAttributes = Arrays.asList(entity.getAttribute("ID"), entity.getAttribute("NAME"));
    Collection<String> nullAttributes = Collections.singleton("NAME");
    DeleteBatchQuery deleteQuery = new DeleteBatchQuery(entity, idAttributes, nullAttributes, 1);
    DeleteBatchTranslator builder = createTranslator(deleteQuery);
    String generatedSql = builder.getSql();
    assertNotNull(generatedSql);
    assertEquals("UPDATE " + entity.getName() + " SET DELETED = ? WHERE ID = ? AND NAME IS NULL", generatedSql);
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) SoftDelete(org.apache.cayenne.testdo.soft_delete.SoftDelete) DeleteBatchQuery(org.apache.cayenne.query.DeleteBatchQuery) DbAttribute(org.apache.cayenne.map.DbAttribute) Test(org.junit.Test)

Aggregations

DbAttribute (org.apache.cayenne.map.DbAttribute)194 DbEntity (org.apache.cayenne.map.DbEntity)109 Test (org.junit.Test)67 ObjEntity (org.apache.cayenne.map.ObjEntity)36 DbRelationship (org.apache.cayenne.map.DbRelationship)35 ObjAttribute (org.apache.cayenne.map.ObjAttribute)32 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)21 DbJoin (org.apache.cayenne.map.DbJoin)18 HashMap (java.util.HashMap)16 ObjRelationship (org.apache.cayenne.map.ObjRelationship)16 ArrayList (java.util.ArrayList)14 DbAttributeBinding (org.apache.cayenne.access.translator.DbAttributeBinding)12 DataMap (org.apache.cayenne.map.DataMap)11 JdbcAdapter (org.apache.cayenne.dba.JdbcAdapter)10 QuotingStrategy (org.apache.cayenne.dba.QuotingStrategy)10 MergerToken (org.apache.cayenne.dbsync.merge.token.MergerToken)10 DeleteBatchQuery (org.apache.cayenne.query.DeleteBatchQuery)10 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)10 ObjectId (org.apache.cayenne.ObjectId)9 Expression (org.apache.cayenne.exp.Expression)8