This commit is contained in:
地平线
2015-11-05 15:46:26 +08:00
parent 67816be311
commit cd90512929
2 changed files with 76 additions and 48 deletions

View File

@@ -396,8 +396,6 @@ final class FilterBeanNode extends FilterNode {
if (rs == null) return null; if (rs == null) return null;
if (string && ((CharSequence) rs).length() == 0) return null; if (string && ((CharSequence) rs).length() == 0) return null;
if (number && ((Number) rs).longValue() < this.least) return null; if (number && ((Number) rs).longValue() < this.least) return null;
if (array && Array.getLength(rs) == 0) return null;
if (collection && ((Collection) rs).isEmpty()) return null;
return rs; return rs;
} }
} }

View File

@@ -315,9 +315,9 @@ public class FilterNode {
} }
} else if (valtype.isArray()) { } else if (valtype.isArray()) {
final int len = Array.getLength(val0); final int len = Array.getLength(val0);
if (len == 0) return null; if (len == 0 && express == NOTIN) return null;
final Class compType = valtype.getComponentType(); final Class compType = valtype.getComponentType();
if (atype != compType) { if (atype != compType && len > 0) {
if (!compType.isPrimitive() && Number.class.isAssignableFrom(compType)) throw new RuntimeException("param(" + val0 + ") type not match " + atype + " for column " + column); if (!compType.isPrimitive() && Number.class.isAssignableFrom(compType)) throw new RuntimeException("param(" + val0 + ") type not match " + atype + " for column " + column);
if (atype == int.class || atype == Integer.class) { if (atype == int.class || atype == Integer.class) {
int[] vs = new int[len]; int[] vs = new int[len];
@@ -359,7 +359,8 @@ public class FilterNode {
} }
} else if (val0 instanceof Collection) { } else if (val0 instanceof Collection) {
final Collection collection = (Collection) val0; final Collection collection = (Collection) val0;
if (collection.isEmpty()) return null; if (collection.isEmpty() && express == NOTIN) return null;
if (!collection.isEmpty()) {
Iterator it = collection.iterator(); Iterator it = collection.iterator();
it.hasNext(); it.hasNext();
Class fs = it.next().getClass(); Class fs = it.next().getClass();
@@ -393,6 +394,7 @@ public class FilterNode {
val0 = list; val0 = list;
} }
} }
}
final Serializable val = val0; final Serializable val = val0;
switch (express) { switch (express) {
case EQUAL: return new Predicate<T>() { case EQUAL: return new Predicate<T>() {
@@ -573,6 +575,20 @@ public class FilterNode {
Predicate<T> filter; Predicate<T> filter;
if (val instanceof Collection) { if (val instanceof Collection) {
Collection array = (Collection) val; Collection array = (Collection) val;
if (array.isEmpty()) { //express 只会是 IN
filter = new Predicate<T>() {
@Override
public boolean test(T t) {
return false;
}
@Override
public String toString() {
return attr.field() + ' ' + express.value() + " []";
}
};
} else {
filter = new Predicate<T>() { filter = new Predicate<T>() {
@Override @Override
@@ -586,9 +602,23 @@ public class FilterNode {
return attr.field() + ' ' + express.value() + ' ' + val; return attr.field() + ' ' + express.value() + ' ' + val;
} }
}; };
}
} else { } else {
Class type = val.getClass(); Class type = val.getClass();
if (type == int[].class) { if (Array.getLength(val) == 0) {//express 只会是 IN
filter = new Predicate<T>() {
@Override
public boolean test(T t) {
return false;
}
@Override
public String toString() {
return attr.field() + ' ' + express.value() + " []";
}
};
} else if (type == int[].class) {
filter = new Predicate<T>() { filter = new Predicate<T>() {
@Override @Override
@@ -909,7 +939,7 @@ public class FilterNode {
return sb; return sb;
} else if (value.getClass().isArray()) { } else if (value.getClass().isArray()) {
int len = Array.getLength(value); int len = Array.getLength(value);
if (len == 0) return null; if (len == 0) return express == NOTIN ? null : new StringBuilder("(NULL)");
if (len == 1) { if (len == 1) {
Object firstval = Array.get(value, 0); Object firstval = Array.get(value, 0);
if (firstval != null && firstval.getClass().isArray()) return formatValue(likefit, express, firstval); if (firstval != null && firstval.getClass().isArray()) return formatValue(likefit, express, firstval);
@@ -928,7 +958,7 @@ public class FilterNode {
return sb.append(')'); return sb.append(')');
} else if (value instanceof Collection) { } else if (value instanceof Collection) {
Collection c = (Collection) value; Collection c = (Collection) value;
if (c.isEmpty()) return null; if (c.isEmpty()) return express == NOTIN ? null : new StringBuilder("(NULL)");
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append('('); sb.append('(');
for (Object o : c) { for (Object o : c) {