diff --git a/wizard-common/src/main/java/org/cobbzilla/wizard/model/SqlDefaultSearchField.java b/wizard-common/src/main/java/org/cobbzilla/wizard/model/SqlDefaultSearchField.java index f1596df..0ff6b4a 100644 --- a/wizard-common/src/main/java/org/cobbzilla/wizard/model/SqlDefaultSearchField.java +++ b/wizard-common/src/main/java/org/cobbzilla/wizard/model/SqlDefaultSearchField.java @@ -8,19 +8,17 @@ import org.cobbzilla.wizard.model.entityconfig.annotations.ECSearchable; import org.cobbzilla.wizard.model.search.SearchBound; import org.cobbzilla.wizard.model.search.SearchBoundBuilder; import org.cobbzilla.wizard.model.search.SearchField; -import org.cobbzilla.wizard.model.search.SearchFieldType; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import static java.util.Arrays.asList; +import static org.cobbzilla.util.daemon.ZillaRuntime.die; import static org.cobbzilla.util.daemon.ZillaRuntime.empty; -import static org.cobbzilla.util.daemon.ZillaRuntime.*; import static org.cobbzilla.util.reflect.ReflectionUtil.instantiate; import static org.cobbzilla.util.string.StringUtil.camelCaseToSnakeCase; import static org.cobbzilla.wizard.model.entityconfig.EntityFieldType.*; -import static org.cobbzilla.wizard.model.search.SearchBoundComparison.*; @EqualsAndHashCode @Slf4j public class SqlDefaultSearchField implements SearchField { @@ -78,18 +76,15 @@ public class SqlDefaultSearchField implements SearchField { bounds.addAll(asList(SearchField.bindDecimal(name()))); break; case flag: - bounds.add(eq.bind(name(), SearchFieldType.flag)); + bounds.addAll(asList(SearchField.bindBoolean(name()))); break; case string: case email: case time_zone: case locale: case ip4: case ip6: case http_url: case us_phone: case us_state: case us_zip: - bounds.addAll(asList(SearchField.bindString(f, name()))); + bounds.addAll(asList(SearchField.bindString(name()))); break; } - if (isNullable(f)) { - bounds.add(is_null.bind(name())); - bounds.add(not_null.bind(name())); - } + if (isNullable(f)) bounds.addAll(asList(SearchField.bindNullable(name()))); } if (empty(bounds)) return die("getBounds: no bounds defined for: "+ bound); return bounds.toArray(SearchBound[]::new); diff --git a/wizard-common/src/main/java/org/cobbzilla/wizard/model/search/SearchField.java b/wizard-common/src/main/java/org/cobbzilla/wizard/model/search/SearchField.java index 2794fd2..56586a5 100644 --- a/wizard-common/src/main/java/org/cobbzilla/wizard/model/search/SearchField.java +++ b/wizard-common/src/main/java/org/cobbzilla/wizard/model/search/SearchField.java @@ -2,7 +2,6 @@ package org.cobbzilla.wizard.model.search; import org.cobbzilla.wizard.validation.SimpleViolationException; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -43,14 +42,20 @@ public interface SearchField { ne.bind(name, SearchFieldType.decimal) }; } - static SearchBound[] bindString(Field f, String name) { + static SearchBound[] bindBoolean(String name) { + return new SearchBound[] { + eq.bind(name, SearchFieldType.flag), + ne.bind(name, SearchFieldType.flag) + }; + } + static SearchBound[] bindString(String name) { return new SearchBound[] { eq.bind(name, SearchFieldType.string), ne.bind(name, SearchFieldType.string), like.bind(name, SearchFieldType.string) }; } - static SearchBound[] bindNullable(String name) { return new SearchBound[] { eq.bind(name), is_null.bind(name), not_null.bind(name) }; } + static SearchBound[] bindNullable(String name) { return new SearchBound[] { is_null.bind(name), not_null.bind(name) }; } String name(); diff --git a/wizard-server/src/main/java/org/cobbzilla/wizard/dao/SearchViewContext.java b/wizard-server/src/main/java/org/cobbzilla/wizard/dao/SearchViewContext.java index d48ea6a..8e6d1a6 100644 --- a/wizard-server/src/main/java/org/cobbzilla/wizard/dao/SearchViewContext.java +++ b/wizard-server/src/main/java/org/cobbzilla/wizard/dao/SearchViewContext.java @@ -69,16 +69,11 @@ public class SearchViewContext { @Getter private final SqlViewField[] searchFields; - private static int longestFieldSet = 0; - private SqlViewField[] initSearchFields() { final Map fields = new LinkedHashMap<>(); final ECSearchDepth mainSearchDepth = clazz.getAnnotation(ECSearchDepth.class); final ECForeignKeySearchDepth mainDepth = mainSearchDepth == null ? inherit : mainSearchDepth.fkDepth(); final Map finalizedFields = initFields(clazz, "", fields, mainDepth, mainDepth); - if (finalizedFields.size() > longestFieldSet) { - longestFieldSet = finalizedFields.size(); - } return finalizedFields.values().toArray(new SqlViewField[0]); }