mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
commit
b8fe61439c
@ -16,20 +16,31 @@
|
|||||||
|
|
||||||
package com.mybatisflex.annotation;
|
package com.mybatisflex.annotation;
|
||||||
|
|
||||||
|
import java.lang.reflect.ParameterizedType;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 类型支持 insert 监听器。
|
* 类型支持 insert 监听器。
|
||||||
*
|
*
|
||||||
* @author snow
|
* @author snow
|
||||||
|
* @author robot.luo
|
||||||
* @since 2023/4/28
|
* @since 2023/4/28
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractInsertListener<T> implements InsertListener {
|
public abstract class AbstractInsertListener<T> implements InsertListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 该监听器支持的 entity 类型。
|
* 支持的类型
|
||||||
*
|
|
||||||
* @return type
|
|
||||||
*/
|
*/
|
||||||
public abstract Class<T> supportType();
|
private final Class<T> supportType;
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
protected AbstractInsertListener() {
|
||||||
|
Type[] params = ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments();
|
||||||
|
if (params.length == 0) {
|
||||||
|
throw new IllegalArgumentException(this.getClass().getSimpleName() + "继承AbstractInsertListener请指定泛型");
|
||||||
|
}
|
||||||
|
supportType = (Class<T>) params[0];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增操作的前置操作。
|
* 新增操作的前置操作。
|
||||||
@ -41,7 +52,6 @@ public abstract class AbstractInsertListener<T> implements InsertListener {
|
|||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void onInsert(Object entity) {
|
public void onInsert(Object entity) {
|
||||||
Class<T> supportType = supportType();
|
|
||||||
if (supportType.isInstance(entity)) {
|
if (supportType.isInstance(entity)) {
|
||||||
T object = (T) entity;
|
T object = (T) entity;
|
||||||
doInsert(object);
|
doInsert(object);
|
||||||
|
|||||||
@ -16,20 +16,31 @@
|
|||||||
|
|
||||||
package com.mybatisflex.annotation;
|
package com.mybatisflex.annotation;
|
||||||
|
|
||||||
|
import java.lang.reflect.ParameterizedType;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 类型支持 update 监听器。
|
* 类型支持 update 监听器。
|
||||||
*
|
*
|
||||||
* @author snow
|
* @author snow
|
||||||
|
* @author robot.luo
|
||||||
* @since 2023/4/28
|
* @since 2023/4/28
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractUpdateListener<T> implements UpdateListener {
|
public abstract class AbstractUpdateListener<T> implements UpdateListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 该监听器支持的 entity 类型。
|
* 支持的类型
|
||||||
*
|
|
||||||
* @return type
|
|
||||||
*/
|
*/
|
||||||
public abstract Class<T> supportType();
|
private final Class<T> supportType;
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
protected AbstractUpdateListener() {
|
||||||
|
Type[] params = ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments();
|
||||||
|
if (params.length == 0) {
|
||||||
|
throw new IllegalArgumentException(this.getClass().getSimpleName() + "继承AbstractUpdateListener请指定泛型");
|
||||||
|
}
|
||||||
|
supportType = (Class<T>) params[0];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新操作的前置操作。
|
* 更新操作的前置操作。
|
||||||
@ -41,7 +52,6 @@ public abstract class AbstractUpdateListener<T> implements UpdateListener {
|
|||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void onUpdate(Object entity) {
|
public void onUpdate(Object entity) {
|
||||||
Class<T> supportType = supportType();
|
|
||||||
if (supportType.isInstance(entity)) {
|
if (supportType.isInstance(entity)) {
|
||||||
T object = (T) entity;
|
T object = (T) entity;
|
||||||
doUpdate(object);
|
doUpdate(object);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user