FilterFuncColumn支持多字段名
This commit is contained in:
@@ -1162,7 +1162,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
if (cache != null && (info.isVirtualEntity() || cache.isFullLoaded())) {
|
||||
if (node == null || node.isCacheUseable(this)) {
|
||||
for (FilterFuncColumn ffc : columns) {
|
||||
map.put(ffc.col(), cache.getNumberResult(ffc.func, ffc.defvalue, ffc.column, node));
|
||||
for (String col : ffc.cols()) {
|
||||
map.put(ffc.col(col), cache.getNumberResult(ffc.func, ffc.defvalue, col, node));
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
@@ -1172,8 +1174,10 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
final CharSequence where = node == null ? null : node.createSQLExpress(info, joinTabalis);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (FilterFuncColumn ffc : columns) {
|
||||
if (sb.length() > 0) sb.append(", ");
|
||||
sb.append(ffc.func.getColumn((ffc.column == null || ffc.column.isEmpty() ? "*" : ("a." + ffc.column))));
|
||||
for (String col : ffc.cols()) {
|
||||
if (sb.length() > 0) sb.append(", ");
|
||||
sb.append(ffc.func.getColumn((col == null || col.isEmpty() ? "*" : ("a." + col))));
|
||||
}
|
||||
}
|
||||
final String sql = "SELECT " + sb + " FROM " + info.getTable(node) + " a"
|
||||
+ (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where));
|
||||
@@ -1184,10 +1188,12 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
if (set.next()) {
|
||||
int index = 0;
|
||||
for (FilterFuncColumn ffc : columns) {
|
||||
Object o = set.getObject(++index);
|
||||
Number rs = ffc.defvalue;
|
||||
if (o != null) rs = (Number) o;
|
||||
map.put(ffc.col(), rs);
|
||||
for (String col : ffc.cols()) {
|
||||
Object o = set.getObject(++index);
|
||||
Number rs = ffc.defvalue;
|
||||
if (o != null) rs = (Number) o;
|
||||
map.put(ffc.col(col), rs);
|
||||
}
|
||||
}
|
||||
}
|
||||
set.close();
|
||||
@@ -1196,7 +1202,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
} catch (SQLException e) {
|
||||
if (info.tableStrategy != null && info.tablenotexistSqlstates.contains(';' + e.getSQLState() + ';')) {
|
||||
for (FilterFuncColumn ffc : columns) {
|
||||
map.put(ffc.col(), ffc.defvalue);
|
||||
for (String col : ffc.cols()) {
|
||||
map.put(ffc.col(col), ffc.defvalue);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class FilterFuncColumn implements java.io.Serializable {
|
||||
|
||||
FilterFunc func;
|
||||
|
||||
String column; //为null,将使用*代替
|
||||
String[] columns; //为null,将使用*代替
|
||||
|
||||
Number defvalue;
|
||||
|
||||
@@ -29,30 +29,34 @@ public class FilterFuncColumn implements java.io.Serializable {
|
||||
return new FilterFuncColumn(func);
|
||||
}
|
||||
|
||||
public static FilterFuncColumn create(final FilterFunc func, final String column) {
|
||||
return new FilterFuncColumn(func, column);
|
||||
public static FilterFuncColumn create(final FilterFunc func, final String... columns) {
|
||||
return new FilterFuncColumn(func, columns);
|
||||
}
|
||||
|
||||
public static FilterFuncColumn create(final FilterFunc func, final String column, final Number defvalue) {
|
||||
return new FilterFuncColumn(func, column, defvalue);
|
||||
public static FilterFuncColumn create(final FilterFunc func, final Number defvalue, final String... columns) {
|
||||
return new FilterFuncColumn(func, defvalue, columns);
|
||||
}
|
||||
|
||||
String col() {
|
||||
String[] cols() {
|
||||
return columns == null || columns.length == 0 ? new String[]{COLUMN_NULL} : columns;
|
||||
}
|
||||
|
||||
String col(String column) {
|
||||
return column == null || column.isEmpty() ? COLUMN_NULL : column;
|
||||
}
|
||||
|
||||
public FilterFuncColumn(final FilterFunc func) {
|
||||
this(func, null, null);
|
||||
this(func, (Number) null);
|
||||
}
|
||||
|
||||
public FilterFuncColumn(final FilterFunc func, final String column) {
|
||||
this(func, column, null);
|
||||
public FilterFuncColumn(final FilterFunc func, final String... columns) {
|
||||
this(func, null, columns);
|
||||
}
|
||||
|
||||
public FilterFuncColumn(final FilterFunc func, final String column, final Number defvalue) {
|
||||
public FilterFuncColumn(final FilterFunc func, final Number defvalue, final String... columns) {
|
||||
this.func = func;
|
||||
this.column = column;
|
||||
this.defvalue = defvalue;
|
||||
this.columns = columns;
|
||||
}
|
||||
|
||||
public FilterFunc getFunc() {
|
||||
@@ -63,12 +67,12 @@ public class FilterFuncColumn implements java.io.Serializable {
|
||||
this.func = func;
|
||||
}
|
||||
|
||||
public String getColumn() {
|
||||
return column;
|
||||
public String[] getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public void setColumn(String column) {
|
||||
this.column = column;
|
||||
public void setColumns(String[] columns) {
|
||||
this.columns = columns;
|
||||
}
|
||||
|
||||
public Number getDefvalue() {
|
||||
|
||||
Reference in New Issue
Block a user