This commit is contained in:
kamhung
2015-11-20 16:29:40 +08:00
parent 412835885a
commit ac4fde73be
2 changed files with 83 additions and 77 deletions

View File

@@ -155,6 +155,8 @@ final class FilterBeanNode extends FilterNode {
private Attribute columnAttribute; private Attribute columnAttribute;
private String tabalis;
private long least; private long least;
private boolean string; private boolean string;
@@ -163,7 +165,7 @@ final class FilterBeanNode extends FilterNode {
protected FilterBeanNode(String col, boolean sign, Attribute beanAttr) { protected FilterBeanNode(String col, boolean sign, Attribute beanAttr) {
this.column = col; this.column = col;
this.and = sign; this.or = sign;
this.beanAttribute = beanAttr; this.beanAttribute = beanAttr;
} }
@@ -190,9 +192,14 @@ final class FilterBeanNode extends FilterNode {
this.tabalis = "a"; this.tabalis = "a";
} }
@Override
protected String getTabalis() {
return tabalis;
}
@Override @Override
protected void append(FilterNode node, boolean sign) { 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.express = this.express;
newnode.nodes = this.nodes; newnode.nodes = this.nodes;
newnode.foreignEntity = this.foreignEntity; newnode.foreignEntity = this.foreignEntity;
@@ -205,7 +212,7 @@ final class FilterBeanNode extends FilterNode {
this.nodes = new FilterNode[]{newnode}; this.nodes = new FilterNode[]{newnode};
this.column = node.column; this.column = node.column;
this.express = node.express; this.express = node.express;
this.and = sign; this.or = sign;
this.setValue(node.getValue()); this.setValue(node.getValue());
if (node instanceof FilterBeanNode) { if (node instanceof FilterBeanNode) {
FilterBeanNode beanNode = ((FilterBeanNode) node); FilterBeanNode beanNode = ((FilterBeanNode) node);
@@ -240,18 +247,7 @@ final class FilterBeanNode extends FilterNode {
if (f == null) continue; if (f == null) continue;
final Predicate<T> one = result; final Predicate<T> one = result;
final Predicate<T> two = f; final Predicate<T> two = f;
result = (result == null) ? f : (and ? new Predicate<T>() { result = (result == null) ? f : (or ? 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>() {
@Override @Override
public boolean test(T t) { public boolean test(T t) {
@@ -262,6 +258,17 @@ final class FilterBeanNode extends FilterNode {
public String toString() { public String toString() {
return "(" + one + " OR " + two + ")"; 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 { } else {
putForeignPredicate(cache, foreign, bean); putForeignPredicate(cache, foreign, bean);
@@ -290,18 +297,7 @@ final class FilterBeanNode extends FilterNode {
}; };
final Predicate<T> one = result; final Predicate<T> one = result;
final Predicate<T> two = f; final Predicate<T> two = f;
result = (result == null) ? f : (and ? new Predicate<T>() { result = (result == null) ? f : (or ? 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>() {
@Override @Override
public boolean test(T t) { public boolean test(T t) {
@@ -312,6 +308,17 @@ final class FilterBeanNode extends FilterNode {
public String toString() { public String toString() {
return "(" + one + " OR " + two + ")"; 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; return result;
@@ -324,12 +331,12 @@ final class FilterBeanNode extends FilterNode {
@Override @Override
public boolean test(T t) { public boolean test(T t) {
return and; return or;
} }
@Override @Override
public String toString() { public String toString() {
return "" + and; return "" + or;
} }
} : super.createElementPredicate(cache, this.columnAttribute, bean); } : super.createElementPredicate(cache, this.columnAttribute, bean);
if (filter == null) return; if (filter == null) return;
@@ -339,18 +346,7 @@ final class FilterBeanNode extends FilterNode {
} else { } else {
final Predicate<T> one = p; final Predicate<T> one = p;
final Predicate<T> two = filter; final Predicate<T> two = filter;
p = and ? new Predicate<T>() { p = or ? 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>() {
@Override @Override
public boolean test(T t) { public boolean test(T t) {
@@ -361,6 +357,17 @@ final class FilterBeanNode extends FilterNode {
public String toString() { public String toString() {
return "(" + one + " OR " + two + ")"; 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); foreign.put(foreignEntity, p);
} }

View File

@@ -29,8 +29,6 @@ public class FilterNode {
class2.put(Double.class, double.class); class2.put(Double.class, double.class);
} }
protected String tabalis;
protected String column; protected String column;
protected FilterExpress express; protected FilterExpress express;
@@ -38,7 +36,7 @@ public class FilterNode {
protected Serializable value; protected Serializable value;
//---------------------------------------------- //----------------------------------------------
protected boolean and = true; protected boolean or;
protected FilterNode[] nodes; protected FilterNode[] nodes;
@@ -64,7 +62,7 @@ public class FilterNode {
} }
public final FilterNode and(FilterNode node) { public final FilterNode and(FilterNode node) {
return any(node, true); return any(node, false);
} }
public final FilterNode and(String column, Serializable value) { public final FilterNode and(String column, Serializable value) {
@@ -76,7 +74,7 @@ public class FilterNode {
} }
public final FilterNode or(FilterNode node) { public final FilterNode or(FilterNode node) {
return any(node, false); return any(node, true);
} }
public final FilterNode or(String column, Serializable value) { public final FilterNode or(String column, Serializable value) {
@@ -97,10 +95,10 @@ public class FilterNode {
} }
if (nodes == null) { if (nodes == null) {
nodes = new FilterNode[]{node}; nodes = new FilterNode[]{node};
this.and = sign; this.or = sign;
return this; return this;
} }
if (and == sign) { if (or == sign) {
FilterNode[] newsiblings = new FilterNode[nodes.length + 1]; FilterNode[] newsiblings = new FilterNode[nodes.length + 1];
System.arraycopy(nodes, 0, newsiblings, 0, nodes.length); System.arraycopy(nodes, 0, newsiblings, 0, nodes.length);
newsiblings[nodes.length] = node; newsiblings[nodes.length] = node;
@@ -119,13 +117,12 @@ public class FilterNode {
*/ */
protected void append(FilterNode node, boolean sign) { protected void append(FilterNode node, boolean sign) {
FilterNode newnode = new FilterNode(this.column, this.express, this.value); FilterNode newnode = new FilterNode(this.column, this.express, this.value);
newnode.and = this.and; newnode.or = this.or;
newnode.nodes = this.nodes; newnode.nodes = this.nodes;
this.nodes = new FilterNode[]{newnode, node}; this.nodes = new FilterNode[]{newnode, node};
this.tabalis = null;
this.column = null; this.column = null;
this.express = null; this.express = null;
this.and = sign; this.or = sign;
this.value = null; this.value = null;
} }
@@ -150,6 +147,15 @@ public class FilterNode {
return null; return null;
} }
/**
* 该方法需要重载
*
* @return
*/
protected String getTabalis() {
return null;
}
/** /**
* 该方法需要重载 * 该方法需要重载
* *
@@ -180,7 +186,7 @@ public class FilterNode {
for (FilterNode node : this.nodes) { for (FilterNode node : this.nodes) {
CharSequence f = node.createSQLExpress(info, bean); CharSequence f = node.createSQLExpress(info, bean);
if (f == null || f.length() < 3) continue; if (f == null || f.length() < 3) continue;
if (more) rs.append(and ? " AND " : " OR "); if (more) rs.append(or ? " OR " : " AND ");
rs.append(f); rs.append(f);
more = true; more = true;
} }
@@ -191,6 +197,7 @@ public class FilterNode {
protected final <T> CharSequence createElementSQLExpress(final EntityInfo<T> info, final FilterBean bean) { protected final <T> CharSequence createElementSQLExpress(final EntityInfo<T> info, final FilterBean bean) {
if (column == null) return null; if (column == null) return null;
final String tabalis = getTabalis();
if (express == ISNULL || express == ISNOTNULL) { if (express == ISNULL || express == ISNOTNULL) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (tabalis != null) sb.append(tabalis).append('.'); if (tabalis != null) sb.append(tabalis).append('.');
@@ -231,18 +238,7 @@ public class FilterNode {
if (f == null) continue; if (f == null) continue;
final Predicate<T> one = filter; final Predicate<T> one = filter;
final Predicate<T> two = f; final Predicate<T> two = f;
filter = (filter == null) ? f : (and ? new Predicate<T>() { filter = (filter == null) ? f : (or ? 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>() {
@Override @Override
public boolean test(T t) { public boolean test(T t) {
@@ -253,6 +249,17 @@ public class FilterNode {
public String toString() { public String toString() {
return "(" + one + " OR " + two + ")"; 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; return filter;
@@ -809,7 +816,7 @@ public class FilterNode {
for (FilterNode node : this.nodes) { for (FilterNode node : this.nodes) {
String s = node.toString(); String s = node.toString();
if (s.isEmpty()) continue; 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); sb.append(s);
} }
if (more) sb.append(')'); if (more) sb.append(')');
@@ -893,20 +900,12 @@ public class FilterNode {
this.value = value; this.value = value;
} }
public final boolean isAnd() { public final boolean isOr() {
return and; return or;
} }
public final void setAnd(boolean and) { public final void setOr(boolean or) {
this.and = and; this.or = or;
}
public final String getTabalis() {
return tabalis;
}
public final void setTabalis(String tabalis) {
this.tabalis = tabalis;
} }
public final String getColumn() { public final String getColumn() {