Skip to content

Commit

Permalink
cleanUp
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan-nikitko committed Feb 23, 2023
1 parent 4bc82cd commit 8af6095
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<IncludeTableFilter> {
public final Pattern pattern;

Expand Down Expand Up @@ -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);
}

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,18 @@ public boolean equals(Object o) {

TableFilter that = (TableFilter) o;

Set<IncludeTableFilter> includeSet = new TreeSet<>(includes);
Set<IncludeTableFilter> thatIncludeSet = new TreeSet<>(that.includes);
Set<Pattern> excludeSet = new TreeSet<>(PatternFilter.PATTERN_COMPARATOR);
Set<Pattern> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
}


Expand Down

0 comments on commit 8af6095

Please sign in to comment.