Search in sources :

Example 1 with PatternFilter

use of org.apache.cayenne.dbsync.reverse.filters.PatternFilter in project cayenne by apache.

the class DefaultDbImportAction method syncProcedures.

private boolean syncProcedures(DataMap targetDataMap, DataMap loadedDataMap, FiltersConfig filters) {
    Collection<Procedure> procedures = loadedDataMap.getProcedures();
    if (procedures.isEmpty()) {
        return false;
    }
    boolean hasChanges = false;
    for (Procedure procedure : procedures) {
        PatternFilter proceduresFilter = filters.proceduresFilter(procedure.getCatalog(), procedure.getSchema());
        if (proceduresFilter == null || !proceduresFilter.isIncluded(procedure.getName())) {
            continue;
        }
        Procedure oldProcedure = targetDataMap.getProcedure(procedure.getName());
        // maybe we need to compare oldProcedure's and procedure's fully qualified names?
        if (oldProcedure != null) {
            targetDataMap.removeProcedure(procedure.getName());
            logger.info("Replace procedure " + procedure.getName());
        } else {
            logger.info("Add new procedure " + procedure.getName());
        }
        targetDataMap.addProcedure(procedure);
        hasChanges = true;
    }
    return hasChanges;
}
Also used : PatternFilter(org.apache.cayenne.dbsync.reverse.filters.PatternFilter) Procedure(org.apache.cayenne.map.Procedure)

Example 2 with PatternFilter

use of org.apache.cayenne.dbsync.reverse.filters.PatternFilter in project cayenne by apache.

the class DbImporterOldMojoConfigurationTest method testLoadSchema2.

public void testLoadSchema2() throws Exception {
    FiltersConfig filters = getCdbImport("pom-schema-2.xml").createConfig(mock(Logger.class)).getDbLoaderConfig().getFiltersConfig();
    TreeSet<IncludeTableFilter> includes = new TreeSet<>();
    includes.add(new IncludeTableFilter(null, new PatternFilter().exclude("^ETL_.*")));
    TreeSet<Pattern> excludes = new TreeSet<>(PatternFilter.PATTERN_COMPARATOR);
    excludes.add(PatternFilter.pattern("^ETL_.*"));
    assertEquals(filters.tableFilter(null, "NHL_STATS"), new TableFilter(includes, excludes));
}
Also used : Pattern(java.util.regex.Pattern) PatternFilter(org.apache.cayenne.dbsync.reverse.filters.PatternFilter) IncludeTableFilter(org.apache.cayenne.dbsync.reverse.filters.IncludeTableFilter) TableFilter(org.apache.cayenne.dbsync.reverse.filters.TableFilter) TreeSet(java.util.TreeSet) FiltersConfig(org.apache.cayenne.dbsync.reverse.filters.FiltersConfig) IncludeTableFilter(org.apache.cayenne.dbsync.reverse.filters.IncludeTableFilter) Logger(org.slf4j.Logger)

Example 3 with PatternFilter

use of org.apache.cayenne.dbsync.reverse.filters.PatternFilter in project cayenne by apache.

the class DataMapMergerTest method testProcedures.

@Test
public void testProcedures() {
    DataMap dataMap1 = dataMap().with(procedure("proc1").callParameters(new ProcedureParameter("test"))).build();
    DataMap dataMap2 = dataMap().build();
    PatternFilter patternFilter = new PatternFilter();
    patternFilter.include("proc1");
    FiltersConfig filtersConfig = FiltersConfig.create(null, null, null, patternFilter);
    DataMapMerger merger = DataMapMerger.builder(factory()).filters(filtersConfig).build();
    assertEquals(1, merger.createMergeTokens(dataMap1, dataMap2).size());
}
Also used : ProcedureParameter(org.apache.cayenne.map.ProcedureParameter) PatternFilter(org.apache.cayenne.dbsync.reverse.filters.PatternFilter) FiltersConfig(org.apache.cayenne.dbsync.reverse.filters.FiltersConfig) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 4 with PatternFilter

use of org.apache.cayenne.dbsync.reverse.filters.PatternFilter in project cayenne by apache.

the class DbImporterMojoConfigurationTest method testLoadSchema2.

@Test
public void testLoadSchema2() throws Exception {
    DbImporterMojo dbImporterMojo = getCdbImport("pom-schema-2.xml");
    DbImportConfiguration dbImportConfiguration = dbImporterMojo.createConfig(mock(Logger.class));
    dbImportConfiguration.setFiltersConfig(new FiltersConfigBuilder(dbImporterMojo.getReverseEngineering()).build());
    FiltersConfig filters = dbImportConfiguration.getDbLoaderConfig().getFiltersConfig();
    TreeSet<IncludeTableFilter> includes = new TreeSet<>();
    includes.add(new IncludeTableFilter(null, new PatternFilter().exclude("^ETL_.*")));
    TreeSet<Pattern> excludes = new TreeSet<>(PatternFilter.PATTERN_COMPARATOR);
    excludes.add(PatternFilter.pattern("^ETL_.*"));
    assertEquals(filters.tableFilter(null, "NHL_STATS"), new TableFilter(includes, excludes));
}
Also used : Pattern(java.util.regex.Pattern) PatternFilter(org.apache.cayenne.dbsync.reverse.filters.PatternFilter) DbImportConfiguration(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration) FiltersConfigBuilder(org.apache.cayenne.dbsync.reverse.filters.FiltersConfigBuilder) IncludeTableFilter(org.apache.cayenne.dbsync.reverse.filters.IncludeTableFilter) TableFilter(org.apache.cayenne.dbsync.reverse.filters.TableFilter) TreeSet(java.util.TreeSet) FiltersConfig(org.apache.cayenne.dbsync.reverse.filters.FiltersConfig) IncludeTableFilter(org.apache.cayenne.dbsync.reverse.filters.IncludeTableFilter) Logger(org.slf4j.Logger) Test(org.junit.Test)

Example 5 with PatternFilter

use of org.apache.cayenne.dbsync.reverse.filters.PatternFilter in project cayenne by apache.

the class AttributeLoader method processResultSetRow.

@Override
protected void processResultSetRow(CatalogFilter catalog, SchemaFilter schema, DbLoadDataStore map, ResultSet rs) throws SQLException {
    if (firstRow) {
        supportAutoIncrement = checkForAutoIncrement(rs);
        firstRow = false;
    }
    // for a reason not quiet apparent to me, Oracle sometimes
    // returns duplicate record sets for the same table, messing up
    // table names. E.g. for the system table "WK$_ATTR_MAPPING" columns
    // are returned twice - as "WK$_ATTR_MAPPING" and "WK$$_ATTR_MAPPING"...
    // Go figure
    String tableName = rs.getString("TABLE_NAME");
    DbEntity entity = map.getDbEntity(tableName);
    if (entity == null) {
        return;
    }
    // Filter out columns by name
    String columnName = rs.getString("COLUMN_NAME");
    PatternFilter columnFilter = schema.tables.getIncludeTableColumnFilter(tableName);
    if (columnFilter == null || !columnFilter.isIncluded(columnName)) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Skip column '" + tableName + "." + columnName + "' (Path: " + catalog.name + "/" + schema.name + "; Filter: " + columnFilter + ")");
        }
        return;
    }
    DbAttribute attribute = createDbAttribute(rs);
    addToDbEntity(entity, attribute);
}
Also used : PatternFilter(org.apache.cayenne.dbsync.reverse.filters.PatternFilter) DbEntity(org.apache.cayenne.map.DbEntity) DetectedDbAttribute(org.apache.cayenne.dbsync.model.DetectedDbAttribute) DbAttribute(org.apache.cayenne.map.DbAttribute)

Aggregations

PatternFilter (org.apache.cayenne.dbsync.reverse.filters.PatternFilter)7 FiltersConfig (org.apache.cayenne.dbsync.reverse.filters.FiltersConfig)3 TableFilter (org.apache.cayenne.dbsync.reverse.filters.TableFilter)3 TreeSet (java.util.TreeSet)2 Pattern (java.util.regex.Pattern)2 IncludeTableFilter (org.apache.cayenne.dbsync.reverse.filters.IncludeTableFilter)2 Procedure (org.apache.cayenne.map.Procedure)2 Test (org.junit.Test)2 Logger (org.slf4j.Logger)2 LinkedList (java.util.LinkedList)1 DetectedDbAttribute (org.apache.cayenne.dbsync.model.DetectedDbAttribute)1 DbImportConfiguration (org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration)1 FiltersConfigBuilder (org.apache.cayenne.dbsync.reverse.filters.FiltersConfigBuilder)1 DataMap (org.apache.cayenne.map.DataMap)1 DbAttribute (org.apache.cayenne.map.DbAttribute)1 DbEntity (org.apache.cayenne.map.DbEntity)1 DbRelationship (org.apache.cayenne.map.DbRelationship)1 ProcedureParameter (org.apache.cayenne.map.ProcedureParameter)1