From 91d02249490ed06d321836cf649d26bc46cf0a0e Mon Sep 17 00:00:00 2001
From: wentch <22250530@qq.com>
Date: Thu, 10 Dec 2015 14:58:48 +0800
Subject: [PATCH]
---
src/javax/persistence/GeneratedValue.java | 15 ----
src/javax/persistence/GenerationType.java | 56 ---------------
src/javax/persistence/Index.java | 68 -------------------
src/javax/persistence/Table.java | 19 ------
src/javax/persistence/UniqueConstraint.java | 52 --------------
.../redkale/service/DataSourceService.java | 26 +++----
src/org/redkale/source/DataDefaultSource.java | 28 ++++----
src/org/redkale/source/DataSource.java | 14 ++--
.../redkale/source/DistributeGenerator.java | 16 -----
src/org/redkale/source/DistributeTables.java | 26 +++++++
src/org/redkale/source/EntityCache.java | 36 +++++-----
src/org/redkale/source/EntityInfo.java | 10 +--
src/org/redkale/source/Range.java | 44 +++++++++++-
src/org/redkale/source/ReckonType.java | 21 ------
14 files changed, 124 insertions(+), 307 deletions(-)
delete mode 100644 src/javax/persistence/GenerationType.java
delete mode 100644 src/javax/persistence/Index.java
delete mode 100644 src/javax/persistence/UniqueConstraint.java
create mode 100644 src/org/redkale/source/DistributeTables.java
delete mode 100644 src/org/redkale/source/ReckonType.java
diff --git a/src/javax/persistence/GeneratedValue.java b/src/javax/persistence/GeneratedValue.java
index 9c90d80af..b24cdbd69 100644
--- a/src/javax/persistence/GeneratedValue.java
+++ b/src/javax/persistence/GeneratedValue.java
@@ -20,7 +20,6 @@ import java.lang.annotation.Retention;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import static javax.persistence.GenerationType.AUTO;
/**
* Provides for the specification of generation strategies for the
@@ -62,18 +61,4 @@ import static javax.persistence.GenerationType.AUTO;
public @interface GeneratedValue {
- /**
- * (Optional) The primary key generation strategy
- * that the persistence provider must use to
- * generate the annotated entity primary key.
- */
- GenerationType strategy() default AUTO;
-
- /**
- * (Optional) The name of the primary key generator
- * to use as specified in the {@link SequenceGenerator}
- * or {@link TableGenerator} annotation.
- *
Defaults to the id generator supplied by persistence provider.
- */
- String generator() default "";
}
diff --git a/src/javax/persistence/GenerationType.java b/src/javax/persistence/GenerationType.java
deleted file mode 100644
index 9d1980e83..000000000
--- a/src/javax/persistence/GenerationType.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 - 2013 Oracle Corporation. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
- * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Linda DeMichiel - Java Persistence 2.1
- * Linda DeMichiel - Java Persistence 2.0
- *
- ******************************************************************************/
-package javax.persistence;
-
-/**
- * Defines the types of primary key generation strategies.
- *
- * @see GeneratedValue
- *
- * @since Java Persistence 1.0
- */
-public enum GenerationType {
-
- /**
- * Indicates that the persistence provider must assign
- * primary keys for the entity using an underlying
- * database table to ensure uniqueness.
- */
- TABLE,
-
- /**
- * Indicates that the persistence provider must assign
- * primary keys for the entity using a database sequence.
- */
- SEQUENCE,
-
- /**
- * Indicates that the persistence provider must assign
- * primary keys for the entity using a database identity column.
- */
- IDENTITY,
-
- /**
- * Indicates that the persistence provider should pick an
- * appropriate strategy for the particular database. The
- * AUTO generation strategy may expect a database
- * resource to exist, or it may attempt to create one. A vendor
- * may provide documentation on how to create such resources
- * in the event that it does not support schema generation
- * or cannot create the schema resource at runtime.
- */
- AUTO
-}
diff --git a/src/javax/persistence/Index.java b/src/javax/persistence/Index.java
deleted file mode 100644
index 5899a0330..000000000
--- a/src/javax/persistence/Index.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 - 2013 Oracle Corporation. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
- * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Linda DeMichiel - Java Persistence 2.1
- *
- ******************************************************************************/
-package javax.persistence;
-
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-/**
- * Used in schema generation to specify creation of an index.
- *
- * Note that it is not necessary to specify an index for a primary key,
- * as the primary key index will be created automatically.
- *
- *
- * The syntax of the columnList element is a
- * column_list, as follows:
- *
- *
- * column::= index_column [,index_column]*
- * index_column::= column_name [ASC | DESC]
- *
- *
- * If ASC or DESC is not specified,
- * ASC (ascending order) is assumed.
- *
- * @see Table
- * @see SecondaryTable
- * @see CollectionTable
- * @see JoinTable
- * @see TableGenerator
- *
- * @since Java Persistence 2.1
- *
- */
-@Target({})
-@Retention(RUNTIME)
-public @interface Index {
-
- /**
- * (Optional) The name of the index; defaults to a provider-generated name.
- */
- String name() default "";
-
- /**
- * (Required) The names of the columns to be included in the index,
- * in order.
- */
- String columnList();
-
- /**
- * (Optional) Whether the index is unique.
- */
- boolean unique() default false;
-
-}
diff --git a/src/javax/persistence/Table.java b/src/javax/persistence/Table.java
index e92b77ca7..6f523b1e1 100644
--- a/src/javax/persistence/Table.java
+++ b/src/javax/persistence/Table.java
@@ -58,23 +58,4 @@ public @interface Table {
*/
String schema() default "";
- /**
- * (Optional) Unique constraints that are to be placed on
- * the table. These are only used if table generation is in
- * effect. These constraints apply in addition to any constraints
- * specified by the Column and JoinColumn
- * annotations and constraints entailed by primary key mappings.
- *
Defaults to no additional constraints.
- */
- UniqueConstraint[] uniqueConstraints() default {};
-
- /**
- * (Optional) Indexes for the table. These are only used if
- * table generation is in effect. Note that it is not necessary
- * to specify an index for a primary key, as the primary key
- * index will be created automatically.
- *
- * @since Java Persistence 2.1
- */
- Index[] indexes() default {};
}
diff --git a/src/javax/persistence/UniqueConstraint.java b/src/javax/persistence/UniqueConstraint.java
deleted file mode 100644
index 2351b4511..000000000
--- a/src/javax/persistence/UniqueConstraint.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 - 2013 Oracle Corporation. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
- * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Linda DeMichiel - Java Persistence 2.1
- * Linda DeMichiel - Java Persistence 2.0
- *
- ******************************************************************************/
-package javax.persistence;
-
-import java.lang.annotation.Target;
-import java.lang.annotation.Retention;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-/**
- * Specifies that a unique constraint is to be included in
- * the generated DDL for a primary or secondary table.
- *
- *
- * Example:
- * @Entity
- * @Table(
- * name="EMPLOYEE",
- * uniqueConstraints=
- * @UniqueConstraint(columnNames={"EMP_ID", "EMP_NAME"})
- * )
- * public class Employee { ... }
- *
- *
- * @since Java Persistence 1.0
- */
-@Target({})
-@Retention(RUNTIME)
-public @interface UniqueConstraint {
-
- /** (Optional) Constraint name. A provider-chosen name will be chosen
- * if a name is not specified.
- *
- * @since Java Persistence 2.0
- */
- String name() default "";
-
- /** (Required) An array of the column names that make up the constraint. */
- String[] columnNames();
-}
diff --git a/src/org/redkale/service/DataSourceService.java b/src/org/redkale/service/DataSourceService.java
index 435ae4f56..d80c95851 100644
--- a/src/org/redkale/service/DataSourceService.java
+++ b/src/org/redkale/service/DataSourceService.java
@@ -9,7 +9,7 @@ import java.io.*;
import java.util.*;
import javax.annotation.*;
import org.redkale.net.sncp.*;
-import org.redkale.source.DataSource.Reckon;
+import org.redkale.source.DataSource.FuncEnum;
import org.redkale.source.*;
import org.redkale.util.*;
@@ -140,33 +140,33 @@ public class DataSourceService implements DataSource, Service {
}
@Override
- public Number getNumberResult(Class entityClass, Reckon reckon, String column) {
- return source.getNumberResult(entityClass, reckon, column);
+ public Number getNumberResult(Class entityClass, FuncEnum func, String column) {
+ return source.getNumberResult(entityClass, func, column);
}
@Override
- public final Number getNumberResult(Class entityClass, Reckon reckon, String column, FilterBean bean) {
- return getNumberResult(entityClass, reckon, column, FilterNodeBean.createFilterNode(bean));
+ public final Number getNumberResult(Class entityClass, FuncEnum func, String column, FilterBean bean) {
+ return getNumberResult(entityClass, func, column, FilterNodeBean.createFilterNode(bean));
}
@Override
- public Number getNumberResult(Class entityClass, Reckon reckon, String column, FilterNode node) {
- return source.getNumberResult(entityClass, reckon, column, node);
+ public Number getNumberResult(Class entityClass, FuncEnum func, String column, FilterNode node) {
+ return source.getNumberResult(entityClass, func, column, node);
}
@Override
- public Map queryColumnMap(Class entityClass, String keyColumn, Reckon reckon, String reckonColumn) {
- return source.queryColumnMap(entityClass, keyColumn, reckon, reckonColumn);
+ public Map queryColumnMap(Class entityClass, String keyColumn, FuncEnum func, String funcColumn) {
+ return source.queryColumnMap(entityClass, keyColumn, func, funcColumn);
}
@Override
- public final Map queryColumnMap(Class entityClass, String keyColumn, Reckon reckon, String reckonColumn, FilterBean bean) {
- return queryColumnMap(entityClass, keyColumn, reckon, reckonColumn, FilterNodeBean.createFilterNode(bean));
+ public final Map queryColumnMap(Class entityClass, String keyColumn, FuncEnum func, String funcColumn, FilterBean bean) {
+ return queryColumnMap(entityClass, keyColumn, func, funcColumn, FilterNodeBean.createFilterNode(bean));
}
@Override
- public Map queryColumnMap(Class entityClass, String keyColumn, Reckon reckon, String reckonColumn, FilterNode node) {
- return source.queryColumnMap(entityClass, keyColumn, reckon, reckonColumn, node);
+ public Map queryColumnMap(Class entityClass, String keyColumn, FuncEnum func, String funcColumn, FilterNode node) {
+ return source.queryColumnMap(entityClass, keyColumn, func, funcColumn, node);
}
@Override
diff --git a/src/org/redkale/source/DataDefaultSource.java b/src/org/redkale/source/DataDefaultSource.java
index ecc6d8faf..32117358e 100644
--- a/src/org/redkale/source/DataDefaultSource.java
+++ b/src/org/redkale/source/DataDefaultSource.java
@@ -1066,30 +1066,30 @@ public final class DataDefaultSource implements DataSource, Nameable, Function joinTabalis = node == null ? null : node.getJoinTabalis();
final CharSequence join = node == null ? null : node.createSQLJoin(this, joinTabalis, info);
final CharSequence where = node == null ? null : node.createSQLExpress(info, joinTabalis);
- final String sql = "SELECT " + reckon.getColumn((column == null || column.isEmpty() ? "*" : ("a." + column))) + " FROM " + info.getTable() + " a"
+ final String sql = "SELECT " + func.getColumn((column == null || column.isEmpty() ? "*" : ("a." + column))) + " FROM " + info.getTable() + " a"
+ (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where));
if (debug.get() && info.isLoggable(Level.FINEST)) logger.finest(entityClass.getSimpleName() + " single sql=" + sql);
final PreparedStatement prestmt = conn.prepareStatement(sql);
@@ -1110,31 +1110,31 @@ public final class DataDefaultSource implements DataSource, Nameable, Function Map queryColumnMap(final Class entityClass, final String keyColumn, Reckon reckon, final String reckonColumn) {
- return queryColumnMap(entityClass, keyColumn, reckon, reckonColumn, (FilterNode) null);
+ public Map queryColumnMap(final Class entityClass, final String keyColumn, FuncEnum func, final String funcColumn) {
+ return queryColumnMap(entityClass, keyColumn, func, funcColumn, (FilterNode) null);
}
@Override
- public Map queryColumnMap(final Class entityClass, final String keyColumn, Reckon reckon, final String reckonColumn, FilterBean bean) {
- return queryColumnMap(entityClass, keyColumn, reckon, reckonColumn, FilterNodeBean.createFilterNode(bean));
+ public Map queryColumnMap(final Class entityClass, final String keyColumn, FuncEnum func, final String funcColumn, FilterBean bean) {
+ return queryColumnMap(entityClass, keyColumn, func, funcColumn, FilterNodeBean.createFilterNode(bean));
}
@Override
- public Map queryColumnMap(final Class entityClass, final String keyColumn, final Reckon reckon, final String reckonColumn, FilterNode node) {
+ public Map queryColumnMap(final Class entityClass, final String keyColumn, final FuncEnum func, final String funcColumn, FilterNode node) {
final Connection conn = createReadSQLConnection();
try {
final EntityInfo info = loadEntityInfo(entityClass);
final EntityCache cache = info.getCache();
if (cache != null && (info.isVirtualEntity() || cache.isFullLoaded())) {
if (node == null || node.isCacheUseable(this)) {
- return cache.getMapResult(keyColumn, reckon, reckonColumn, node);
+ return cache.getMapResult(keyColumn, func, funcColumn, node);
}
}
final String sqlkey = info.getSQLColumn(null, keyColumn);
final Map joinTabalis = node == null ? null : node.getJoinTabalis();
final CharSequence join = node == null ? null : node.createSQLJoin(this, joinTabalis, info);
final CharSequence where = node == null ? null : node.createSQLExpress(info, joinTabalis);
- final String sql = "SELECT a." + sqlkey + ", " + reckon.getColumn((reckonColumn == null || reckonColumn.isEmpty() ? "*" : ("a." + reckonColumn)))
+ final String sql = "SELECT a." + sqlkey + ", " + func.getColumn((funcColumn == null || funcColumn.isEmpty() ? "*" : ("a." + funcColumn)))
+ " FROM " + info.getTable() + " a" + (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where)) + " GROUP BY a." + sqlkey;
if (debug.get() && info.isLoggable(Level.FINEST)) logger.finest(entityClass.getSimpleName() + " single sql=" + sql);
final PreparedStatement prestmt = conn.prepareStatement(sql);
diff --git a/src/org/redkale/source/DataSource.java b/src/org/redkale/source/DataSource.java
index 31b60bdac..69edc5e3e 100644
--- a/src/org/redkale/source/DataSource.java
+++ b/src/org/redkale/source/DataSource.java
@@ -16,7 +16,7 @@ import org.redkale.util.*;
@SuppressWarnings("unchecked")
public interface DataSource {
- public static enum Reckon {
+ public static enum FuncEnum {
AVG, COUNT, DISTINCTCOUNT, MAX, MIN, SUM;
@@ -110,17 +110,17 @@ public interface DataSource {
public void updateColumnOr(final DataConnection conn, Class clazz, Serializable id, String column, long incvalue);
//-----------------------getXXXXResult-----------------------------
- public Number getNumberResult(final Class entityClass, final Reckon reckon, final String column);
+ public Number getNumberResult(final Class entityClass, final FuncEnum func, final String column);
- public Number getNumberResult(final Class entityClass, final Reckon reckon, final String column, FilterBean bean);
+ public Number getNumberResult(final Class entityClass, final FuncEnum func, final String column, FilterBean bean);
- public Number getNumberResult(final Class entityClass, final Reckon reckon, final String column, FilterNode node);
+ public Number getNumberResult(final Class entityClass, final FuncEnum func, final String column, FilterNode node);
- public Map queryColumnMap(Class entityClass, final String keyColumn, Reckon reckon, final String reckonColumn);
+ public Map queryColumnMap(Class entityClass, final String keyColumn, FuncEnum func, final String funcColumn);
- public Map queryColumnMap(Class entityClass, final String keyColumn, Reckon reckon, final String reckonColumn, final FilterBean bean);
+ public Map queryColumnMap(Class entityClass, final String keyColumn, FuncEnum func, final String funcColumn, final FilterBean bean);
- public Map queryColumnMap(Class entityClass, final String keyColumn, Reckon reckon, final String reckonColumn, final FilterNode node);
+ public Map queryColumnMap(Class entityClass, final String keyColumn, FuncEnum func, final String funcColumn, final FilterNode node);
//-----------------------find----------------------------
/**
diff --git a/src/org/redkale/source/DistributeGenerator.java b/src/org/redkale/source/DistributeGenerator.java
index 020bcc6c7..6c24e2089 100644
--- a/src/org/redkale/source/DistributeGenerator.java
+++ b/src/org/redkale/source/DistributeGenerator.java
@@ -17,22 +17,6 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Retention(RUNTIME)
public @interface DistributeGenerator {
- /**
- * 当使用DistributeGenerator控制主键值时, 如果表A删除的数据迁移到表B时, 就需要将表A的class标记:
- * DistributeTables({B.class})
- * public class A {
- * }
- * 这样DistributeGenerator将从A、B表中取最大值来初始化主键值。
- *
- * @author zhangjx
- */
- @Target({TYPE})
- @Retention(RUNTIME)
- public @interface DistributeTables {
-
- Class[] value();
- }
-
long initialValue() default 1;
/**
diff --git a/src/org/redkale/source/DistributeTables.java b/src/org/redkale/source/DistributeTables.java
new file mode 100644
index 000000000..7106f6676
--- /dev/null
+++ b/src/org/redkale/source/DistributeTables.java
@@ -0,0 +1,26 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.redkale.source;
+
+import java.lang.annotation.*;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * 当使用DistributeGenerator控制主键值时, 如果表A与表B使用同一主键时, 就需要将表A的class标记:
+ * DistributeTables({B.class})
+ * public class A {
+ * }
+ * 这样DistributeGenerator将从A、B表中取最大值来初始化主键值。 常见场景就是表B是数据表A对应的历史表
+ *
+ * @author zhangjx
+ */
+@Target({TYPE})
+@Retention(RUNTIME)
+public @interface DistributeTables {
+
+ Class[] value();
+}
diff --git a/src/org/redkale/source/EntityCache.java b/src/org/redkale/source/EntityCache.java
index 8ee93bec4..7f1403176 100644
--- a/src/org/redkale/source/EntityCache.java
+++ b/src/org/redkale/source/EntityCache.java
@@ -12,8 +12,8 @@ import java.util.function.*;
import java.util.logging.*;
import java.util.stream.Stream;
import javax.persistence.Transient;
-import org.redkale.source.DataSource.Reckon;
-import static org.redkale.source.DataSource.Reckon.*;
+import org.redkale.source.DataSource.FuncEnum;
+import static org.redkale.source.DataSource.FuncEnum.*;
import java.util.stream.*;
import org.redkale.util.*;
@@ -150,48 +150,48 @@ public final class EntityCache {
return (filter != null) && this.list.stream().filter(filter).findFirst().isPresent();
}
- public Map getMapResult(final String keyColumn, final Reckon reckon, final String reckonColumn, FilterNode node) {
+ public Map getMapResult(final String keyColumn, final FuncEnum func, final String funcColumn, FilterNode node) {
final Attribute keyAttr = info.getAttribute(keyColumn);
final Predicate filter = node == null ? null : node.createPredicate(this);
- final Attribute reckonAttr = reckonColumn == null ? null : info.getAttribute(reckonColumn);
+ final Attribute funcAttr = funcColumn == null ? null : info.getAttribute(funcColumn);
Stream stream = this.list.stream();
if (filter != null) stream = stream.filter(filter);
Collector collector = null;
- final Class valtype = reckonAttr == null ? null : reckonAttr.type();
- switch (reckon) {
+ final Class valtype = funcAttr == null ? null : funcAttr.type();
+ switch (func) {
case AVG:
if (valtype == float.class || valtype == Float.class || valtype == double.class || valtype == Double.class) {
- collector = (Collector) Collectors.averagingDouble((T t) -> ((Number) reckonAttr.get(t)).doubleValue());
+ collector = (Collector) Collectors.averagingDouble((T t) -> ((Number) funcAttr.get(t)).doubleValue());
} else {
- collector = (Collector) Collectors.averagingLong((T t) -> ((Number) reckonAttr.get(t)).longValue());
+ collector = (Collector) Collectors.averagingLong((T t) -> ((Number) funcAttr.get(t)).longValue());
}
break;
case COUNT: collector = (Collector) Collectors.counting();
break;
case DISTINCTCOUNT:
- collector = (Collector) Collectors.mapping((t) -> reckonAttr.get(t), Collectors.toSet());
+ collector = (Collector) Collectors.mapping((t) -> funcAttr.get(t), Collectors.toSet());
break;
case MAX:
case MIN:
- Comparator comp = (o1, o2) -> o1 == null ? (o2 == null ? 0 : -1) : ((Comparable) reckonAttr.get(o1)).compareTo(reckonAttr.get(o2));
- collector = (Collector) ((reckon == MAX) ? Collectors.maxBy(comp) : Collectors.minBy(comp));
+ Comparator comp = (o1, o2) -> o1 == null ? (o2 == null ? 0 : -1) : ((Comparable) funcAttr.get(o1)).compareTo(funcAttr.get(o2));
+ collector = (Collector) ((func == MAX) ? Collectors.maxBy(comp) : Collectors.minBy(comp));
break;
case SUM:
if (valtype == float.class || valtype == Float.class || valtype == double.class || valtype == Double.class) {
- collector = (Collector) Collectors.summingDouble((T t) -> ((Number) reckonAttr.get(t)).doubleValue());
+ collector = (Collector) Collectors.summingDouble((T t) -> ((Number) funcAttr.get(t)).doubleValue());
} else {
- collector = (Collector) Collectors.summingLong((T t) -> ((Number) reckonAttr.get(t)).longValue());
+ collector = (Collector) Collectors.summingLong((T t) -> ((Number) funcAttr.get(t)).longValue());
}
break;
}
Map rs = stream.collect(Collectors.groupingBy(t -> keyAttr.get(t), LinkedHashMap::new, collector));
- if (reckon == MAX || reckon == MIN) {
+ if (func == MAX || func == MIN) {
Map rs2 = new LinkedHashMap();
rs.forEach((x, y) -> {
- if (((Optional) y).isPresent()) rs2.put(x, reckonAttr.get((T) ((Optional) y).get()));
+ if (((Optional) y).isPresent()) rs2.put(x, funcAttr.get((T) ((Optional) y).get()));
});
rs = rs2;
- } else if (reckon == DISTINCTCOUNT) {
+ } else if (func == DISTINCTCOUNT) {
Map rs2 = new LinkedHashMap();
rs.forEach((x, y) -> rs2.put(x, ((Set) y).size()));
rs = rs2;
@@ -199,12 +199,12 @@ public final class EntityCache {
return rs;
}
- public Number getNumberResult(final Reckon reckon, final String column, FilterNode node) {
+ public Number getNumberResult(final FuncEnum func, final String column, FilterNode node) {
final Attribute attr = column == null ? null : info.getAttribute(column);
final Predicate filter = node == null ? null : node.createPredicate(this);
Stream stream = this.list.stream();
if (filter != null) stream = stream.filter(filter);
- switch (reckon) {
+ switch (func) {
case AVG:
if (attr.type() == int.class || attr.type() == Integer.class) {
return (int) stream.mapToInt(x -> (Integer) attr.get(x)).average().orElse(0);
diff --git a/src/org/redkale/source/EntityInfo.java b/src/org/redkale/source/EntityInfo.java
index 82eaf2df6..8f62860ed 100644
--- a/src/org/redkale/source/EntityInfo.java
+++ b/src/org/redkale/source/EntityInfo.java
@@ -116,7 +116,7 @@ public final class EntityInfo {
this.type = type;
//---------------------------------------------
this.nodeid = nodeid >= 0 ? nodeid : 0;
- DistributeGenerator.DistributeTables dt = type.getAnnotation(DistributeGenerator.DistributeTables.class);
+ DistributeTables dt = type.getAnnotation(DistributeTables.class);
this.distributeTables = dt == null ? null : dt.value();
LogLevel ll = type.getAnnotation(LogLevel.class);
@@ -165,12 +165,12 @@ public final class EntityInfo {
idAttr0 = attr;
GeneratedValue gv = field.getAnnotation(GeneratedValue.class);
auto = gv != null;
- if (gv != null && gv.strategy() != GenerationType.IDENTITY) {
- throw new RuntimeException(cltmp.getName() + "'s @ID primary not a GenerationType.IDENTITY");
- }
+// if (gv != null && gv.strategy() != GenerationType.IDENTITY) {
+// throw new RuntimeException(cltmp.getName() + "'s @ID primary not a GenerationType.IDENTITY");
+// }
DistributeGenerator dg = field.getAnnotation(DistributeGenerator.class);
if (dg != null) {
- if (!field.getType().isPrimitive()) throw new RuntimeException(cltmp.getName() + "'s @DistributeGenerator primary must be primitive class type field");
+ if (!field.getType().isPrimitive()) throw new RuntimeException(cltmp.getName() + "'s @" + DistributeGenerator.class.getSimpleName() + " primary must be primitive class type field");
sqldistribute = true;
auto = false;
allocationSize0 = dg.allocationSize();
diff --git a/src/org/redkale/source/Range.java b/src/org/redkale/source/Range.java
index d97318d3b..78b18bce2 100644
--- a/src/org/redkale/source/Range.java
+++ b/src/org/redkale/source/Range.java
@@ -5,12 +5,14 @@
*/
package org.redkale.source;
+import java.util.function.*;
+
/**
*
* @author zhangjx
* @param
*/
-public interface Range extends java.io.Serializable {
+public interface Range extends java.io.Serializable, Predicate {
public E getMin();
@@ -48,10 +50,16 @@ public interface Range extends java.io.Serializable {
if (max != null) this.max = max;
}
+ @Override
+ public boolean test(Byte t) {
+ return t >= min && t <= max;
+ }
+
@Override
public String toString() {
return "{min:" + min + ", max:" + max + "}";
}
+
}
public static final class ShortRange implements Range {
@@ -86,6 +94,11 @@ public interface Range extends java.io.Serializable {
if (max != null) this.max = max;
}
+ @Override
+ public boolean test(Short t) {
+ return t >= min && t <= max;
+ }
+
@Override
public String toString() {
return "{min:" + min + ", max:" + max + "}";
@@ -124,6 +137,11 @@ public interface Range extends java.io.Serializable {
if (max != null) this.max = max;
}
+ @Override
+ public boolean test(Integer t) {
+ return t >= min && t <= max;
+ }
+
@Override
public String toString() {
return "{min:" + min + ", max:" + max + "}";
@@ -162,6 +180,11 @@ public interface Range extends java.io.Serializable {
if (max != null) this.max = max;
}
+ @Override
+ public boolean test(Long t) {
+ return t >= min && t <= max;
+ }
+
@Override
public String toString() {
return "{min:" + min + ", max:" + max + "}";
@@ -200,6 +223,11 @@ public interface Range extends java.io.Serializable {
if (max != null) this.max = max;
}
+ @Override
+ public boolean test(Float t) {
+ return t >= min && t <= max;
+ }
+
@Override
public String toString() {
return "{min:" + min + ", max:" + max + "}";
@@ -238,6 +266,11 @@ public interface Range extends java.io.Serializable {
if (max != null) this.max = max;
}
+ @Override
+ public boolean test(Double t) {
+ return t >= min && t <= max;
+ }
+
@Override
public String toString() {
return "{min:" + min + ", max:" + max + "}";
@@ -269,11 +302,16 @@ public interface Range extends java.io.Serializable {
}
public void setMin(String min) {
- this.min = min;
+ if (min != null) this.min = min;
}
public void setMax(String max) {
- this.max = max;
+ if (max != null) this.max = max;
+ }
+
+ @Override
+ public boolean test(String t) {
+ return t.compareTo(min) >= 0 && t.compareTo(max) <= 0;
}
@Override
diff --git a/src/org/redkale/source/ReckonType.java b/src/org/redkale/source/ReckonType.java
deleted file mode 100644
index eae309a45..000000000
--- a/src/org/redkale/source/ReckonType.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package org.redkale.source;
-
-/**
- *
- * @author zhangjx
- */
-public enum ReckonType {
-
- AVG, COUNT, DISTINCTCOUNT, MAX, MIN, SUM;
-
- public String getReckonColumn(String col) {
- if (this == COUNT) return this.name() + "(*)";
- if (this == DISTINCTCOUNT) return "COUNT(DISTINCT " + col + ")";
- return this.name() + "(" + col + ")";
- }
-}