废弃Cacheable类
This commit is contained in:
@@ -31,8 +31,11 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
* <code>Cacheable(false)</code> means that the entity and its state must
|
||||
* not be cached by the provider.
|
||||
*
|
||||
* @deprecated replace by {@link org.redkale.persistence.Entity#cacheable() }
|
||||
*
|
||||
* @since Java Persistence 2.0
|
||||
*/
|
||||
@Deprecated(since = "2.8.0")
|
||||
@Target({TYPE})
|
||||
@Retention(RUNTIME)
|
||||
public @interface Cacheable {
|
||||
|
||||
@@ -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 org.redkale.persistence;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
@@ -22,7 +22,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
/**
|
||||
* Specifies that the class is an entity. This annotation is applied to the
|
||||
* entity class.
|
||||
*
|
||||
*
|
||||
* @since Java Persistence 1.0
|
||||
*/
|
||||
@Inherited
|
||||
@@ -31,19 +31,41 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
@Retention(RUNTIME)
|
||||
public @interface Entity {
|
||||
|
||||
/**
|
||||
* (Optional) The entity name. Defaults to the unqualified
|
||||
* 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.
|
||||
/**
|
||||
* (Optional) The entity name. Defaults to the unqualified
|
||||
* 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 "";
|
||||
|
||||
*/
|
||||
String name() default "";
|
||||
|
||||
/**
|
||||
* (Optional) The comment of the entity.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
String comment() default "";
|
||||
|
||||
/**
|
||||
* (Optional) 是否缓存实体对象
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
boolean cacheable() default false;
|
||||
|
||||
/**
|
||||
* (Optional) 定时自动更新缓存的周期秒数,为0表示不做定时更新, 大于0表示每经过interval秒后会自动从数据库中拉取数据更新Cache
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int cacheInterval() default 0;
|
||||
|
||||
/**
|
||||
* (Optional) DataSource是否直接返回对象的真实引用, 而不是copy一份
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
boolean cacheDirect() default false;
|
||||
}
|
||||
|
||||
@@ -687,10 +687,37 @@ public final class EntityInfo<T> {
|
||||
this.updateQuestionPrepareCaseSQLs = null;
|
||||
}
|
||||
//----------------cache--------------
|
||||
Cacheable c1 = type.getAnnotation(Cacheable.class);
|
||||
javax.persistence.Cacheable c2 = type.getAnnotation(javax.persistence.Cacheable.class);
|
||||
if (this.table == null || (!cacheForbidden && c1 != null && c1.value()) || (!cacheForbidden && c2 != null && c2.value())) {
|
||||
this.cache = new EntityCache<>(this, c1 == null ? (c2 == null ? 0 : c2.interval()) : c1.interval(), c1 == null ? (c2 != null && c2.direct()) : c1.direct());
|
||||
boolean cacheable = false;
|
||||
int interval = 0;
|
||||
boolean direct = false;
|
||||
org.redkale.persistence.Entity en = type.getAnnotation(org.redkale.persistence.Entity.class);
|
||||
if (en != null) {
|
||||
cacheable = en.cacheable();
|
||||
interval = en.cacheInterval();
|
||||
direct = en.cacheDirect();
|
||||
} else {
|
||||
org.redkale.persistence.VirtualEntity ve = type.getAnnotation(org.redkale.persistence.VirtualEntity.class);
|
||||
if (ve != null) {
|
||||
cacheable = true;
|
||||
direct = ve.direct();
|
||||
}
|
||||
}
|
||||
{ //兼容旧类
|
||||
org.redkale.persistence.Cacheable c1 = type.getAnnotation(org.redkale.persistence.Cacheable.class);
|
||||
if (c1 != null) {
|
||||
cacheable = c1.value();
|
||||
interval = c1.interval();
|
||||
direct = c1.direct();
|
||||
}
|
||||
javax.persistence.Cacheable c2 = type.getAnnotation(javax.persistence.Cacheable.class);
|
||||
if (c2 != null) {
|
||||
cacheable = c2.value();
|
||||
interval = c2.interval();
|
||||
direct = c2.direct();
|
||||
}
|
||||
}
|
||||
if (this.table == null || (!cacheForbidden && cacheable)) {
|
||||
this.cache = new EntityCache<>(this, interval, direct);
|
||||
} else {
|
||||
this.cache = null;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.function.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.redkale.annotation.AutoLoad;
|
||||
import org.redkale.convert.json.*;
|
||||
import org.redkale.persistence.Cacheable;
|
||||
import org.redkale.persistence.Entity;
|
||||
import org.redkale.persistence.Id;
|
||||
import org.redkale.persistence.Transient;
|
||||
import org.redkale.source.*;
|
||||
@@ -187,7 +187,7 @@ public class FilterNodeTest {
|
||||
}
|
||||
|
||||
@AutoLoad
|
||||
@Cacheable
|
||||
@Entity(cacheable = true)
|
||||
public static class CarTestTable {
|
||||
|
||||
public static List<CarTestTable> createList() {
|
||||
@@ -280,7 +280,7 @@ public class FilterNodeTest {
|
||||
}
|
||||
|
||||
@AutoLoad
|
||||
@Cacheable
|
||||
@Entity(cacheable = true)
|
||||
public static class CarTypeTable {
|
||||
|
||||
public static List<CarTypeTable> createList() {
|
||||
@@ -337,7 +337,7 @@ public class FilterNodeTest {
|
||||
}
|
||||
|
||||
@AutoLoad
|
||||
@Cacheable
|
||||
@Entity(cacheable = true)
|
||||
public static class UserTestTable {
|
||||
|
||||
public static List<UserTestTable> createList() {
|
||||
|
||||
@@ -86,7 +86,6 @@ public class TestSourceCache {
|
||||
}
|
||||
|
||||
@VirtualEntity
|
||||
@Cacheable
|
||||
public static class TestEntity {
|
||||
|
||||
@Id
|
||||
|
||||
Reference in New Issue
Block a user