use of org.apache.cayenne.map.DbEntity 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);
}
use of org.apache.cayenne.map.DbEntity 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);
}
use of org.apache.cayenne.map.DbEntity 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);
}
use of org.apache.cayenne.map.DbEntity 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);
}
use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class UpdateBatchTranslatorIT method testCreateSqlStringWithNulls.
@Test
public void testCreateSqlStringWithNulls() throws Exception {
DbEntity entity = runtime.getDataDomain().getEntityResolver().getObjEntity(SimpleLockingTestEntity.class).getDbEntity();
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);
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 = ? AND NAME IS NULL", generatedSql);
}
Aggregations