This commit is contained in:
wentch
2016-01-04 18:11:24 +08:00
parent e75dab5cc8
commit cf333b27ff
57 changed files with 569 additions and 355 deletions

View File

@@ -39,6 +39,7 @@ public @interface Cacheable {
/**
* (Optional) Whether or not the entity should be cached.
* @return boolean
*/
boolean value() default true;
}

View File

@@ -1,4 +1,4 @@
/*******************************************************************************
/** *****************************************************************************
* Copyright (c) 2008 - 2013 Oracle Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
@@ -12,7 +12,7 @@
* Linda DeMichiel - Java Persistence 2.1
* Linda DeMichiel - Java Persistence 2.0
*
******************************************************************************/
***************************************************************************** */
package javax.persistence;
import java.lang.annotation.Target;
@@ -48,75 +48,96 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
*
*
* @since Java Persistence 1.0
*/
@Target({METHOD, FIELD})
*/
@Target({METHOD, FIELD})
@Retention(RUNTIME)
public @interface Column {
/**
* (Optional) The name of the column. Defaults to
* (Optional) The name of the column. Defaults to
* the property or field name.
*
* @return String
*/
String name() default "";
/**
* (Optional) Whether the column is a unique key. This is a
* shortcut for the <code>UniqueConstraint</code> annotation at the table
* level and is useful for when the unique key constraint
* corresponds to only a single column. This constraint applies
* in addition to any constraint entailed by primary key mapping and
* (Optional) Whether the column is a unique key. This is a
* shortcut for the <code>UniqueConstraint</code> annotation at the table
* level and is useful for when the unique key constraint
* corresponds to only a single column. This constraint applies
* in addition to any constraint entailed by primary key mapping and
* to constraints specified at the table level.
*
* @return boolean
*/
boolean unique() default false;
/**
* (Optional) Whether the database column is nullable.
*
* @return boolean
*/
boolean nullable() default true;
/**
* (Optional) Whether the column is included in SQL INSERT
* (Optional) Whether the column is included in SQL INSERT
* statements generated by the persistence provider.
*
* @return boolean
*/
boolean insertable() default true;
/**
* (Optional) Whether the column is included in SQL UPDATE
* (Optional) Whether the column is included in SQL UPDATE
* statements generated by the persistence provider.
*
* @return boolean
*/
boolean updatable() default true;
/**
* (Optional) The SQL fragment that is used when
* (Optional) The SQL fragment that is used when
* generating the DDL for the column.
* <p> Defaults to the generated SQL to create a
* <p>
* Defaults to the generated SQL to create a
* column of the inferred type.
*
* @return String
*/
String columnDefinition() default "";
/**
* (Optional) The name of the table that contains the column.
* (Optional) The name of the table that contains the column.
* If absent the column is assumed to be in the primary table.
*
* @return String
*/
String table() default "";
/**
* (Optional) The column length. (Applies only if a
* string-valued column is used.)
*
* @return int
*/
int length() default 255;
/**
* (Optional) The precision for a decimal (exact numeric)
* (Optional) The precision for a decimal (exact numeric)
* column. (Applies only if a decimal column is used.)
* Value must be set by developer if used when generating
* Value must be set by developer if used when generating
* the DDL for the column.
*
* @return int
*/
int precision() default 0;
/**
* (Optional) The scale for a decimal (exact numeric) column.
* (Optional) The scale for a decimal (exact numeric) column.
* (Applies only if a decimal column is used.)
*
* @return int
*/
int scale() default 0;
}

View File

@@ -37,6 +37,7 @@ public @interface Entity {
* name of the entity class. This name is used to refer to the
* entity in queries. The name must not be a reserved literal
* in the Java Persistence query language.
* @return String
*/
String name() default "";
}

View File

@@ -51,8 +51,6 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
* </pre>
*
* @see Id
* @see TableGenerator
* @see SequenceGenerator
*
* @since Java Persistence 1.0
*/
@@ -64,15 +62,17 @@ public @interface GeneratedValue {
* (Optional) The primary key generation strategy
* that the persistence provider must use to
* generate the annotated entity primary key.
* @return GenerationType
*/
@Deprecated
GenerationType strategy() default GenerationType.AUTO;
/**
* (Optional) The name of the primary key generator
* to use as specified in the {@link SequenceGenerator}
* or {@link TableGenerator} annotation.
* to use as specified in the SequenceGenerator
* or TableGenerator annotation.
* <p> Defaults to the id generator supplied by persistence provider.
* @return String
*/
@Deprecated
String generator() default "";

View File

@@ -22,8 +22,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* Specifies the primary table for the annotated entity. Additional
* tables may be specified using {@link SecondaryTable} or {@link
* SecondaryTables} annotation.
* tables may be specified using SecondaryTable or SecondaryTables annotation.
*
* <p> If no <code>Table</code> annotation is specified for an entity
* class, the default values apply.
@@ -45,16 +44,19 @@ public @interface Table {
/**
* (Optional) The name of the table.
* <p> Defaults to the entity name.
* @return String
*/
String name() default "";
/** (Optional) The catalog of the table.
* <p> Defaults to the default catalog.
* @return String
*/
String catalog() default "";
/** (Optional) The schema of the table.
* <p> Defaults to the default schema for user.
* @return String
*/
String schema() default "";

View File

@@ -22,7 +22,9 @@ import java.util.regex.*;
/**
* class过滤器 符合条件的class会保留下来存入FilterEntry。
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
* @param <T>
*/
@@ -70,8 +72,8 @@ public final class ClassFilter<T> {
/**
* 获取符合条件的class集合
* <p>
* @return
*
* @return Set&lt;FilterEntry&lt;T&gt;&gt;
*/
public final Set<FilterEntry<T>> getFilterEntrys() {
return entrys;
@@ -79,9 +81,9 @@ public final class ClassFilter<T> {
/**
* 自动扫描地过滤指定的class
* <p>
* @param property
* @param clazzname
*
* @param property AnyValue
* @param clazzname String
*/
@SuppressWarnings("unchecked")
public final void filter(AnyValue property, String clazzname) {
@@ -90,7 +92,7 @@ public final class ClassFilter<T> {
/**
* 过滤指定的class
* <p>
*
* @param property application.xml中对应class节点下的property属性项
* @param clazzname class名称
* @param autoscan 为true表示自动扫描的 false表示显著调用filter AutoLoad的注解将被忽略
@@ -149,10 +151,10 @@ public final class ClassFilter<T> {
/**
* 判断class是否有效
* <p>
* @param property
* @param classname
* @return
*
* @param property AnyValue
* @param classname String
* @return boolean
*/
public boolean accept(AnyValue property, String classname) {
boolean r = accept0(property, classname);
@@ -187,11 +189,11 @@ public final class ClassFilter<T> {
/**
* 判断class是否有效
* <p>
* @param property
* @param clazz
* @param autoscan
* @return
*
* @param property AnyValue
* @param clazz Class
* @param autoscan boolean
* @return boolean
*/
@SuppressWarnings("unchecked")
public boolean accept(AnyValue property, Class clazz, boolean autoscan) {
@@ -247,8 +249,8 @@ public final class ClassFilter<T> {
/**
* 存放符合条件的class与class指定的属性项
* <p>
* @param <T>
*
* @param <T> 泛型
*/
public static final class FilterEntry<T> {
@@ -330,10 +332,10 @@ public final class ClassFilter<T> {
/**
* 加载当前线程的classpath扫描所有class进行过滤
* <p>
*
* @param exclude 不需要扫描的文件夹, 可以为null
* @param filters
* @throws IOException
* @param filters 过滤器
* @throws IOException 异常
*/
public static void load(final File exclude, final ClassFilter... filters) throws IOException {
URLClassLoader loader = (URLClassLoader) Thread.currentThread().getContextClassLoader();

View File

@@ -12,7 +12,7 @@ import java.lang.reflect.Type;
*
* <p> 详情见: http://www.redkale.org
* @author zhangjx
* @param <T>
* @param <T> 序列化的泛型类型
*/
public final class AnyEncoder<T> implements Encodeable<Writer, T> {

View File

@@ -10,12 +10,14 @@ import java.util.*;
/**
* 对象数组的序列化不包含int[]、long[]这样的primitive class数组.
* 数组长度不能超过 32767。 在BSON中数组长度设定的是short对于大于32767长度的数组传输会影响性能所以没有采用int存储。
* 数组长度不能超过 32767。 在BSON中数组长度设定的是short对于大于32767长度的数组传输会影响性能所以没有采用int存储。
* 支持一定程度的泛型。
*
* <p> 详情见: http://www.redkale.org
*
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
* @param <T>
* @param <T> 反解析的数组元素类型
*/
@SuppressWarnings("unchecked")
public final class ArrayDecoder<T> implements Decodeable<Reader, T[]> {

View File

@@ -12,9 +12,11 @@ import java.lang.reflect.*;
* 数组长度不能超过 32767。 在BSON中数组长度设定的是short对于大于32767长度的数组传输会影响性能所以没有必要采用int存储。
* 支持一定程度的泛型。
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
* @param <T>
* @param <T> 序列化的数组元素类型
*/
@SuppressWarnings("unchecked")
public final class ArrayEncoder<T> implements Encodeable<Writer, T[]> {

View File

@@ -12,12 +12,14 @@ import java.util.Collection;
/**
* 对象集合的反序列化.
* 集合大小不能超过 32767。 在BSON中集合大小设定的是short对于大于32767长度的集合传输会影响性能所以没有采用int存储。
* 集合大小不能超过 32767。 在BSON中集合大小设定的是short对于大于32767长度的集合传输会影响性能所以没有采用int存储。
* 支持一定程度的泛型。
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
* @param <T>
* @param <T> 反解析的集合元素类型
*/
@SuppressWarnings("unchecked")
public final class CollectionDecoder<T> implements Decodeable<Reader, Collection<T>> {

View File

@@ -15,7 +15,7 @@ import java.util.Collection;
*
* <p> 详情见: http://www.redkale.org
* @author zhangjx
* @param <T>
* @param <T> 序列化的集合元素类型
*/
@SuppressWarnings("unchecked")
public final class CollectionEncoder<T> implements Encodeable<Writer, Collection<T>> {

View File

@@ -8,10 +8,12 @@ package org.redkale.convert;
/**
* 序列化操作类
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
* @param <R>
* @param <W>
* @param <R> Reader输入的子类
* @param <W> Writer输出的子类
*/
public abstract class Convert<R extends Reader, W extends Writer> {

View File

@@ -12,7 +12,9 @@ import static java.lang.annotation.RetentionPolicy.*;
/**
* 依附在setter、getter方法、字段进行简单的配置
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
*/
@Inherited
@@ -25,21 +27,21 @@ public @interface ConvertColumn {
/**
* 给字段取个别名, 只对JSON有效
*
* @return
* @return 字段别名
*/
String name() default "";
/**
* 解析/序列化时是否屏蔽该字段
*
* @return
* @return 是否屏蔽该字段
*/
boolean ignore() default false;
/**
* 解析/序列化定制化的TYPE
*
* @return
* @return JSON or BSON or ALL
*/
ConvertType type() default ConvertType.ALL;
}

View File

@@ -9,11 +9,13 @@ import org.redkale.util.Attribute;
/**
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
* @param <R>
* @param <T>
* @param <F>
* @param <R> Reader输入的子类
* @param <T> 字段依附的类
* @param <F> 字段的数据类型
*/
@SuppressWarnings("unchecked")
public final class DeMember<R extends Reader, T, F> implements Comparable<DeMember<R, T, F>> {

View File

@@ -9,10 +9,12 @@ import java.lang.reflect.Type;
/**
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
* @param <R>
* @param <T>
* @param <R> Reader输入的子类
* @param <T> 反解析的数据类型
*/
public interface Decodeable<R extends Reader, T> {
@@ -21,7 +23,7 @@ public interface Decodeable<R extends Reader, T> {
/**
* 泛型映射接口
*
* @return
* @return 反解析的数据类型
*/
public Type getType();

View File

@@ -9,11 +9,13 @@ import org.redkale.util.Attribute;
/**
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
* @param <W>
* @param <T>
* @param <F>
* @param <W> Writer输出的子类
* @param <T> 字段依附的类
* @param <F> 字段的数据类型
*/
@SuppressWarnings("unchecked")
public final class EnMember<W extends Writer, T, F> implements Comparable<EnMember<W, T, F>> {

View File

@@ -9,10 +9,12 @@ import java.lang.reflect.Type;
/**
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
* @param <W>
* @param <T>
* @param <W> Writer输出的子类
* @param <T> 序列化的数据类型
*/
public interface Encodeable<W extends Writer, T> {

View File

@@ -21,10 +21,12 @@ import org.redkale.util.*;
/**
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
* @param <R>
* @param <W>
* @param <R> Reader输入的子类
* @param <W> Writer输出的子类
*/
@SuppressWarnings("unchecked")
public abstract class Factory<R extends Reader, W extends Writer> {
@@ -168,8 +170,8 @@ public abstract class Factory<R extends Reader, W extends Writer> {
/**
* 使所有类的所有被声明为ConvertColumn.ignore = true 的字段或方法变为ConvertColumn.ignore = false
* <p>
* @param skipIgnore
*
* @param skipIgnore 是否忽略Ignore注解
*/
public final void registerSkipAllIgnore(final boolean skipIgnore) {
this.skipAllIgnore = skipIgnore;
@@ -177,8 +179,8 @@ public abstract class Factory<R extends Reader, W extends Writer> {
/**
* 使该类所有被声明为ConvertColumn.ignore = true 的字段或方法变为ConvertColumn.ignore = false
* <p>
* @param type
*
* @param type 指定的类
*/
public final void registerSkipIgnore(final Class type) {
skipIgnores.add(type);

View File

@@ -14,8 +14,8 @@ import java.util.Map;
*
* <p> 详情见: http://www.redkale.org
* @author zhangjx
* @param <K>
* @param <V>
* @param <K> Map key的数据类型
* @param <V> Map value的数据类型
*/
@SuppressWarnings("unchecked")
public final class MapDecoder<K, V> implements Decodeable<Reader, Map<K, V>> {

View File

@@ -11,10 +11,12 @@ import java.util.Map;
/**
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
* @param <K>
* @param <V>
* @param <K> Map key的数据类型
* @param <V> Map value的数据类型
*/
@SuppressWarnings("unchecked")
public final class MapEncoder<K, V> implements Encodeable<Writer, Map<K, V>> {

View File

@@ -17,8 +17,8 @@ import org.redkale.util.*;
*
* <p> 详情见: http://www.redkale.org
* @author zhangjx
* @param <R>
* @param <T>
* @param <R> Reader输入的子类
* @param <T> 反解析的数据类型
*/
@SuppressWarnings("unchecked")
public final class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T> {
@@ -159,8 +159,8 @@ public final class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T
/**
* 对象格式: [0x1][short字段个数][字段名][字段值]...[0x2]
*
* @param in
* @return
* @param in 输入流
* @return 反解析后的对象结果
*/
@Override
public final T convertFrom(final R in) {

View File

@@ -14,8 +14,8 @@ import org.redkale.util.*;
*
* <p> 详情见: http://www.redkale.org
* @author zhangjx
* @param <W>
* @param <T>
* @param <W> Writer输出的子类
* @param <T> 序列化的数据类型
*/
@SuppressWarnings("unchecked")
public final class ObjectEncoder<W extends Writer, T> implements Encodeable<W, T> {

View File

@@ -9,7 +9,9 @@ import java.util.concurrent.atomic.AtomicInteger;
/**
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
*/
public interface Reader {
@@ -21,7 +23,7 @@ public interface Reader {
/**
* 是否还存在下个元素或字段
*
* @return
* @return 是否还存在下个元素或字段
*/
public boolean hasNext();
@@ -38,7 +40,7 @@ public interface Reader {
/**
* 读取对象的开头 返回字段数
*
* @return
* @return 返回字段数
*/
public int readObjectB();
@@ -51,7 +53,7 @@ public interface Reader {
/**
* 读取数组的开头并返回数组的长度
*
* @return
* @return 返回数组的长度
*/
public int readArrayB();
@@ -64,7 +66,7 @@ public interface Reader {
/**
* 读取map的开头并返回map的size
*
* @return
* @return 返回map的size
*/
public int readMapB();
@@ -77,37 +79,87 @@ public interface Reader {
/**
* 根据字段读取字段对应的DeMember
*
* @param index
* @param members
* @return
* @param index 当前members的游标位置
* @param members DeMember的全量集合
* @return 匹配的DeMember
*/
public DeMember readField(final AtomicInteger index, final DeMember[] members);
/**
* 读取一个boolean值
*
* @return boolean值
*/
public boolean readBoolean();
/**
* 读取一个byte值
*
* @return byte值
*/
public byte readByte();
/**
* 读取一个char值
*
* @return char值
*/
public char readChar();
/**
* 读取一个short值
*
* @return short值
*/
public short readShort();
/**
* 读取一个int值
*
* @return int值
*/
public int readInt();
/**
* 读取一个long值
*
* @return long值
*/
public long readLong();
/**
* 读取一个float值
*
* @return float值
*/
public float readFloat();
/**
* 读取一个double值
*
* @return double值
*/
public double readDouble();
/**
* 读取无转义字符长度不超过255的字符串 例如枚举值、字段名、类名字符串等
*
* @return
* @return String值
*/
public String readSmallString();
/**
* 读取反解析对象的类名
*
* @return 类名
*/
public String readClassName();
/**
* 读取一个String值
*
* @return String值
*/
public String readString();
}

View File

@@ -10,11 +10,13 @@ import java.lang.reflect.Type;
/**
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
* @param <R>
* @param <W>
* @param <T>
* @param <R> Reader输入的子类
* @param <W> Writer输出的子类
* @param <T> 序列化/反解析的数据类型
*/
public abstract class SimpledCoder<R extends Reader, W extends Writer, T> implements Decodeable<R, T>, Encodeable<W, T> {

View File

@@ -9,15 +9,17 @@ import org.redkale.util.Attribute;
/**
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
*/
public interface Writer {
/**
* 当tiny=true时 字符串为空、boolean为false的字段值都会被跳过 不会输出。
* <p>
* @return
*
* @return 是否简化
*/
public boolean isTiny();
@@ -27,8 +29,9 @@ public interface Writer {
public void writeNull();
/**
* 写入类名
*
* @param clazz
* @param clazz 类名
*/
public void wirteClassName(String clazz);
@@ -37,14 +40,14 @@ public interface Writer {
*
* @param fieldCount 字段个数
*
* @param obj
* @param obj 写入的对象
*/
public void writeObjectB(int fieldCount, Object obj);
/**
* 输出一个对象后的操作
*
* @param obj
* @param obj 写入的对象
*/
public void writeObjectE(Object obj);
@@ -90,32 +93,77 @@ public interface Writer {
* 输出一个字段
*
* @param comma 是否非第一个字段
* @param attribute
* @param attribute 字段的Attribute对象
*/
public void writeField(boolean comma, Attribute attribute);
/**
* 写入一个boolean值
*
* @param value boolean值
*/
public void writeBoolean(boolean value);
/**
* 写入一个byte值
*
* @param value byte值
*/
public void writeByte(byte value);
/**
* 写入一个char值
*
* @param value char值
*/
public void writeChar(char value);
/**
* 写入一个short值
*
* @param value short值
*/
public void writeShort(short value);
/**
* 写入一个int值
*
* @param value int值
*/
public void writeInt(int value);
/**
* 写入一个long值
*
* @param value long值
*/
public void writeLong(long value);
/**
* 写入一个float值
*
* @param value float值
*/
public void writeFloat(float value);
/**
* 写入一个double值
*
* @param value double值
*/
public void writeDouble(double value);
/**
* 写入无转义字符长度不超过255的字符串 例如枚举值、字段名、类名字符串等 *
*
* @param value
* @param value 非空且不含需要转义的字符的String值
*/
public void writeSmallString(String value);
/**
* 写入一个String值
*
* @param value String值
*/
public void writeString(String value);
}

View File

@@ -44,7 +44,7 @@ public final class BsonByteBufferReader extends BsonReader {
/**
* 判断下一个非空白字节是否为[
*
* @return
* @return 数组长度或 SIGN_NULL
*/
@Override
public int readArrayB() {

View File

@@ -12,6 +12,7 @@ import org.redkale.convert.*;
import org.redkale.util.*;
/**
* <blockquote><pre>
* BSON协议格式:
* 1). 基本数据类型: 直接转换成byte[]
* 2). SmallString(无特殊字符且长度小于256的字符串): length(1 byte) + byte[](utf8); 通常用于类名、字段名、枚举。
@@ -23,13 +24,16 @@ import org.redkale.util.*;
* 3. SIGN_OBJECTB 标记位值固定为0xBB (short)
* 4. 循环字段值:
* 4.1 SIGN_HASNEXT 标记位值固定为1 (byte)
* 4.2 字段类型; 1-9为基本类型&字符串; 101-109为基本类型&字符串的数组; 127为Object
* 4.2 字段类型; 1-9为基本类型字符串; 101-109为基本类型字符串的数组; 127为Object
* 4.3 字段名 (SmallString)
* 4.4 字段的值Object
* 5. SIGN_NONEXT 标记位值固定为0 (byte)
* 6. SIGN_OBJECTE 标记位值固定为0xEE (short)
*
* <p> 详情见: http://www.redkale.org
* </pre></blockquote>
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
*/
public final class BsonConvert extends Convert<BsonReader, BsonWriter> {

View File

@@ -14,7 +14,9 @@ import org.redkale.util.*;
/**
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
*/
public class BsonReader implements Reader {
@@ -193,7 +195,7 @@ public class BsonReader implements Reader {
/**
* 判断下一个非空白字节是否为[
*
* @return
* @return 数组长度或SIGN_NULL
*/
@Override
public int readArrayB() {
@@ -216,7 +218,7 @@ public class BsonReader implements Reader {
/**
* 判断对象是否存在下一个属性或者数组是否存在下一个元素
*
* @return
* @return 是否存在
*/
@Override
public final boolean hasNext() {

View File

@@ -9,9 +9,11 @@ import org.redkale.convert.SimpledCoder;
/**
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
* @param <T>
* @param <T> 序列化/反解析的数据类型
*/
public abstract class BsonSimpledCoder<T> extends SimpledCoder<BsonReader, BsonWriter, T> {

View File

@@ -79,8 +79,8 @@ public class BsonWriter implements Writer {
/**
* 扩充指定长度的缓冲区
*
* @param len
* @return
* @param len 扩容长度
* @return 固定0
*/
protected int expand(int len) {
int newcount = count + len;
@@ -231,7 +231,7 @@ public class BsonWriter implements Writer {
/**
* 对于类的字段名、枚举值这些长度一般不超过255且不会出现双字节字符的字符串采用writeSmallString处理, readSmallString用于读取
*
* @param value
* @param value String值
*/
@Override
public final void writeSmallString(String value) {

View File

@@ -57,7 +57,7 @@ public class JsonByteBufferReader extends JsonReader {
/**
* 读取下一个字符, 不跳过空白字符
*
* @return
* @return 有效字符或空白字符
*/
@Override
protected char nextChar() {
@@ -80,6 +80,11 @@ public class JsonByteBufferReader extends JsonReader {
}
}
/**
* 读取下一个有效字符
*
* @return 有效字符
*/
@Override
protected char nextGoodChar() {
char c = nextChar();
@@ -93,7 +98,7 @@ public class JsonByteBufferReader extends JsonReader {
/**
* 回退最后读取的字符
*
* @param ch
* @param ch 回退的字符
*/
@Override
protected void backChar(char ch) {
@@ -103,6 +108,7 @@ public class JsonByteBufferReader extends JsonReader {
/**
* 判断下一个非空白字符是否为{
*
* @return SIGN_NOLENGTH 或 SIGN_NULL
*/
@Override
public int readObjectB() {
@@ -116,7 +122,7 @@ public class JsonByteBufferReader extends JsonReader {
/**
* 判断下一个非空白字符是否为[
*
* @return
* @return SIGN_NOLENGTH 或 SIGN_NULL
*/
@Override
public int readArrayB() {
@@ -140,7 +146,7 @@ public class JsonByteBufferReader extends JsonReader {
/**
* 判断对象是否存在下一个属性或者数组是否存在下一个元素
*
* @return
* @return 是否存在
*/
@Override
public boolean hasNext() {
@@ -151,6 +157,11 @@ public class JsonByteBufferReader extends JsonReader {
return true;
}
/**
* 读取小字符串
*
* @return String值
*/
@Override
public String readSmallString() {
char ch = nextGoodChar();
@@ -243,9 +254,9 @@ public class JsonByteBufferReader extends JsonReader {
}
/**
* 读取一个int
* 读取一个int
*
* @return
* @return int值
*/
@Override
public int readInt() {
@@ -277,9 +288,9 @@ public class JsonByteBufferReader extends JsonReader {
}
/**
* 读取一个long
* 读取一个long
*
* @return
* @return long值
*/
@Override
public long readLong() {
@@ -313,7 +324,7 @@ public class JsonByteBufferReader extends JsonReader {
/**
* 读取字符串, 必须是"或者'包围的字符串值
*
* @return
* @return String值
*/
@Override
public String readString() {

View File

@@ -235,8 +235,8 @@ public final class JsonByteBufferWriter extends JsonWriter {
/**
* <b>注意:</b> 该String值不能为null且不会进行转义 只用于不含需要转义字符的字符串例如enum、double、BigInteger转换的String
*
* @param quote
* @param value
* @param quote 是否写入双引号
* @param value String值
*/
@Override
public void writeTo(final boolean quote, final String value) {

View File

@@ -13,7 +13,9 @@ import org.redkale.util.*;
/**
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
*/
public class JsonReader implements Reader {
@@ -83,7 +85,7 @@ public class JsonReader implements Reader {
/**
* 找到指定的属性值 例如: {id : 1, data : { name : 'a', items : [1,2,3]}} seek('data.items') 直接跳转到 [1,2,3];
*
* @param key
* @param key 指定的属性名
*/
public final void seek(String key) {
if (key == null || key.length() < 1) return;
@@ -135,7 +137,7 @@ public class JsonReader implements Reader {
/**
* 读取下一个字符, 不跳过空白字符
*
* @return
* @return 空白字符或有效字符
*/
protected char nextChar() {
return this.text[++this.position];
@@ -144,7 +146,7 @@ public class JsonReader implements Reader {
/**
* 跳过空白字符, 返回一个非空白字符
*
* @return
* @return 有效字符
*/
protected char nextGoodChar() {
char c = nextChar();
@@ -158,7 +160,7 @@ public class JsonReader implements Reader {
/**
* 回退最后读取的字符
*
* @param ch
* @param ch 后退的字符
*/
protected void backChar(char ch) {
this.position--;
@@ -167,6 +169,7 @@ public class JsonReader implements Reader {
/**
* 判断下一个非空白字符是否为{
*
* @return SIGN_NOLENGTH 或 SIGN_NULL
*/
@Override
public int readObjectB() {
@@ -191,6 +194,7 @@ public class JsonReader implements Reader {
/**
* 判断下一个非空白字符是否为{
*
* @return SIGN_NOLENGTH 或 SIGN_NULL
*/
@Override
public final int readMapB() {
@@ -204,7 +208,7 @@ public class JsonReader implements Reader {
/**
* 判断下一个非空白字符是否为[
*
* @return
* @return SIGN_NOLENGTH 或 SIGN_NULL
*/
@Override
public int readArrayB() {
@@ -248,7 +252,7 @@ public class JsonReader implements Reader {
/**
* 判断对象是否存在下一个属性或者数组是否存在下一个元素
*
* @return
* @return 是否存在
*/
@Override
public boolean hasNext() {
@@ -320,9 +324,9 @@ public class JsonReader implements Reader {
}
/**
* 读取一个int
* 读取一个int
*
* @return
* @return int值
*/
@Override
public int readInt() {
@@ -366,9 +370,9 @@ public class JsonReader implements Reader {
}
/**
* 读取一个long
* 读取一个long
*
* @return
* @return long值
*/
@Override
public long readLong() {
@@ -474,7 +478,7 @@ public class JsonReader implements Reader {
/**
* 读取字符串, 必须是"或者'包围的字符串值
*
* @return
* @return String值
*/
@Override
public String readString() {

View File

@@ -9,9 +9,11 @@ import org.redkale.convert.SimpledCoder;
/**
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
* @param <T>
* @param <T> 序列化/反解析的数据类型
*/
public abstract class JsonSimpledCoder<T> extends SimpledCoder<JsonReader, JsonWriter, T> {

View File

@@ -14,7 +14,9 @@ import org.redkale.util.*;
*
* writeTo系列的方法输出的字符不能含特殊字符
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
*/
public class JsonWriter implements Writer {
@@ -96,8 +98,8 @@ public class JsonWriter implements Writer {
/**
* <b>注意:</b> 该String值不能为null且不会进行转义 只用于不含需要转义字符的字符串例如enum、double、BigInteger转换的String
*
* @param quote
* @param value
* @param quote 是否加双引号
* @param value 非null且不含需要转义的字符的String值
*/
public void writeTo(final boolean quote, final String value) {
int len = value.length();

View File

@@ -14,7 +14,9 @@ import java.util.concurrent.*;
/**
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
*/
public abstract class AsyncConnection implements AsynchronousByteChannel, AutoCloseable {
@@ -89,13 +91,13 @@ public abstract class AsyncConnection implements AsynchronousByteChannel, AutoCl
/**
* 创建客户端连接
*
* @param protocol
* @param address
* @param group
* @param readTimeoutSecond0
* @param writeTimeoutSecond0
* @return
* @throws java.io.IOException
* @param protocol 连接类型 只能是TCP或UDP
* @param address 连接点子
* @param group 连接AsynchronousChannelGroup
* @param readTimeoutSecond0 读取超时秒数
* @param writeTimeoutSecond0 写入超时秒数
* @return 连接
* @throws java.io.IOException 异常
*/
public static AsyncConnection create(final String protocol, final AsynchronousChannelGroup group, final SocketAddress address,
final int readTimeoutSecond0, final int writeTimeoutSecond0) throws IOException {
@@ -428,8 +430,8 @@ public abstract class AsyncConnection implements AsynchronousByteChannel, AutoCl
/**
* 通常用于 ssl socket
*
* @param socket
* @return
* @param socket Socket对象
* @return 连接对象
*/
public static AsyncConnection create(final Socket socket) {
return create(socket, null, 0, 0);

View File

@@ -15,8 +15,8 @@ import java.util.logging.*;
*
* <p> 详情见: http://www.redkale.org
* @author zhangjx
* @param <R>
* @param <P>
* @param <R> Request的子类型
* @param <P> Response的子类型
*/
public abstract class PrepareServlet<R extends Request, P extends Response<R>> extends Servlet<R, P> {

View File

@@ -12,7 +12,9 @@ import org.redkale.convert.json.*;
/**
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
*/
public abstract class Request {
@@ -44,18 +46,18 @@ public abstract class Request {
}
/**
* 返回值Integer.MIN_VALUE: 帧数据; -1数据不合法 0解析完毕 >0: 需再读取的字节数。
* 返回值Integer.MIN_VALUE: 帧数据; -1数据不合法 0解析完毕 &gt;0: 需再读取的字节数。
*
* @param buffer
* @return
* @param buffer ByteBuffer对象
* @return 缺少的字节数
*/
protected abstract int readHeader(ByteBuffer buffer);
/**
* 读取buffer并返回读取的有效数据长度
*
* @param buffer
* @return
* @param buffer ByteBuffer对象
* @return 有效数据长度
*/
protected abstract int readBody(ByteBuffer buffer);

View File

@@ -10,9 +10,11 @@ import java.nio.channels.*;
/**
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
* @param <R>
* @param <R> Request的子类型
*/
@SuppressWarnings("unchecked")
public abstract class Response<R extends Request> {

View File

@@ -10,10 +10,12 @@ import java.io.IOException;
/**
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
* @param <R>
* @param <P>
* @param <R> Request的子类型
* @param <P> Response的子类型
*/
public abstract class Servlet<R extends Request, P extends Response<R>> {

View File

@@ -22,16 +22,20 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
/**
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
*/
public abstract class BasedHttpServlet extends HttpServlet {
/**
* 配合 BasedHttpServlet 使用。
* 当标记为 @AuthIgnore 的方法不会再调用之前调用authenticate 方法。
* 当标记为 &#64;AuthIgnore 的方法不会再调用之前调用authenticate 方法。
*
* <p>
* 详情见: http://www.redkale.org
*
* <p> 详情见: http://www.redkale.org
* @author zhangjx
*/
@Inherited
@@ -44,9 +48,11 @@ public abstract class BasedHttpServlet extends HttpServlet {
/**
* 配合 BasedHttpServlet 使用。
* 用于对@WebServlet对应的url进行细分。 其 url
* 用于对&#64;WebServlet对应的url进行细分。 其 url
*
* <p>
* 详情见: http://www.redkale.org
*
* <p> 详情见: http://www.redkale.org
* @author zhangjx
*/
@Target({ElementType.METHOD})
@@ -61,10 +67,12 @@ public abstract class BasedHttpServlet extends HttpServlet {
/**
* 配合 BasedHttpServlet 使用。
* 当标记为 @HttpCacheable 的方法使用response.finish的参数将被缓存一定时间(默认值timeout=15秒)。
* 通常情况下 @HttpCacheable 需要与 @AuthIgnore 一起使用,因为没有标记@AuthIgnore的方法一般输出的结果与当前用户信息有关。
* 当标记为 &#64;HttpCacheable 的方法使用response.finish的参数将被缓存一定时间(默认值timeout=15秒)。
* 通常情况下 &#64;HttpCacheable 需要与 &#64;AuthIgnore 一起使用,因为没有标记&#64;AuthIgnore的方法一般输出的结果与当前用户信息有关。
*
* <p>
* 详情见: http://www.redkale.org
*
* <p> 详情见: http://www.redkale.org
* @author zhangjx
*/
@Target({ElementType.METHOD})
@@ -75,7 +83,7 @@ public abstract class BasedHttpServlet extends HttpServlet {
/**
* 超时的秒数
*
* @return
* @return 超时秒数
*/
int timeout() default 15;
}

View File

@@ -379,7 +379,7 @@ public class HttpRequest extends Request {
/**
* 截取getRequestURI最后的一个/后面的部分
*
* @return
* @return String
*/
public String getRequstURILastPath() {
if (requestURI == null) return "";
@@ -390,8 +390,8 @@ public class HttpRequest extends Request {
*
* 从prefix之后截取getRequestURI再对"/"进行分隔
* <p>
* @param prefix
* @return
* @param prefix 前缀
* @return String[]
*/
public String[] getRequstURIPaths(String prefix) {
if (requestURI == null || prefix == null) return new String[0];

View File

@@ -24,10 +24,12 @@ import org.redkale.util.*;
* 同时提供发送json的系列接口: public void finishJson(Type type, Object obj)
* RedKale提倡http+json的接口风格 所以主要输出的数据格式为json 同时提供异步接口。
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
*
* @param <R>
* @param <R> HttpRequest的子类型
*/
public class HttpResponse<R extends HttpRequest> extends Response<R> {

View File

@@ -57,8 +57,8 @@ public final class MultiPart {
* 将文件流读进bytes 如果超出max指定的值则返回null
*
* @param max 最大长度限制
* @return
* @throws IOException
* @return 内容
* @throws IOException 异常
*/
public byte[] getContentBytes(long max) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -73,9 +73,9 @@ public final class MultiPart {
* 将文件流写进out 如果超出max指定的值则中断并返回false
*
* @param max 最大长度限制
* @param out
* @return
* @throws IOException
* @param out 输出流
* @return 是否成功
* @throws IOException 异常
*/
public boolean save(long max, OutputStream out) throws IOException {
byte[] bytes = new byte[4096];

View File

@@ -33,9 +33,8 @@ import org.redkale.net.*;
* 此模式下 以上方法都应该被重载。
* </pre></blockquote>
* <p>
* 详情见: http://www.redkale.org
*
*
* <p> 详情见: http://www.redkale.org
* @author zhangjx
*/
public abstract class WebSocket {
@@ -84,9 +83,9 @@ public abstract class WebSocket {
//----------------------------------------------------------------
/**
* 发送消息体, 包含二进制/文本
* <p>
* @param packet
* @return
*
* @param packet WebSocketPacket
* @return 0表示成功 非0表示错误码
*/
public final int send(WebSocketPacket packet) {
int rs = RETCODE_WSOCKET_CLOSED;
@@ -104,9 +103,9 @@ public abstract class WebSocket {
/**
* 发送单一的文本消息
* <p>
*
* @param text 不可为空
* @return
* @return 0表示成功 非0表示错误码
*/
public final int send(String text) {
return send(text, true);
@@ -114,10 +113,10 @@ public abstract class WebSocket {
/**
* 发送文本消息
* <p>
*
* @param text 不可为空
* @param last 是否最后一条
* @return
* @return 0表示成功 非0表示错误码
*/
public final int send(String text, boolean last) {
return send(new WebSocketPacket(text, last));
@@ -125,9 +124,9 @@ public abstract class WebSocket {
/**
* 发送单一的二进制消息
* <p>
* @param data
* @return
*
* @param data byte[]
* @return 0表示成功 非0表示错误码
*/
public final int send(byte[] data) {
return send(data, true);
@@ -152,10 +151,10 @@ public abstract class WebSocket {
/**
* 发送二进制消息
* <p>
*
* @param data 不可为空
* @param last 是否最后一条
* @return
* @return 0表示成功 非0表示错误码
*/
public final int send(byte[] data, boolean last) {
return send(new WebSocketPacket(data, last));
@@ -163,10 +162,10 @@ public abstract class WebSocket {
/**
* 发送消息, 消息类型是String或byte[]
* <p>
*
* @param message 不可为空, 只能是String或者byte[]
* @param last 是否最后一条
* @return
* @return 0表示成功 非0表示错误码
*/
public final int send(Serializable message, boolean last) {
return send(new WebSocketPacket(message, last));
@@ -175,8 +174,8 @@ public abstract class WebSocket {
//----------------------------------------------------------------
/**
* 给指定groupid的WebSocketGroup下所有WebSocket节点发送文本消息
* <p>
* @param groupid
*
* @param groupid groupid
* @param text 不可为空
* @return 为0表示成功 其他值表示异常
*/
@@ -186,8 +185,8 @@ public abstract class WebSocket {
/**
* 给指定groupid的WebSocketGroup下所有WebSocket节点发送二进制消息
* <p>
* @param groupid
*
* @param groupid groupid
* @param data 不可为空
* @return 为0表示成功 其他值表示异常
*/
@@ -197,10 +196,10 @@ public abstract class WebSocket {
/**
* 给指定groupid的WebSocketGroup下所有WebSocket节点发送文本消息
* <p>
* @param groupid
*
* @param groupid groupid
* @param text 不可为空
* @param last
* @param last 是否最后一条
* @return 为0表示成功 其他值表示异常
*/
public final int sendEachMessage(Serializable groupid, String text, boolean last) {
@@ -209,8 +208,8 @@ public abstract class WebSocket {
/**
* 给指定groupid的WebSocketGroup下所有WebSocket节点发送二进制消息
* <p>
* @param groupid
*
* @param groupid groupid
* @param data 不可为空
* @param last 是否最后一条
* @return 为0表示成功 其他值表示异常
@@ -221,8 +220,8 @@ public abstract class WebSocket {
/**
* 给指定groupid的WebSocketGroup下最近活跃的WebSocket节点发送文本消息
* <p>
* @param groupid
*
* @param groupid groupid
* @param text 不可为空
* @return 为0表示成功 其他值表示异常
*/
@@ -232,8 +231,8 @@ public abstract class WebSocket {
/**
* 给指定groupid的WebSocketGroup下最近活跃的WebSocket节点发送二进制消息
* <p>
* @param groupid
*
* @param groupid groupid
* @param data 不可为空
* @return 为0表示成功 其他值表示异常
*/
@@ -243,8 +242,8 @@ public abstract class WebSocket {
/**
* 给指定groupid的WebSocketGroup下最近活跃的WebSocket节点发送文本消息
* <p>
* @param groupid
*
* @param groupid groupid
* @param text 不可为空
* @param last 是否最后一条
* @return 为0表示成功 其他值表示异常
@@ -255,8 +254,8 @@ public abstract class WebSocket {
/**
* 给指定groupid的WebSocketGroup下最近活跃的WebSocket节点发送二进制消息
* <p>
* @param groupid
*
* @param groupid groupid
* @param data 不可为空
* @param last 是否最后一条
* @return 为0表示成功 其他值表示异常
@@ -282,8 +281,8 @@ public abstract class WebSocket {
/**
* 获取在线用户的节点地址列表
*
* @param groupid
* @return
* @param groupid groupid
* @return 地址列表
*/
protected final Collection<InetSocketAddress> getOnlineNodes(Serializable groupid) {
return _engine.node.getOnlineNodes(groupid);
@@ -292,8 +291,8 @@ public abstract class WebSocket {
/**
* 获取在线用户的详细连接信息
*
* @param groupid
* @return
* @param groupid groupid
* @return 地址集合
*/
protected final Map<InetSocketAddress, List<String>> getOnlineRemoteAddress(Serializable groupid) {
return _engine.node.getOnlineRemoteAddress(groupid);
@@ -301,10 +300,10 @@ public abstract class WebSocket {
/**
* 获取当前WebSocket下的属性
* <p>
* @param <T>
* @param name
* @return
*
* @param <T> 属性值的类型
* @param name 属性名
* @return 属性值
*/
@SuppressWarnings("unchecked")
public final <T> T getAttribute(String name) {
@@ -313,10 +312,10 @@ public abstract class WebSocket {
/**
* 移出当前WebSocket下的属性
* <p>
* @param <T>
* @param name
* @return
*
* @param <T> 属性值的类型
* @param name 属性名
* @return 属性值
*/
public final <T> T removeAttribute(String name) {
return (T) attributes.remove(name);
@@ -324,9 +323,9 @@ public abstract class WebSocket {
/**
* 给当前WebSocket下的增加属性
* <p>
* @param name
* @param value
*
* @param name 属性值
* @param value 属性值
*/
public final void setAttribute(String name, Object value) {
attributes.put(name, value);
@@ -334,8 +333,8 @@ public abstract class WebSocket {
/**
* 获取当前WebSocket所属的groupid
* <p>
* @return
*
* @return groupid
*/
public final Serializable getGroupid() {
return _groupid;
@@ -343,8 +342,8 @@ public abstract class WebSocket {
/**
* 获取当前WebSocket的会话ID 不会为null
* <p>
* @return
*
* @return sessionid
*/
public final Serializable getSessionid() {
return _sessionid;
@@ -353,7 +352,7 @@ public abstract class WebSocket {
/**
* 获取客户端直接地址, 当WebSocket连接是由代理服务器转发的则该值固定为代理服务器的IP地址
*
* @return
* @return SocketAddress
*/
public final SocketAddress getRemoteAddress() {
return _remoteAddress;
@@ -362,7 +361,7 @@ public abstract class WebSocket {
/**
* 获取客户端真实地址
*
* @return
* @return String
*/
public final String getRemoteAddr() {
return _remoteAddr;
@@ -371,8 +370,8 @@ public abstract class WebSocket {
//-------------------------------------------------------------------
/**
* 获取当前WebSocket所属的WebSocketGroup 不会为null
* <p>
* @return
*
* @return WebSocketGroup
*/
protected final WebSocketGroup getWebSocketGroup() {
return _group;
@@ -380,9 +379,9 @@ public abstract class WebSocket {
/**
* 获取指定groupid的WebSocketGroup, 没有返回null
* <p>
* @param groupid
* @return
*
* @param groupid groupid
* @return WebSocketGroup
*/
protected final WebSocketGroup getWebSocketGroup(Serializable groupid) {
return _engine.getWebSocketGroup(groupid);
@@ -396,8 +395,8 @@ public abstract class WebSocket {
/**
* 返回sessionid, null表示连接不合法或异常
*
* @param request
* @return
* @param request HttpRequest
* @return sessionid
*/
public Serializable onOpen(final HttpRequest request) {
return request.getSessionid(false);
@@ -406,13 +405,13 @@ public abstract class WebSocket {
/**
* 创建groupid null表示异常
*
* @return
* @return groupid
*/
protected abstract Serializable createGroupid();
/**
*
* @param channel
* @param channel 请求连接
*/
public void onRead(AsyncConnection channel) {
}

View File

@@ -12,7 +12,9 @@ import java.util.stream.Stream;
/**
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
*/
public final class WebSocketGroup {
@@ -61,8 +63,8 @@ public final class WebSocketGroup {
/**
* 最近发送消息的WebSocket
* <p>
* @return
*
* @return WebSocket
*/
public final WebSocket getRecentWebSocket() {
return recentWebSocket;

View File

@@ -18,7 +18,9 @@ import org.redkale.util.*;
/**
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
*/
public abstract class WebSocketNode {
@@ -77,8 +79,8 @@ public abstract class WebSocketNode {
/**
* 获取在线用户的节点地址列表
*
* @param groupid
* @return
* @param groupid groupid
* @return 地址列表
*/
public Collection<InetSocketAddress> getOnlineNodes(final Serializable groupid) {
return source.getCollection(groupid);
@@ -87,8 +89,8 @@ public abstract class WebSocketNode {
/**
* 获取在线用户的详细连接信息
*
* @param groupid
* @return
* @param groupid groupid
* @return 地址集合
*/
public Map<InetSocketAddress, List<String>> getOnlineRemoteAddress(final Serializable groupid) {
Collection<InetSocketAddress> nodes = getOnlineNodes(groupid);

View File

@@ -811,7 +811,7 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
}
/**
* 根据主键值给对象的column对应的值 & andvalue 必须是Entity Class
* 根据主键值给对象的column对应的值 &#38; andvalue 必须是Entity Class
*
* @param <T>
* @param clazz

View File

@@ -9,8 +9,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
import jdk.internal.org.objectweb.asm.*;
/**
* 该类实现动态映射一个JavaBean类中成员对应的getter、setter方法 代替低效的反射实现方式。 <br>
* <p>
* 该类实现动态映射一个JavaBean类中成员对应的getter、setter方法 代替低效的反射实现方式。
* <blockquote><pre>
* public class Record {
*
@@ -66,31 +65,33 @@ import jdk.internal.org.objectweb.asm.*;
* 当不存在getter方法时get操作固定返回null <br>
* 当不存在setter方法时set操作为空方法 <br>
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
* @param <T>
* @param <F>
* @param <T> 字段依附的类
* @param <F> 字段的数据类型
*/
public interface Attribute<T, F> {
/**
* 返回字段的数据类型
*
* @return
* @return 字段的数据类型
*/
public Class<? extends F> type();
/**
* 返回字段依附的类名
*
* @return
* @return 依附的类名
*/
public Class<T> declaringClass();
/**
* 返回字段名
*
* @return
* @return 字段名
*/
public String field();
@@ -98,7 +99,7 @@ public interface Attribute<T, F> {
* 获取指定对象的该字段的值
*
* @param obj 指定对象
* @return
* @return 字段的值
*/
public F get(T obj);
@@ -116,7 +117,7 @@ public interface Attribute<T, F> {
* @param <T> 依附类的类型
* @param <F> 字段类型
* @param field 字段,如果该字段不存在则抛异常
* @return
* @return Attribute对象
*/
public static <T, F> Attribute<T, F> create(final java.lang.reflect.Field field) {
return create((Class<T>) field.getDeclaringClass(), field.getName(), field, null, null);
@@ -129,7 +130,7 @@ public interface Attribute<T, F> {
* @param <F> 字段类型
* @param fieldalias 别名
* @param field 字段,如果该字段不存在则抛异常
* @return
* @return Attribute对象
*/
public static <T, F> Attribute<T, F> create(String fieldalias, final java.lang.reflect.Field field) {
return create((Class<T>) field.getDeclaringClass(), fieldalias, field, null, null);
@@ -142,7 +143,7 @@ public interface Attribute<T, F> {
* @param <F> 字段类型
* @param clazz 指定依附的类
* @param fieldname 字段名,如果该字段不存在则抛异常
* @return
* @return Attribute对象
*/
public static <T, F> Attribute<T, F> create(Class<T> clazz, final String fieldname) {
try {
@@ -159,7 +160,7 @@ public interface Attribute<T, F> {
* @param <F> 字段类型
* @param clazz 指定依附的类
* @param field 字段,如果该字段不存在则抛异常
* @return
* @return Attribute对象
*/
public static <T, F> Attribute<T, F> create(Class<T> clazz, final java.lang.reflect.Field field) {
return create(clazz, field.getName(), field);
@@ -173,28 +174,28 @@ public interface Attribute<T, F> {
* @param clazz 指定依附的类
* @param fieldalias 字段别名
* @param field 字段,如果该字段不存在则抛异常
* @return
* @return Attribute对象
*/
public static <T, F> Attribute<T, F> create(Class<T> clazz, final String fieldalias, final java.lang.reflect.Field field) {
return create(clazz, fieldalias, field, null, null);
}
/**
* 根据一个getter和setter方法生成 Attribute 对象。 <br/>
* 根据一个getter和setter方法生成 Attribute 对象。
* tgetter、setter不能同时为null
*
* @param <T> 依附类的类型
* @param <F> 字段类型
* @param getter getter方法
* @param setter setter方法
* @return
* @return Attribute对象
*/
public static <T, F> Attribute<T, F> create(final java.lang.reflect.Method getter, final java.lang.reflect.Method setter) {
return create((Class) (getter == null ? setter.getDeclaringClass() : getter.getDeclaringClass()), null, null, getter, setter);
}
/**
* 根据Class、getter和setter方法生成 Attribute 对象。 <br/>
* 根据Class、getter和setter方法生成 Attribute 对象。
* tgetter、setter不能同时为null
*
* @param <T> 依附类的类型
@@ -202,14 +203,14 @@ public interface Attribute<T, F> {
* @param clazz 指定依附的类
* @param getter getter方法
* @param setter setter方法
* @return
* @return Attribute对象
*/
public static <T, F> Attribute<T, F> create(Class<T> clazz, final java.lang.reflect.Method getter, final java.lang.reflect.Method setter) {
return create(clazz, null, null, getter, setter);
}
/**
* 根据Class、字段别名、getter和setter方法生成 Attribute 对象。 <br/>
* 根据Class、字段别名、getter和setter方法生成 Attribute 对象。
* tgetter、setter不能同时为null
*
* @param <T> 依附类的类型
@@ -218,14 +219,14 @@ public interface Attribute<T, F> {
* @param fieldalias 字段别名
* @param getter getter方法
* @param setter setter方法
* @return
* @return Attribute对象
*/
public static <T, F> Attribute<T, F> create(Class<T> clazz, final String fieldalias, final java.lang.reflect.Method getter, final java.lang.reflect.Method setter) {
return create(clazz, fieldalias, null, getter, setter);
}
/**
* 根据Class、字段别名、Field、getter和setter方法生成 Attribute 对象。 <br/>
* 根据Class、字段别名、Field、getter和setter方法生成 Attribute 对象。
* Field、tgetter、setter不能同时为null
*
* @param <T> 依附类的类型
@@ -235,7 +236,7 @@ public interface Attribute<T, F> {
* @param field 字段
* @param getter getter方法
* @param setter setter方法
* @return
* @return Attribute对象
*/
@SuppressWarnings("unchecked")
public static <T, F> Attribute<T, F> create(final Class<T> clazz, String fieldalias, final java.lang.reflect.Field field, java.lang.reflect.Method getter, java.lang.reflect.Method setter) {

View File

@@ -16,21 +16,21 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
/**
* <p>
* 实现一个类的构造方法。 代替低效的反射实现方式。 不支持数组类。 <br/>
* 常见的无参数的构造函数类都可以自动生成Creator 对应自定义的类可以提供一个静态构建Creator方法。 <br/>
* 例如:
* 实现一个类的构造方法。 代替低效的反射实现方式。 不支持数组类。
* 常见的无参数的构造函数类都可以自动生成Creator 对应自定义的类可以提供一个静态构建Creator方法。
* 例如:
* <blockquote><pre>
* public class Record {
*
*
* private final int id;
*
*
* private String name;
*
*
* Record(int id, String name) {
* this.id = id;
* this.name = name;
* }
*
*
* private static Creator createCreator() {
* return new Creator&lt;Record&gt;() {
* &#64;Override
@@ -43,15 +43,15 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
* }
* }
* </pre></blockquote>
*
* 或者:
*
* 或者:
* <blockquote><pre>
* public class Record {
*
*
* private final int id;
*
*
* private String name;
*
*
* &#64;java.beans.ConstructorProperties({"id", "name"})
* public Record(int id, String name) {
* this.id = id;
@@ -59,15 +59,18 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
* }
* }
* </pre></blockquote>
*
* <p> 详情见: http://www.redkale.org
*
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
* @param <T>
* @param <T> 构建对象的数据类型
*/
public interface Creator<T> {
/**
* 该注解只用于Creator.create方法上 与 java.beans.ConstructorProperties 类似。
*
*
*/
@Documented
@Target({METHOD})
@@ -76,20 +79,21 @@ public interface Creator<T> {
String[] value();
}
/**
* 创建对象
*
* @param params 构造函数的参数
* @return
*
* @param params 构造函数的参数
* @return 构建的对象
*/
public T create(Object... params);
/**
* 根据指定的class采用ASM技术生产Creator。
*
* @param <T> 构建类的数据类型
* @param clazz 构建类
* @return
*
* @param <T> 构建类的数据类型
* @param clazz 构建类
* @return Creator对象
*/
@SuppressWarnings("unchecked")
public static <T> Creator<T> create(Class<T> clazz) {
@@ -268,7 +272,7 @@ public interface Creator<T> {
final byte[] bytes = cw.toByteArray();
try {
if (!Modifier.isPublic(constructor.getModifiers())) throw new RuntimeException("[" + clazz + "] have no public or java.beans.ConstructorProperties-Annotation constructor.");
Class<?> resultClazz = new ClassLoader(loader) {
Class<?> resultClazz = new ClassLoader(loader) {
public final Class<?> loadClass(String name, byte[] b) {
return defineClass(name, b, 0, b.length);
}

View File

@@ -12,9 +12,11 @@ import java.util.logging.*;
/**
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
* @param <T>
* @param <T> 对象池元素的数据类型
*/
public final class ObjectPool<T> implements Supplier<T> {

View File

@@ -11,8 +11,8 @@ import jdk.internal.org.objectweb.asm.*;
* 详情见: http://www.redkale.org
*
* @author zhangjx
* @param <D>
* @param <S>
* @param <D> 目标对象的数据类型
* @param <S> 源对象的数据类型
*/
public interface Reproduce<D, S> {

View File

@@ -11,7 +11,9 @@ import java.util.regex.*;
/**
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
*/
public class SelectColumn implements Predicate<String> {
@@ -69,8 +71,8 @@ public class SelectColumn implements Predicate<String> {
/**
* class中的字段名
*
* @param columns
* @return
* @param columns 包含的字段名集合
* @return SelectColumn
*/
public static SelectColumn createIncludes(String... columns) {
return new SelectColumn(columns, false);
@@ -79,8 +81,8 @@ public class SelectColumn implements Predicate<String> {
/**
* class中的字段名
*
* @param columns
* @return
* @param columns 排除的字段名集合
* @return SelectColumn
*/
public static SelectColumn createExcludes(String... columns) {
return new SelectColumn(columns, true);

View File

@@ -14,7 +14,7 @@ import java.util.*;
* 详情见: http://www.redkale.org
*
* @author zhangjx
* @param <T>
* @param <T> 集合元素的数据类型
*/
@SuppressWarnings("unchecked")
public class Sheet<T> implements java.io.Serializable {
@@ -54,7 +54,7 @@ public class Sheet<T> implements java.io.Serializable {
/**
* 判断数据列表是否为空
*
* @return
* @return 是否为空
*/
public boolean isEmpty() {
return this.rows == null || this.rows.isEmpty();

View File

@@ -14,9 +14,11 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
*
* 获取泛型的Type类
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
* @param <T>
* @param <T> 泛型
*/
public abstract class TypeToken<T> {
@@ -34,8 +36,8 @@ public abstract class TypeToken<T> {
* 判断Type是否能确定最终的class 是则返回true存在通配符或者不确定类型则返回false。
* 例如: Map&#60; String, String &#62; 返回 ture; Map&#60; ? extends Serializable, String &#62; 返回false;
*
* @param type
* @return
* @param type Type对象
* @return 是否可反解析
*/
public final static boolean isClassType(final Type type) {
if (type instanceof Class) return true;
@@ -55,10 +57,10 @@ public abstract class TypeToken<T> {
/**
* 动态创建 ParameterizedType
*
* @param ownerType0
* @param rawType0
* @param actualTypeArguments0
* @return
* @param ownerType0 ParameterizedType 的 ownerType
* @param rawType0 ParameterizedType 的 rawType
* @param actualTypeArguments0 ParameterizedType 的 actualTypeArguments
* @return Type
*/
public static Type createParameterizedType(final Type ownerType0, final Type rawType0, final Type... actualTypeArguments0) {
if (ownerType0 == null && rawType0 instanceof Class) {

View File

@@ -15,7 +15,9 @@ import javax.net.ssl.*;
/**
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
*/
public final class Utility {
@@ -108,8 +110,8 @@ public final class Utility {
/**
* 返回本机的第一个内网IPv4地址 没有则返回null
* <p>
* @return
*
* @return IPv4地址
*/
public static InetAddress localInetAddress() {
InetAddress back = null;
@@ -134,7 +136,7 @@ public final class Utility {
/**
* 获取当天凌晨零点的格林时间
*
* @return
* @return 毫秒数
*/
public static long midnight() {
return midnight(System.currentTimeMillis());
@@ -143,8 +145,8 @@ public final class Utility {
/**
* 获取指定时间当天凌晨零点的格林时间
*
* @param time
* @return
* @param time 指定时间
* @return 毫秒数
*/
public static long midnight(long time) {
return (time + zoneRawOffset) / 86400000 * 86400000 - zoneRawOffset;
@@ -153,7 +155,7 @@ public final class Utility {
/**
* 获取当天20151231格式的int值
*
* @return
* @return 20151231格式的int值
*/
public static int today() {
java.time.LocalDate today = java.time.LocalDate.now();
@@ -163,8 +165,8 @@ public final class Utility {
/**
* 获取时间点所在星期的周一
*
* @param time
* @return
* @param time 指定时间
* @return 毫秒数
*/
public static long monday(long time) {
ZoneId zid = ZoneId.systemDefault();
@@ -177,8 +179,8 @@ public final class Utility {
/**
* 获取时间点所在星期的周日
*
* @param time
* @return
* @param time 指定时间
* @return 毫秒数
*/
public static long sunday(long time) {
ZoneId zid = ZoneId.systemDefault();
@@ -191,8 +193,8 @@ public final class Utility {
/**
* 获取时间点所在月份的1号
*
* @param time
* @return
* @param time 指定时间
* @return 毫秒数
*/
public static long monthFirstDay(long time) {
ZoneId zid = ZoneId.systemDefault();
@@ -390,10 +392,10 @@ public final class Utility {
/**
* 将两个数字组装成一个long
* <p>
* @param high
* @param low
* @return
*
* @param high 高位值
* @param low 低位值
* @return long值
*/
public static long merge(int high, int low) {
return (0L + high) << 32 | low;

View File

@@ -12,7 +12,9 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* 该注解只能放在field类型为Collection, Map, 或者java.util.concurrent.atomic.AtomicXXX的Number类);
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
*/
@Inherited
@@ -29,7 +31,7 @@ public @interface Watchable {
* 该值指明是不是只收集阶段数据, 而且被注解的字段只能被赋予java.util.concurrent.atomic.AtomicXXX的Number类型字段。
* 例如收集每分钟的注册用户数, 就需要将interval设置true。
*
* @return
* @return 是否收集
*/
boolean interval() default false;
}