use of org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration in project cayenne by apache.
the class DbImporterMojo method createConfig.
DbImportConfiguration createConfig(final Logger logger) {
DbImportConfiguration config = new DbImportConfiguration();
if (dbImportConfig.getCatalogs().size() == 0 && dbImportConfig.isEmptyContainer()) {
config.setUseDataMapReverseEngineering(true);
}
config.setAdapter(adapter);
config.setDefaultPackage(dbImportConfig.getDefaultPackage());
config.setDriver(dataSource.getDriver());
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;
}
use of org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration in project cayenne by apache.
the class DbImportTaskTest method testFullConfigCreation.
@Test
public void testFullConfigCreation() {
File mockFile = mock(File.class);
// configure task
task.setMap(mockFile);
task.setAdapter("org.apache.cayenne.test.adapter");
task.dataSource(new Closure<DataSourceConfig>(task, task) {
DataSourceConfig doCall(DataSourceConfig dataSourceConfig) {
assertNotNull(dataSourceConfig);
dataSourceConfig.setUrl("test://url");
dataSourceConfig.setDriver("org.apache.cayenne.test.driver");
dataSourceConfig.setUsername("username");
dataSourceConfig.setPassword("password");
return dataSourceConfig;
}
});
task.dbImport(new Closure<DataSourceConfig>(task, task) {
DbImportConfig doCall(DbImportConfig config) {
assertNotNull(config);
config.setDefaultPackage("com.example.package");
config.setMeaningfulPkTables("pk_tables");
config.setNamingStrategy("com.example.naming");
config.setSkipPrimaryKeyLoading(true);
config.setSkipRelationshipsLoading(true);
config.setStripFromTableNames("strip");
config.tableTypes("view", "alias");
config.setForceDataMapCatalog(true);
config.setForceDataMapSchema(true);
config.setUseJava7Types(true);
config.setUsePrimitives(false);
return config;
}
});
// Testing this:
DbImportConfiguration dbImportConfiguration = task.createConfig();
// Check that all values in end configuration is properly set
assertEquals("org.apache.cayenne.test.adapter", dbImportConfiguration.getAdapter());
assertEquals("test://url", dbImportConfiguration.getUrl());
assertEquals("org.apache.cayenne.test.driver", dbImportConfiguration.getDriver());
assertEquals("username", dbImportConfiguration.getUsername());
assertEquals("password", dbImportConfiguration.getPassword());
assertEquals("com.example.package", dbImportConfiguration.getDefaultPackage());
assertEquals("pk_tables", dbImportConfiguration.getMeaningfulPkTables());
assertEquals("com.example.naming", dbImportConfiguration.getNamingStrategy());
assertTrue(dbImportConfiguration.getDbLoaderConfig().isSkipPrimaryKeyLoading());
assertTrue(dbImportConfiguration.getDbLoaderConfig().isSkipRelationshipsLoading());
assertEquals("strip", dbImportConfiguration.getStripFromTableNames());
assertEquals("password", dbImportConfiguration.getPassword());
assertArrayEquals(new String[] { "view", "alias" }, dbImportConfiguration.getDbLoaderConfig().getTableTypes());
assertTrue(dbImportConfiguration.isForceDataMapCatalog());
assertTrue(dbImportConfiguration.isForceDataMapSchema());
assertTrue(dbImportConfiguration.isUseJava7Types());
assertFalse(dbImportConfiguration.isUsePrimitives());
}
Aggregations