mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 09:08:24 +08:00
optimize Entity Listeners
This commit is contained in:
parent
c4420668f3
commit
354f2efdb0
@ -65,7 +65,7 @@ public class EntitySqlProvider {
|
||||
tableInfo.initLogicDeleteValueIfNecessary(entity);
|
||||
|
||||
//执行 onInsert 监听器
|
||||
tableInfo.invokeOnInsert(entity);
|
||||
tableInfo.invokeOnInsertListener(entity);
|
||||
|
||||
Object[] values = tableInfo.buildInsertSqlArgs(entity);
|
||||
ProviderUtil.setSqlArgs(params, values);
|
||||
@ -96,7 +96,7 @@ public class EntitySqlProvider {
|
||||
tableInfo.initLogicDeleteValueIfNecessary(entity);
|
||||
|
||||
//执行 onInsert 监听器
|
||||
tableInfo.invokeOnInsert(entity);
|
||||
tableInfo.invokeOnInsertListener(entity);
|
||||
}
|
||||
|
||||
|
||||
@ -200,7 +200,7 @@ public class EntitySqlProvider {
|
||||
TableInfo tableInfo = ProviderUtil.getTableInfo(context);
|
||||
|
||||
//执行 onUpdate 监听器
|
||||
tableInfo.invokeUpUpdate(entity);
|
||||
tableInfo.invokeOnUpdateListener(entity);
|
||||
|
||||
Object[] updateValues = tableInfo.buildUpdateSqlArgs(entity, ignoreNulls, false);
|
||||
Object[] primaryValues = tableInfo.buildPkSqlArgs(entity);
|
||||
|
||||
@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.mybatisflex.core.table;
|
||||
|
||||
import com.mybatisflex.annotation.SetListener;
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
import org.apache.ibatis.reflection.property.PropertyTokenizer;
|
||||
import org.apache.ibatis.reflection.wrapper.BeanWrapper;
|
||||
@ -45,20 +44,17 @@ public class EntityWrapperFactory implements ObjectWrapperFactory {
|
||||
static class FlexBeanWrapper extends BeanWrapper {
|
||||
|
||||
private Object entity;
|
||||
private SetListener onSetListener;
|
||||
private TableInfo tableInfo;
|
||||
|
||||
public FlexBeanWrapper(MetaObject metaObject, Object object) {
|
||||
super(metaObject, object);
|
||||
this.entity = object;
|
||||
this.onSetListener = TableInfoFactory.getByEntityClass(object.getClass()).getOnSetListener();
|
||||
this.tableInfo = TableInfoFactory.getByEntityClass(object.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(PropertyTokenizer prop, Object value) {
|
||||
Object v = value;
|
||||
if (onSetListener != null) {
|
||||
v = onSetListener.onSet(entity, prop.getName(), value);
|
||||
}
|
||||
Object v = tableInfo.invokeOnSetListener(entity, prop.getName(), value);
|
||||
super.set(prop, v);
|
||||
}
|
||||
}
|
||||
|
||||
@ -660,15 +660,22 @@ public class TableInfo {
|
||||
}
|
||||
|
||||
|
||||
public void invokeOnInsert(Object entity) {
|
||||
public void invokeOnInsertListener(Object entity) {
|
||||
if (onInsertListener != null) {
|
||||
onInsertListener.onInsert(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public void invokeUpUpdate(Object entity) {
|
||||
public void invokeOnUpdateListener(Object entity) {
|
||||
if (onUpdateListener != null) {
|
||||
onUpdateListener.onUpdate(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public Object invokeOnSetListener(Object entity, String property, Object value) {
|
||||
if (onSetListener != null) {
|
||||
return onSetListener.onSet(entity, property, value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user