新增extension模块

This commit is contained in:
邢鹏成 2022-03-07 17:28:08 +08:00
parent 9d95764196
commit ac0e5bbc97
19 changed files with 82 additions and 54 deletions

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>easy-es-parent</artifactId> <artifactId>easy-es-parent</artifactId>
<groupId>io.github.xpc1024</groupId> <groupId>io.github.xpc1024</groupId>
<version>0.9.6</version> <version>0.9.7</version>
<relativePath>../easy-es-parent</relativePath> <relativePath>../easy-es-parent</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -21,7 +21,12 @@
<dependency> <dependency>
<groupId>io.github.xpc1024</groupId> <groupId>io.github.xpc1024</groupId>
<artifactId>easy-es-core</artifactId> <artifactId>easy-es-core</artifactId>
<version>0.9.6</version> <version>0.9.7</version>
</dependency>
<dependency>
<groupId>io.github.xpc1024</groupId>
<artifactId>easy-es-extension</artifactId>
<version>0.9.7</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>

View File

@ -1,7 +1,8 @@
package com.xpc.easyes.autoconfig.config; package com.xpc.easyes.autoconfig.config;
import com.xpc.easyes.core.plugin.interceptor.Interceptor;
import com.xpc.easyes.core.plugin.interceptor.InterceptorChain; import com.xpc.easyes.extension.plugins.Interceptor;
import com.xpc.easyes.extension.plugins.InterceptorChain;
import lombok.Data; import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
@ -58,14 +59,15 @@ public class EsConfigProperties {
*/ */
protected InterceptorChain interceptorChain; protected InterceptorChain interceptorChain;
public void initInterceptorChain(){ public void initInterceptorChain() {
if(interceptorChain == null){ if (interceptorChain == null) {
interceptorChain = new InterceptorChain(); interceptorChain = new InterceptorChain();
} }
} }
/** /**
* 添加拦截器 * 添加拦截器
*
* @param interceptor * @param interceptor
*/ */
public void addInterceptor(Interceptor interceptor) { public void addInterceptor(Interceptor interceptor) {

View File

@ -2,10 +2,10 @@ package com.xpc.easyes.autoconfig.register;
import com.xpc.easyes.autoconfig.config.EsConfigProperties; import com.xpc.easyes.autoconfig.config.EsConfigProperties;
import com.xpc.easyes.core.cache.BaseCache; import com.xpc.easyes.core.cache.BaseCache;
import com.xpc.easyes.core.plugin.interceptor.Interceptor;
import com.xpc.easyes.core.plugin.interceptor.InterceptorChain;
import com.xpc.easyes.core.plugin.interceptor.Intercepts;
import com.xpc.easyes.core.proxy.EsMapperProxy; import com.xpc.easyes.core.proxy.EsMapperProxy;
import com.xpc.easyes.extension.anno.Intercepts;
import com.xpc.easyes.extension.plugins.Interceptor;
import com.xpc.easyes.extension.plugins.InterceptorChain;
import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;

View File

@ -7,13 +7,13 @@
<parent> <parent>
<groupId>io.github.xpc1024</groupId> <groupId>io.github.xpc1024</groupId>
<artifactId>easy-es-parent</artifactId> <artifactId>easy-es-parent</artifactId>
<version>0.9.6</version> <version>0.9.7</version>
<relativePath>../easy-es-parent</relativePath> <relativePath>../easy-es-parent</relativePath>
</parent> </parent>
<groupId>io.github.xpc1024</groupId> <groupId>io.github.xpc1024</groupId>
<artifactId>easy-es-core</artifactId> <artifactId>easy-es-core</artifactId>
<version>0.9.6</version> <version>0.9.7</version>
<properties> <properties>
<maven.compiler.source>8</maven.compiler.source> <maven.compiler.source>8</maven.compiler.source>

23
easy-es-extension/pom.xml Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.github.xpc1024</groupId>
<artifactId>easy-es-parent</artifactId>
<version>0.9.7</version>
<relativePath>../easy-es-parent</relativePath>
</parent>
<groupId>io.github.xpc1024</groupId>
<artifactId>easy-es-extension</artifactId>
<version>0.9.7</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>

View File

@ -1,4 +1,4 @@
package com.xpc.easyes.core.plugin.interceptor; package com.xpc.easyes.extension.anno;
import java.lang.annotation.*; import java.lang.annotation.*;

View File

@ -1,4 +1,4 @@
package com.xpc.easyes.core.plugin.interceptor; package com.xpc.easyes.extension.anno;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;

View File

@ -1,4 +1,4 @@
package com.xpc.easyes.core.plugin.interceptor; package com.xpc.easyes.extension.plugins;
/** /**
* <p> * <p>

View File

@ -1,4 +1,4 @@
package com.xpc.easyes.core.plugin.interceptor; package com.xpc.easyes.extension.plugins;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;

View File

@ -1,4 +1,4 @@
package com.xpc.easyes.core.plugin.interceptor; package com.xpc.easyes.extension.plugins;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;

View File

@ -1,8 +1,9 @@
package com.xpc.easyes.core.plugin.interceptor; package com.xpc.easyes.extension.plugins;
import com.xpc.easyes.core.exception.EasyEsException; import com.xpc.easyes.extension.anno.Intercepts;
import com.xpc.easyes.core.utils.ExceptionUtil; import com.xpc.easyes.extension.anno.Signature;
import com.xpc.easyes.extension.utils.ExceptionUtil;
import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -64,7 +65,7 @@ public class Plugin implements InvocationHandler {
Intercepts interceptsAnnotation = interceptor.getClass().getAnnotation(Intercepts.class); Intercepts interceptsAnnotation = interceptor.getClass().getAnnotation(Intercepts.class);
// 检查类是否被@Intercepts标记 // 检查类是否被@Intercepts标记
if (interceptsAnnotation == null) { if (interceptsAnnotation == null) {
throw new EasyEsException("No @Intercepts annotation was found in interceptor " + interceptor.getClass().getName()); throw new RuntimeException("No @Intercepts annotation was found in interceptor " + interceptor.getClass().getName());
} }
Signature[] sigs = interceptsAnnotation.value(); Signature[] sigs = interceptsAnnotation.value();
Map<Class<?>, Set<Method>> signatureMap = new HashMap<>(); Map<Class<?>, Set<Method>> signatureMap = new HashMap<>();
@ -75,7 +76,7 @@ public class Plugin implements InvocationHandler {
Method method = sig.type().getMethod(sig.method(), sig.args()); Method method = sig.type().getMethod(sig.method(), sig.args());
methods.add(method); methods.add(method);
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
throw new EasyEsException("Could not find method on " + sig.type() + " named " + sig.method() + ". Cause: " + e, e); throw new RuntimeException("Could not find method on " + sig.type() + " named " + sig.method() + ". Cause: " + e, e);
} }
} }
return signatureMap; return signatureMap;

View File

@ -1,4 +1,4 @@
package com.xpc.easyes.core.utils; package com.xpc.easyes.extension.utils;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.UndeclaredThrowableException; import java.lang.reflect.UndeclaredThrowableException;

View File

@ -6,7 +6,7 @@
<groupId>io.github.xpc1024</groupId> <groupId>io.github.xpc1024</groupId>
<artifactId>easy-es-parent</artifactId> <artifactId>easy-es-parent</artifactId>
<version>0.9.6</version> <version>0.9.7</version>
<name>easy-es-parent</name> <name>easy-es-parent</name>
<description>easy use for elastic search</description> <description>easy use for elastic search</description>
@ -22,6 +22,7 @@
<modules> <modules>
<module>../easy-es-core</module> <module>../easy-es-core</module>
<module>../easy-es-boot-starter</module> <module>../easy-es-boot-starter</module>
<module>../easy-es-extension</module>
</modules> </modules>
<properties> <properties>

View File

@ -9,7 +9,7 @@
<parent> <parent>
<artifactId>easy-es</artifactId> <artifactId>easy-es</artifactId>
<groupId>io.github.xpc1024</groupId> <groupId>io.github.xpc1024</groupId>
<version>0.9.6</version> <version>0.9.7</version>
</parent> </parent>
<properties> <properties>
@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>io.github.xpc1024</groupId> <groupId>io.github.xpc1024</groupId>
<artifactId>easy-es-boot-starter</artifactId> <artifactId>easy-es-boot-starter</artifactId>
<version>0.9.6</version> <version>0.9.7</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>

View File

@ -1,18 +1,15 @@
package com.xpc.easyes.sample; package com.xpc.easyes.sample;
import com.xpc.easyes.autoconfig.annotation.EsMapperScan; import com.xpc.easyes.autoconfig.annotation.EsMapperScan;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
/** /**
* 启动类 * 启动类
* <p> * <p>
* Copyright © 2021 xpc1024 All Rights Reserved * Copyright © 2021 xpc1024 All Rights Reserved
**/ **/
@SpringBootApplication(scanBasePackages = {"com.xpc.easyes"}) @SpringBootApplication
@EsMapperScan("com.xpc.easyes.sample.mapper") @EsMapperScan("com.xpc.easyes.sample.mapper")
public class EasyEsApplication { public class EasyEsApplication {
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -14,7 +14,7 @@ import lombok.Data;
public class GeneralBean { public class GeneralBean {
/** /**
* 删除状态 * 逻辑删除状态
*/ */
private Boolean existStatus; private Boolean existStatus;

View File

@ -2,11 +2,10 @@ package com.xpc.easyes.sample.interceptor;
import com.xpc.easyes.core.conditions.LambdaEsQueryWrapper; import com.xpc.easyes.core.conditions.LambdaEsQueryWrapper;
import com.xpc.easyes.core.conditions.interfaces.BaseEsMapper; import com.xpc.easyes.core.conditions.interfaces.BaseEsMapper;
import com.xpc.easyes.core.plugin.interceptor.Interceptor; import com.xpc.easyes.extension.anno.Intercepts;
import com.xpc.easyes.core.plugin.interceptor.Intercepts; import com.xpc.easyes.extension.anno.Signature;
import com.xpc.easyes.core.plugin.interceptor.Invocation; import com.xpc.easyes.extension.plugins.Interceptor;
import com.xpc.easyes.core.plugin.interceptor.Signature; import com.xpc.easyes.extension.plugins.Invocation;
import com.xpc.easyes.sample.entity.GeneralBean;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
@ -29,8 +28,8 @@ public class DeleteInterceptor implements Interceptor {
@Override @Override
public Object intercept(Invocation invocation) throws Throwable { public Object intercept(Invocation invocation) throws Throwable {
// 统一逻辑删除拦截 // 统一逻辑删除拦截
System.out.println("啊啊啊,我拦截到了删除,禁止删除"); System.out.println("啊啊啊,我拦截到了删除,禁止直接删除");
// 这里直接改为update // 这里直接改为update逻辑删除...
return 0; return 0;
} }

View File

@ -2,10 +2,10 @@ package com.xpc.easyes.sample.interceptor;
import com.xpc.easyes.core.conditions.LambdaEsQueryWrapper; import com.xpc.easyes.core.conditions.LambdaEsQueryWrapper;
import com.xpc.easyes.core.conditions.interfaces.BaseEsMapper; import com.xpc.easyes.core.conditions.interfaces.BaseEsMapper;
import com.xpc.easyes.core.plugin.interceptor.Interceptor; import com.xpc.easyes.extension.anno.Intercepts;
import com.xpc.easyes.core.plugin.interceptor.Intercepts; import com.xpc.easyes.extension.anno.Signature;
import com.xpc.easyes.core.plugin.interceptor.Invocation; import com.xpc.easyes.extension.plugins.Interceptor;
import com.xpc.easyes.core.plugin.interceptor.Signature; import com.xpc.easyes.extension.plugins.Invocation;
import com.xpc.easyes.sample.entity.GeneralBean; import com.xpc.easyes.sample.entity.GeneralBean;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -29,9 +29,9 @@ public class QueryInterceptor implements Interceptor {
public Object intercept(Invocation invocation) throws Throwable { public Object intercept(Invocation invocation) throws Throwable {
System.out.println("啊啊啊,我拦截到了查询,统一增加查询条件"); System.out.println("啊啊啊,我拦截到了查询,统一增加查询条件");
// 统一逻辑删除拦截 // 统一逻辑删除拦截
Object[] args = invocation.getArgs(); // Object[] args = invocation.getArgs();
LambdaEsQueryWrapper<GeneralBean> arg = (LambdaEsQueryWrapper) args[0]; // LambdaEsQueryWrapper<GeneralBean> arg = (LambdaEsQueryWrapper) args[0];
arg.eq(GeneralBean::getExistStatus, true); // arg.eq(GeneralBean::getExistStatus, true);
return invocation.proceed(); return invocation.proceed();
} }

View File

@ -6,7 +6,7 @@
<groupId>io.github.xpc1024</groupId> <groupId>io.github.xpc1024</groupId>
<artifactId>easy-es</artifactId> <artifactId>easy-es</artifactId>
<version>0.9.6</version> <version>0.9.7</version>
<name>easy-es</name> <name>easy-es</name>
<description>easy use for elastic search</description> <description>easy use for elastic search</description>