use of org.apache.cayenne.dba.DbAdapter in project cayenne by apache.
the class DefaultDbImportActionTest method buildDbImportAction.
private DefaultDbImportAction buildDbImportAction(FileProjectSaver projectSaver, DataMapLoader mapLoader, final DbLoader dbLoader) throws Exception {
Logger log = mock(Logger.class);
when(log.isDebugEnabled()).thenReturn(true);
when(log.isInfoEnabled()).thenReturn(true);
DbAdapter dbAdapter = mock(DbAdapter.class);
DbAdapterFactory adapterFactory = mock(DbAdapterFactory.class);
when(adapterFactory.createAdapter((DataNodeDescriptor) any(), (DataSource) any())).thenReturn(dbAdapter);
DataSourceFactory dataSourceFactory = mock(DataSourceFactory.class);
DataSource mock = mock(DataSource.class);
when(dataSourceFactory.getDataSource((DataNodeDescriptor) any())).thenReturn(mock);
MergerTokenFactoryProvider mergerTokenFactoryProvider = mock(MergerTokenFactoryProvider.class);
when(mergerTokenFactoryProvider.get((DbAdapter) any())).thenReturn(new DefaultMergerTokenFactory());
DataChannelDescriptorLoader dataChannelDescriptorLoader = mock(DataChannelDescriptorLoader.class);
return new DefaultDbImportAction(log, projectSaver, dataSourceFactory, adapterFactory, mapLoader, mergerTokenFactoryProvider, dataChannelDescriptorLoader) {
protected DbLoader createDbLoader(DbAdapter adapter, Connection connection, DbImportConfiguration config) {
return dbLoader;
}
};
}
use of org.apache.cayenne.dba.DbAdapter in project cayenne by apache.
the class DbGenerateTask method createDbAdapter.
DbAdapter createDbAdapter() {
Injector injector = DIBootstrap.createInjector(new DbSyncModule(), new ToolsModule(getLogger()));
AdhocObjectFactory objectFactory = injector.getInstance(AdhocObjectFactory.class);
return (adapter == null) ? objectFactory.newInstance(DbAdapter.class, JdbcAdapter.class.getName()) : objectFactory.newInstance(DbAdapter.class, adapter);
}
use of org.apache.cayenne.dba.DbAdapter in project cayenne by apache.
the class FirebirdMergerTokenFactory method createSetAllowNullToDb.
@Override
public MergerToken createSetAllowNullToDb(DbEntity entity, DbAttribute column) {
return new SetAllowNullToDb(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 system tables
return Collections.singletonList(String.format("UPDATE RDB$RELATION_FIELDS SET RDB$NULL_FLAG = NULL " + " 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 IngresMergerTokenFactory method createSetNotNullToDb.
@Override
public MergerToken createSetNotNullToDb(DbEntity entity, DbAttribute column) {
return new SetNotNullToDb(entity, column) {
@Override
public List<String> createSql(DbAdapter adapter) {
/*
* TODO: we generate this query as in ingres db documentation,
* but unfortunately ingres don't support it
*/
StringBuilder sqlBuffer = new StringBuilder();
QuotingStrategy context = adapter.getQuotingStrategy();
sqlBuffer.append("ALTER TABLE ");
sqlBuffer.append(getEntity().getFullyQualifiedName());
sqlBuffer.append(" ALTER COLUMN ");
sqlBuffer.append(context.quotedName(getColumn()));
sqlBuffer.append(" ");
sqlBuffer.append(adapter.externalTypesForJdbcType(getColumn().getType())[0]);
if (adapter.typeSupportsLength(getColumn().getType()) && getColumn().getMaxLength() > 0) {
sqlBuffer.append("(");
sqlBuffer.append(getColumn().getMaxLength());
sqlBuffer.append(")");
}
sqlBuffer.append(" NOT NULL");
return Collections.singletonList(sqlBuffer.toString());
}
};
}
use of org.apache.cayenne.dba.DbAdapter in project cayenne by apache.
the class IngresMergerTokenFactory method createDropColumnToDb.
@Override
public MergerToken createDropColumnToDb(DbEntity entity, DbAttribute column) {
return new DropColumnToDb(entity, column) {
@Override
public List<String> createSql(DbAdapter adapter) {
StringBuilder buf = new StringBuilder();
QuotingStrategy context = adapter.getQuotingStrategy();
buf.append("ALTER TABLE ");
buf.append(context.quotedFullyQualifiedName(getEntity()));
buf.append(" DROP COLUMN ");
buf.append(context.quotedName(getColumn()));
buf.append(" RESTRICT ");
return Collections.singletonList(buf.toString());
}
};
}
Aggregations