This commit is contained in:
@@ -103,6 +103,21 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
|||||||
return source.getNumberResult(entityClass, func, column, node);
|
return source.getNumberResult(entityClass, func, column, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Number getNumberResult(final Class entityClass, FilterFunc func, final Number defVal, final String column) {
|
||||||
|
return source.getNumberResult(entityClass, func, defVal, column);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final Number getNumberResult(final Class entityClass, FilterFunc func, final Number defVal, final String column, FilterBean bean) {
|
||||||
|
return getNumberResult(entityClass, func, defVal, column, FilterNodeBean.createFilterNode(bean));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Number getNumberResult(final Class entityClass, FilterFunc func, final Number defVal, final String column, FilterNode node) {
|
||||||
|
return source.getNumberResult(entityClass, func, defVal, column, node);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(final Class<T> entityClass, final String keyColumn, FilterFunc func, final String funcColumn) {
|
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(final Class<T> entityClass, final String keyColumn, FilterFunc func, final String funcColumn) {
|
||||||
return source.queryColumnMap(entityClass, keyColumn, func, funcColumn);
|
return source.queryColumnMap(entityClass, keyColumn, func, funcColumn);
|
||||||
|
|||||||
@@ -1035,23 +1035,38 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
|||||||
//-----------------------getNumberResult-----------------------------
|
//-----------------------getNumberResult-----------------------------
|
||||||
@Override
|
@Override
|
||||||
public Number getNumberResult(final Class entityClass, final FilterFunc func, final String column) {
|
public Number getNumberResult(final Class entityClass, final FilterFunc func, final String column) {
|
||||||
return getNumberResult(entityClass, func, column, (FilterNode) null);
|
return getNumberResult(entityClass, func, null, column, (FilterNode) null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Number getNumberResult(final Class entityClass, final FilterFunc func, final String column, FilterBean bean) {
|
public Number getNumberResult(final Class entityClass, final FilterFunc func, final String column, FilterBean bean) {
|
||||||
return getNumberResult(entityClass, func, column, FilterNodeBean.createFilterNode(bean));
|
return getNumberResult(entityClass, func, null, column, FilterNodeBean.createFilterNode(bean));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Number getNumberResult(final Class entityClass, final FilterFunc func, final String column, final FilterNode node) {
|
public Number getNumberResult(final Class entityClass, final FilterFunc func, final String column, final FilterNode node) {
|
||||||
|
return getNumberResult(entityClass, func, null, column, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Number getNumberResult(final Class entityClass, final FilterFunc func, final Number defVal, final String column) {
|
||||||
|
return getNumberResult(entityClass, func, defVal, column, (FilterNode) null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Number getNumberResult(final Class entityClass, final FilterFunc func, final Number defVal, final String column, FilterBean bean) {
|
||||||
|
return getNumberResult(entityClass, func, defVal, column, FilterNodeBean.createFilterNode(bean));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Number getNumberResult(final Class entityClass, final FilterFunc func, final Number defVal, final String column, final FilterNode node) {
|
||||||
final Connection conn = createReadSQLConnection();
|
final Connection conn = createReadSQLConnection();
|
||||||
try {
|
try {
|
||||||
final EntityInfo info = loadEntityInfo(entityClass);
|
final EntityInfo info = loadEntityInfo(entityClass);
|
||||||
final EntityCache cache = info.getCache();
|
final EntityCache cache = info.getCache();
|
||||||
if (cache != null && (info.isVirtualEntity() || cache.isFullLoaded())) {
|
if (cache != null && (info.isVirtualEntity() || cache.isFullLoaded())) {
|
||||||
if (node == null || node.isCacheUseable(this)) {
|
if (node == null || node.isCacheUseable(this)) {
|
||||||
return cache.getNumberResult(func, column, node);
|
return cache.getNumberResult(func, defVal, column, node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final Map<Class, String> joinTabalis = node == null ? null : node.getJoinTabalis();
|
final Map<Class, String> joinTabalis = node == null ? null : node.getJoinTabalis();
|
||||||
@@ -1061,7 +1076,7 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
|||||||
+ (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where));
|
+ (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where));
|
||||||
if (debug.get() && info.isLoggable(Level.FINEST)) logger.finest(entityClass.getSimpleName() + " single sql=" + sql);
|
if (debug.get() && info.isLoggable(Level.FINEST)) logger.finest(entityClass.getSimpleName() + " single sql=" + sql);
|
||||||
final PreparedStatement prestmt = conn.prepareStatement(sql);
|
final PreparedStatement prestmt = conn.prepareStatement(sql);
|
||||||
Number rs = null;
|
Number rs = defVal;
|
||||||
ResultSet set = prestmt.executeQuery();
|
ResultSet set = prestmt.executeQuery();
|
||||||
if (set.next()) {
|
if (set.next()) {
|
||||||
rs = (Number) set.getObject(1);
|
rs = (Number) set.getObject(1);
|
||||||
|
|||||||
@@ -84,6 +84,12 @@ public interface DataSource {
|
|||||||
|
|
||||||
public Number getNumberResult(final Class entityClass, final FilterFunc func, final String column, final FilterNode node);
|
public Number getNumberResult(final Class entityClass, final FilterFunc func, final String column, final FilterNode node);
|
||||||
|
|
||||||
|
public Number getNumberResult(final Class entityClass, final FilterFunc func, final Number defVal, final String column);
|
||||||
|
|
||||||
|
public Number getNumberResult(final Class entityClass, final FilterFunc func, final Number defVal, final String column, final FilterBean bean);
|
||||||
|
|
||||||
|
public Number getNumberResult(final Class entityClass, final FilterFunc func, final Number defVal, final String column, final FilterNode node);
|
||||||
|
|
||||||
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(final Class<T> entityClass, final String keyColumn, final FilterFunc func, final String funcColumn);
|
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(final Class<T> entityClass, final String keyColumn, final FilterFunc func, final String funcColumn);
|
||||||
|
|
||||||
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(final Class<T> entityClass, final String keyColumn, final FilterFunc func, final String funcColumn, final FilterBean bean);
|
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(final Class<T> entityClass, final String keyColumn, final FilterFunc func, final String funcColumn, final FilterBean bean);
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ public final class EntityCache<T> {
|
|||||||
return rs;
|
return rs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <V> Number getNumberResult(final FilterFunc func, final String column, FilterNode node) {
|
public <V> Number getNumberResult(final FilterFunc func, final Number defResult, final String column, final FilterNode node) {
|
||||||
final Attribute<T, Serializable> attr = column == null ? null : info.getAttribute(column);
|
final Attribute<T, Serializable> attr = column == null ? null : info.getAttribute(column);
|
||||||
final Predicate<T> filter = node == null ? null : node.createPredicate(this);
|
final Predicate<T> filter = node == null ? null : node.createPredicate(this);
|
||||||
Stream<T> stream = this.list.stream();
|
Stream<T> stream = this.list.stream();
|
||||||
@@ -228,15 +228,20 @@ public final class EntityCache<T> {
|
|||||||
switch (func) {
|
switch (func) {
|
||||||
case AVG:
|
case AVG:
|
||||||
if (attr.type() == int.class || attr.type() == Integer.class) {
|
if (attr.type() == int.class || attr.type() == Integer.class) {
|
||||||
return (int) stream.mapToInt(x -> (Integer) attr.get(x)).average().orElse(0);
|
OptionalDouble rs = stream.mapToInt(x -> (Integer) attr.get(x)).average();
|
||||||
|
return rs.isPresent() ? (int) rs.getAsDouble() : defResult;
|
||||||
} else if (attr.type() == long.class || attr.type() == Long.class) {
|
} else if (attr.type() == long.class || attr.type() == Long.class) {
|
||||||
return (long) stream.mapToLong(x -> (Long) attr.get(x)).average().orElse(0);
|
OptionalDouble rs = stream.mapToLong(x -> (Long) attr.get(x)).average();
|
||||||
|
return rs.isPresent() ? (long) rs.getAsDouble() : defResult;
|
||||||
} else if (attr.type() == short.class || attr.type() == Short.class) {
|
} else if (attr.type() == short.class || attr.type() == Short.class) {
|
||||||
return (short) stream.mapToInt(x -> ((Short) attr.get(x)).intValue()).average().orElse(0);
|
OptionalDouble rs = stream.mapToInt(x -> ((Short) attr.get(x)).intValue()).average();
|
||||||
|
return rs.isPresent() ? (short) rs.getAsDouble() : defResult;
|
||||||
} else if (attr.type() == float.class || attr.type() == Float.class) {
|
} else if (attr.type() == float.class || attr.type() == Float.class) {
|
||||||
return (float) stream.mapToDouble(x -> ((Float) attr.get(x)).doubleValue()).average().orElse(0);
|
OptionalDouble rs = stream.mapToDouble(x -> ((Float) attr.get(x)).doubleValue()).average();
|
||||||
|
return rs.isPresent() ? (float) rs.getAsDouble() : defResult;
|
||||||
} else if (attr.type() == double.class || attr.type() == Double.class) {
|
} else if (attr.type() == double.class || attr.type() == Double.class) {
|
||||||
return stream.mapToDouble(x -> (Double) attr.get(x)).average().orElse(0);
|
OptionalDouble rs = stream.mapToDouble(x -> (Double) attr.get(x)).average();
|
||||||
|
return rs.isPresent() ? rs.getAsDouble() : defResult;
|
||||||
}
|
}
|
||||||
throw new RuntimeException("getNumberResult error(type:" + type + ", attr.declaringClass: " + attr.declaringClass() + ", attr.field: " + attr.field() + ", attr.type: " + attr.type());
|
throw new RuntimeException("getNumberResult error(type:" + type + ", attr.declaringClass: " + attr.declaringClass() + ", attr.field: " + attr.field() + ", attr.type: " + attr.type());
|
||||||
case COUNT:
|
case COUNT:
|
||||||
@@ -246,29 +251,39 @@ public final class EntityCache<T> {
|
|||||||
|
|
||||||
case MAX:
|
case MAX:
|
||||||
if (attr.type() == int.class || attr.type() == Integer.class) {
|
if (attr.type() == int.class || attr.type() == Integer.class) {
|
||||||
return stream.mapToInt(x -> (Integer) attr.get(x)).max().orElse(0);
|
OptionalInt rs = stream.mapToInt(x -> (Integer) attr.get(x)).max();
|
||||||
|
return rs.isPresent() ? rs.getAsInt() : defResult;
|
||||||
} else if (attr.type() == long.class || attr.type() == Long.class) {
|
} else if (attr.type() == long.class || attr.type() == Long.class) {
|
||||||
return stream.mapToLong(x -> (Long) attr.get(x)).max().orElse(0);
|
OptionalLong rs = stream.mapToLong(x -> (Long) attr.get(x)).max();
|
||||||
|
return rs.isPresent() ? rs.getAsLong() : defResult;
|
||||||
} else if (attr.type() == short.class || attr.type() == Short.class) {
|
} else if (attr.type() == short.class || attr.type() == Short.class) {
|
||||||
return (short) stream.mapToInt(x -> ((Short) attr.get(x)).intValue()).max().orElse(0);
|
OptionalInt rs = stream.mapToInt(x -> ((Short) attr.get(x)).intValue()).max();
|
||||||
|
return rs.isPresent() ? (short) rs.getAsInt() : defResult;
|
||||||
} else if (attr.type() == float.class || attr.type() == Float.class) {
|
} else if (attr.type() == float.class || attr.type() == Float.class) {
|
||||||
return (float) stream.mapToDouble(x -> ((Float) attr.get(x)).doubleValue()).max().orElse(0);
|
OptionalDouble rs = stream.mapToDouble(x -> ((Float) attr.get(x)).doubleValue()).max();
|
||||||
|
return rs.isPresent() ? (float) rs.getAsDouble() : defResult;
|
||||||
} else if (attr.type() == double.class || attr.type() == Double.class) {
|
} else if (attr.type() == double.class || attr.type() == Double.class) {
|
||||||
return stream.mapToDouble(x -> (Double) attr.get(x)).max().orElse(0);
|
OptionalDouble rs = stream.mapToDouble(x -> (Double) attr.get(x)).max();
|
||||||
|
return rs.isPresent() ? rs.getAsDouble() : defResult;
|
||||||
}
|
}
|
||||||
throw new RuntimeException("getNumberResult error(type:" + type + ", attr.declaringClass: " + attr.declaringClass() + ", attr.field: " + attr.field() + ", attr.type: " + attr.type());
|
throw new RuntimeException("getNumberResult error(type:" + type + ", attr.declaringClass: " + attr.declaringClass() + ", attr.field: " + attr.field() + ", attr.type: " + attr.type());
|
||||||
|
|
||||||
case MIN:
|
case MIN:
|
||||||
if (attr.type() == int.class || attr.type() == Integer.class) {
|
if (attr.type() == int.class || attr.type() == Integer.class) {
|
||||||
return stream.mapToInt(x -> (Integer) attr.get(x)).min().orElse(0);
|
OptionalInt rs = stream.mapToInt(x -> (Integer) attr.get(x)).min();
|
||||||
|
return rs.isPresent() ? rs.getAsInt() : defResult;
|
||||||
} else if (attr.type() == long.class || attr.type() == Long.class) {
|
} else if (attr.type() == long.class || attr.type() == Long.class) {
|
||||||
return stream.mapToLong(x -> (Long) attr.get(x)).min().orElse(0);
|
OptionalLong rs = stream.mapToLong(x -> (Long) attr.get(x)).min();
|
||||||
|
return rs.isPresent() ? rs.getAsLong() : defResult;
|
||||||
} else if (attr.type() == short.class || attr.type() == Short.class) {
|
} else if (attr.type() == short.class || attr.type() == Short.class) {
|
||||||
return (short) stream.mapToInt(x -> ((Short) attr.get(x)).intValue()).min().orElse(0);
|
OptionalInt rs = stream.mapToInt(x -> ((Short) attr.get(x)).intValue()).min();
|
||||||
|
return rs.isPresent() ? (short) rs.getAsInt() : defResult;
|
||||||
} else if (attr.type() == float.class || attr.type() == Float.class) {
|
} else if (attr.type() == float.class || attr.type() == Float.class) {
|
||||||
return (float) stream.mapToDouble(x -> ((Float) attr.get(x)).doubleValue()).min().orElse(0);
|
OptionalDouble rs = stream.mapToDouble(x -> ((Float) attr.get(x)).doubleValue()).min();
|
||||||
|
return rs.isPresent() ? (float) rs.getAsDouble() : defResult;
|
||||||
} else if (attr.type() == double.class || attr.type() == Double.class) {
|
} else if (attr.type() == double.class || attr.type() == Double.class) {
|
||||||
return stream.mapToDouble(x -> (Double) attr.get(x)).min().orElse(0);
|
OptionalDouble rs = stream.mapToDouble(x -> (Double) attr.get(x)).min();
|
||||||
|
return rs.isPresent() ? rs.getAsDouble() : defResult;
|
||||||
}
|
}
|
||||||
throw new RuntimeException("getNumberResult error(type:" + type + ", attr.declaringClass: " + attr.declaringClass() + ", attr.field: " + attr.field() + ", attr.type: " + attr.type());
|
throw new RuntimeException("getNumberResult error(type:" + type + ", attr.declaringClass: " + attr.declaringClass() + ", attr.field: " + attr.field() + ", attr.type: " + attr.type());
|
||||||
|
|
||||||
@@ -286,7 +301,7 @@ public final class EntityCache<T> {
|
|||||||
}
|
}
|
||||||
throw new RuntimeException("getNumberResult error(type:" + type + ", attr.declaringClass: " + attr.declaringClass() + ", attr.field: " + attr.field() + ", attr.type: " + attr.type());
|
throw new RuntimeException("getNumberResult error(type:" + type + ", attr.declaringClass: " + attr.declaringClass() + ", attr.field: " + attr.field() + ", attr.type: " + attr.type());
|
||||||
}
|
}
|
||||||
return -1;
|
return defResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sheet<T> querySheet(final SelectColumn selects, final Flipper flipper, final FilterNode node) {
|
public Sheet<T> querySheet(final SelectColumn selects, final Flipper flipper, final FilterNode node) {
|
||||||
|
|||||||
Reference in New Issue
Block a user