This commit is contained in:
@@ -155,6 +155,8 @@ final class FilterBeanNode extends FilterNode {
|
||||
|
||||
private Attribute columnAttribute;
|
||||
|
||||
private String tabalis;
|
||||
|
||||
private long least;
|
||||
|
||||
private boolean string;
|
||||
@@ -163,7 +165,7 @@ final class FilterBeanNode extends FilterNode {
|
||||
|
||||
protected FilterBeanNode(String col, boolean sign, Attribute beanAttr) {
|
||||
this.column = col;
|
||||
this.and = sign;
|
||||
this.or = sign;
|
||||
this.beanAttribute = beanAttr;
|
||||
}
|
||||
|
||||
@@ -190,9 +192,14 @@ final class FilterBeanNode extends FilterNode {
|
||||
this.tabalis = "a";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTabalis() {
|
||||
return tabalis;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void append(FilterNode node, boolean sign) {
|
||||
FilterBeanNode newnode = new FilterBeanNode(this.column, this.and, this.beanAttribute);
|
||||
FilterBeanNode newnode = new FilterBeanNode(this.column, this.or, this.beanAttribute);
|
||||
newnode.express = this.express;
|
||||
newnode.nodes = this.nodes;
|
||||
newnode.foreignEntity = this.foreignEntity;
|
||||
@@ -205,7 +212,7 @@ final class FilterBeanNode extends FilterNode {
|
||||
this.nodes = new FilterNode[]{newnode};
|
||||
this.column = node.column;
|
||||
this.express = node.express;
|
||||
this.and = sign;
|
||||
this.or = sign;
|
||||
this.setValue(node.getValue());
|
||||
if (node instanceof FilterBeanNode) {
|
||||
FilterBeanNode beanNode = ((FilterBeanNode) node);
|
||||
@@ -240,18 +247,7 @@ final class FilterBeanNode extends FilterNode {
|
||||
if (f == null) continue;
|
||||
final Predicate<T> one = result;
|
||||
final Predicate<T> two = f;
|
||||
result = (result == null) ? f : (and ? new Predicate<T>() {
|
||||
|
||||
@Override
|
||||
public boolean test(T t) {
|
||||
return one.test(t) && two.test(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + one + " AND " + two + ")";
|
||||
}
|
||||
} : new Predicate<T>() {
|
||||
result = (result == null) ? f : (or ? new Predicate<T>() {
|
||||
|
||||
@Override
|
||||
public boolean test(T t) {
|
||||
@@ -262,6 +258,17 @@ final class FilterBeanNode extends FilterNode {
|
||||
public String toString() {
|
||||
return "(" + one + " OR " + two + ")";
|
||||
}
|
||||
} : new Predicate<T>() {
|
||||
|
||||
@Override
|
||||
public boolean test(T t) {
|
||||
return one.test(t) && two.test(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + one + " AND " + two + ")";
|
||||
}
|
||||
});
|
||||
} else {
|
||||
putForeignPredicate(cache, foreign, bean);
|
||||
@@ -290,18 +297,7 @@ final class FilterBeanNode extends FilterNode {
|
||||
};
|
||||
final Predicate<T> one = result;
|
||||
final Predicate<T> two = f;
|
||||
result = (result == null) ? f : (and ? new Predicate<T>() {
|
||||
|
||||
@Override
|
||||
public boolean test(T t) {
|
||||
return one.test(t) && two.test(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + one + " AND " + two + ")";
|
||||
}
|
||||
} : new Predicate<T>() {
|
||||
result = (result == null) ? f : (or ? new Predicate<T>() {
|
||||
|
||||
@Override
|
||||
public boolean test(T t) {
|
||||
@@ -312,6 +308,17 @@ final class FilterBeanNode extends FilterNode {
|
||||
public String toString() {
|
||||
return "(" + one + " OR " + two + ")";
|
||||
}
|
||||
} : new Predicate<T>() {
|
||||
|
||||
@Override
|
||||
public boolean test(T t) {
|
||||
return one.test(t) && two.test(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + one + " AND " + two + ")";
|
||||
}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
@@ -324,12 +331,12 @@ final class FilterBeanNode extends FilterNode {
|
||||
|
||||
@Override
|
||||
public boolean test(T t) {
|
||||
return and;
|
||||
return or;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "" + and;
|
||||
return "" + or;
|
||||
}
|
||||
} : super.createElementPredicate(cache, this.columnAttribute, bean);
|
||||
if (filter == null) return;
|
||||
@@ -339,18 +346,7 @@ final class FilterBeanNode extends FilterNode {
|
||||
} else {
|
||||
final Predicate<T> one = p;
|
||||
final Predicate<T> two = filter;
|
||||
p = and ? new Predicate<T>() {
|
||||
|
||||
@Override
|
||||
public boolean test(T t) {
|
||||
return one.test(t) && two.test(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + one + " AND " + two + ")";
|
||||
}
|
||||
} : new Predicate<T>() {
|
||||
p = or ? new Predicate<T>() {
|
||||
|
||||
@Override
|
||||
public boolean test(T t) {
|
||||
@@ -361,6 +357,17 @@ final class FilterBeanNode extends FilterNode {
|
||||
public String toString() {
|
||||
return "(" + one + " OR " + two + ")";
|
||||
}
|
||||
} : new Predicate<T>() {
|
||||
|
||||
@Override
|
||||
public boolean test(T t) {
|
||||
return one.test(t) && two.test(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + one + " AND " + two + ")";
|
||||
}
|
||||
};
|
||||
foreign.put(foreignEntity, p);
|
||||
}
|
||||
|
||||
@@ -29,8 +29,6 @@ public class FilterNode {
|
||||
class2.put(Double.class, double.class);
|
||||
}
|
||||
|
||||
protected String tabalis;
|
||||
|
||||
protected String column;
|
||||
|
||||
protected FilterExpress express;
|
||||
@@ -38,7 +36,7 @@ public class FilterNode {
|
||||
protected Serializable value;
|
||||
|
||||
//----------------------------------------------
|
||||
protected boolean and = true;
|
||||
protected boolean or;
|
||||
|
||||
protected FilterNode[] nodes;
|
||||
|
||||
@@ -64,7 +62,7 @@ public class FilterNode {
|
||||
}
|
||||
|
||||
public final FilterNode and(FilterNode node) {
|
||||
return any(node, true);
|
||||
return any(node, false);
|
||||
}
|
||||
|
||||
public final FilterNode and(String column, Serializable value) {
|
||||
@@ -76,7 +74,7 @@ public class FilterNode {
|
||||
}
|
||||
|
||||
public final FilterNode or(FilterNode node) {
|
||||
return any(node, false);
|
||||
return any(node, true);
|
||||
}
|
||||
|
||||
public final FilterNode or(String column, Serializable value) {
|
||||
@@ -97,10 +95,10 @@ public class FilterNode {
|
||||
}
|
||||
if (nodes == null) {
|
||||
nodes = new FilterNode[]{node};
|
||||
this.and = sign;
|
||||
this.or = sign;
|
||||
return this;
|
||||
}
|
||||
if (and == sign) {
|
||||
if (or == sign) {
|
||||
FilterNode[] newsiblings = new FilterNode[nodes.length + 1];
|
||||
System.arraycopy(nodes, 0, newsiblings, 0, nodes.length);
|
||||
newsiblings[nodes.length] = node;
|
||||
@@ -119,13 +117,12 @@ public class FilterNode {
|
||||
*/
|
||||
protected void append(FilterNode node, boolean sign) {
|
||||
FilterNode newnode = new FilterNode(this.column, this.express, this.value);
|
||||
newnode.and = this.and;
|
||||
newnode.or = this.or;
|
||||
newnode.nodes = this.nodes;
|
||||
this.nodes = new FilterNode[]{newnode, node};
|
||||
this.tabalis = null;
|
||||
this.column = null;
|
||||
this.express = null;
|
||||
this.and = sign;
|
||||
this.or = sign;
|
||||
this.value = null;
|
||||
}
|
||||
|
||||
@@ -150,6 +147,15 @@ public class FilterNode {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 该方法需要重载
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected String getTabalis() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 该方法需要重载
|
||||
*
|
||||
@@ -180,7 +186,7 @@ public class FilterNode {
|
||||
for (FilterNode node : this.nodes) {
|
||||
CharSequence f = node.createSQLExpress(info, bean);
|
||||
if (f == null || f.length() < 3) continue;
|
||||
if (more) rs.append(and ? " AND " : " OR ");
|
||||
if (more) rs.append(or ? " OR " : " AND ");
|
||||
rs.append(f);
|
||||
more = true;
|
||||
}
|
||||
@@ -191,6 +197,7 @@ public class FilterNode {
|
||||
|
||||
protected final <T> CharSequence createElementSQLExpress(final EntityInfo<T> info, final FilterBean bean) {
|
||||
if (column == null) return null;
|
||||
final String tabalis = getTabalis();
|
||||
if (express == ISNULL || express == ISNOTNULL) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (tabalis != null) sb.append(tabalis).append('.');
|
||||
@@ -231,18 +238,7 @@ public class FilterNode {
|
||||
if (f == null) continue;
|
||||
final Predicate<T> one = filter;
|
||||
final Predicate<T> two = f;
|
||||
filter = (filter == null) ? f : (and ? new Predicate<T>() {
|
||||
|
||||
@Override
|
||||
public boolean test(T t) {
|
||||
return one.test(t) && two.test(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + one + " AND " + two + ")";
|
||||
}
|
||||
} : new Predicate<T>() {
|
||||
filter = (filter == null) ? f : (or ? new Predicate<T>() {
|
||||
|
||||
@Override
|
||||
public boolean test(T t) {
|
||||
@@ -253,6 +249,17 @@ public class FilterNode {
|
||||
public String toString() {
|
||||
return "(" + one + " OR " + two + ")";
|
||||
}
|
||||
} : new Predicate<T>() {
|
||||
|
||||
@Override
|
||||
public boolean test(T t) {
|
||||
return one.test(t) && two.test(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + one + " AND " + two + ")";
|
||||
}
|
||||
});
|
||||
}
|
||||
return filter;
|
||||
@@ -809,7 +816,7 @@ public class FilterNode {
|
||||
for (FilterNode node : this.nodes) {
|
||||
String s = node.toString();
|
||||
if (s.isEmpty()) continue;
|
||||
if (sb.length() > 0) sb.append(and ? " AND " : " OR ");
|
||||
if (sb.length() > 0) sb.append(or ? " OR " : " AND ");
|
||||
sb.append(s);
|
||||
}
|
||||
if (more) sb.append(')');
|
||||
@@ -893,20 +900,12 @@ public class FilterNode {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public final boolean isAnd() {
|
||||
return and;
|
||||
public final boolean isOr() {
|
||||
return or;
|
||||
}
|
||||
|
||||
public final void setAnd(boolean and) {
|
||||
this.and = and;
|
||||
}
|
||||
|
||||
public final String getTabalis() {
|
||||
return tabalis;
|
||||
}
|
||||
|
||||
public final void setTabalis(String tabalis) {
|
||||
this.tabalis = tabalis;
|
||||
public final void setOr(boolean or) {
|
||||
this.or = or;
|
||||
}
|
||||
|
||||
public final String getColumn() {
|
||||
|
||||
Reference in New Issue
Block a user