Search in sources :

Example 11 with Catalog

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

the class SchemaProcedureNode method getContainers.

@Override
List<FilterContainer> getContainers(ReverseEngineering config) {
    List<FilterContainer> containers = new ArrayList<>();
    if (getParent() != null && getParent().getParent() != null) {
        Catalog catalog = getParent().getParent().getCatalog(config);
        if (catalog != null) {
            containers.add(getParent().getSchema(catalog));
            containers.add(catalog);
        }
        containers.add(getParent().getSchema(config));
    }
    containers.add(config);
    return containers;
}
Also used : FilterContainer(org.apache.cayenne.dbsync.reverse.dbimport.FilterContainer) ArrayList(java.util.ArrayList) Catalog(org.apache.cayenne.dbsync.reverse.dbimport.Catalog)

Example 12 with Catalog

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

the class FiltersConfigBuilder method clearGlobalFilters.

private void clearGlobalFilters() {
    for (Catalog catalog : engineering.getCatalogs()) {
        catalog.clearIncludeTables();
        catalog.clearExcludeTables();
        catalog.clearIncludeProcedures();
        catalog.clearExcludeProcedures();
        catalog.clearIncludeColumns();
        catalog.clearExcludeColumns();
        catalog.clearExcludeRelationships();
        for (Schema schema : catalog.getSchemas()) {
            schema.clearIncludeColumns();
            schema.clearExcludeColumns();
            schema.clearExcludeRelationships();
        }
    }
    engineering.clearIncludeTables();
    engineering.clearExcludeTables();
    engineering.clearIncludeProcedures();
    engineering.clearExcludeProcedures();
    engineering.clearIncludeColumns();
    engineering.clearExcludeColumns();
    engineering.clearExcludeRelationships();
    engineering.getSchemas().clear();
}
Also used : Schema(org.apache.cayenne.dbsync.reverse.dbimport.Schema) Catalog(org.apache.cayenne.dbsync.reverse.dbimport.Catalog)

Example 13 with Catalog

use of org.apache.cayenne.dbsync.reverse.dbimport.Catalog 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)

Example 14 with Catalog

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

the class FiltersConfigBuilder method processCatalogs.

private void processCatalogs(DatabaseMetaData databaseMetaData, DbAdapter dbAdapter) throws SQLException {
    try (ResultSet catalogRs = databaseMetaData.getCatalogs()) {
        List<String> systemCatalogs = dbAdapter.getSystemCatalogs();
        List<String> systemSchemas = dbAdapter.getSystemSchemas();
        boolean hasCatalogs = false;
        while (catalogRs.next()) {
            hasCatalogs = true;
            String catalogName = catalogRs.getString("TABLE_CAT");
            if (!systemCatalogs.contains(catalogName)) {
                Catalog catalog = new Catalog(catalogName);
                List<Schema> schemas = processSchemas(databaseMetaData, catalogName, systemSchemas);
                catalog.getSchemas().addAll(schemas);
                engineering.addCatalog(catalog);
            }
        }
        if (!hasCatalogs) {
            List<Schema> schemas = processSchemas(databaseMetaData, null, systemSchemas);
            engineering.getSchemas().addAll(schemas);
        }
    }
}
Also used : Schema(org.apache.cayenne.dbsync.reverse.dbimport.Schema) ResultSet(java.sql.ResultSet) Catalog(org.apache.cayenne.dbsync.reverse.dbimport.Catalog)

Example 15 with Catalog

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

the class FiltersConfigBuilder method compactProcedureFilter.

private void compactProcedureFilter() {
    Collection<IncludeProcedure> engIncludeProcedures = engineering.getIncludeProcedures();
    Collection<ExcludeProcedure> engExcludeProcedures = engineering.getExcludeProcedures();
    for (Catalog catalog : engineering.getCatalogs()) {
        Collection<IncludeProcedure> catalogIncludeProcedures = catalog.getIncludeProcedures();
        Collection<ExcludeProcedure> catalogExcludeProcedures = catalog.getExcludeProcedures();
        for (Schema schema : catalog.getSchemas()) {
            schema.getIncludeProcedures().addAll(engIncludeProcedures);
            schema.getIncludeProcedures().addAll(catalogIncludeProcedures);
            schema.getExcludeProcedures().addAll(engExcludeProcedures);
            schema.getExcludeProcedures().addAll(catalogExcludeProcedures);
        }
    }
    for (Schema schema : engineering.getSchemas()) {
        schema.getIncludeProcedures().addAll(engIncludeProcedures);
        schema.getExcludeProcedures().addAll(engExcludeProcedures);
    }
}
Also used : Schema(org.apache.cayenne.dbsync.reverse.dbimport.Schema) ExcludeProcedure(org.apache.cayenne.dbsync.reverse.dbimport.ExcludeProcedure) IncludeProcedure(org.apache.cayenne.dbsync.reverse.dbimport.IncludeProcedure) 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