Search in sources :

Example 6 with DbImportConfiguration

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

the class DbImporterMojoTest method testToParameters_MeaningfulPkTables.

@Test
public void testToParameters_MeaningfulPkTables() throws Exception {
    DbImportConfiguration parameters1 = getCdbImport("dbimporter-pom1.xml").createConfig(mock(Logger.class));
    assertNull(parameters1.getMeaningfulPkTables());
    assertPathEquals("target/test/org/apache/cayenne/tools/dbimporter-map1.map.xml", parameters1.getTargetDataMap().getPath());
    assertEquals("x,b*", getCdbImport("dbimporter-pom2.xml").createConfig(mock(Logger.class)).getMeaningfulPkTables());
    assertEquals("*", getCdbImport("dbimporter-pom3.xml").createConfig(mock(Logger.class)).getMeaningfulPkTables());
}
Also used : DbImportConfiguration(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration) Logger(org.slf4j.Logger) Test(org.junit.Test)

Example 7 with DbImportConfiguration

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

the class DbImporterMojoTest method testToParameters_Map.

public void testToParameters_Map() throws Exception {
    DbImportConfiguration parameters1 = getCdbImport("dbimporter-pom1.xml").createConfig(mock(Logger.class));
    assertNotNull(parameters1.getTargetDataMap());
    assertPathEquals("target/test/org/apache/cayenne/tools/dbimporter-map1.map.xml", parameters1.getTargetDataMap().getPath());
    assertNull(getCdbImport("dbimporter-pom2.xml").createConfig(mock(Logger.class)).getTargetDataMap());
}
Also used : DbImportConfiguration(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration) Logger(org.slf4j.Logger)

Example 8 with DbImportConfiguration

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

the class DbLoaderContext method buildConfig.

public boolean buildConfig(DataSourceWizard connectionWizard, DbLoaderOptionsDialog dialog) {
    if (dialog == null || connectionWizard == null) {
        return false;
    }
    // Build filters
    ReverseEngineering reverseEngineering = new ReverseEngineering();
    reverseEngineering.addCatalog(new Catalog(dialog.getSelectedCatalog()));
    reverseEngineering.addSchema(new Schema(dialog.getSelectedSchema()));
    reverseEngineering.addIncludeTable(new IncludeTable(dialog.getTableIncludePattern()));
    if (dialog.getTableExcludePattern() != null) {
        reverseEngineering.addExcludeTable(new ExcludeTable(dialog.getTableExcludePattern()));
    }
    // Add here auto_pk_support table
    reverseEngineering.addExcludeTable(new ExcludeTable("auto_pk_support|AUTO_PK_SUPPORT"));
    reverseEngineering.addIncludeProcedure(new IncludeProcedure(dialog.getProcedureNamePattern()));
    FiltersConfigBuilder filtersConfigBuilder = new FiltersConfigBuilder(reverseEngineering);
    DbImportConfiguration config = new DbImportConfiguration() {

        @Override
        public DbLoaderDelegate createLoaderDelegate() {
            return new LoaderDelegate(DbLoaderContext.this);
        }
    };
    // Build config
    DBConnectionInfo connectionInfo = connectionWizard.getConnectionInfo();
    config.setAdapter(connectionWizard.getAdapter().getClass().getName());
    config.setUsername(connectionInfo.getUserName());
    config.setPassword(connectionInfo.getPassword());
    config.setDriver(connectionInfo.getJdbcDriver());
    config.setUrl(connectionInfo.getUrl());
    config.getDbLoaderConfig().setFiltersConfig(filtersConfigBuilder.build());
    config.setMeaningfulPkTables(dialog.getMeaningfulPk());
    config.setNamingStrategy(dialog.getNamingStrategy());
    config.setUsePrimitives(dialog.isUsePrimitives());
    config.setUseJava7Types(dialog.isUseJava7Typed());
    setConfig(config);
    prepareDataMap();
    return true;
}
Also used : DbImportConfiguration(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration) FiltersConfigBuilder(org.apache.cayenne.dbsync.reverse.filters.FiltersConfigBuilder) ReverseEngineering(org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering) Schema(org.apache.cayenne.dbsync.reverse.dbimport.Schema) IncludeTable(org.apache.cayenne.dbsync.reverse.dbimport.IncludeTable) DbLoaderDelegate(org.apache.cayenne.dbsync.reverse.dbload.DbLoaderDelegate) IncludeProcedure(org.apache.cayenne.dbsync.reverse.dbimport.IncludeProcedure) DBConnectionInfo(org.apache.cayenne.modeler.pref.DBConnectionInfo) Catalog(org.apache.cayenne.dbsync.reverse.dbimport.Catalog) ExcludeTable(org.apache.cayenne.dbsync.reverse.dbimport.ExcludeTable)

Example 9 with DbImportConfiguration

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

the class DbImporterOldMojoConfigurationTest method testDefaultPackage.

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)

Example 10 with DbImportConfiguration

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

the class DbImporterMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    final Logger logger = new MavenLogger(this);
    if (project == null) {
        throw new MojoExecutionException("Can't load MavenProject.");
    }
    // check missing data source parameters
    dataSource.validate();
    final Injector injector = DIBootstrap.createInjector(new DbSyncModule(), new ToolsModule(logger), new DbImportModule(), binder -> binder.bind(ClassLoaderManager.class).toInstance(new MavenPluginClassLoaderManager(project)));
    final DbImportConfiguration config = createConfig(logger);
    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(dbImportConfig).dataSource(dataSource).dbAdapter(dbAdapter).build());
    } catch (Exception e) {
        throw new MojoExecutionException("Error getting dataSource", e);
    }
    final DbImportConfigurationValidator validator = new DbImportConfigurationValidator(dbImportConfig, config, injector);
    try {
        validator.validate();
    } catch (Exception ex) {
        throw new MojoExecutionException(ex.getMessage(), 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();
        }
        getLog().error(message);
        throw new MojoExecutionException(message, th);
    }
}
Also used : DataSourceFactory(org.apache.cayenne.configuration.server.DataSourceFactory) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DbImportConfigurationValidator(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfigurationValidator) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) Logger(org.slf4j.Logger) DbImportAction(org.apache.cayenne.dbsync.reverse.dbimport.DbImportAction) ToolsModule(org.apache.cayenne.dbsync.reverse.configuration.ToolsModule) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) DataSource(javax.sql.DataSource) 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) DbImportModule(org.apache.cayenne.dbsync.reverse.dbimport.DbImportModule)

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