You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by li...@apache.org on 2022/06/05 10:34:07 UTC
[incubator-shenyu] branch master updated: Admin module Oracle add operation_ record_ Log table processing (#3490)
This is an automated email from the ASF dual-hosted git repository.
likeguo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 68fe42df8 Admin module Oracle add operation_ record_ Log table processing (#3490)
68fe42df8 is described below
commit 68fe42df8cf6d34d12d39eb57e1429dc7d879ba5
Author: renzhuyan <40...@qq.com>
AuthorDate: Sun Jun 5 05:34:03 2022 -0500
Admin module Oracle add operation_ record_ Log table processing (#3490)
* Add operation_ record_ Log table processing
* fix
---
db/init/oracle/schema.sql | 30 ++++++++++++++++++++++
shenyu-admin/pom.xml | 7 +++++
.../shenyu/admin/config/DataBaseConfiguration.java | 21 +++++++++++++++
.../oracle/OracleSQLPrepareInterceptor.java | 2 +-
.../mappers/operation-record-log-sqlmap.xml | 21 ++++++++++++++-
.../src/main/resources/mappers/plugin-sqlmap.xml | 15 +++++++++++
6 files changed, 94 insertions(+), 2 deletions(-)
diff --git a/db/init/oracle/schema.sql b/db/init/oracle/schema.sql
index 2f6f772c9..3de5be7ef 100644
--- a/db/init/oracle/schema.sql
+++ b/db/init/oracle/schema.sql
@@ -284,6 +284,36 @@ comment on column META_DATA.date_updated
comment on column META_DATA.enabled
is 'enabled state';
+create table operation_record_log
+(
+ id NUMBER(20) not null PRIMARY KEY,
+ color VARCHAR2(20) not null,
+ context CLOB not null,
+ operator VARCHAR2(200) not null,
+ operation_time date not null,
+ operation_type VARCHAR2(60) DEFAULT 'update' not null
+);
+-- Add comments to the columns
+comment on column OPERATION_RECORD_LOG.id
+ is 'id';
+comment on column OPERATION_RECORD_LOG.color
+ is 'log color';
+comment on column OPERATION_RECORD_LOG.context
+ is 'log context';
+comment on column OPERATION_RECORD_LOG.operator
+ is 'operator [user or app]]';
+comment on column OPERATION_RECORD_LOG.operation_time
+ is 'operation time';
+comment on column OPERATION_RECORD_LOG.operation_type
+ is 'operation type:create/update/delete/register...';
+
+create sequence operation_record_log_seq
+ increment by 1
+ START WITH 1
+ NOMAXVALUE
+ NOCYCLE
+ NOCACHE;
+
create table app_auth
(
id VARCHAR2(128) not null,
diff --git a/shenyu-admin/pom.xml b/shenyu-admin/pom.xml
index 872b1bdb5..01b596b17 100644
--- a/shenyu-admin/pom.xml
+++ b/shenyu-admin/pom.xml
@@ -27,6 +27,7 @@
<properties>
<commons-io.version>2.11.0</commons-io.version>
+ <orai18n.version>19.7.0.0</orai18n.version>
</properties>
<dependencies>
@@ -236,6 +237,12 @@
<scope>runtime</scope>
</dependency>
+ <dependency>
+ <groupId>com.oracle.database.nls</groupId>
+ <artifactId>orai18n</artifactId>
+ <version>${orai18n.version}</version>
+ </dependency>
+
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/config/DataBaseConfiguration.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/config/DataBaseConfiguration.java
index ba931cb19..096c564e5 100644
--- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/config/DataBaseConfiguration.java
+++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/config/DataBaseConfiguration.java
@@ -17,12 +17,16 @@
package org.apache.shenyu.admin.config;
+import org.apache.ibatis.mapping.DatabaseIdProvider;
+import org.apache.ibatis.mapping.VendorDatabaseIdProvider;
import org.apache.shenyu.admin.config.properties.DataBaseProperties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import java.util.Properties;
+
/**
* Local Data Source Configuration.
*/
@@ -48,4 +52,21 @@ public class DataBaseConfiguration {
dataSourceProperties.setInitEnable(initEnable);
return dataSourceProperties;
}
+
+ /**
+ * Database dialect configuration.
+ *
+ * @return {@linkplain DatabaseIdProvider}
+ */
+ @Bean
+ public DatabaseIdProvider databaseIdProvider() {
+ Properties properties = new Properties();
+ properties.setProperty("Oracle", "oracle");
+ properties.setProperty("MySQL", "mysql");
+ properties.setProperty("PostgreSQL", "postgresql");
+ properties.setProperty("H2", "h2");
+ VendorDatabaseIdProvider databaseIdProvider = new VendorDatabaseIdProvider();
+ databaseIdProvider.setProperties(properties);
+ return databaseIdProvider;
+ }
}
diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mybatis/oracle/OracleSQLPrepareInterceptor.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mybatis/oracle/OracleSQLPrepareInterceptor.java
index a168f275f..786c858fa 100644
--- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mybatis/oracle/OracleSQLPrepareInterceptor.java
+++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mybatis/oracle/OracleSQLPrepareInterceptor.java
@@ -72,7 +72,7 @@ public class OracleSQLPrepareInterceptor implements Interceptor {
.replace("update resource", "update \"resource\"");
}
// replace insert into
- if (replaceSql.contains("insert into")) {
+ if (replaceSql.contains("insert into") && !replaceSql.contains("insert into operation_record_log")) {
replaceSql = replaceSql.replaceAll("\r|\n|\\s", "")
.replace("insertinto", "insert into ")
.replace("values", " SELECT * FROM (")
diff --git a/shenyu-admin/src/main/resources/mappers/operation-record-log-sqlmap.xml b/shenyu-admin/src/main/resources/mappers/operation-record-log-sqlmap.xml
index e97fcc9f2..190ab6588 100644
--- a/shenyu-admin/src/main/resources/mappers/operation-record-log-sqlmap.xml
+++ b/shenyu-admin/src/main/resources/mappers/operation-record-log-sqlmap.xml
@@ -45,7 +45,26 @@
limit #{limit}
</select>
- <insert id="insert" parameterType="org.apache.shenyu.admin.model.entity.OperationRecordLog" useGeneratedKeys="true" keyProperty="id">
+ <select id="selectLimit" parameterType="java.lang.Integer" resultMap="BaseResultMap" databaseId="oracle">
+ SELECT
+ <include refid="Base_Column_List"/>
+ FROM operation_record_log
+ where rownum <![CDATA[<=]]> #{limit}
+ order by operation_time desc
+ </select>
+
+ <insert id="insert" parameterType="org.apache.shenyu.admin.model.entity.OperationRecordLog">
+
+ <!-- Generate before inserting non auto increment PK -->
+ <selectKey keyProperty="id" resultType="java.lang.Long" order="BEFORE" databaseId="oracle">
+ select operation_record_log_seq.nextval from dual
+ </selectKey>
+
+ <!-- Generated after auto increment primary key is inserted -->
+ <selectKey keyProperty="id" resultType="java.lang.Long" order="AFTER">
+ select LAST_INSERT_ID()
+ </selectKey>
+
insert into operation_record_log(
<if test="id != null">
id,
diff --git a/shenyu-admin/src/main/resources/mappers/plugin-sqlmap.xml b/shenyu-admin/src/main/resources/mappers/plugin-sqlmap.xml
index eb6865e48..9f65d75bf 100644
--- a/shenyu-admin/src/main/resources/mappers/plugin-sqlmap.xml
+++ b/shenyu-admin/src/main/resources/mappers/plugin-sqlmap.xml
@@ -159,6 +159,21 @@
order by p.sort, p.id
</select>
+ <select id="activePluginSnapshot" resultType="org.apache.shenyu.admin.model.vo.PluginSnapshotVO" databaseId="oracle">
+ select p.id,
+ p.name,
+ to_char(config),
+ role,
+ count(ph.id) handlecount,
+ count(s.id) selectorcount
+ from plugin p
+ left join plugin_handle ph on p.id = ph.plugin_id
+ left join selector s on p.id = s.plugin_id
+ where p.enabled = 1
+ group by p.id, p.name, to_char(config), p.role, p.sort
+ order by p.sort, p.id
+ </select>
+
<select id="searchByCondition" resultType="org.apache.shenyu.admin.model.vo.PluginVO">
SELECT