Search in sources :

Example 1 with DbAdapterFactory

use of org.apache.cayenne.configuration.server.DbAdapterFactory in project cayenne by apache.

the class CayenneTask method getAdapter.

protected DbAdapter getAdapter(Injector injector, DataSource dataSource) throws Exception {
    DbAdapterFactory adapterFactory = injector.getInstance(DbAdapterFactory.class);
    DataNodeDescriptor nodeDescriptor = new DataNodeDescriptor();
    nodeDescriptor.setAdapterType(adapter);
    return adapterFactory.createAdapter(nodeDescriptor, dataSource);
}
Also used : DbAdapterFactory(org.apache.cayenne.configuration.server.DbAdapterFactory) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor)

Example 2 with DbAdapterFactory

use of org.apache.cayenne.configuration.server.DbAdapterFactory in project cayenne by apache.

the class ToolsModuleTest method testDbApdater.

@Test
public void testDbApdater() throws Exception {
    Logger log = mock(Logger.class);
    Injector i = DIBootstrap.createInjector(new ToolsModule(log));
    DbAdapterFactory factory = i.getInstance(DbAdapterFactory.class);
    DataNodeDescriptor nodeDescriptor = mock(DataNodeDescriptor.class);
    DataSource dataSource = mock(DataSource.class);
    assertTrue(factory.createAdapter(nodeDescriptor, dataSource) instanceof AutoAdapter);
}
Also used : DefaultDbAdapterFactory(org.apache.cayenne.configuration.server.DefaultDbAdapterFactory) DbAdapterFactory(org.apache.cayenne.configuration.server.DbAdapterFactory) Injector(org.apache.cayenne.di.Injector) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) Logger(org.slf4j.Logger) AutoAdapter(org.apache.cayenne.dba.AutoAdapter) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 3 with DbAdapterFactory

use of org.apache.cayenne.configuration.server.DbAdapterFactory 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)

Aggregations

DbAdapterFactory (org.apache.cayenne.configuration.server.DbAdapterFactory)3 DataSource (javax.sql.DataSource)2 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)2 Logger (org.slf4j.Logger)2 Connection (java.sql.Connection)1 DataChannelDescriptorLoader (org.apache.cayenne.configuration.DataChannelDescriptorLoader)1 DataSourceFactory (org.apache.cayenne.configuration.server.DataSourceFactory)1 DefaultDbAdapterFactory (org.apache.cayenne.configuration.server.DefaultDbAdapterFactory)1 AutoAdapter (org.apache.cayenne.dba.AutoAdapter)1 DbAdapter (org.apache.cayenne.dba.DbAdapter)1 DefaultMergerTokenFactory (org.apache.cayenne.dbsync.merge.factory.DefaultMergerTokenFactory)1 MergerTokenFactoryProvider (org.apache.cayenne.dbsync.merge.factory.MergerTokenFactoryProvider)1 Injector (org.apache.cayenne.di.Injector)1 Test (org.junit.Test)1