Search in sources :

Example 1 with FiltersConfigBuilder

use of org.apache.cayenne.dbsync.reverse.filters.FiltersConfigBuilder in project cayenne by apache.

the class DbImportTask method createConfig.

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

Example 2 with FiltersConfigBuilder

use of org.apache.cayenne.dbsync.reverse.filters.FiltersConfigBuilder in project cayenne by apache.

the class DbImporterTask method execute.

@Override
public void execute() {
    config.setFiltersConfig(new FiltersConfigBuilder(reverseEngineering).build());
    validateAttributes();
    Logger logger = new AntLogger(this);
    config.setLogger(logger);
    config.setSkipRelationshipsLoading(reverseEngineering.getSkipRelationshipsLoading());
    config.setSkipPrimaryKeyLoading(reverseEngineering.getSkipPrimaryKeyLoading());
    config.setTableTypes(reverseEngineering.getTableTypes());
    Injector injector = DIBootstrap.createInjector(new DbSyncModule(), new ToolsModule(logger), new DbImportModule());
    DbImportConfigurationValidator validator = new DbImportConfigurationValidator(reverseEngineering, config, injector);
    try {
        validator.validate();
    } catch (Exception ex) {
        throw new BuildException(ex.getMessage(), ex);
    }
    try {
        injector.getInstance(DbImportAction.class).execute(config);
    } catch (Exception ex) {
        Throwable th = Util.unwindException(ex);
        String message = "Error importing database schema";
        if (th.getLocalizedMessage() != null) {
            message += ": " + th.getLocalizedMessage();
        }
        log(message, Project.MSG_ERR);
        throw new BuildException(message, th);
    } finally {
        injector.shutdown();
    }
}
Also used : DbImportConfigurationValidator(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfigurationValidator) Logger(org.slf4j.Logger) DbImportAction(org.apache.cayenne.dbsync.reverse.dbimport.DbImportAction) ToolsModule(org.apache.cayenne.dbsync.reverse.configuration.ToolsModule) BuildException(org.apache.tools.ant.BuildException) FiltersConfigBuilder(org.apache.cayenne.dbsync.reverse.filters.FiltersConfigBuilder) Injector(org.apache.cayenne.di.Injector) DbSyncModule(org.apache.cayenne.dbsync.DbSyncModule) BuildException(org.apache.tools.ant.BuildException) DbImportModule(org.apache.cayenne.dbsync.reverse.dbimport.DbImportModule)

Example 3 with FiltersConfigBuilder

use of org.apache.cayenne.dbsync.reverse.filters.FiltersConfigBuilder 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 4 with FiltersConfigBuilder

use of org.apache.cayenne.dbsync.reverse.filters.FiltersConfigBuilder in project cayenne by apache.

the class DbImporterMojo method createConfig.

DbImportConfiguration createConfig(Logger logger) {
    DbImportConfiguration config = new DbImportConfiguration();
    config.setAdapter(adapter);
    config.setDefaultPackage(dbImportConfig.getDefaultPackage());
    config.setDriver(dataSource.getDriver());
    config.setFiltersConfig(new FiltersConfigBuilder(dbImportConfig).build());
    config.setForceDataMapCatalog(dbImportConfig.isForceDataMapCatalog());
    config.setForceDataMapSchema(dbImportConfig.isForceDataMapSchema());
    config.setLogger(logger);
    config.setMeaningfulPkTables(dbImportConfig.getMeaningfulPkTables());
    config.setNamingStrategy(dbImportConfig.getNamingStrategy());
    config.setPassword(dataSource.getPassword());
    config.setSkipRelationshipsLoading(dbImportConfig.getSkipRelationshipsLoading());
    config.setSkipPrimaryKeyLoading(dbImportConfig.getSkipPrimaryKeyLoading());
    config.setStripFromTableNames(dbImportConfig.getStripFromTableNames());
    config.setTableTypes(dbImportConfig.getTableTypes());
    config.setTargetDataMap(map);
    config.setCayenneProject(cayenneProject);
    config.setUrl(dataSource.getUrl());
    config.setUsername(dataSource.getUsername());
    config.setUsePrimitives(dbImportConfig.isUsePrimitives());
    config.setUseJava7Types(dbImportConfig.isUseJava7Types());
    return config;
}
Also used : DbImportConfiguration(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration) FiltersConfigBuilder(org.apache.cayenne.dbsync.reverse.filters.FiltersConfigBuilder)

Aggregations

FiltersConfigBuilder (org.apache.cayenne.dbsync.reverse.filters.FiltersConfigBuilder)4 DbImportConfiguration (org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration)3 DbSyncModule (org.apache.cayenne.dbsync.DbSyncModule)1 ToolsModule (org.apache.cayenne.dbsync.reverse.configuration.ToolsModule)1 Catalog (org.apache.cayenne.dbsync.reverse.dbimport.Catalog)1 DbImportAction (org.apache.cayenne.dbsync.reverse.dbimport.DbImportAction)1 DbImportConfigurationValidator (org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfigurationValidator)1 DbImportModule (org.apache.cayenne.dbsync.reverse.dbimport.DbImportModule)1 ExcludeTable (org.apache.cayenne.dbsync.reverse.dbimport.ExcludeTable)1 IncludeProcedure (org.apache.cayenne.dbsync.reverse.dbimport.IncludeProcedure)1 IncludeTable (org.apache.cayenne.dbsync.reverse.dbimport.IncludeTable)1 ReverseEngineering (org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering)1 Schema (org.apache.cayenne.dbsync.reverse.dbimport.Schema)1 DbLoaderDelegate (org.apache.cayenne.dbsync.reverse.dbload.DbLoaderDelegate)1 Injector (org.apache.cayenne.di.Injector)1 DBConnectionInfo (org.apache.cayenne.modeler.pref.DBConnectionInfo)1 BuildException (org.apache.tools.ant.BuildException)1 Logger (org.slf4j.Logger)1