diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/filters/IncludeTableFilter.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/filters/IncludeTableFilter.java index 35d504f5ba..670b638236 100644 --- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/filters/IncludeTableFilter.java +++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/filters/IncludeTableFilter.java @@ -18,11 +18,12 @@ ****************************************************************/ package org.apache.cayenne.dbsync.reverse.filters; +import java.util.Objects; import java.util.regex.Pattern; /** -* @since 4.0. -*/ + * @since 4.0. + */ public class IncludeTableFilter implements Comparable { public final Pattern pattern; @@ -50,14 +51,14 @@ public IncludeTableFilter(String pattern, PatternFilter columnsFilter, PatternFi this.relationshipFilter = relationshipFilter; } - public boolean isIncludeColumn (String name) { + public boolean isIncludeColumn(String name) { return columnsFilter.isIncluded(name); } /** * @since 4.1 */ - public boolean isIncludeRelationship (String name) { + public boolean isIncludeRelationship(String name) { return relationshipFilter.isIncluded(name); } @@ -75,6 +76,18 @@ public int compareTo(IncludeTableFilter o) { } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + IncludeTableFilter that = (IncludeTableFilter) o; + + if (!Objects.equals(pattern, that.pattern)) return false; + if (!Objects.equals(columnsFilter, that.columnsFilter)) return false; + return Objects.equals(relationshipFilter, that.relationshipFilter); + } + @Override public String toString() { return toString(new StringBuilder(), "").toString(); diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/filters/PatternFilter.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/filters/PatternFilter.java index 9e2a15c30e..eac1d2667a 100644 --- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/filters/PatternFilter.java +++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/filters/PatternFilter.java @@ -136,14 +136,31 @@ public boolean equals(Object o) { return true; } - if (o == null || getClass() != o.getClass()) { + if (!(o instanceof PatternFilter)) { return false; } - PatternFilter filter = (PatternFilter) o; - return includes.equals(filter.includes) - && excludes.equals(filter.excludes); + + if (includes == filter.includes) { + return true; + } + + if (includes.size() != filter.includes.size()) { + return false; + } + + // Check if the lists have the same patterns in the same order + for (int i = 0; i < includes.size(); i++) { + Pattern patternA = includes.get(i); + Pattern patternB = filter.includes.get(i); + if (!patternA.pattern().equals(patternB.pattern())) { + return false; + } + } + + return true; + } @Override diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/filters/TableFilter.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/filters/TableFilter.java index 3cd00dc665..7b7f6d80cd 100644 --- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/filters/TableFilter.java +++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/filters/TableFilter.java @@ -139,16 +139,18 @@ public boolean equals(Object o) { TableFilter that = (TableFilter) o; - Set includeSet = new TreeSet<>(includes); - Set thatIncludeSet = new TreeSet<>(that.includes); - Set excludeSet = new TreeSet<>(PatternFilter.PATTERN_COMPARATOR); - Set thatExcludeSet = new TreeSet<>(PatternFilter.PATTERN_COMPARATOR); - excludeSet.addAll(excludes); - thatExcludeSet.addAll(that.excludes); - - return includeSet.equals(thatIncludeSet) - && excludeSet.equals(thatExcludeSet); + boolean excludeEquals = true; + // Check if the lists have the same patterns in the same order + for (int i = 0; i < excludes.size(); i++) { + Pattern pattern = excludes.get(i); + Pattern thatPattern = that.excludes.get(i); + if (!pattern.pattern().equals(thatPattern.pattern())) { + excludeEquals = false; + break; + } + } + return includes.equals(that.includes) && excludeEquals; } @Override diff --git a/cayenne-dbsync/src/test/java/org/apache/cayenne/dbsync/reverse/dbload/DbLoaderIT.java b/cayenne-dbsync/src/test/java/org/apache/cayenne/dbsync/reverse/dbload/DbLoaderIT.java index efdbb6395a..ef7dda350a 100644 --- a/cayenne-dbsync/src/test/java/org/apache/cayenne/dbsync/reverse/dbload/DbLoaderIT.java +++ b/cayenne-dbsync/src/test/java/org/apache/cayenne/dbsync/reverse/dbload/DbLoaderIT.java @@ -26,6 +26,7 @@ import org.apache.cayenne.dbsync.reverse.dbimport.ExcludeColumn; import org.apache.cayenne.dbsync.reverse.dbimport.IncludeTable; import org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering; +import org.apache.cayenne.dbsync.reverse.dbimport.Schema; import org.apache.cayenne.dbsync.reverse.filters.FiltersConfig; import org.apache.cayenne.dbsync.reverse.filters.FiltersConfigBuilder; import org.apache.cayenne.di.Inject; @@ -96,8 +97,12 @@ public void testLoadingOrder() throws Exception { DataMap loaded = loader.load(); assertNotNull(loaded); - assertNull(loaded.getDbEntity("ARTIST").getAttribute("DATE_OF_BIRTH")); - assertNotNull(loaded.getDbEntity("PAINTING").getAttribute("PAINTING_DESCRIPTION")); + DbEntity artist = loaded.getDbEntity("ARTIST"); + DbEntity painting = loaded.getDbEntity("PAINTING"); + assertNotNull(artist); + assertNotNull(painting); + assertNull(getDbAttribute(artist,"DATE_OF_BIRTH")); + assertNotNull(getDbAttribute(painting,"PAINTING_DESCRIPTION")); }