diect
This commit is contained in:
@@ -51,7 +51,11 @@ public @interface Cacheable {
|
|||||||
*/
|
*/
|
||||||
int interval() default 0;
|
int interval() default 0;
|
||||||
|
|
||||||
@Deprecated
|
/**
|
||||||
|
* (Optional) DataSource是否直接返回对象的真实引用, 而不是copy一份
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
boolean direct() default false;
|
boolean direct() default false;
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
|||||||
@@ -81,17 +81,28 @@ public final class EntityCache<T> {
|
|||||||
private CompletableFuture<List<T>> loadFuture;
|
private CompletableFuture<List<T>> loadFuture;
|
||||||
|
|
||||||
public EntityCache(final EntityInfo<T> info, final Cacheable c) {
|
public EntityCache(final EntityInfo<T> info, final Cacheable c) {
|
||||||
this(info, c != null ? c.interval() : 0);
|
this(info, c != null ? c.interval() : 0, c != null && c.direct());
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityCache(final EntityInfo<T> info, final int cacheInterval) {
|
EntityCache(final EntityInfo<T> info, final int cacheInterval, final boolean cacheDirect) {
|
||||||
this.info = info;
|
this.info = info;
|
||||||
this.interval = cacheInterval < 0 ? 0 : cacheInterval;
|
this.interval = cacheInterval < 0 ? 0 : cacheInterval;
|
||||||
this.type = info.getType();
|
this.type = info.getType();
|
||||||
this.arrayer = info.getArrayer();
|
this.arrayer = info.getArrayer();
|
||||||
this.creator = info.getCreator();
|
this.creator = info.getCreator();
|
||||||
this.primary = info.primary;
|
this.primary = info.primary;
|
||||||
this.needCopy = true;
|
org.redkale.persistence.VirtualEntity ve = info.getType().getAnnotation(org.redkale.persistence.VirtualEntity.class);
|
||||||
|
boolean direct = cacheDirect;
|
||||||
|
if (!direct) {
|
||||||
|
direct = ve != null && ve.direct();
|
||||||
|
}
|
||||||
|
{ //兼容废弃类
|
||||||
|
org.redkale.source.VirtualEntity ve2 = info.getType().getAnnotation(org.redkale.source.VirtualEntity.class);
|
||||||
|
if (!direct && ve2 != null) {
|
||||||
|
direct = ve2.direct();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.needCopy = !direct;
|
||||||
this.newCopier = Copier.create(type, type, (e, c) -> {
|
this.newCopier = Copier.create(type, type, (e, c) -> {
|
||||||
try {
|
try {
|
||||||
return e.getAnnotation(Transient.class) == null && e.getAnnotation(javax.persistence.Transient.class) == null;
|
return e.getAnnotation(Transient.class) == null && e.getAnnotation(javax.persistence.Transient.class) == null;
|
||||||
|
|||||||
@@ -687,7 +687,7 @@ public final class EntityInfo<T> {
|
|||||||
Cacheable c1 = type.getAnnotation(Cacheable.class);
|
Cacheable c1 = type.getAnnotation(Cacheable.class);
|
||||||
javax.persistence.Cacheable c2 = type.getAnnotation(javax.persistence.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())) {
|
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());
|
this.cache = new EntityCache<>(this, c1 == null ? (c2 == null ? 0 : c2.interval()) : c1.interval(), c1 == null ? (c2 == null ? false : c2.direct()) : c1.direct());
|
||||||
} else {
|
} else {
|
||||||
this.cache = null;
|
this.cache = null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user