use of org.apache.cayenne.dba.DbAdapter in project cayenne by apache.
the class SybaseMergerTokenFactory method createAddColumnToDb.
/**
* @since 3.0
*/
@Override
public MergerToken createAddColumnToDb(DbEntity entity, final DbAttribute column) {
return new AddColumnToDb(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(" ADD ");
boolean magnatory = column.isMandatory();
column.setMandatory(false);
adapter.createTableAppendColumn(sqlBuffer, column);
if (magnatory) {
column.setMandatory(magnatory);
}
return Collections.singletonList(sqlBuffer.toString());
}
};
}
use of org.apache.cayenne.dba.DbAdapter in project cayenne by apache.
the class CreateTableToDb method execute.
@Override
public void execute(MergerContext mergerContext) {
try {
DataNode node = mergerContext.getDataNode();
DbAdapter adapter = node.getAdapter();
if (needAutoPkSupport()) {
adapter.getPkGenerator().createAutoPk(node, Collections.singletonList(getEntity()));
}
executeSql(mergerContext, adapter.createTable(getEntity()));
} catch (Exception e) {
mergerContext.getValidationResult().addFailure(new SimpleValidationFailure(this, e.getMessage()));
}
}
use of org.apache.cayenne.dba.DbAdapter in project cayenne by apache.
the class DbImportConfigurationValidator method validate.
public void validate() throws Exception {
DataNodeDescriptor dataNodeDescriptor = config.createDataNodeDescriptor();
DbAdapter adapter;
try {
DataSource dataSource = injector.getInstance(DataSourceFactory.class).getDataSource(dataNodeDescriptor);
adapter = injector.getInstance(DbAdapterFactory.class).createAdapter(dataNodeDescriptor, dataSource);
} catch (Exception ex) {
throw new Exception("Error creating DataSource or DbAdapter for DataNodeDescriptor (" + dataNodeDescriptor + ")", ex);
}
if (adapter != null && !adapter.supportsCatalogsOnReverseEngineering() && !isReverseEngineeringCatalogsEmpty()) {
String message = "Your database does not support catalogs on reverse engineering. " + "It allows to connect to only one at the moment. " + "Please don't note catalogs in <dbimport> configuration.";
throw new Exception(message);
}
}
use of org.apache.cayenne.dba.DbAdapter in project cayenne by apache.
the class BatchAction method runAsIndividualQueries.
/**
* Executes batch as individual queries over the same prepared statement.
*/
protected void runAsIndividualQueries(Connection connection, BatchTranslator translator, OperationObserver delegate, boolean generatesKeys) throws SQLException, Exception {
JdbcEventLogger logger = dataNode.getJdbcEventLogger();
boolean useOptimisticLock = query.isUsingOptimisticLocking();
String queryStr = translator.getSql();
// log batch SQL execution
logger.log(queryStr);
// run batch queries one by one
DbAdapter adapter = dataNode.getAdapter();
try (PreparedStatement statement = prepareStatement(connection, queryStr, adapter, generatesKeys)) {
for (BatchQueryRow row : query.getRows()) {
DbAttributeBinding[] bindings = translator.updateBindings(row);
logger.logQueryParameters("bind", bindings);
bind(adapter, statement, bindings);
int updated = statement.executeUpdate();
if (useOptimisticLock && updated != 1) {
throw new OptimisticLockException(row.getObjectId(), query.getDbEntity(), queryStr, row.getQualifier());
}
delegate.nextCount(query, updated);
if (generatesKeys) {
processGeneratedKeys(statement, delegate, row);
}
logger.logUpdateCount(updated);
}
}
}
Aggregations