mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-15 12:15:15 +00:00
chore[orm]: revise warning
This commit is contained in:
1 parent
28d2ac6078
commit
1b4626e033
2 files changed
+14
-16
No files matched your search
+13
-15
@@ -59,7 +59,7 @@ public class EntityCache<PK extends Comparable<PK>, E extends IEntity<PK>> imple
|
|||||||
|
|
||||||
private final EntityDef entityDef;
|
private final EntityDef entityDef;
|
||||||
|
|
||||||
private final LazyCache<PK, PNode<E>> cache;
|
private final LazyCache<PK, PNode<PK, E>> cache;
|
||||||
|
|
||||||
private ICacheVersion<PK, E> cacheVersion = new CacheVersionDefault<>();
|
private ICacheVersion<PK, E> cacheVersion = new CacheVersionDefault<>();
|
||||||
|
|
||||||
@@ -75,9 +75,9 @@ public class EntityCache<PK extends Comparable<PK>, E extends IEntity<PK>> imple
|
|||||||
cacheVersion = new CacheVersion<>(filed.getName(), getMethod, setMethod);
|
cacheVersion = new CacheVersion<>(filed.getName(), getMethod, setMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
var removeCallback = new BiConsumer<Pair<PK, PNode<E>>, LazyCache.RemovalCause>() {
|
var removeCallback = new BiConsumer<Pair<PK, PNode<PK, E>>, LazyCache.RemovalCause>() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(Pair<PK, PNode<E>> pair, LazyCache.RemovalCause removalCause) {
|
public void accept(Pair<PK, PNode<PK, E>> pair, LazyCache.RemovalCause removalCause) {
|
||||||
if (removalCause == LazyCache.RemovalCause.EXPLICIT) {
|
if (removalCause == LazyCache.RemovalCause.EXPLICIT) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -176,7 +176,7 @@ public class EntityCache<PK extends Comparable<PK>, E extends IEntity<PK>> imple
|
|||||||
/**
|
/**
|
||||||
* 校验需要更新的entity和缓存的entity是否为同一个entity
|
* 校验需要更新的entity和缓存的entity是否为同一个entity
|
||||||
*/
|
*/
|
||||||
private PNode<E> fetchCachePnode(E entity, boolean safe) {
|
private PNode<PK, E> fetchCachePnode(E entity, boolean safe) {
|
||||||
var id = entity.id();
|
var id = entity.id();
|
||||||
var cachePnode = cache.get(id);
|
var cachePnode = cache.get(id);
|
||||||
if (cachePnode == null) {
|
if (cachePnode == null) {
|
||||||
@@ -273,9 +273,9 @@ public class EntityCache<PK extends Comparable<PK>, E extends IEntity<PK>> imple
|
|||||||
var currentTime = TimeUtils.currentTimeMillis();
|
var currentTime = TimeUtils.currentTimeMillis();
|
||||||
// key为threadId
|
// key为threadId
|
||||||
var updateMap = new HashMap<Long, List<E>>();
|
var updateMap = new HashMap<Long, List<E>>();
|
||||||
cache.forEach(new BiConsumer<PK, PNode<E>>() {
|
cache.forEach(new BiConsumer<PK, PNode<PK, E>>() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(PK pk, PNode<E> pnode) {
|
public void accept(PK pk, PNode<PK, E> pnode) {
|
||||||
var entity = pnode.getEntity();
|
var entity = pnode.getEntity();
|
||||||
if (pnode.getModifiedTime() != pnode.getWriteToDbTime()) {
|
if (pnode.getModifiedTime() != pnode.getWriteToDbTime()) {
|
||||||
pnode.resetTime(currentTime);
|
pnode.resetTime(currentTime);
|
||||||
@@ -303,9 +303,9 @@ public class EntityCache<PK extends Comparable<PK>, E extends IEntity<PK>> imple
|
|||||||
public void persistAllBlock() {
|
public void persistAllBlock() {
|
||||||
var currentTime = TimeUtils.currentTimeMillis();
|
var currentTime = TimeUtils.currentTimeMillis();
|
||||||
var updateList = new ArrayList<E>();
|
var updateList = new ArrayList<E>();
|
||||||
cache.forEach(new BiConsumer<PK, PNode<E>>() {
|
cache.forEach(new BiConsumer<PK, PNode<PK, E>>() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(PK pk, PNode<E> pnode) {
|
public void accept(PK pk, PNode<PK, E> pnode) {
|
||||||
var entity = pnode.getEntity();
|
var entity = pnode.getEntity();
|
||||||
if (pnode.getModifiedTime() != pnode.getWriteToDbTime()) {
|
if (pnode.getModifiedTime() != pnode.getWriteToDbTime()) {
|
||||||
pnode.resetTime(currentTime);
|
pnode.resetTime(currentTime);
|
||||||
@@ -405,13 +405,11 @@ public class EntityCache<PK extends Comparable<PK>, E extends IEntity<PK>> imple
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果数据库版本号较大,说明缓存的数据不是最新的,直接清除缓存,下次重新加载
|
// 数据库版本号较大,说明缓存的数据不是最新的,直接清除缓存,下次重新加载
|
||||||
if (dbEntityVersion > entityVersion) {
|
cache.remove(id);
|
||||||
cache.remove(id);
|
load(id);
|
||||||
load(id);
|
logger.warn("[database:{}] document of entity [id:{}] version [{}] is greater than cache [vs:{}]", entityClass.getSimpleName(), id, dbEntityVersion, entityVersion);
|
||||||
logger.warn("[database:{}] document of entity [id:{}] version [{}] is greater than cache [vs:{}]", entityClass.getSimpleName(), id, dbEntityVersion, entityVersion);
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import com.zfoo.scheduler.util.TimeUtils;
|
|||||||
*
|
*
|
||||||
* @author godotg
|
* @author godotg
|
||||||
*/
|
*/
|
||||||
public class PNode<E extends IEntity<?>> {
|
public class PNode<PK extends Comparable<PK>, E extends IEntity<PK>> {
|
||||||
|
|
||||||
// 写入数据库的时间
|
// 写入数据库的时间
|
||||||
private volatile long writeToDbTime;
|
private volatile long writeToDbTime;
|
||||||
|
|||||||
Reference in new issue
Block a user