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));
}
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));
}
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;
}
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);
}
}
Aggregations