Search in sources :

Example 1 with TableFilter

use of org.apache.cayenne.dbsync.reverse.filters.TableFilter 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 2 with TableFilter

use of org.apache.cayenne.dbsync.reverse.filters.TableFilter 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 3 with TableFilter

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

the class DbRelationshipDictionary method filter.

/**
 * @since 4.1
 */
private Collection<DbRelationship> filter() {
    if (filtersConfig == null) {
        return container.getRelationships();
    }
    Collection<DbRelationship> existingFiltered = new LinkedList<>();
    TableFilter tableFilter = filtersConfig.tableFilter(container.getCatalog(), container.getSchema());
    if (tableFilter != null && tableFilter.isIncludeTable(container.getName())) {
        PatternFilter patternFilter = tableFilter.getIncludeTableRelationshipFilter(container.getName());
        for (DbRelationship rel : container.getRelationships()) {
            if (patternFilter.isIncluded(rel.getName())) {
                existingFiltered.add(rel);
            }
        }
    }
    return existingFiltered;
}
Also used : PatternFilter(org.apache.cayenne.dbsync.reverse.filters.PatternFilter) TableFilter(org.apache.cayenne.dbsync.reverse.filters.TableFilter) DbRelationship(org.apache.cayenne.map.DbRelationship) LinkedList(java.util.LinkedList)

Example 4 with TableFilter

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

the class RelationshipLoader method checkAndAddRelationship.

private void checkAndAddRelationship(DbEntity entity, DbRelationship relationship) {
    TableFilter sourceTableFilter = config.getFiltersConfig().tableFilter(relationship.getSourceEntity().getCatalog(), relationship.getSourceEntity().getSchema());
    TableFilter targetTableFilter = config.getFiltersConfig().tableFilter(relationship.getTargetEntity().getCatalog(), relationship.getTargetEntity().getSchema());
    // check that relationship can be included
    if (sourceTableFilter != null && !sourceTableFilter.getIncludeTableRelationshipFilter(entity.getName()).isIncluded(relationship.getName())) {
        return;
    }
    // but still better to check everything here too, so we can assert that added relationship is valid.
    if (relationship.getJoins().isEmpty()) {
        return;
    }
    if (sourceTableFilter != null && targetTableFilter != null) {
        // check that all join attributes are included
        for (DbJoin join : relationship.getJoins()) {
            if (!sourceTableFilter.getIncludeTableColumnFilter(entity.getName()).isIncluded(join.getSourceName()) || !targetTableFilter.getIncludeTableColumnFilter(relationship.getTargetEntityName()).isIncluded(join.getTargetName())) {
                return;
            }
        }
    }
    // add relationship if delegate permit it
    if (delegate.dbRelationshipLoaded(entity, relationship)) {
        entity.addRelationship(relationship);
    }
}
Also used : TableFilter(org.apache.cayenne.dbsync.reverse.filters.TableFilter) DbJoin(org.apache.cayenne.map.DbJoin)

Aggregations

TableFilter (org.apache.cayenne.dbsync.reverse.filters.TableFilter)4 PatternFilter (org.apache.cayenne.dbsync.reverse.filters.PatternFilter)3 TreeSet (java.util.TreeSet)2 Pattern (java.util.regex.Pattern)2 FiltersConfig (org.apache.cayenne.dbsync.reverse.filters.FiltersConfig)2 IncludeTableFilter (org.apache.cayenne.dbsync.reverse.filters.IncludeTableFilter)2 Logger (org.slf4j.Logger)2 LinkedList (java.util.LinkedList)1 DbImportConfiguration (org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration)1 FiltersConfigBuilder (org.apache.cayenne.dbsync.reverse.filters.FiltersConfigBuilder)1 DbJoin (org.apache.cayenne.map.DbJoin)1 DbRelationship (org.apache.cayenne.map.DbRelationship)1 Test (org.junit.Test)1