Search in sources :

Example 11 with DbImportConfiguration

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;
}
Also used : DbImportConfiguration(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration)

Example 12 with DbImportConfiguration

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());
}
Also used : DbImportConfig(org.apache.cayenne.tools.model.DbImportConfig) DbImportConfiguration(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration) DataSourceConfig(org.apache.cayenne.tools.model.DataSourceConfig) File(java.io.File) Test(org.junit.Test)

Aggregations

DbImportConfiguration (org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration)12 Logger (org.slf4j.Logger)6 FiltersConfigBuilder (org.apache.cayenne.dbsync.reverse.filters.FiltersConfigBuilder)4 Test (org.junit.Test)4 DataSource (javax.sql.DataSource)2 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)2 DataSourceFactory (org.apache.cayenne.configuration.server.DataSourceFactory)2 DbAdapterFactory (org.apache.cayenne.configuration.server.DbAdapterFactory)2 DbAdapter (org.apache.cayenne.dba.DbAdapter)2 DbSyncModule (org.apache.cayenne.dbsync.DbSyncModule)2 ToolsModule (org.apache.cayenne.dbsync.reverse.configuration.ToolsModule)2 DbImportAction (org.apache.cayenne.dbsync.reverse.dbimport.DbImportAction)2 DbImportConfigurationValidator (org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfigurationValidator)2 DbImportModule (org.apache.cayenne.dbsync.reverse.dbimport.DbImportModule)2 ReverseEngineering (org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering)2 DbLoaderDelegate (org.apache.cayenne.dbsync.reverse.dbload.DbLoaderDelegate)2 Injector (org.apache.cayenne.di.Injector)2 File (java.io.File)1 TreeSet (java.util.TreeSet)1 Pattern (java.util.regex.Pattern)1