Search in sources :

Example 6 with ReverseEngineering

use of org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering in project cayenne by apache.

the class FiltersConfigBuilderTest method testCompact_03.

@Test
public void testCompact_03() {
    ReverseEngineering engineering = new ReverseEngineering();
    engineering.addCatalog(new Catalog("APP1"));
    engineering.addCatalog(new Catalog("APP2"));
    engineering.addExcludeTable(new ExcludeTable("SYS_.*"));
    engineering.addExcludeColumn(new ExcludeColumn("calculated_.*"));
    FiltersConfigBuilder builder = new FiltersConfigBuilder(engineering);
    builder.compact();
    assertEquals("ReverseEngineering: \n" + "  Catalog: APP1\n" + "    Schema: null\n" + "      IncludeTable: null\n" + "        ExcludeColumn: calculated_.*\n" + "      ExcludeTable: SYS_.*\n" + "  Catalog: APP2\n" + "    Schema: null\n" + "      IncludeTable: null\n" + "        ExcludeColumn: calculated_.*\n" + "      ExcludeTable: SYS_.*\n", engineering.toString());
}
Also used : ReverseEngineering(org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering) ExcludeColumn(org.apache.cayenne.dbsync.reverse.dbimport.ExcludeColumn) Catalog(org.apache.cayenne.dbsync.reverse.dbimport.Catalog) ExcludeTable(org.apache.cayenne.dbsync.reverse.dbimport.ExcludeTable) Test(org.junit.Test)

Example 7 with ReverseEngineering

use of org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering in project cayenne by apache.

the class FiltersConfigBuilderTest method testCompact_04.

@Test
public void testCompact_04() {
    ReverseEngineering engineering = new ReverseEngineering();
    engineering.addSchema(new Schema("s"));
    FiltersConfigBuilder builder = new FiltersConfigBuilder(engineering);
    builder.compact();
    assertEquals("ReverseEngineering: \n" + "  Catalog: null\n" + "    Schema: s\n" + "      IncludeTable: null\n", engineering.toString());
}
Also used : ReverseEngineering(org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering) Schema(org.apache.cayenne.dbsync.reverse.dbimport.Schema) Test(org.junit.Test)

Example 8 with ReverseEngineering

use of org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering in project cayenne by apache.

the class DbImportConfigTest method toReverseEngineering.

@Test
public void toReverseEngineering() throws Exception {
    DbImportConfig config = new DbImportConfig();
    config.catalog("catalog1");
    config.schema("schema1");
    config.setDefaultPackage("com.example.package");
    config.setMeaningfulPkTables("pk_tables");
    config.setNamingStrategy("com.example.naming");
    config.setSkipPrimaryKeyLoading(true);
    config.setSkipRelationshipsLoading(true);
    config.setStripFromTableNames("strip");
    config.tableType("table");
    config.tableTypes("view", "alias");
    config.setForceDataMapCatalog(true);
    config.setForceDataMapSchema(true);
    config.setUseJava7Types(true);
    config.setUsePrimitives(false);
    ReverseEngineering rr = config.toReverseEngineering();
    assertNotNull(rr);
    assertEquals(1, rr.getCatalogs().size());
    assertEquals("catalog1", rr.getCatalogs().iterator().next().getName());
    assertEquals(1, rr.getSchemas().size());
    assertEquals("schema1", rr.getSchemas().iterator().next().getName());
    assertEquals(0, rr.getIncludeTables().size());
    assertEquals(0, rr.getExcludeTables().size());
    assertEquals(0, rr.getIncludeColumns().size());
    assertEquals(0, rr.getExcludeColumns().size());
    assertEquals(0, rr.getIncludeProcedures().size());
    assertEquals(0, rr.getExcludeProcedures().size());
    assertEquals("com.example.package", rr.getDefaultPackage());
    assertEquals("pk_tables", rr.getMeaningfulPkTables());
    assertEquals("com.example.naming", rr.getNamingStrategy());
    assertTrue(rr.getSkipPrimaryKeyLoading());
    assertTrue(rr.getSkipRelationshipsLoading());
    assertEquals("strip", rr.getStripFromTableNames());
    assertArrayEquals(new String[] { "table", "view", "alias" }, rr.getTableTypes());
    assertTrue(rr.isForceDataMapCatalog());
    assertTrue(rr.isForceDataMapSchema());
    assertTrue(rr.isUseJava7Types());
    assertFalse(rr.isUsePrimitives());
}
Also used : ReverseEngineering(org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering) Test(org.junit.Test)

Example 9 with ReverseEngineering

use of org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering 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;
}
Also used : DbImportConfiguration(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration) FiltersConfigBuilder(org.apache.cayenne.dbsync.reverse.filters.FiltersConfigBuilder) ReverseEngineering(org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering) Schema(org.apache.cayenne.dbsync.reverse.dbimport.Schema) IncludeTable(org.apache.cayenne.dbsync.reverse.dbimport.IncludeTable) DbLoaderDelegate(org.apache.cayenne.dbsync.reverse.dbload.DbLoaderDelegate) IncludeProcedure(org.apache.cayenne.dbsync.reverse.dbimport.IncludeProcedure) DBConnectionInfo(org.apache.cayenne.modeler.pref.DBConnectionInfo) Catalog(org.apache.cayenne.dbsync.reverse.dbimport.Catalog) ExcludeTable(org.apache.cayenne.dbsync.reverse.dbimport.ExcludeTable)

Aggregations

ReverseEngineering (org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering)9 Test (org.junit.Test)7 Schema (org.apache.cayenne.dbsync.reverse.dbimport.Schema)5 Catalog (org.apache.cayenne.dbsync.reverse.dbimport.Catalog)4 ExcludeTable (org.apache.cayenne.dbsync.reverse.dbimport.ExcludeTable)4 IncludeColumn (org.apache.cayenne.dbsync.reverse.dbimport.IncludeColumn)3 IncludeTable (org.apache.cayenne.dbsync.reverse.dbimport.IncludeTable)3 ExcludeColumn (org.apache.cayenne.dbsync.reverse.dbimport.ExcludeColumn)2 IncludeProcedure (org.apache.cayenne.dbsync.reverse.dbimport.IncludeProcedure)2 DbImportConfiguration (org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration)1 ExcludeProcedure (org.apache.cayenne.dbsync.reverse.dbimport.ExcludeProcedure)1 DbLoaderDelegate (org.apache.cayenne.dbsync.reverse.dbload.DbLoaderDelegate)1 FiltersConfigBuilder (org.apache.cayenne.dbsync.reverse.filters.FiltersConfigBuilder)1 DBConnectionInfo (org.apache.cayenne.modeler.pref.DBConnectionInfo)1