This commit is contained in:
wentch
2015-12-10 14:58:48 +08:00
parent b6bc4182e9
commit 91d0224949
14 changed files with 124 additions and 307 deletions

View File

@@ -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.
* <p> Defaults to the id generator supplied by persistence provider.
*/
String generator() default "";
}

View File

@@ -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
* <code>AUTO</code> 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
}

View File

@@ -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.
* <p>
* Note that it is not necessary to specify an index for a primary key,
* as the primary key index will be created automatically.
*
* <p>
* The syntax of the <code>columnList</code> element is a
* <code>column_list</code>, as follows:
*
* <pre>
* column::= index_column [,index_column]*
* index_column::= column_name [ASC | DESC]
* </pre>
*
* <p> If <code>ASC</code> or <code>DESC</code> is not specified,
* <code>ASC</code> (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;
}

View File

@@ -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 <code>Column</code> and <code>JoinColumn</code>
* annotations and constraints entailed by primary key mappings.
* <p> 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 {};
}

View File

@@ -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.
*
* <pre>
* Example:
* &#064;Entity
* &#064;Table(
* name="EMPLOYEE",
* uniqueConstraints=
* &#064;UniqueConstraint(columnNames={"EMP_ID", "EMP_NAME"})
* )
* public class Employee { ... }
* </pre>
*
* @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();
}

View File

@@ -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 <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(Class<T> entityClass, String keyColumn, Reckon reckon, String reckonColumn) {
return source.queryColumnMap(entityClass, keyColumn, reckon, reckonColumn);
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(Class<T> entityClass, String keyColumn, FuncEnum func, String funcColumn) {
return source.queryColumnMap(entityClass, keyColumn, func, funcColumn);
}
@Override
public final <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(Class<T> entityClass, String keyColumn, Reckon reckon, String reckonColumn, FilterBean bean) {
return queryColumnMap(entityClass, keyColumn, reckon, reckonColumn, FilterNodeBean.createFilterNode(bean));
public final <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(Class<T> entityClass, String keyColumn, FuncEnum func, String funcColumn, FilterBean bean) {
return queryColumnMap(entityClass, keyColumn, func, funcColumn, FilterNodeBean.createFilterNode(bean));
}
@Override
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(Class<T> entityClass, String keyColumn, Reckon reckon, String reckonColumn, FilterNode node) {
return source.queryColumnMap(entityClass, keyColumn, reckon, reckonColumn, node);
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(Class<T> entityClass, String keyColumn, FuncEnum func, String funcColumn, FilterNode node) {
return source.queryColumnMap(entityClass, keyColumn, func, funcColumn, node);
}
@Override

View File

@@ -1066,30 +1066,30 @@ public final class DataDefaultSource implements DataSource, Nameable, Function<C
//-----------------------getNumberResult-----------------------------
@Override
public Number getNumberResult(final Class entityClass, final Reckon reckon, final String column) {
return getNumberResult(entityClass, reckon, column, (FilterNode) null);
public Number getNumberResult(final Class entityClass, final FuncEnum func, final String column) {
return getNumberResult(entityClass, func, column, (FilterNode) null);
}
@Override
public Number getNumberResult(final Class entityClass, final Reckon reckon, final String column, FilterBean bean) {
return getNumberResult(entityClass, reckon, column, FilterNodeBean.createFilterNode(bean));
public Number getNumberResult(final Class entityClass, final FuncEnum func, final String column, FilterBean bean) {
return getNumberResult(entityClass, func, column, FilterNodeBean.createFilterNode(bean));
}
@Override
public Number getNumberResult(final Class entityClass, final Reckon reckon, final String column, final FilterNode node) {
public Number getNumberResult(final Class entityClass, final FuncEnum func, final String column, final 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.getNumberResult(reckon, column, node);
return cache.getNumberResult(func, column, node);
}
}
final Map<Class, String> 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<C
//-----------------------queryColumnMap-----------------------------
@Override
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(final Class<T> entityClass, final String keyColumn, Reckon reckon, final String reckonColumn) {
return queryColumnMap(entityClass, keyColumn, reckon, reckonColumn, (FilterNode) null);
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(final Class<T> entityClass, final String keyColumn, FuncEnum func, final String funcColumn) {
return queryColumnMap(entityClass, keyColumn, func, funcColumn, (FilterNode) null);
}
@Override
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(final Class<T> entityClass, final String keyColumn, Reckon reckon, final String reckonColumn, FilterBean bean) {
return queryColumnMap(entityClass, keyColumn, reckon, reckonColumn, FilterNodeBean.createFilterNode(bean));
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(final Class<T> entityClass, final String keyColumn, FuncEnum func, final String funcColumn, FilterBean bean) {
return queryColumnMap(entityClass, keyColumn, func, funcColumn, FilterNodeBean.createFilterNode(bean));
}
@Override
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(final Class<T> entityClass, final String keyColumn, final Reckon reckon, final String reckonColumn, FilterNode node) {
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(final Class<T> 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<Class, String> 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);

View File

@@ -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 <T> void updateColumnOr(final DataConnection conn, Class<T> 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 <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(Class<T> entityClass, final String keyColumn, Reckon reckon, final String reckonColumn);
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(Class<T> entityClass, final String keyColumn, FuncEnum func, final String funcColumn);
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(Class<T> entityClass, final String keyColumn, Reckon reckon, final String reckonColumn, final FilterBean bean);
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(Class<T> entityClass, final String keyColumn, FuncEnum func, final String funcColumn, final FilterBean bean);
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(Class<T> entityClass, final String keyColumn, Reckon reckon, final String reckonColumn, final FilterNode node);
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(Class<T> entityClass, final String keyColumn, FuncEnum func, final String funcColumn, final FilterNode node);
//-----------------------find----------------------------
/**

View File

@@ -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;
/**

View File

@@ -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();
}

View File

@@ -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<T> {
return (filter != null) && this.list.stream().filter(filter).findFirst().isPresent();
}
public <K, V> Map<Serializable, Number> getMapResult(final String keyColumn, final Reckon reckon, final String reckonColumn, FilterNode node) {
public <K, V> Map<Serializable, Number> getMapResult(final String keyColumn, final FuncEnum func, final String funcColumn, FilterNode node) {
final Attribute<T, Serializable> 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<T> stream = this.list.stream();
if (filter != null) stream = stream.filter(filter);
Collector<T, Map, ?> 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<T, Map, ?>) Collectors.averagingDouble((T t) -> ((Number) reckonAttr.get(t)).doubleValue());
collector = (Collector<T, Map, ?>) Collectors.averagingDouble((T t) -> ((Number) funcAttr.get(t)).doubleValue());
} else {
collector = (Collector<T, Map, ?>) Collectors.averagingLong((T t) -> ((Number) reckonAttr.get(t)).longValue());
collector = (Collector<T, Map, ?>) Collectors.averagingLong((T t) -> ((Number) funcAttr.get(t)).longValue());
}
break;
case COUNT: collector = (Collector<T, Map, ?>) Collectors.counting();
break;
case DISTINCTCOUNT:
collector = (Collector<T, Map, ?>) Collectors.mapping((t) -> reckonAttr.get(t), Collectors.toSet());
collector = (Collector<T, Map, ?>) Collectors.mapping((t) -> funcAttr.get(t), Collectors.toSet());
break;
case MAX:
case MIN:
Comparator<T> comp = (o1, o2) -> o1 == null ? (o2 == null ? 0 : -1) : ((Comparable) reckonAttr.get(o1)).compareTo(reckonAttr.get(o2));
collector = (Collector<T, Map, ?>) ((reckon == MAX) ? Collectors.maxBy(comp) : Collectors.minBy(comp));
Comparator<T> comp = (o1, o2) -> o1 == null ? (o2 == null ? 0 : -1) : ((Comparable) funcAttr.get(o1)).compareTo(funcAttr.get(o2));
collector = (Collector<T, Map, ?>) ((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<T, Map, ?>) Collectors.summingDouble((T t) -> ((Number) reckonAttr.get(t)).doubleValue());
collector = (Collector<T, Map, ?>) Collectors.summingDouble((T t) -> ((Number) funcAttr.get(t)).doubleValue());
} else {
collector = (Collector<T, Map, ?>) Collectors.summingLong((T t) -> ((Number) reckonAttr.get(t)).longValue());
collector = (Collector<T, Map, ?>) 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<T> {
return rs;
}
public <V> Number getNumberResult(final Reckon reckon, final String column, FilterNode node) {
public <V> Number getNumberResult(final FuncEnum func, final String column, FilterNode node) {
final Attribute<T, Serializable> attr = column == null ? null : info.getAttribute(column);
final Predicate<T> filter = node == null ? null : node.createPredicate(this);
Stream<T> 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);

View File

@@ -116,7 +116,7 @@ public final class EntityInfo<T> {
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<T> {
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();

View File

@@ -5,12 +5,14 @@
*/
package org.redkale.source;
import java.util.function.*;
/**
*
* @author zhangjx
* @param <E>
*/
public interface Range<E extends Comparable> extends java.io.Serializable {
public interface Range<E extends Comparable> extends java.io.Serializable, Predicate<E> {
public E getMin();
@@ -48,10 +50,16 @@ public interface Range<E extends Comparable> 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<Short> {
@@ -86,6 +94,11 @@ public interface Range<E extends Comparable> 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<E extends Comparable> 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<E extends Comparable> 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<E extends Comparable> 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<E extends Comparable> 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<E extends Comparable> 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

View File

@@ -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 + ")";
}
}