This commit is contained in:
地平线
2015-07-15 15:48:09 +08:00
parent 65765032a5
commit ecd406341e

View File

@@ -99,13 +99,13 @@ public class FilterNode {
FilterNode newnode = new FilterNode(this.column, this.express, this.value); FilterNode newnode = new FilterNode(this.column, this.express, this.value);
newnode.signand = this.signand; newnode.signand = this.signand;
newnode.nodes = this.nodes; newnode.nodes = this.nodes;
this.nodes = new FilterNode[]{newnode}; this.nodes = new FilterNode[]{newnode, node};
this.tabalis = node.tabalis; this.tabalis = null;
this.column = node.column; this.column = null;
this.express = node.express; this.express = null;
this.likefit = node.likefit; this.likefit = false;
this.signand = sign; this.signand = sign;
this.value = node.value; this.value = null;
} }
protected Serializable getValue(FilterBean bean) { protected Serializable getValue(FilterBean bean) {
@@ -128,7 +128,7 @@ public class FilterNode {
return createFilterSQLExpress(true, info, bean); return createFilterSQLExpress(true, info, bean);
} }
protected <T> StringBuilder createFilterSQLExpress(final boolean first, final EntityInfo<T> info, FilterBean bean) { protected <T> StringBuilder createFilterSQLExpress(final boolean first, final EntityInfo<T> info, FilterBean bean) {
final Serializable val = getValue(bean); final Serializable val = getValue(bean);
if (val == null && (express == ISNULL || express == ISNOTNULL)) return new StringBuilder(0); if (val == null && (express == ISNULL || express == ISNOTNULL)) return new StringBuilder(0);
StringBuilder sb0 = createFilterSQLExpress(info, val); StringBuilder sb0 = createFilterSQLExpress(info, val);
@@ -156,30 +156,8 @@ public class FilterNode {
return rs; return rs;
} }
protected static <E> String createFilterSQLOrderBy(EntityInfo<E> info, Flipper flipper) {
if (flipper == null || flipper.getSort() == null || flipper.getSort().isEmpty()) return "";
final StringBuilder sb = new StringBuilder();
sb.append(" ORDER BY ");
if (info.isNoAlias()) {
sb.append(flipper.getSort());
} else {
boolean flag = false;
for (String item : flipper.getSort().split(",")) {
if (item.isEmpty()) continue;
String[] sub = item.split("\\s+");
if (flag) sb.append(',');
if (sub.length < 2 || sub[1].equalsIgnoreCase("ASC")) {
sb.append("a.").append(info.getSQLColumn(sub[0])).append(" ASC");
} else {
sb.append("a.").append(info.getSQLColumn(sub[0])).append(" DESC");
}
flag = true;
}
}
return sb.toString();
}
private <T> StringBuilder createFilterSQLExpress(final EntityInfo<T> info, Serializable val0) { private <T> StringBuilder createFilterSQLExpress(final EntityInfo<T> info, Serializable val0) {
if(column == null) return null;
final StringBuilder val = formatValue(val0); final StringBuilder val = formatValue(val0);
if (val == null) return null; if (val == null) return null;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@@ -204,8 +182,31 @@ public class FilterNode {
return sb; return sb;
} }
protected static <E> String createFilterSQLOrderBy(EntityInfo<E> info, Flipper flipper) {
if (flipper == null || flipper.getSort() == null || flipper.getSort().isEmpty()) return "";
final StringBuilder sb = new StringBuilder();
sb.append(" ORDER BY ");
if (info.isNoAlias()) {
sb.append(flipper.getSort());
} else {
boolean flag = false;
for (String item : flipper.getSort().split(",")) {
if (item.isEmpty()) continue;
String[] sub = item.split("\\s+");
if (flag) sb.append(',');
if (sub.length < 2 || sub[1].equalsIgnoreCase("ASC")) {
sb.append("a.").append(info.getSQLColumn(sub[0])).append(" ASC");
} else {
sb.append("a.").append(info.getSQLColumn(sub[0])).append(" DESC");
}
flag = true;
}
}
return sb.toString();
}
protected <T> Predicate<T> createFilterPredicate(final EntityInfo<T> info, FilterBean bean) { protected <T> Predicate<T> createFilterPredicate(final EntityInfo<T> info, FilterBean bean) {
if (info == null) return null; if (info == null || column == null) return null;
final Serializable val = getValue(bean); final Serializable val = getValue(bean);
Predicate<T> filter = val == null ? null : createFilterPredicate(info.getAttribute(column), val); Predicate<T> filter = val == null ? null : createFilterPredicate(info.getAttribute(column), val);
if (this.nodes == null) return filter; if (this.nodes == null) return filter;
@@ -405,9 +406,10 @@ public class FilterNode {
if (nodes == null) { if (nodes == null) {
sb.append(column).append(' ').append(express.value()).append(' ').append(formatValue(value)); sb.append(column).append(' ').append(express.value()).append(' ').append(formatValue(value));
} else { } else {
sb.append('(').append(column).append(' ').append(express.value()).append(' ').append(formatValue(value)); if (column != null) sb.append('(').append(column).append(' ').append(express.value()).append(' ').append(formatValue(value));
for (FilterNode node : this.nodes) { for (FilterNode node : this.nodes) {
sb.append(signand ? " AND " : " OR ").append(node.toString()); if (sb.length() > 0) sb.append(signand ? " AND " : " OR ");
sb.append(node.toString());
} }
sb.append(')'); sb.append(')');
} }