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