use of org.apache.cayenne.dba.DbAdapter in project cayenne by apache.
the class DefaultBatchTranslatorIT method testAppendDbAttribute2.
@Test
public void testAppendDbAttribute2() throws Exception {
DbAdapter adapter = objectFactory.newInstance(DbAdapter.class, JdbcAdapter.class.getName());
DefaultBatchTranslator builder = new DefaultBatchTranslator(mock(BatchQuery.class), adapter, null) {
@Override
protected String createSql() {
return null;
}
@Override
protected DbAttributeBinding[] createBindings() {
return new DbAttributeBinding[0];
}
@Override
protected DbAttributeBinding[] doUpdateBindings(BatchQueryRow row) {
return new DbAttributeBinding[0];
}
};
StringBuilder buf = new StringBuilder();
DbEntity entity = new DbEntity("Test");
DbAttribute attr = new DbAttribute("testAttr", Types.CHAR, null);
attr.setEntity(entity);
builder.appendDbAttribute(buf, attr);
assertEquals("testAttr", buf.toString());
buf = new StringBuilder();
attr = new DbAttribute("testAttr", Types.VARCHAR, null);
attr.setEntity(entity);
builder.appendDbAttribute(buf, attr);
assertEquals("testAttr", buf.toString());
}
use of org.apache.cayenne.dba.DbAdapter in project cayenne by apache.
the class InsertBatchTranslatorIT method testConstructor.
@Test
public void testConstructor() throws Exception {
DbAdapter adapter = objectFactory.newInstance(DbAdapter.class, JdbcAdapter.class.getName());
InsertBatchTranslator builder = new InsertBatchTranslator(mock(InsertBatchQuery.class), adapter);
assertSame(adapter, builder.adapter);
}
use of org.apache.cayenne.dba.DbAdapter in project cayenne by apache.
the class UpdateBatchTranslatorIT method testConstructor.
@Test
public void testConstructor() throws Exception {
DbAdapter adapter = objectFactory.newInstance(DbAdapter.class, JdbcAdapter.class.getName());
UpdateBatchTranslator builder = new UpdateBatchTranslator(mock(UpdateBatchQuery.class), adapter, null);
assertSame(adapter, builder.adapter);
}
use of org.apache.cayenne.dba.DbAdapter in project cayenne by apache.
the class SchemaBuilder method tableCreateQueries.
/**
* Returns iterator of preprocessed table create queries.
*/
private Collection<String> tableCreateQueries(DataNode node, DataMap map) throws Exception {
DbAdapter adapter = node.getAdapter();
DbGenerator gen = new DbGenerator(adapter, map, null, domain, jdbcEventLogger);
List<DbEntity> orderedEnts = dbEntitiesInInsertOrder(node, map);
List<String> queries = new ArrayList<String>();
// table definitions
for (DbEntity ent : orderedEnts) {
queries.add(adapter.createTable(ent));
}
// FK constraints
for (DbEntity ent : orderedEnts) {
if (!unitDbAdapter.supportsFKConstraints(ent)) {
continue;
}
List<String> qs = gen.createConstraintsQueries(ent);
queries.addAll(qs);
}
return queries;
}
use of org.apache.cayenne.dba.DbAdapter in project cayenne by apache.
the class FlattenedArcKey method buildJoinSnapshotForInsert.
/**
* Returns a snapshot for join record for the single-step flattened
* relationship, generating value for the primary key column if it is not
* propagated via the relationships.
*/
Map<String, Object> buildJoinSnapshotForInsert(DataNode node) {
Map<String, Object> snapshot = lazyJoinSnapshot();
boolean autoPkDone = false;
DbEntity joinEntity = getJoinEntity();
for (DbAttribute dbAttr : joinEntity.getPrimaryKeys()) {
String dbAttrName = dbAttr.getName();
if (snapshot.containsKey(dbAttrName)) {
continue;
}
DbAdapter adapter = node.getAdapter();
// value here, so no need to retrieve db-generated pk back to Java.
if (adapter.supportsGeneratedKeys() && dbAttr.isGenerated()) {
continue;
}
if (autoPkDone) {
throw new CayenneRuntimeException("Primary Key autogeneration only works for a single attribute.");
}
// finally, use database generation mechanism
try {
Object pkValue = adapter.getPkGenerator().generatePk(node, dbAttr);
snapshot.put(dbAttrName, pkValue);
autoPkDone = true;
} catch (Exception ex) {
throw new CayenneRuntimeException("Error generating PK: %s", ex, ex.getMessage());
}
}
return snapshot;
}
Aggregations