use of org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfigurationValidator in project cayenne by apache.
the class DbImporterTask method execute.
@Override
public void execute() {
Logger logger = new AntLogger(this);
final Injector injector = DIBootstrap.createInjector(new DbSyncModule(), new ToolsModule(logger), new DbImportModule());
if (reverseEngineering.getCatalogs().size() == 0 && reverseEngineering.isEmptyContainer()) {
config.setUseDataMapReverseEngineering(true);
}
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 BuildException("Error getting dataSource", e);
}
validateAttributes();
config.setLogger(logger);
config.setSkipRelationshipsLoading(reverseEngineering.getSkipRelationshipsLoading());
config.setSkipPrimaryKeyLoading(reverseEngineering.getSkipPrimaryKeyLoading());
config.setTableTypes(reverseEngineering.getTableTypes());
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();
}
}
use of org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfigurationValidator 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);
}
}
use of org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfigurationValidator 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);
}
}
Aggregations