This commit is contained in:
@@ -878,102 +878,22 @@ public final class DataJDBCSource implements DataSource {
|
||||
}
|
||||
|
||||
//-----------------------getNumberResult-----------------------------
|
||||
//-----------------------------MAX-----------------------------
|
||||
@Override
|
||||
public Number getMaxNumberResult(final Class entityClass, final String column) {
|
||||
return getMaxNumberResult(entityClass, column, (FilterNode) null);
|
||||
public Number getNumberResult(final Class entityClass, final Reckon reckon, final String column) {
|
||||
return getNumberResult(entityClass, reckon, column, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getMaxNumberResult(final Class entityClass, final String column, FilterBean bean) {
|
||||
return getNumberResult(ReckonType.MAX, entityClass, column, null, bean);
|
||||
public Number getNumberResult(final Class entityClass, final Reckon reckon, final String column, FilterBean bean) {
|
||||
return getNumberResult(entityClass, reckon, column, null, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getMaxNumberResult(final Class entityClass, final String column, FilterNode node) {
|
||||
return getNumberResult(ReckonType.MAX, entityClass, column, node, null);
|
||||
public Number getNumberResult(final Class entityClass, final Reckon reckon, final String column, FilterNode node) {
|
||||
return getNumberResult(entityClass, reckon, column, node, null);
|
||||
}
|
||||
|
||||
//-----------------------------MIN-----------------------------
|
||||
@Override
|
||||
public Number getMinNumberResult(final Class entityClass, final String column) {
|
||||
return getMinNumberResult(entityClass, column, (FilterNode) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getMinNumberResult(final Class entityClass, final String column, FilterBean bean) {
|
||||
return getNumberResult(ReckonType.MIN, entityClass, column, null, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getMinNumberResult(final Class entityClass, final String column, FilterNode node) {
|
||||
return getNumberResult(ReckonType.MIN, entityClass, column, node, null);
|
||||
}
|
||||
|
||||
//-----------------------------SUM-----------------------------
|
||||
@Override
|
||||
public Number getSumNumberResult(final Class entityClass, final String column) {
|
||||
return getSumNumberResult(entityClass, column, (FilterNode) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getSumNumberResult(final Class entityClass, final String column, FilterBean bean) {
|
||||
return getNumberResult(ReckonType.SUM, entityClass, column, null, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getSumNumberResult(final Class entityClass, final String column, FilterNode node) {
|
||||
return getNumberResult(ReckonType.SUM, entityClass, column, node, null);
|
||||
}
|
||||
|
||||
//----------------------------COUNT----------------------------
|
||||
@Override
|
||||
public Number getCountNumberResult(final Class entityClass) {
|
||||
return getCountNumberResult(entityClass, (FilterNode) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getCountNumberResult(final Class entityClass, FilterBean bean) {
|
||||
return getNumberResult(ReckonType.COUNT, entityClass, null, null, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getCountNumberResult(final Class entityClass, FilterNode node) {
|
||||
return getNumberResult(ReckonType.COUNT, entityClass, null, node, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getCountDistinctNumberResult(final Class entityClass, String column) {
|
||||
return getCountDistinctNumberResult(entityClass, column, (FilterNode) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getCountDistinctNumberResult(final Class entityClass, String column, FilterBean bean) {
|
||||
return getNumberResult(ReckonType.DISTINCTCOUNT, entityClass, column, null, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getCountDistinctNumberResult(final Class entityClass, final String column, FilterNode node) {
|
||||
return getNumberResult(ReckonType.DISTINCTCOUNT, entityClass, column, node, null);
|
||||
}
|
||||
|
||||
//-----------------------------AVG-----------------------------
|
||||
@Override
|
||||
public Number getAvgNumberResult(final Class entityClass, final String column) {
|
||||
return getAvgNumberResult(entityClass, column, (FilterNode) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getAvgNumberResult(final Class entityClass, final String column, FilterBean bean) {
|
||||
return getNumberResult(ReckonType.AVG, entityClass, column, null, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getAvgNumberResult(final Class entityClass, final String column, FilterNode node) {
|
||||
return getNumberResult(ReckonType.AVG, entityClass, column, node, null);
|
||||
}
|
||||
|
||||
private <T> Number getNumberResult(final ReckonType type, final Class<T> entityClass, final String column, FilterNode node, FilterBean bean) {
|
||||
private <T> Number getNumberResult(final Class<T> entityClass, final Reckon reckon, final String column, FilterNode node, FilterBean bean) {
|
||||
final Connection conn = createReadSQLConnection();
|
||||
try {
|
||||
final EntityInfo<T> info = loadEntityInfo(entityClass);
|
||||
@@ -982,10 +902,10 @@ public final class DataJDBCSource implements DataSource {
|
||||
if (cache != null && cache.isFullLoaded()) {
|
||||
Predicate<T> filter = node == null ? null : node.createFilterPredicate(info, bean);
|
||||
if (node == null || node.isJoinAllCached()) {
|
||||
return cache.getNumberResult(type, column == null ? null : info.getAttribute(column), filter);
|
||||
return cache.getNumberResult(reckon, column == null ? null : info.getAttribute(column), filter);
|
||||
}
|
||||
}
|
||||
final String sql = "SELECT " + type.getReckonColumn("a." + column) + " FROM " + info.getTable() + " a"
|
||||
final String sql = "SELECT " + reckon.getColumn("a." + (column == null || column.isEmpty() ? "*" : column)) + " FROM " + info.getTable() + " a"
|
||||
+ (node == null ? "" : node.createFilterSQLExpress(info, bean));
|
||||
if (debug.get() && info.isLoggable(Level.FINEST)) logger.finest(entityClass.getSimpleName() + " single sql=" + sql);
|
||||
final PreparedStatement prestmt = conn.prepareStatement(sql);
|
||||
@@ -1004,6 +924,54 @@ public final class DataJDBCSource implements DataSource {
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------getMapResult-----------------------------
|
||||
@Override
|
||||
public Map<Serializable, Number> getMapResult(Class entityClass, final String keyColumn, Reckon reckon, final String reckonColumn) {
|
||||
return getMapResult(entityClass, keyColumn, reckon, reckonColumn, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Serializable, Number> getMapResult(Class entityClass, final String keyColumn, Reckon reckon, final String reckonColumn, FilterBean bean) {
|
||||
return getMapResult(entityClass, keyColumn, reckon, reckonColumn, null, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Serializable, Number> getMapResult(Class entityClass, final String keyColumn, Reckon reckon, final String reckonColumn, FilterNode node) {
|
||||
return getMapResult(entityClass, keyColumn, reckon, reckonColumn, node, null);
|
||||
}
|
||||
|
||||
private <T> Map<Serializable, Number> getMapResult(final Class entityClass, final String keyColumn, final Reckon reckon, final String reckonColumn, FilterNode node, FilterBean bean) {
|
||||
final Connection conn = createReadSQLConnection();
|
||||
try {
|
||||
final EntityInfo<T> info = loadEntityInfo(entityClass);
|
||||
if (node == null && bean != null) node = loadFilterBeanNode(bean.getClass());
|
||||
final EntityCache<T> cache = info.getCache();
|
||||
if (cache != null && cache.isFullLoaded()) {
|
||||
Predicate<T> filter = node == null ? null : node.createFilterPredicate(info, bean);
|
||||
if (node == null || node.isJoinAllCached()) {
|
||||
return cache.getMapResult(info.getAttribute(keyColumn), reckon, reckonColumn == null ? null : info.getAttribute(reckonColumn), filter);
|
||||
}
|
||||
}
|
||||
final String sqlkey = info.getSQLColumn(keyColumn);
|
||||
final String sql = "SELECT a." + sqlkey + ", " + reckon.getColumn("a." + (reckonColumn == null || reckonColumn.isEmpty() ? "*" : reckonColumn))
|
||||
+ " FROM " + info.getTable() + " a" + (node == null ? "" : node.createFilterSQLExpress(info, bean)) + " GROUP BY a." + sqlkey;
|
||||
if (debug.get() && info.isLoggable(Level.FINEST)) logger.finest(entityClass.getSimpleName() + " single sql=" + sql);
|
||||
final PreparedStatement prestmt = conn.prepareStatement(sql);
|
||||
Map<Serializable, Number> rs = new LinkedHashMap<>();
|
||||
ResultSet set = prestmt.executeQuery();
|
||||
while (set.next()) {
|
||||
rs.put((Serializable) set.getObject(1), (Number) set.getObject(2));
|
||||
}
|
||||
set.close();
|
||||
prestmt.close();
|
||||
return rs;
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (conn != null) closeSQLConnection(conn);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------find----------------------------
|
||||
/**
|
||||
* 根据主键获取对象
|
||||
|
||||
@@ -29,241 +29,128 @@ final class DataJPASource implements DataSource {
|
||||
|
||||
private final Logger logger = Logger.getLogger(DataJPASource.class.getSimpleName());
|
||||
|
||||
public <T> void updateColumnIncrement(Class<T> clazz, Serializable id, String column, long incvalue) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public <T> void updateColumnIncrement(DataConnection conn, Class<T> clazz, Serializable id, String column, long incvalue) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void refreshCache(Class<T> clazz) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public <T> T find(Class<T> clazz, FilterBean bean) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public Number getCountDistinctSingleResult(Class entityClass, String column) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public Number getCountDistinctSingleResult(Class entityClass, String column, FilterBean bean) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public <T, V> Sheet<V> queryColumnSheet(String selectedColumn, Class<T> clazz, Flipper flipper, FilterBean bean) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public <T, V> Set<V> queryColumnSet(String selectedColumn, Class<T> clazz, String column, Serializable key) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public <T, V> Set<V> queryColumnSet(String selectedColumn, Class<T> clazz, String column, FilterExpress express, Serializable key) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public <T, V> List<V> queryColumnList(String selectedColumn, Class<T> clazz, String column, FilterExpress express, Serializable key) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public <T> int[] queryColumnIntSet(String selectedColumn, Class<T> clazz, String column, Serializable key) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public <T> long[] queryColumnLongSet(String selectedColumn, Class<T> clazz, String column, Serializable key) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public <T> int[] queryColumnIntList(String selectedColumn, Class<T> clazz, String column, Serializable key) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public <T> long[] queryColumnLongList(String selectedColumn, Class<T> clazz, String column, Serializable key) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public <T> int[] queryColumnIntSet(String selectedColumn, Class<T> clazz, String column, FilterExpress express, Serializable key) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public <T> long[] queryColumnLongSet(String selectedColumn, Class<T> clazz, String column, FilterExpress express, Serializable key) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public <T> int[] queryColumnIntList(String selectedColumn, Class<T> clazz, String column, FilterExpress express, Serializable key) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public <T> long[] queryColumnLongList(String selectedColumn, Class<T> clazz, String column, FilterExpress express, Serializable key) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public <T> T find(Class<T> clazz, SelectColumn selects, Serializable pk) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void delete(Class<T> clazz, FilterNode node) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void delete(DataConnection conn, Class<T> clazz, FilterNode node) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public Number getMaxSingleResult(Class entityClass, String column, FilterNode node) {
|
||||
@Override
|
||||
public <T> void updateColumnIncrement(Class<T> clazz, Serializable id, String column, long incvalue) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public Number getMinSingleResult(Class entityClass, String column, FilterNode node) {
|
||||
@Override
|
||||
public <T> void updateColumnIncrement(DataConnection conn, Class<T> clazz, Serializable id, String column, long incvalue) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public Number getSumSingleResult(Class entityClass, String column, FilterNode node) {
|
||||
@Override
|
||||
public Number getNumberResult(Class entityClass, Reckon reckon, String column) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public Number getCountSingleResult(Class entityClass, FilterNode node) {
|
||||
@Override
|
||||
public Number getNumberResult(Class entityClass, Reckon reckon, String column, FilterBean bean) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public Number getCountDistinctSingleResult(Class entityClass, String column, FilterNode node) {
|
||||
@Override
|
||||
public Number getNumberResult(Class entityClass, Reckon reckon, String column, FilterNode node) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public Number getAvgSingleResult(Class entityClass, String column, FilterNode node) {
|
||||
@Override
|
||||
public <T> T find(Class<T> clazz, SelectColumn selects, Serializable pk) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(Class<T> clazz, FilterNode node) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public <T> List<T> queryList(Class<T> clazz, FilterNode node) {
|
||||
@Override
|
||||
public <T> T find(Class<T> clazz, FilterBean bean) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public <T> List<T> queryList(Class<T> clazz, SelectColumn selects, FilterNode node) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public <T> Sheet<T> querySheet(Class<T> clazz, Flipper flipper, FilterNode node) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public <T> Sheet<T> querySheet(Class<T> clazz, SelectColumn selects, Flipper flipper, FilterNode node) {
|
||||
@Override
|
||||
public <T, V> Set<V> queryColumnSet(String selectedColumn, Class<T> clazz, String column, Serializable key) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V> Set<V> queryColumnSet(String selectedColumn, Class<T> clazz, FilterNode node) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V> Set<V> queryColumnSet(String selectedColumn, Class<T> clazz, FilterBean bean) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V> List<V> queryColumnList(String selectedColumn, Class<T> clazz, FilterNode node) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V> List<V> queryColumnList(String selectedColumn, Class<T> clazz, FilterBean bean) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(Class<T> clazz, FilterNode node) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(Class<T> clazz, SelectColumn selects, FilterNode node) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V> Sheet<V> queryColumnSheet(String selectedColumn, Class<T> clazz, Flipper flipper, FilterBean bean) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V> Sheet<V> queryColumnSheet(String selectedColumn, Class<T> clazz, Flipper flipper, FilterNode node) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getMaxNumberResult(Class entityClass, String column) {
|
||||
public <T> Sheet<T> querySheet(Class<T> clazz, Flipper flipper, FilterNode node) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getMaxNumberResult(Class entityClass, String column, FilterBean bean) {
|
||||
public <T> Sheet<T> querySheet(Class<T> clazz, SelectColumn selects, Flipper flipper, FilterNode node) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getMaxNumberResult(Class entityClass, String column, FilterNode node) {
|
||||
public Map<Serializable, Number> getMapResult(Class entityClass, String keyColumn, Reckon reckon, String reckonColumn) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getMinNumberResult(Class entityClass, String column) {
|
||||
public Map<Serializable, Number> getMapResult(Class entityClass, String keyColumn, Reckon reckon, String reckonColumn, FilterBean bean) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getMinNumberResult(Class entityClass, String column, FilterBean bean) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getMinNumberResult(Class entityClass, String column, FilterNode node) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getSumNumberResult(Class entityClass, String column) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getSumNumberResult(Class entityClass, String column, FilterBean bean) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getSumNumberResult(Class entityClass, String column, FilterNode node) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getCountNumberResult(Class entityClass) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getCountNumberResult(Class entityClass, FilterBean bean) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getCountNumberResult(Class entityClass, FilterNode node) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getCountDistinctNumberResult(Class entityClass, String column) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getCountDistinctNumberResult(Class entityClass, String column, FilterBean bean) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getCountDistinctNumberResult(Class entityClass, String column, FilterNode node) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getAvgNumberResult(Class entityClass, String column) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getAvgNumberResult(Class entityClass, String column, FilterBean bean) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getAvgNumberResult(Class entityClass, String column, FilterNode node) {
|
||||
public Map<Serializable, Number> getMapResult(Class entityClass, String keyColumn, Reckon reckon, String reckonColumn, FilterNode node) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,16 @@ import java.util.*;
|
||||
@SuppressWarnings("unchecked")
|
||||
public interface DataSource {
|
||||
|
||||
public static enum Reckon {
|
||||
|
||||
AVG, COUNT, DISTINCTCOUNT, MAX, MIN, SUM;
|
||||
|
||||
public String getColumn(String col) {
|
||||
if (this == DISTINCTCOUNT) return "COUNT(DISTINCT " + col + ")";
|
||||
return this.name() + "(" + col + ")";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建读连接
|
||||
*
|
||||
@@ -87,52 +97,22 @@ public interface DataSource {
|
||||
|
||||
public <T> void updateColumns(final DataConnection conn, final T value, final String... columns);
|
||||
|
||||
public <T> void updateColumnIncrement(Class<T> clazz, Serializable id, String column, long incvalue);
|
||||
public <T> void updateColumnIncrement(final Class<T> clazz, Serializable id, String column, long incvalue);
|
||||
|
||||
public <T> void updateColumnIncrement(final DataConnection conn, Class<T> clazz, Serializable id, String column, long incvalue);
|
||||
|
||||
//-----------------------getNumberResult-----------------------------
|
||||
//-----------------------------MAX-----------------------------
|
||||
public Number getMaxNumberResult(final Class entityClass, final String column);
|
||||
//-----------------------getXXXXResult-----------------------------
|
||||
public Number getNumberResult(final Class entityClass, final Reckon reckon, final String column);
|
||||
|
||||
public Number getMaxNumberResult(final Class entityClass, final String column, FilterBean bean);
|
||||
public Number getNumberResult(final Class entityClass, final Reckon reckon, final String column, FilterBean bean);
|
||||
|
||||
public Number getMaxNumberResult(final Class entityClass, final String column, FilterNode node);
|
||||
public Number getNumberResult(final Class entityClass, final Reckon reckon, final String column, FilterNode node);
|
||||
|
||||
//-----------------------------MIN-----------------------------
|
||||
public Number getMinNumberResult(final Class entityClass, final String column);
|
||||
public Map<Serializable, Number> getMapResult(Class entityClass, final String keyColumn, Reckon reckon, final String reckonColumn);
|
||||
|
||||
public Number getMinNumberResult(final Class entityClass, final String column, FilterBean bean);
|
||||
public Map<Serializable, Number> getMapResult(Class entityClass, final String keyColumn, Reckon reckon, final String reckonColumn, FilterBean bean);
|
||||
|
||||
public Number getMinNumberResult(final Class entityClass, final String column, FilterNode node);
|
||||
|
||||
//-----------------------------SUM-----------------------------
|
||||
public Number getSumNumberResult(final Class entityClass, final String column);
|
||||
|
||||
public Number getSumNumberResult(final Class entityClass, final String column, FilterBean bean);
|
||||
|
||||
public Number getSumNumberResult(final Class entityClass, final String column, FilterNode node);
|
||||
|
||||
//----------------------------COUNT----------------------------
|
||||
public Number getCountNumberResult(final Class entityClass);
|
||||
|
||||
public Number getCountNumberResult(final Class entityClass, FilterBean bean);
|
||||
|
||||
public Number getCountNumberResult(final Class entityClass, FilterNode node);
|
||||
|
||||
//----------------------------DISTINCT COUNT----------------------------
|
||||
public Number getCountDistinctNumberResult(final Class entityClass, String column);
|
||||
|
||||
public Number getCountDistinctNumberResult(final Class entityClass, String column, FilterBean bean);
|
||||
|
||||
public Number getCountDistinctNumberResult(final Class entityClass, String column, FilterNode node);
|
||||
|
||||
//-----------------------------AVG-----------------------------
|
||||
public Number getAvgNumberResult(final Class entityClass, final String column);
|
||||
|
||||
public Number getAvgNumberResult(final Class entityClass, final String column, FilterBean bean);
|
||||
|
||||
public Number getAvgNumberResult(final Class entityClass, final String column, FilterNode node);
|
||||
public Map<Serializable, Number> getMapResult(Class entityClass, final String keyColumn, Reckon reckon, final String reckonColumn, FilterNode node);
|
||||
|
||||
//-----------------------find----------------------------
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
*/
|
||||
package com.wentch.redkale.source;
|
||||
|
||||
import com.wentch.redkale.util.*;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
@@ -14,6 +13,10 @@ import java.util.function.*;
|
||||
import java.util.logging.*;
|
||||
import java.util.stream.Stream;
|
||||
import javax.persistence.Transient;
|
||||
import com.wentch.redkale.util.*;
|
||||
import com.wentch.redkale.source.DataSource.Reckon;
|
||||
import static com.wentch.redkale.source.DataSource.Reckon.*;
|
||||
import java.util.stream.*;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -99,10 +102,43 @@ final class EntityCache<T> {
|
||||
return (filter != null) && listStream().filter(filter).findFirst().isPresent();
|
||||
}
|
||||
|
||||
public <V> Number getNumberResult(final ReckonType type, final Attribute<T, V> attr, final Predicate<T> filter) {
|
||||
public <K, V> Map<Serializable, Number> getMapResult(final Attribute<T, K> keyAttr, final Reckon reckon, final Attribute<T, V> reckonAttr, final Predicate<T> filter) {
|
||||
Stream<T> stream = listStream();
|
||||
if (filter != null) stream = stream.filter(filter);
|
||||
switch (type) {
|
||||
Collector<T, Map, ?> collector = null;
|
||||
final Class valtype = reckonAttr.type();
|
||||
switch (reckon) {
|
||||
case AVG:
|
||||
if (valtype == float.class || valtype == Float.class || valtype == double.class || valtype == Double.class) {
|
||||
collector = (Collector<T, Map, ?>) Collectors.averagingDouble((T t) -> ((Number) reckonAttr.get(t)).doubleValue());
|
||||
} else {
|
||||
collector = (Collector<T, Map, ?>) Collectors.averagingLong((T t) -> ((Number) reckonAttr.get(t)).longValue());
|
||||
}
|
||||
break;
|
||||
case COUNT: collector = (Collector<T, Map, ?>) Collectors.counting();
|
||||
break;
|
||||
case DISTINCTCOUNT: collector = (Collector<T, Map, ?>) Collectors.counting();
|
||||
break;
|
||||
case MAX: collector = (Collector<T, Map, ?>) Collectors.maxBy(null);
|
||||
break;
|
||||
case MIN: collector = (Collector<T, Map, ?>) Collectors.minBy(null);
|
||||
break;
|
||||
case SUM:
|
||||
if (valtype == float.class || valtype == Float.class || valtype == double.class || valtype == Double.class) {
|
||||
collector = (Collector<T, Map, ?>) Collectors.summingDouble((T t) -> ((Number) reckonAttr.get(t)).doubleValue());
|
||||
} else {
|
||||
collector = (Collector<T, Map, ?>) Collectors.summingLong((T t) -> ((Number) reckonAttr.get(t)).longValue());
|
||||
}
|
||||
break;
|
||||
}
|
||||
final Map rs = stream.collect(Collectors.groupingBy(t -> keyAttr.get(t), LinkedHashMap::new, collector));
|
||||
return rs;
|
||||
}
|
||||
|
||||
public <V> Number getNumberResult(final Reckon reckon, final Attribute<T, V> attr, final Predicate<T> filter) {
|
||||
Stream<T> stream = listStream();
|
||||
if (filter != null) stream = stream.filter(filter);
|
||||
switch (reckon) {
|
||||
case AVG:
|
||||
if (attr.type() == int.class || attr.type() == Integer.class) {
|
||||
return (int) stream.mapToInt(x -> (Integer) attr.get(x)).average().orElse(0);
|
||||
@@ -310,7 +346,7 @@ final class EntityCache<T> {
|
||||
return this.list.size() > 1024 * 16;
|
||||
}
|
||||
|
||||
private Stream<T> listStream() {
|
||||
protected Stream<T> listStream() {
|
||||
return isParallel() ? this.list.parallelStream() : this.list.stream();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user