Search in sources :

Example 1 with DbImportConfiguration

use of org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration in project cayenne by apache.

the class DbLoaderContext method buildConfig.

public boolean buildConfig(DBConnectionInfo connectionInfo, DbImportView view, boolean headless) {
    if (connectionInfo == null) {
        return false;
    }
    // Build reverse engineering from metadata and dialog values
    ReverseEngineering metaReverseEngineering = metaData.get(getProjectController().getCurrentDataMap(), ReverseEngineering.class);
    if (metaReverseEngineering == null) {
        return false;
    }
    // skip this step for batch run from domain tab
    if (!headless) {
        fillReverseEngineeringFromView(metaReverseEngineering, view);
    }
    // Create copy of metaReverseEngineering
    ReverseEngineering reverseEngineering = new ReverseEngineering(metaReverseEngineering);
    DbImportConfiguration config = new DbImportConfiguration() {

        @Override
        public DbLoaderDelegate createLoaderDelegate() {
            return new LoaderDelegate(DbLoaderContext.this);
        }
    };
    fillConfig(config, connectionInfo, reverseEngineering);
    setConfig(config);
    prepareDataMap();
    return true;
}
Also used : DbImportConfiguration(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration) ReverseEngineering(org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering) DbLoaderDelegate(org.apache.cayenne.dbsync.reverse.dbload.DbLoaderDelegate)

Example 2 with DbImportConfiguration

use of org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration in project cayenne by apache.

the class DbImportTask method createConfig.

DbImportConfiguration createConfig() {
    reverseEngineering = config.toReverseEngineering();
    DbImportConfiguration config = new DbImportConfiguration();
    if (reverseEngineering.getCatalogs().size() == 0 && reverseEngineering.isEmptyContainer()) {
        config.setUseDataMapReverseEngineering(true);
    }
    config.setAdapter(adapter);
    config.setDriver(dataSource.getDriver());
    config.setLogger(getLogger());
    config.setPassword(dataSource.getPassword());
    config.setTargetDataMap(getDataMapFile());
    config.setUrl(dataSource.getUrl());
    config.setUsername(dataSource.getUsername());
    config.setSkipRelationshipsLoading(reverseEngineering.getSkipRelationshipsLoading());
    config.setSkipPrimaryKeyLoading(reverseEngineering.getSkipPrimaryKeyLoading());
    config.setStripFromTableNames(reverseEngineering.getStripFromTableNames());
    config.setTableTypes(reverseEngineering.getTableTypes());
    config.setMeaningfulPkTables(reverseEngineering.getMeaningfulPkTables());
    config.setNamingStrategy(reverseEngineering.getNamingStrategy());
    config.setForceDataMapCatalog(reverseEngineering.isForceDataMapCatalog());
    config.setForceDataMapSchema(reverseEngineering.isForceDataMapSchema());
    config.setDefaultPackage(reverseEngineering.getDefaultPackage());
    config.setUsePrimitives(reverseEngineering.isUsePrimitives());
    config.setUseJava7Types(reverseEngineering.isUseJava7Types());
    config.setCayenneProject(cayenneProject);
    return config;
}
Also used : DbImportConfiguration(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration)

Example 3 with DbImportConfiguration

use of org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration in project cayenne by apache.

the class DbImportTask method runImport.

@TaskAction
public void runImport() {
    dataSource.validate();
    final Injector injector = DIBootstrap.createInjector(new DbSyncModule(), new ToolsModule(getLogger()), new DbImportModule(), binder -> binder.bind(ClassLoaderManager.class).toInstance(new DefaultClassLoaderManager()));
    final DbImportConfiguration config = createConfig();
    DataSourceFactory dataSourceFactory = injector.getInstance(DataSourceFactory.class);
    DbAdapterFactory dbAdapterFactory = injector.getInstance(DbAdapterFactory.class);
    DataNodeDescriptor dataNodeDescriptor = config.createDataNodeDescriptor();
    try {
        DataSource dataSource = dataSourceFactory.getDataSource(dataNodeDescriptor);
        DbAdapter dbAdapter = dbAdapterFactory.createAdapter(dataNodeDescriptor, dataSource);
        config.setFiltersConfig(new FiltersConfigBuilder(reverseEngineering).dataSource(dataSource).dbAdapter(dbAdapter).build());
    } catch (Exception e) {
        throw new TaskExecutionException(this, e);
    }
    final DbImportConfigurationValidator validator = new DbImportConfigurationValidator(reverseEngineering, config, injector);
    try {
        validator.validate();
    } catch (Exception ex) {
        throw new TaskExecutionException(this, ex);
    }
    try {
        injector.getInstance(DbImportAction.class).execute(config);
    } catch (Exception ex) {
        final Throwable th = Util.unwindException(ex);
        String message = "Error importing database schema";
        if (th.getLocalizedMessage() != null) {
            message += ": " + th.getLocalizedMessage();
        }
        getLogger().error(message);
        throw new TaskExecutionException(this, th);
    }
}
Also used : DataSourceFactory(org.apache.cayenne.configuration.server.DataSourceFactory) DbImportConfigurationValidator(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfigurationValidator) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DbImportAction(org.apache.cayenne.dbsync.reverse.dbimport.DbImportAction) ToolsModule(org.apache.cayenne.dbsync.reverse.configuration.ToolsModule) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) DataSource(javax.sql.DataSource) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) DbAdapterFactory(org.apache.cayenne.configuration.server.DbAdapterFactory) DbImportConfiguration(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration) DbAdapter(org.apache.cayenne.dba.DbAdapter) FiltersConfigBuilder(org.apache.cayenne.dbsync.reverse.filters.FiltersConfigBuilder) Injector(org.apache.cayenne.di.Injector) DbSyncModule(org.apache.cayenne.dbsync.DbSyncModule) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) DbImportModule(org.apache.cayenne.dbsync.reverse.dbimport.DbImportModule) TaskAction(org.gradle.api.tasks.TaskAction)

Example 4 with DbImportConfiguration

use of org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration in project cayenne by apache.

the class DbImporterMojoConfigurationTest method testLoadSchema2.

@Test
public void testLoadSchema2() throws Exception {
    DbImporterMojo dbImporterMojo = getCdbImport("pom-schema-2.xml");
    DbImportConfiguration dbImportConfiguration = dbImporterMojo.createConfig(mock(Logger.class));
    dbImportConfiguration.setFiltersConfig(new FiltersConfigBuilder(dbImporterMojo.getReverseEngineering()).build());
    FiltersConfig filters = dbImportConfiguration.getDbLoaderConfig().getFiltersConfig();
    TreeSet<IncludeTableFilter> includes = new TreeSet<>();
    includes.add(new IncludeTableFilter(null, new PatternFilter().exclude("^ETL_.*")));
    TreeSet<Pattern> excludes = new TreeSet<>(PatternFilter.PATTERN_COMPARATOR);
    excludes.add(PatternFilter.pattern("^ETL_.*"));
    assertEquals(filters.tableFilter(null, "NHL_STATS"), new TableFilter(includes, excludes));
}
Also used : Pattern(java.util.regex.Pattern) PatternFilter(org.apache.cayenne.dbsync.reverse.filters.PatternFilter) DbImportConfiguration(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration) FiltersConfigBuilder(org.apache.cayenne.dbsync.reverse.filters.FiltersConfigBuilder) IncludeTableFilter(org.apache.cayenne.dbsync.reverse.filters.IncludeTableFilter) TableFilter(org.apache.cayenne.dbsync.reverse.filters.TableFilter) TreeSet(java.util.TreeSet) FiltersConfig(org.apache.cayenne.dbsync.reverse.filters.FiltersConfig) IncludeTableFilter(org.apache.cayenne.dbsync.reverse.filters.IncludeTableFilter) Logger(org.slf4j.Logger) Test(org.junit.Test)

Example 5 with DbImportConfiguration

use of org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration in project cayenne by apache.

the class DbImporterMojoConfigurationTest method testDefaultPackage.

@Test
public void testDefaultPackage() throws Exception {
    DbImportConfiguration config = getCdbImport("pom-default-package.xml").createConfig(mock(Logger.class));
    assertEquals("com.example.test", config.getDefaultPackage());
}
Also used : DbImportConfiguration(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration) Logger(org.slf4j.Logger) Test(org.junit.Test)

Aggregations

DbImportConfiguration (org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration)12 Logger (org.slf4j.Logger)6 FiltersConfigBuilder (org.apache.cayenne.dbsync.reverse.filters.FiltersConfigBuilder)4 Test (org.junit.Test)4 DataSource (javax.sql.DataSource)2 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)2 DataSourceFactory (org.apache.cayenne.configuration.server.DataSourceFactory)2 DbAdapterFactory (org.apache.cayenne.configuration.server.DbAdapterFactory)2 DbAdapter (org.apache.cayenne.dba.DbAdapter)2 DbSyncModule (org.apache.cayenne.dbsync.DbSyncModule)2 ToolsModule (org.apache.cayenne.dbsync.reverse.configuration.ToolsModule)2 DbImportAction (org.apache.cayenne.dbsync.reverse.dbimport.DbImportAction)2 DbImportConfigurationValidator (org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfigurationValidator)2 DbImportModule (org.apache.cayenne.dbsync.reverse.dbimport.DbImportModule)2 ReverseEngineering (org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering)2 DbLoaderDelegate (org.apache.cayenne.dbsync.reverse.dbload.DbLoaderDelegate)2 Injector (org.apache.cayenne.di.Injector)2 File (java.io.File)1 TreeSet (java.util.TreeSet)1 Pattern (java.util.regex.Pattern)1