Search in sources :

Example 31 with DbAdapter

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;
        }
    };
}
Also used : DbAdapterFactory(org.apache.cayenne.configuration.server.DbAdapterFactory) DataSourceFactory(org.apache.cayenne.configuration.server.DataSourceFactory) DbAdapter(org.apache.cayenne.dba.DbAdapter) DefaultMergerTokenFactory(org.apache.cayenne.dbsync.merge.factory.DefaultMergerTokenFactory) DataChannelDescriptorLoader(org.apache.cayenne.configuration.DataChannelDescriptorLoader) Connection(java.sql.Connection) Logger(org.slf4j.Logger) MergerTokenFactoryProvider(org.apache.cayenne.dbsync.merge.factory.MergerTokenFactoryProvider) DataSource(javax.sql.DataSource)

Example 32 with DbAdapter

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);
}
Also used : DbAdapter(org.apache.cayenne.dba.DbAdapter) Injector(org.apache.cayenne.di.Injector) DbSyncModule(org.apache.cayenne.dbsync.DbSyncModule) AdhocObjectFactory(org.apache.cayenne.di.AdhocObjectFactory) ToolsModule(org.apache.cayenne.dbsync.reverse.configuration.ToolsModule)

Example 33 with DbAdapter

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));
        }
    };
}
Also used : DbAdapter(org.apache.cayenne.dba.DbAdapter) SetAllowNullToDb(org.apache.cayenne.dbsync.merge.token.db.SetAllowNullToDb) QuotingStrategy(org.apache.cayenne.dba.QuotingStrategy)

Example 34 with DbAdapter

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());
        }
    };
}
Also used : DbAdapter(org.apache.cayenne.dba.DbAdapter) SetNotNullToDb(org.apache.cayenne.dbsync.merge.token.db.SetNotNullToDb) QuotingStrategy(org.apache.cayenne.dba.QuotingStrategy)

Example 35 with DbAdapter

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());
        }
    };
}
Also used : DropColumnToDb(org.apache.cayenne.dbsync.merge.token.db.DropColumnToDb) DbAdapter(org.apache.cayenne.dba.DbAdapter) QuotingStrategy(org.apache.cayenne.dba.QuotingStrategy)

Aggregations

DbAdapter (org.apache.cayenne.dba.DbAdapter)44 Test (org.junit.Test)17 DbEntity (org.apache.cayenne.map.DbEntity)16 JdbcAdapter (org.apache.cayenne.dba.JdbcAdapter)11 QuotingStrategy (org.apache.cayenne.dba.QuotingStrategy)11 UnitDbAdapter (org.apache.cayenne.unit.UnitDbAdapter)10 Injector (org.apache.cayenne.di.Injector)8 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)7 List (java.util.List)6 AdhocObjectFactory (org.apache.cayenne.di.AdhocObjectFactory)6 JdbcEventLogger (org.apache.cayenne.log.JdbcEventLogger)6 ArrayList (java.util.ArrayList)5 DbAttributeBinding (org.apache.cayenne.access.translator.DbAttributeBinding)5 AutoAdapter (org.apache.cayenne.dba.AutoAdapter)5 DataMap (org.apache.cayenne.map.DataMap)5 BatchQueryRow (org.apache.cayenne.query.BatchQueryRow)5 SimpleLockingTestEntity (org.apache.cayenne.testdo.locking.SimpleLockingTestEntity)5 MockConnection (com.mockrunner.mock.jdbc.MockConnection)4 MockDataSource (com.mockrunner.mock.jdbc.MockDataSource)4 DatabaseMetaData (java.sql.DatabaseMetaData)4