use of org.apache.cayenne.dba.DbAdapter in project cayenne by apache.
the class DbGenerator method buildStatements.
/**
* Creates and stores internally a set of statements for database schema
* creation, ignoring configured schema creation preferences. Statements are
* NOT executed in this method.
*/
protected void buildStatements() {
dropTables = new HashMap<>();
createTables = new HashMap<>();
createConstraints = new HashMap<>();
DbAdapter adapter = getAdapter();
for (final DbEntity dbe : this.dbEntitiesInInsertOrder) {
String name = dbe.getName();
// build "DROP TABLE"
dropTables.put(name, adapter.dropTableStatements(dbe));
// build "CREATE TABLE"
createTables.put(name, adapter.createTable(dbe));
// build constraints
createConstraints.put(name, createConstraintsQueries(dbe));
}
PkGenerator pkGenerator = adapter.getPkGenerator();
dropPK = pkGenerator.dropAutoPkStatements(dbEntitiesRequiringAutoPK);
createPK = pkGenerator.createAutoPkStatements(dbEntitiesRequiringAutoPK);
}
use of org.apache.cayenne.dba.DbAdapter in project cayenne by apache.
the class BatchAction method runAsBatch.
protected void runAsBatch(Connection con, BatchTranslator translator, OperationObserver delegate) throws SQLException, Exception {
String sql = translator.getSql();
JdbcEventLogger logger = dataNode.getJdbcEventLogger();
boolean isLoggable = logger.isLoggable();
// log batch SQL execution
logger.log(sql);
// run batch
DbAdapter adapter = dataNode.getAdapter();
try (PreparedStatement statement = con.prepareStatement(sql)) {
for (BatchQueryRow row : query.getRows()) {
DbAttributeBinding[] bindings = translator.updateBindings(row);
logger.logQueryParameters("batch bind", bindings);
bind(adapter, statement, bindings);
statement.addBatch();
}
// execute the whole batch
int[] results = statement.executeBatch();
delegate.nextBatchCount(query, results);
if (isLoggable) {
int totalUpdateCount = 0;
for (int result : results) {
// Statement.EXECUTE_FAILED
if (result < 0) {
totalUpdateCount = Statement.SUCCESS_NO_INFO;
break;
}
totalUpdateCount += result;
}
logger.logUpdateCount(totalUpdateCount);
}
}
}
use of org.apache.cayenne.dba.DbAdapter in project cayenne by apache.
the class FirebirdMergerTokenFactory method createSetNotNullToDb.
@Override
public MergerToken createSetNotNullToDb(DbEntity entity, DbAttribute column) {
return new SetNotNullToDb(entity, column) {
public List<String> createSql(DbAdapter adapter) {
QuotingStrategy context = adapter.getQuotingStrategy();
String entityName = context.quotedFullyQualifiedName(getEntity());
String columnName = context.quotedName(getColumn());
// but this might be achived by modyfication of system tables
return Collections.singletonList(String.format("UPDATE RDB$RELATION_FIELDS SET RDB$NULL_FLAG = 1 " + "WHERE RDB$FIELD_NAME = '%s' AND RDB$RELATION_NAME = '%s'", columnName, entityName));
}
};
}
use of org.apache.cayenne.dba.DbAdapter in project cayenne by apache.
the class MySQLMergerTokenFactory method createSetNotNullToDb.
@Override
public MergerToken createSetNotNullToDb(final DbEntity entity, final DbAttribute column) {
return new SetNotNullToDb(entity, column) {
@Override
public List<String> createSql(DbAdapter adapter) {
StringBuffer sqlBuffer = new StringBuffer();
QuotingStrategy context = adapter.getQuotingStrategy();
sqlBuffer.append("ALTER TABLE ");
sqlBuffer.append(context.quotedFullyQualifiedName(getEntity()));
sqlBuffer.append(" CHANGE ");
sqlBuffer.append(context.quotedName(getColumn()));
sqlBuffer.append(" ");
adapter.createTableAppendColumn(sqlBuffer, column);
return Collections.singletonList(sqlBuffer.toString());
}
};
}
use of org.apache.cayenne.dba.DbAdapter in project cayenne by apache.
the class OpenBaseMergerTokenFactory method createDropRelationshipToDb.
@Override
public MergerToken createDropRelationshipToDb(final DbEntity entity, final DbRelationship rel) {
return new DropRelationshipToDb(entity, rel) {
@Override
public List<String> createSql(DbAdapter adapter) {
// FK_NAME form jdbc metadata seem to be wrong. It contain a column name
// and not the 'relationshipName'
// TODO: tell openbase developer mail list
DbEntity source = getEntity();
DbEntity dest = rel.getTargetEntity();
// only use the first. See adapter
// TODO: can we be sure this is the first and same as used by the adapter?
DbJoin join = rel.getJoins().get(0);
return Collections.singletonList("delete from _SYS_RELATIONSHIP where " + " source_table = '" + dest.getFullyQualifiedName() + "'" + " and source_column = '" + join.getTargetName() + "'" + " and dest_table = '" + source.getFullyQualifiedName() + "'" + " and dest_column = '" + join.getSourceName() + "'");
}
};
}
Aggregations