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;
}
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;
}
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);
}
}
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));
}
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());
}
Aggregations