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