mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-08-14 00:23:38 +00:00
perf[module]: 优化IEntity接口,新增insert delete save
This commit is contained in:
@@ -144,7 +144,7 @@ public class EntityCaches<PK extends Comparable<PK>, E extends IEntity<PK>> impl
|
||||
}
|
||||
|
||||
if (currentPnode.getThreadId() != Thread.currentThread().getId()) {
|
||||
logger.error("[{}]被多线程访问了,先后2次访问线程ID分别是[{}] [{}]", entity.getClass().getSimpleName(),
|
||||
logger.error("[{} id:{}]被多线程访问了,先后2次访问线程id分别是[{}][{}]", entity.getClass().getSimpleName(), entity.id(),
|
||||
currentPnode.getThreadId(), Thread.currentThread().getId());
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
package com.zfoo.orm.model.entity;
|
||||
|
||||
import com.zfoo.orm.OrmContext;
|
||||
import com.zfoo.protocol.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -53,7 +54,7 @@ public interface IEntity<PK extends Comparable<PK>> {
|
||||
*
|
||||
* @return EntityCaches中取出的值在数据库中是否存在
|
||||
*/
|
||||
default boolean checkNull() {
|
||||
default boolean empty() {
|
||||
PK idValue = id();
|
||||
if (idValue == null) {
|
||||
return true;
|
||||
@@ -65,4 +66,39 @@ public interface IEntity<PK extends Comparable<PK>> {
|
||||
return StringUtils.isEmpty((CharSequence) idValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入数据库时使用
|
||||
*/
|
||||
default void insert() {
|
||||
OrmContext.getAccessor().insert(this);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 从数据库删除时使用
|
||||
*/
|
||||
default void delete() {
|
||||
OrmContext.getAccessor().delete(this);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存到数据库时使用
|
||||
*/
|
||||
default void save() {
|
||||
OrmContext.getOrmManager().getEntityCaches(this.getClass()).update(queryEntity());
|
||||
}
|
||||
|
||||
private void invalidate() {
|
||||
OrmContext.getOrmManager().getEntityCaches(this.getClass()).invalidate(queryId());
|
||||
}
|
||||
|
||||
private <E extends IEntity> E queryEntity() {
|
||||
return (E) this;
|
||||
}
|
||||
|
||||
private <PK extends Comparable> PK queryId() {
|
||||
return (PK) id();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user