Search in sources :

Example 21 with Catalog

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

the class FiltersConfigBuilderTest method testCompact_02.

@Test
public void testCompact_02() {
    ReverseEngineering engineering = new ReverseEngineering();
    engineering.addCatalog(new Catalog("catalogName"));
    engineering.addSchema(new Schema("schemaName01"));
    engineering.addSchema(new Schema("schemaName02"));
    engineering.addIncludeTable(new IncludeTable("table1"));
    engineering.addExcludeTable(new ExcludeTable("table2"));
    engineering.addIncludeColumn(new IncludeColumn("includeColumn"));
    FiltersConfigBuilder builder = new FiltersConfigBuilder(engineering);
    builder.compact();
    assertEquals("ReverseEngineering: \n" + "  Catalog: catalogName\n" + "    Schema: schemaName01\n" + "      IncludeTable: table1\n" + "        IncludeColumn: includeColumn\n" + "      ExcludeTable: table2\n" + "    Schema: schemaName02\n" + "      IncludeTable: table1\n" + "        IncludeColumn: includeColumn\n" + "      ExcludeTable: table2\n\n" + "  Use primitives", engineering.toString());
}
Also used : ReverseEngineering(org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering) Schema(org.apache.cayenne.dbsync.reverse.dbimport.Schema) IncludeTable(org.apache.cayenne.dbsync.reverse.dbimport.IncludeTable) IncludeColumn(org.apache.cayenne.dbsync.reverse.dbimport.IncludeColumn) Catalog(org.apache.cayenne.dbsync.reverse.dbimport.Catalog) ExcludeTable(org.apache.cayenne.dbsync.reverse.dbimport.ExcludeTable) Test(org.junit.Test)

Example 22 with Catalog

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

the class LoadDbSchemaAction method performAction.

public void performAction(ActionEvent e, TreePath tablePath) {
    final DbImportView rootParent = ((DbImportView) draggableTreePanel.getParent().getParent());
    rootParent.getLoadDbSchemaProgress().setVisible(true);
    rootParent.getLoadDbSchemaButton().setEnabled(false);
    Thread thread = new Thread(() -> {
        LoadDbSchemaAction.this.setEnabled(false);
        rootParent.lockToolbarButtons();
        draggableTreePanel.getMoveButton().setEnabled(false);
        draggableTreePanel.getMoveInvertButton().setEnabled(false);
        try {
            DBConnectionInfo connectionInfo = getConnectionInfo("Load Db Schema");
            if (connectionInfo == null) {
                return;
            }
            if (tablePath != null) {
                Object userObject = ((DbImportTreeNode) tablePath.getLastPathComponent()).getUserObject();
                if (userObject instanceof Catalog) {
                    Catalog catalog = (Catalog) userObject;
                    if (catalog.getSchemas().isEmpty()) {
                        loadTables(connectionInfo, tablePath, rootParent);
                    }
                } else if (userObject instanceof Schema) {
                    loadTables(connectionInfo, tablePath, rootParent);
                } else if (userObject instanceof IncludeTable) {
                    loadColumns(connectionInfo, tablePath);
                } else {
                    loadTables(connectionInfo, tablePath, rootParent);
                }
            } else {
                loadDataBase(connectionInfo);
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(Application.getFrame(), ex.getMessage(), "Error loading db schema", JOptionPane.ERROR_MESSAGE);
            LOGGER.warn("Error loading db schema", ex);
        } finally {
            rootParent.getLoadDbSchemaButton().setEnabled(true);
            rootParent.getLoadDbSchemaProgress().setVisible(false);
            rootParent.unlockToolbarButtons();
        }
    });
    thread.start();
}
Also used : DbImportView(org.apache.cayenne.modeler.editor.dbimport.DbImportView) DbImportTreeNode(org.apache.cayenne.modeler.dialog.db.load.DbImportTreeNode) Schema(org.apache.cayenne.dbsync.reverse.dbimport.Schema) IncludeTable(org.apache.cayenne.dbsync.reverse.dbimport.IncludeTable) DBConnectionInfo(org.apache.cayenne.modeler.pref.DBConnectionInfo) Catalog(org.apache.cayenne.dbsync.reverse.dbimport.Catalog) SQLException(java.sql.SQLException)

Example 23 with Catalog

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

the class FilterContainerTest method fillContainer.

@Test
public void fillContainer() throws Exception {
    Catalog catalog = new Catalog();
    FilterContainer container = new FilterContainer();
    container.setName("name");
    container.includeTable("table1");
    container.includeTables("table2", "table3");
    container.excludeTable("table4");
    container.excludeTables("table5", "table6");
    container.includeColumn("column1");
    container.includeColumns("column2", "column3");
    container.excludeColumn("column4");
    container.excludeColumns("column5", "collum6");
    container.includeProcedure("proc1");
    container.includeProcedures("proc2", "proc3");
    container.excludeProcedure("proc4");
    container.excludeProcedures("proc5", "proc6");
    container.fillContainer(catalog);
    assertEquals("name", catalog.getName());
    assertEquals(3, catalog.getIncludeTables().size());
    assertEquals("table1", catalog.getIncludeTables().iterator().next().getPattern());
    assertEquals(3, catalog.getExcludeTables().size());
    assertEquals("table4", catalog.getExcludeTables().iterator().next().getPattern());
    assertEquals(3, catalog.getIncludeColumns().size());
    assertEquals("column1", catalog.getIncludeColumns().iterator().next().getPattern());
    assertEquals(3, catalog.getExcludeColumns().size());
    assertEquals("column4", catalog.getExcludeColumns().iterator().next().getPattern());
    assertEquals(3, catalog.getIncludeProcedures().size());
    assertEquals("proc1", catalog.getIncludeProcedures().iterator().next().getPattern());
    assertEquals(3, catalog.getExcludeProcedures().size());
    assertEquals("proc4", catalog.getExcludeProcedures().iterator().next().getPattern());
}
Also used : Catalog(org.apache.cayenne.dbsync.reverse.dbimport.Catalog) Test(org.junit.Test)

Example 24 with Catalog

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

the class DatabaseSchemaLoader method packFilterContainer.

private FilterContainer packFilterContainer(String catalogName, String schemaName) {
    SchemaContainer parentCatalog;
    if (catalogName == null) {
        parentCatalog = databaseReverseEngineering;
    } else {
        parentCatalog = getCatalogByName(databaseReverseEngineering.getCatalogs(), catalogName);
        if (parentCatalog == null) {
            parentCatalog = new Catalog();
            parentCatalog.setName(catalogName);
            databaseReverseEngineering.addCatalog((Catalog) parentCatalog);
        }
    }
    Schema parentSchema = null;
    if (schemaName != null) {
        parentSchema = getSchemaByName(parentCatalog.getSchemas(), schemaName);
        if (parentSchema == null) {
            parentSchema = new Schema();
            parentSchema.setName(schemaName);
            parentCatalog.addSchema(parentSchema);
        }
    }
    return parentSchema == null ? parentCatalog : parentSchema;
}
Also used : SchemaContainer(org.apache.cayenne.dbsync.reverse.dbimport.SchemaContainer) Schema(org.apache.cayenne.dbsync.reverse.dbimport.Schema) Catalog(org.apache.cayenne.dbsync.reverse.dbimport.Catalog)

Example 25 with Catalog

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

the class DatabaseSchemaLoader method loadTables.

public ReverseEngineering loadTables(DBConnectionInfo connectionInfo, ClassLoadingService loadingService, TreePath path, String[] tableTypesFromConfig) throws SQLException {
    int pathIndex = 1;
    String catalogName = null, schemaName = null;
    Object userObject = getUserObjectOrNull(path, pathIndex);
    if (userObject != null) {
        if (userObject instanceof Catalog) {
            Catalog catalog = (Catalog) userObject;
            catalogName = catalog.getName();
            if (!catalog.getSchemas().isEmpty()) {
                userObject = getUserObjectOrNull(path, ++pathIndex);
                if (userObject instanceof Schema) {
                    schemaName = ((Schema) userObject).getName();
                }
            }
        } else if (userObject instanceof Schema) {
            schemaName = ((Schema) userObject).getName();
        }
    }
    try (Connection connection = connectionInfo.makeDataSource(loadingService).getConnection()) {
        String[] types = tableTypesFromConfig != null && tableTypesFromConfig.length != 0 ? tableTypesFromConfig : new String[] { "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY", "ALIAS", "SYNONYM" };
        try (ResultSet resultSet = connection.getMetaData().getTables(catalogName, schemaName, INCLUDE_ALL_PATTERN, types)) {
            boolean hasTables = false;
            while (resultSet.next()) {
                hasTables = true;
                String table = resultSet.getString("TABLE_NAME");
                String schema = resultSet.getString("TABLE_SCHEM");
                String catalog = resultSet.getString("TABLE_CAT");
                packTable(table, catalog == null ? catalogName : catalog, schema, null);
            }
            if (!hasTables && (catalogName != null || schemaName != null)) {
                packFilterContainer(catalogName, schemaName);
            }
            packProcedures(connection);
        }
    }
    return databaseReverseEngineering;
}
Also used : Schema(org.apache.cayenne.dbsync.reverse.dbimport.Schema) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Catalog(org.apache.cayenne.dbsync.reverse.dbimport.Catalog)

Aggregations

Catalog (org.apache.cayenne.dbsync.reverse.dbimport.Catalog)30 Schema (org.apache.cayenne.dbsync.reverse.dbimport.Schema)18 IncludeTable (org.apache.cayenne.dbsync.reverse.dbimport.IncludeTable)11 ExcludeTable (org.apache.cayenne.dbsync.reverse.dbimport.ExcludeTable)7 ReverseEngineering (org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering)7 Test (org.junit.Test)7 DbImportTreeNode (org.apache.cayenne.modeler.dialog.db.load.DbImportTreeNode)6 ResultSet (java.sql.ResultSet)4 IncludeColumn (org.apache.cayenne.dbsync.reverse.dbimport.IncludeColumn)4 ArrayList (java.util.ArrayList)3 ExcludeColumn (org.apache.cayenne.dbsync.reverse.dbimport.ExcludeColumn)3 FilterContainer (org.apache.cayenne.dbsync.reverse.dbimport.FilterContainer)3 IncludeProcedure (org.apache.cayenne.dbsync.reverse.dbimport.IncludeProcedure)3 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 HashMap (java.util.HashMap)2 TreePath (javax.swing.tree.TreePath)2 ExcludeProcedure (org.apache.cayenne.dbsync.reverse.dbimport.ExcludeProcedure)2 TransferableNode (org.apache.cayenne.modeler.dialog.db.load.TransferableNode)2 DbImportView (org.apache.cayenne.modeler.editor.dbimport.DbImportView)2