Search in sources :

Example 1 with DbImportModule

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

the class DbImportTask method runImport.

@TaskAction
public void runImport() {
    dataSource.validate();
    DbImportConfiguration config = createConfig();
    Injector injector = DIBootstrap.createInjector(new DbSyncModule(), new ToolsModule(getLogger()), new DbImportModule());
    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) {
        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 : TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) DbImportConfiguration(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration) Injector(org.apache.cayenne.di.Injector) DbImportConfigurationValidator(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfigurationValidator) DbSyncModule(org.apache.cayenne.dbsync.DbSyncModule) DbImportAction(org.apache.cayenne.dbsync.reverse.dbimport.DbImportAction) ToolsModule(org.apache.cayenne.dbsync.reverse.configuration.ToolsModule) DbImportModule(org.apache.cayenne.dbsync.reverse.dbimport.DbImportModule) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) TaskAction(org.gradle.api.tasks.TaskAction)

Example 2 with DbImportModule

use of org.apache.cayenne.dbsync.reverse.dbimport.DbImportModule 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 DbImportModule

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

the class DbImporterMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    Logger logger = new MavenLogger(this);
    // check missing data source parameters
    dataSource.validate();
    DbImportConfiguration config = createConfig(logger);
    Injector injector = DIBootstrap.createInjector(new DbSyncModule(), new ToolsModule(logger), new DbImportModule());
    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) {
        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 : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) 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) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) DbImportConfiguration(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration) Injector(org.apache.cayenne.di.Injector) DbSyncModule(org.apache.cayenne.dbsync.DbSyncModule) DbImportModule(org.apache.cayenne.dbsync.reverse.dbimport.DbImportModule)

Aggregations

DbSyncModule (org.apache.cayenne.dbsync.DbSyncModule)3 ToolsModule (org.apache.cayenne.dbsync.reverse.configuration.ToolsModule)3 DbImportAction (org.apache.cayenne.dbsync.reverse.dbimport.DbImportAction)3 DbImportConfigurationValidator (org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfigurationValidator)3 DbImportModule (org.apache.cayenne.dbsync.reverse.dbimport.DbImportModule)3 Injector (org.apache.cayenne.di.Injector)3 DbImportConfiguration (org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration)2 Logger (org.slf4j.Logger)2 FiltersConfigBuilder (org.apache.cayenne.dbsync.reverse.filters.FiltersConfigBuilder)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 BuildException (org.apache.tools.ant.BuildException)1 TaskAction (org.gradle.api.tasks.TaskAction)1 TaskExecutionException (org.gradle.api.tasks.TaskExecutionException)1