This commit is contained in:
@@ -877,103 +877,103 @@ public final class DataJDBCSource implements DataSource {
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------getSingleResult-----------------------------
|
||||
//-----------------------getNumberResult-----------------------------
|
||||
//-----------------------------MAX-----------------------------
|
||||
@Override
|
||||
public Number getMaxSingleResult(final Class entityClass, final String column) {
|
||||
return getMaxSingleResult(entityClass, column, (FilterNode) null);
|
||||
public Number getMaxNumberResult(final Class entityClass, final String column) {
|
||||
return getMaxNumberResult(entityClass, column, (FilterNode) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getMaxSingleResult(final Class entityClass, final String column, FilterBean bean) {
|
||||
return getSingleResult(ReckonType.MAX, entityClass, column, null, bean);
|
||||
public Number getMaxNumberResult(final Class entityClass, final String column, FilterBean bean) {
|
||||
return getNumberResult(ReckonType.MAX, entityClass, column, null, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getMaxSingleResult(final Class entityClass, final String column, FilterNode node) {
|
||||
return getSingleResult(ReckonType.MAX, entityClass, column, node, null);
|
||||
public Number getMaxNumberResult(final Class entityClass, final String column, FilterNode node) {
|
||||
return getNumberResult(ReckonType.MAX, entityClass, column, node, null);
|
||||
}
|
||||
|
||||
//-----------------------------MIN-----------------------------
|
||||
@Override
|
||||
public Number getMinSingleResult(final Class entityClass, final String column) {
|
||||
return getMinSingleResult(entityClass, column, (FilterNode) null);
|
||||
public Number getMinNumberResult(final Class entityClass, final String column) {
|
||||
return getMinNumberResult(entityClass, column, (FilterNode) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getMinSingleResult(final Class entityClass, final String column, FilterBean bean) {
|
||||
return getSingleResult(ReckonType.MIN, entityClass, column, null, bean);
|
||||
public Number getMinNumberResult(final Class entityClass, final String column, FilterBean bean) {
|
||||
return getNumberResult(ReckonType.MIN, entityClass, column, null, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getMinSingleResult(final Class entityClass, final String column, FilterNode node) {
|
||||
return getSingleResult(ReckonType.MIN, entityClass, column, node, null);
|
||||
public Number getMinNumberResult(final Class entityClass, final String column, FilterNode node) {
|
||||
return getNumberResult(ReckonType.MIN, entityClass, column, node, null);
|
||||
}
|
||||
|
||||
//-----------------------------SUM-----------------------------
|
||||
@Override
|
||||
public Number getSumSingleResult(final Class entityClass, final String column) {
|
||||
return getSumSingleResult(entityClass, column, (FilterNode) null);
|
||||
public Number getSumNumberResult(final Class entityClass, final String column) {
|
||||
return getSumNumberResult(entityClass, column, (FilterNode) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getSumSingleResult(final Class entityClass, final String column, FilterBean bean) {
|
||||
return getSingleResult(ReckonType.SUM, entityClass, column, null, bean);
|
||||
public Number getSumNumberResult(final Class entityClass, final String column, FilterBean bean) {
|
||||
return getNumberResult(ReckonType.SUM, entityClass, column, null, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getSumSingleResult(final Class entityClass, final String column, FilterNode node) {
|
||||
return getSingleResult(ReckonType.SUM, entityClass, column, node, null);
|
||||
public Number getSumNumberResult(final Class entityClass, final String column, FilterNode node) {
|
||||
return getNumberResult(ReckonType.SUM, entityClass, column, node, null);
|
||||
}
|
||||
|
||||
//----------------------------COUNT----------------------------
|
||||
@Override
|
||||
public Number getCountSingleResult(final Class entityClass) {
|
||||
return getCountSingleResult(entityClass, (FilterNode) null);
|
||||
public Number getCountNumberResult(final Class entityClass) {
|
||||
return getCountNumberResult(entityClass, (FilterNode) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getCountSingleResult(final Class entityClass, FilterBean bean) {
|
||||
return getSingleResult(ReckonType.COUNT, entityClass, null, null, bean);
|
||||
public Number getCountNumberResult(final Class entityClass, FilterBean bean) {
|
||||
return getNumberResult(ReckonType.COUNT, entityClass, null, null, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getCountSingleResult(final Class entityClass, FilterNode node) {
|
||||
return getSingleResult(ReckonType.COUNT, entityClass, null, node, null);
|
||||
public Number getCountNumberResult(final Class entityClass, FilterNode node) {
|
||||
return getNumberResult(ReckonType.COUNT, entityClass, null, node, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getCountDistinctSingleResult(final Class entityClass, String column) {
|
||||
return getCountDistinctSingleResult(entityClass, column, (FilterNode) null);
|
||||
public Number getCountDistinctNumberResult(final Class entityClass, String column) {
|
||||
return getCountDistinctNumberResult(entityClass, column, (FilterNode) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getCountDistinctSingleResult(final Class entityClass, String column, FilterBean bean) {
|
||||
return getSingleResult(ReckonType.DISTINCTCOUNT, entityClass, column, null, bean);
|
||||
public Number getCountDistinctNumberResult(final Class entityClass, String column, FilterBean bean) {
|
||||
return getNumberResult(ReckonType.DISTINCTCOUNT, entityClass, column, null, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getCountDistinctSingleResult(final Class entityClass, final String column, FilterNode node) {
|
||||
return getSingleResult(ReckonType.DISTINCTCOUNT, entityClass, column, node, null);
|
||||
public Number getCountDistinctNumberResult(final Class entityClass, final String column, FilterNode node) {
|
||||
return getNumberResult(ReckonType.DISTINCTCOUNT, entityClass, column, node, null);
|
||||
}
|
||||
|
||||
//-----------------------------AVG-----------------------------
|
||||
@Override
|
||||
public Number getAvgSingleResult(final Class entityClass, final String column) {
|
||||
return getAvgSingleResult(entityClass, column, (FilterNode) null);
|
||||
public Number getAvgNumberResult(final Class entityClass, final String column) {
|
||||
return getAvgNumberResult(entityClass, column, (FilterNode) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getAvgSingleResult(final Class entityClass, final String column, FilterBean bean) {
|
||||
return getSingleResult(ReckonType.AVG, entityClass, column, null, bean);
|
||||
public Number getAvgNumberResult(final Class entityClass, final String column, FilterBean bean) {
|
||||
return getNumberResult(ReckonType.AVG, entityClass, column, null, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getAvgSingleResult(final Class entityClass, final String column, FilterNode node) {
|
||||
return getSingleResult(ReckonType.AVG, entityClass, column, node, null);
|
||||
public Number getAvgNumberResult(final Class entityClass, final String column, FilterNode node) {
|
||||
return getNumberResult(ReckonType.AVG, entityClass, column, node, null);
|
||||
}
|
||||
|
||||
private <T> Number getSingleResult(final ReckonType type, final Class<T> entityClass, final String column, FilterNode node, FilterBean bean) {
|
||||
private <T> Number getNumberResult(final ReckonType type, final Class<T> entityClass, final String column, FilterNode node, FilterBean bean) {
|
||||
final Connection conn = createReadSQLConnection();
|
||||
try {
|
||||
final EntityInfo<T> info = loadEntityInfo(entityClass);
|
||||
@@ -982,7 +982,7 @@ 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.getSingleResult(type, column == null ? null : info.getAttribute(column), filter);
|
||||
return cache.getNumberResult(type, column == null ? null : info.getAttribute(column), filter);
|
||||
}
|
||||
}
|
||||
final String sql = "SELECT " + type.getReckonColumn("a." + column) + " FROM " + info.getTable() + " a"
|
||||
|
||||
@@ -177,6 +177,96 @@ final class DataJPASource implements DataSource {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getMaxNumberResult(Class entityClass, String column) {
|
||||
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) {
|
||||
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) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getMinNumberResult(Class entityClass, String column) {
|
||||
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) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
private static class DataJPAConnection extends DataConnection {
|
||||
|
||||
private final EntityManager manager;
|
||||
|
||||
@@ -91,48 +91,48 @@ public interface DataSource {
|
||||
|
||||
public <T> void updateColumnIncrement(final DataConnection conn, Class<T> clazz, Serializable id, String column, long incvalue);
|
||||
|
||||
//-----------------------getSingleResult-----------------------------
|
||||
//-----------------------getNumberResult-----------------------------
|
||||
//-----------------------------MAX-----------------------------
|
||||
public Number getMaxSingleResult(final Class entityClass, final String column);
|
||||
public Number getMaxNumberResult(final Class entityClass, final String column);
|
||||
|
||||
public Number getMaxSingleResult(final Class entityClass, final String column, FilterBean bean);
|
||||
public Number getMaxNumberResult(final Class entityClass, final String column, FilterBean bean);
|
||||
|
||||
public Number getMaxSingleResult(final Class entityClass, final String column, FilterNode node);
|
||||
public Number getMaxNumberResult(final Class entityClass, final String column, FilterNode node);
|
||||
|
||||
//-----------------------------MIN-----------------------------
|
||||
public Number getMinSingleResult(final Class entityClass, final String column);
|
||||
public Number getMinNumberResult(final Class entityClass, final String column);
|
||||
|
||||
public Number getMinSingleResult(final Class entityClass, final String column, FilterBean bean);
|
||||
public Number getMinNumberResult(final Class entityClass, final String column, FilterBean bean);
|
||||
|
||||
public Number getMinSingleResult(final Class entityClass, final String column, FilterNode node);
|
||||
public Number getMinNumberResult(final Class entityClass, final String column, FilterNode node);
|
||||
|
||||
//-----------------------------SUM-----------------------------
|
||||
public Number getSumSingleResult(final Class entityClass, final String column);
|
||||
public Number getSumNumberResult(final Class entityClass, final String column);
|
||||
|
||||
public Number getSumSingleResult(final Class entityClass, final String column, FilterBean bean);
|
||||
public Number getSumNumberResult(final Class entityClass, final String column, FilterBean bean);
|
||||
|
||||
public Number getSumSingleResult(final Class entityClass, final String column, FilterNode node);
|
||||
public Number getSumNumberResult(final Class entityClass, final String column, FilterNode node);
|
||||
|
||||
//----------------------------COUNT----------------------------
|
||||
public Number getCountSingleResult(final Class entityClass);
|
||||
public Number getCountNumberResult(final Class entityClass);
|
||||
|
||||
public Number getCountSingleResult(final Class entityClass, FilterBean bean);
|
||||
public Number getCountNumberResult(final Class entityClass, FilterBean bean);
|
||||
|
||||
public Number getCountSingleResult(final Class entityClass, FilterNode node);
|
||||
public Number getCountNumberResult(final Class entityClass, FilterNode node);
|
||||
|
||||
//----------------------------DISTINCT COUNT----------------------------
|
||||
public Number getCountDistinctSingleResult(final Class entityClass, String column);
|
||||
public Number getCountDistinctNumberResult(final Class entityClass, String column);
|
||||
|
||||
public Number getCountDistinctSingleResult(final Class entityClass, String column, FilterBean bean);
|
||||
public Number getCountDistinctNumberResult(final Class entityClass, String column, FilterBean bean);
|
||||
|
||||
public Number getCountDistinctSingleResult(final Class entityClass, String column, FilterNode node);
|
||||
public Number getCountDistinctNumberResult(final Class entityClass, String column, FilterNode node);
|
||||
|
||||
//-----------------------------AVG-----------------------------
|
||||
public Number getAvgSingleResult(final Class entityClass, final String column);
|
||||
public Number getAvgNumberResult(final Class entityClass, final String column);
|
||||
|
||||
public Number getAvgSingleResult(final Class entityClass, final String column, FilterBean bean);
|
||||
public Number getAvgNumberResult(final Class entityClass, final String column, FilterBean bean);
|
||||
|
||||
public Number getAvgSingleResult(final Class entityClass, final String column, FilterNode node);
|
||||
public Number getAvgNumberResult(final Class entityClass, final String column, FilterNode node);
|
||||
|
||||
//-----------------------find----------------------------
|
||||
/**
|
||||
|
||||
@@ -99,7 +99,7 @@ final class EntityCache<T> {
|
||||
return (filter != null) && listStream().filter(filter).findFirst().isPresent();
|
||||
}
|
||||
|
||||
public <V> Number getSingleResult(final ReckonType type, final Attribute<T, V> attr, final Predicate<T> filter) {
|
||||
public <V> Number getNumberResult(final ReckonType type, final Attribute<T, V> attr, final Predicate<T> filter) {
|
||||
Stream<T> stream = listStream();
|
||||
if (filter != null) stream = stream.filter(filter);
|
||||
switch (type) {
|
||||
@@ -115,7 +115,7 @@ final class EntityCache<T> {
|
||||
} else if (attr.type() == double.class || attr.type() == Double.class) {
|
||||
return stream.mapToDouble(x -> (Double) attr.get(x)).average().orElse(0);
|
||||
}
|
||||
throw new RuntimeException("getSingleResult 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: return stream.count();
|
||||
case DISTINCTCOUNT: return stream.map(x -> attr.get(x)).distinct().count();
|
||||
|
||||
@@ -131,7 +131,7 @@ final class EntityCache<T> {
|
||||
} else if (attr.type() == double.class || attr.type() == Double.class) {
|
||||
return stream.mapToDouble(x -> (Double) attr.get(x)).max().orElse(0);
|
||||
}
|
||||
throw new RuntimeException("getSingleResult 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:
|
||||
if (attr.type() == int.class || attr.type() == Integer.class) {
|
||||
@@ -145,7 +145,7 @@ final class EntityCache<T> {
|
||||
} else if (attr.type() == double.class || attr.type() == Double.class) {
|
||||
return stream.mapToDouble(x -> (Double) attr.get(x)).min().orElse(0);
|
||||
}
|
||||
throw new RuntimeException("getSingleResult 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 SUM:
|
||||
if (attr.type() == int.class || attr.type() == Integer.class) {
|
||||
@@ -159,7 +159,7 @@ final class EntityCache<T> {
|
||||
} else if (attr.type() == double.class || attr.type() == Double.class) {
|
||||
return stream.mapToDouble(x -> (Double) attr.get(x)).sum();
|
||||
}
|
||||
throw new RuntimeException("getSingleResult 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user