From 8aeb21265cb9190b451f505c52e12bcffdcd28e3 Mon Sep 17 00:00:00 2001
From: hongawen <83944980@qq.com>
Date: Fri, 21 Apr 2023 13:23:33 +0800
Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E7=AC=AC=E4=B8=80?=
=?UTF-8?q?=E7=89=88influxORM?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 51 +++++----
pom.xml | 78 +++++++++++++
src/main/java/com/njcn/influx/ano/Delete.java | 27 +++++
src/main/java/com/njcn/influx/ano/Insert.java | 15 +++
src/main/java/com/njcn/influx/ano/Param.java | 14 +++
src/main/java/com/njcn/influx/ano/Select.java | 25 ++++
.../njcn/influx/base/InfluxDbBaseMapper.java | 26 +++++
.../influx/base/InfluxProxyMapperFactory.java | 33 ++++++
.../com/njcn/influx/base/ProxyMapper.java | 68 +++++++++++
.../njcn/influx/base/ProxyMapperRegister.java | 70 ++++++++++++
.../njcn/influx/config/InfluxDbConfig.java | 44 +++++++
.../influx/constant/InfluxDbSqlConstant.java | 107 ++++++++++++++++++
.../com/njcn/influx/core/InfluxExecutor.java | 90 +++++++++++++++
.../njcn/influx/core/ParameterHandler.java | 41 +++++++
.../njcn/influx/core/ResultSetHandler.java | 20 ++++
.../com/njcn/influx/utils/InfluxStrUtil.java | 12 ++
.../influx/utils/ManualRegisterBeanUtil.java | 30 +++++
src/main/resources/META-INF/spring.factories | 1 +
18 files changed, 730 insertions(+), 22 deletions(-)
create mode 100644 pom.xml
create mode 100644 src/main/java/com/njcn/influx/ano/Delete.java
create mode 100644 src/main/java/com/njcn/influx/ano/Insert.java
create mode 100644 src/main/java/com/njcn/influx/ano/Param.java
create mode 100644 src/main/java/com/njcn/influx/ano/Select.java
create mode 100644 src/main/java/com/njcn/influx/base/InfluxDbBaseMapper.java
create mode 100644 src/main/java/com/njcn/influx/base/InfluxProxyMapperFactory.java
create mode 100644 src/main/java/com/njcn/influx/base/ProxyMapper.java
create mode 100644 src/main/java/com/njcn/influx/base/ProxyMapperRegister.java
create mode 100644 src/main/java/com/njcn/influx/config/InfluxDbConfig.java
create mode 100644 src/main/java/com/njcn/influx/constant/InfluxDbSqlConstant.java
create mode 100644 src/main/java/com/njcn/influx/core/InfluxExecutor.java
create mode 100644 src/main/java/com/njcn/influx/core/ParameterHandler.java
create mode 100644 src/main/java/com/njcn/influx/core/ResultSetHandler.java
create mode 100644 src/main/java/com/njcn/influx/utils/InfluxStrUtil.java
create mode 100644 src/main/java/com/njcn/influx/utils/ManualRegisterBeanUtil.java
create mode 100644 src/main/resources/META-INF/spring.factories
diff --git a/.gitignore b/.gitignore
index 9154f4c..549e00a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,26 +1,33 @@
-# ---> Java
-# Compiled class file
-*.class
+HELP.md
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
-# Log file
-*.log
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
-# BlueJ files
-*.ctxt
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
-# Mobile Tools for Java (J2ME)
-.mtj.tmp/
-
-# Package Files #
-*.jar
-*.war
-*.nar
-*.ear
-*.zip
-*.tar.gz
-*.rar
-
-# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
-hs_err_pid*
-replay_pid*
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+### VS Code ###
+.vscode/
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..f090830
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,78 @@
+
+
+ 4.0.0
+
+ com.njcn
+ influxdb-springboot-starter
+ 1.0.0
+ influxdb-springboot-starter
+ 封装influxdb的orm工具
+
+ 1.8
+ UTF-8
+ 2.3.12.RELEASE
+ 2.0.0.RELEASE
+ 2.18
+
+
+
+
+ hongawen
+ 83944980@qq.com
+
+
+
+
+
+ com.njcn
+ common-core
+ 1.0.0
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+ ${configuration-processor.version}
+
+
+ org.springframework.boot
+ spring-boot-autoconfigure
+ ${autoconfigure.version}
+
+
+ org.influxdb
+ influxdb-java
+ ${influxdb-java.version}
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+ 1.8
+ 1.8
+
+
+
+ org.sonatype.plugins
+ nexus-staging-maven-plugin
+ 1.6.7
+ true
+
+ ossrh
+ https://s01.oss.sonatype.org/
+ false
+
+
+
+
+
+
+
+
+
diff --git a/src/main/java/com/njcn/influx/ano/Delete.java b/src/main/java/com/njcn/influx/ano/Delete.java
new file mode 100644
index 0000000..fcf38ba
--- /dev/null
+++ b/src/main/java/com/njcn/influx/ano/Delete.java
@@ -0,0 +1,27 @@
+package com.njcn.influx.ano;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * 删除记录注解
+ * @author hongawen
+ */
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Delete {
+
+ /**
+ * 用于传参
+ * @return String 参数内容
+ */
+ String value();
+
+ /***
+ * 数据库名
+ * todo... 处理成获取配置文件内的,减少开发人员编码输出
+ */
+ String database();
+}
diff --git a/src/main/java/com/njcn/influx/ano/Insert.java b/src/main/java/com/njcn/influx/ano/Insert.java
new file mode 100644
index 0000000..758cb47
--- /dev/null
+++ b/src/main/java/com/njcn/influx/ano/Insert.java
@@ -0,0 +1,15 @@
+package com.njcn.influx.ano;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * 插入注解
+ * @author hongawen
+ */
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Insert {
+}
diff --git a/src/main/java/com/njcn/influx/ano/Param.java b/src/main/java/com/njcn/influx/ano/Param.java
new file mode 100644
index 0000000..f0bfdcd
--- /dev/null
+++ b/src/main/java/com/njcn/influx/ano/Param.java
@@ -0,0 +1,14 @@
+package com.njcn.influx.ano;
+
+import java.lang.annotation.*;
+
+/**
+ * 便于将方法中的参数赋值进注解内容中,通过#{paramName}
+ * @author hongawen
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.PARAMETER})
+public @interface Param {
+ String value();
+}
diff --git a/src/main/java/com/njcn/influx/ano/Select.java b/src/main/java/com/njcn/influx/ano/Select.java
new file mode 100644
index 0000000..3a7a763
--- /dev/null
+++ b/src/main/java/com/njcn/influx/ano/Select.java
@@ -0,0 +1,25 @@
+package com.njcn.influx.ano;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * 查询记录
+ * @author hongawen
+ */
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Select {
+
+ /***
+ * 查询sql
+ */
+ String value();
+
+ /***
+ * 返回映射的实体对象
+ */
+ Class resultType();
+}
diff --git a/src/main/java/com/njcn/influx/base/InfluxDbBaseMapper.java b/src/main/java/com/njcn/influx/base/InfluxDbBaseMapper.java
new file mode 100644
index 0000000..0f105c8
--- /dev/null
+++ b/src/main/java/com/njcn/influx/base/InfluxDbBaseMapper.java
@@ -0,0 +1,26 @@
+package com.njcn.influx.base;
+
+
+import com.njcn.influx.ano.Insert;
+
+import java.util.List;
+
+/**
+ * @author hongawen
+ */
+public interface InfluxDbBaseMapper {
+
+ /***
+ * 插入数据
+ * @param entity 数据
+ */
+ @Insert
+ void insertOne(T entity);
+
+ /***
+ * 批量插入数据
+ * @param entityList 数据
+ */
+ @Insert
+ void insertBatch(List entityList);
+}
diff --git a/src/main/java/com/njcn/influx/base/InfluxProxyMapperFactory.java b/src/main/java/com/njcn/influx/base/InfluxProxyMapperFactory.java
new file mode 100644
index 0000000..8004f2b
--- /dev/null
+++ b/src/main/java/com/njcn/influx/base/InfluxProxyMapperFactory.java
@@ -0,0 +1,33 @@
+package com.njcn.influx.base;
+
+import com.njcn.influx.core.InfluxExecutor;
+import com.njcn.influx.core.ParameterHandler;
+import com.njcn.influx.core.ResultSetHandler;
+import org.springframework.beans.factory.FactoryBean;
+
+import javax.annotation.Resource;
+import java.lang.reflect.Proxy;
+
+public class InfluxProxyMapperFactory implements FactoryBean {
+
+ @Resource
+ InfluxExecutor executor;
+
+ private Class interfaceClass;
+
+ public InfluxProxyMapperFactory(Class interfaceClass) {
+ this.interfaceClass = interfaceClass;
+ }
+
+ @Override
+ public Object getObject() throws Exception {
+ Object proxyInstance = Proxy.newProxyInstance(
+ interfaceClass.getClassLoader(), new Class[]{interfaceClass}, new ProxyMapper(new ParameterHandler(), executor, new ResultSetHandler()));
+ return proxyInstance;
+ }
+
+ @Override
+ public Class> getObjectType() {
+ return interfaceClass;
+ }
+}
diff --git a/src/main/java/com/njcn/influx/base/ProxyMapper.java b/src/main/java/com/njcn/influx/base/ProxyMapper.java
new file mode 100644
index 0000000..3518879
--- /dev/null
+++ b/src/main/java/com/njcn/influx/base/ProxyMapper.java
@@ -0,0 +1,68 @@
+package com.njcn.influx.base;
+
+
+import com.njcn.influx.ano.Delete;
+import com.njcn.influx.ano.Select;
+import com.njcn.influx.ano.Insert;
+import com.njcn.influx.core.InfluxExecutor;
+import com.njcn.influx.core.ParameterHandler;
+import com.njcn.influx.core.ResultSetHandler;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Parameter;
+import java.util.List;
+
+public class ProxyMapper implements InvocationHandler {
+
+ private ParameterHandler parameterHandler;
+ private InfluxExecutor executor;
+ private ResultSetHandler resultSetHandler;
+
+ public ProxyMapper(ParameterHandler parameterHandler, InfluxExecutor executor, ResultSetHandler resultSetHandler) {
+ this.parameterHandler = parameterHandler;
+ this.executor = executor;
+ this.resultSetHandler = resultSetHandler;
+ }
+
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ Annotation[] annotations = method.getAnnotations();
+ if (annotations.length == 1) {
+ Annotation annotation = annotations[0];
+ Class extends Annotation> annotationType = annotation.annotationType();
+ //是查询的
+ if (annotationType == Select.class) {
+ Select selectAnnotation = method.getAnnotation(Select.class);
+ //拼接sql
+ String sql = selectAnnotation.value();
+ Parameter[] parameters = method.getParameters();
+ sql = parameterHandler.handleParameter(parameters, args, sql);
+ //查询结果
+ Class resultType = selectAnnotation.resultType();
+ List