You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampark.apache.org by be...@apache.org on 2024/02/16 09:38:24 UTC

(incubator-streampark) 01/01: [Imprpve] JDBC "like" syntax is compatible with mysql and pgsql

This is an automated email from the ASF dual-hosted git repository.

benjobs pushed a commit to branch like
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git

commit a791b4e94a761cb5b69ce2a844c5ec7b9b81ffcf
Author: benjobs <be...@gmail.com>
AuthorDate: Fri Feb 16 17:38:08 2024 +0800

    [Imprpve] JDBC "like" syntax is compatible with mysql and pgsql
---
 .../console/base/config/MybatisConfig.java          | 16 ++++++++++++++++
 .../resources/mapper/core/ApplicationMapper.xml     | 21 ++++++++++++++++++---
 .../main/resources/mapper/core/ProjectMapper.xml    |  7 ++++++-
 .../main/resources/mapper/core/VariableMapper.xml   | 21 ++++++++++++++++++---
 .../main/resources/mapper/core/YarnQueueMapper.xml  |  7 ++++++-
 .../main/resources/mapper/system/MemberMapper.xml   |  7 ++++++-
 .../src/main/resources/mapper/system/RoleMapper.xml |  7 ++++++-
 .../src/main/resources/mapper/system/TeamMapper.xml |  7 ++++++-
 .../src/main/resources/mapper/system/UserMapper.xml |  7 ++++++-
 9 files changed, 88 insertions(+), 12 deletions(-)

diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/MybatisConfig.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/MybatisConfig.java
index 5be603899..206b035e1 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/MybatisConfig.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/MybatisConfig.java
@@ -17,6 +17,8 @@
 
 package org.apache.streampark.console.base.config;
 
+import org.apache.ibatis.mapping.DatabaseIdProvider;
+import org.apache.ibatis.mapping.VendorDatabaseIdProvider;
 import org.apache.streampark.console.base.mybatis.interceptor.PostgreSQLPrepareInterceptor;
 import org.apache.streampark.console.base.mybatis.interceptor.PostgreSQLQueryInterceptor;
 
@@ -34,6 +36,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
+import java.util.Properties;
+
 /** for MyBatis Configure management. */
 @Configuration
 @MapperScan(value = {"org.apache.streampark.console.*.mapper"})
@@ -89,4 +93,16 @@ public class MybatisConfig {
       properties.setGlobalConfig(globalConfig);
     };
   }
+
+    @Bean
+    public DatabaseIdProvider databaseIdProvider() {
+        VendorDatabaseIdProvider databaseIdProvider = new VendorDatabaseIdProvider();
+        Properties properties = new Properties();
+        properties.put("MySQL","mysql");
+        // h2 is also used as the processing strategy for MySQL
+        properties.setProperty("H2", "mysql");
+        properties.setProperty("PostgreSQL", "pgsql");
+        databaseIdProvider.setProperties(properties);
+        return databaseIdProvider;
+    }
 }
diff --git a/streampark-console/streampark-console-service/src/main/resources/mapper/core/ApplicationMapper.xml b/streampark-console/streampark-console-service/src/main/resources/mapper/core/ApplicationMapper.xml
index ebc1a275e..b6f71849c 100644
--- a/streampark-console/streampark-console-service/src/main/resources/mapper/core/ApplicationMapper.xml
+++ b/streampark-console/streampark-console-service/src/main/resources/mapper/core/ApplicationMapper.xml
@@ -163,10 +163,20 @@
                 and t.execution_mode = #{application.executionMode}
             </if>
             <if test="application.jobName != null and application.jobName != ''">
-                and t.job_name like concat('%','${application.jobName}','%')
+                <if test="_databaseId == 'mysql'">
+                    and t.job_name like concat('%', #{application.jobName},'%')
+                </if>
+                <if test="_databaseId == 'pgsql'">
+                    and t.job_name like '%' || #{application.jobName} || '%'
+                </if>
             </if>
             <if test="application.projectName != null and application.projectName != ''">
-                and p.name like concat('%','${application.projectName}','%')
+                <if test="_databaseId == 'mysql'">
+                    and p.name like concat('%', #{application.projectName},'%')
+                </if>
+                <if test="_databaseId == 'pgsql'">
+                    and p.name like '%' || #{application.projectName} || '%'
+                </if>
             </if>
             <if test="application.appId != null and application.appId != ''">
                 and t.app_id = #{application.appId}
@@ -185,7 +195,12 @@
                 </foreach>
             </if>
             <if test="application.tags != null and application.tags != ''">
-                and t.tags like concat('%','${application.tags}','%')
+                <if test="_databaseId == 'mysql'">
+                    and t.tags like concat('%', #{application.tags},'%')
+                </if>
+                <if test="_databaseId == 'pgsql'">
+                    and t.tags like '%' || #{application.tags} || '%'
+                </if>
             </if>
         </where>
     </select>
diff --git a/streampark-console/streampark-console-service/src/main/resources/mapper/core/ProjectMapper.xml b/streampark-console/streampark-console-service/src/main/resources/mapper/core/ProjectMapper.xml
index a04ab7305..eb242ba38 100644
--- a/streampark-console/streampark-console-service/src/main/resources/mapper/core/ProjectMapper.xml
+++ b/streampark-console/streampark-console-service/src/main/resources/mapper/core/ProjectMapper.xml
@@ -72,7 +72,12 @@
         <where>
             t.team_id = #{project.teamId}
             <if test="project.name != null and project.name != ''">
-                and t.name like concat('%','${project.name}','%')
+                <if test="_databaseId == 'mysql'">
+                    and t.name like concat('%', #{project.name},'%')
+                </if>
+                <if test="_databaseId == 'pgsql'">
+                    and t.name like '%' || #{project.name} || '%'
+                </if>
             </if>
             <if test="project.buildState != null">
                 and t.build_state = #{project.buildState}
diff --git a/streampark-console/streampark-console-service/src/main/resources/mapper/core/VariableMapper.xml b/streampark-console/streampark-console-service/src/main/resources/mapper/core/VariableMapper.xml
index 855ec164c..c55480aa6 100644
--- a/streampark-console/streampark-console-service/src/main/resources/mapper/core/VariableMapper.xml
+++ b/streampark-console/streampark-console-service/src/main/resources/mapper/core/VariableMapper.xml
@@ -38,10 +38,20 @@
         on v.creator_id = u.user_id
         and v.team_id = #{variable.teamId}
         <if test="variable.description != null and variable.description != ''">
-            and v.description like concat('%','${variable.description}','%')
+            <if test="_databaseId == 'mysql'">
+                and v.description like concat('%', #{variable.description},'%')
+            </if>
+            <if test="_databaseId == 'pgsql'">
+                and v.description like '%' || #{variable.description} || '%'
+            </if>
         </if>
         <if test="variable.variableCode != null and variable.variableCode != ''">
-            and v.variable_code like concat('%','${variable.variableCode}','%')
+            <if test="_databaseId == 'mysql'">
+                and v.variable_code like concat('%', #{variable.variableCode},'%')
+            </if>
+            <if test="_databaseId == 'pgsql'">
+                and v.variable_code like '%' || #{variable.variableCode} || '%'
+            </if>
         </if>
     </select>
 
@@ -61,7 +71,12 @@
         <where>
             team_id = #{teamId}
             <if test="keyword != null and keyword != ''">
-                and variable_code like concat('%', '${keyword}', '%') or description like concat('%', '${keyword}', '%')
+                <if test="_databaseId == 'mysql'">
+                    and variable_code like concat('%', #{keyword}, '%') or description like concat('%', #{keyword}, '%')
+                </if>
+                <if test="_databaseId == 'pgsql'">
+                    and variable_code like '%' || #{keyword} || '%' or description like '%' || #{keyword} || '%'
+                </if>
             </if>
         </where>
     </select>
diff --git a/streampark-console/streampark-console-service/src/main/resources/mapper/core/YarnQueueMapper.xml b/streampark-console/streampark-console-service/src/main/resources/mapper/core/YarnQueueMapper.xml
index a1f27f4a8..a49b439f0 100644
--- a/streampark-console/streampark-console-service/src/main/resources/mapper/core/YarnQueueMapper.xml
+++ b/streampark-console/streampark-console-service/src/main/resources/mapper/core/YarnQueueMapper.xml
@@ -33,7 +33,12 @@
                 team_id = #{yarnQueue.teamId}
             </if>
             <if test="yarnQueue.queueLabel != null and yarnQueue.queueLabel != ''">
-                and queue_label like concat('%','${yarnQueue.queueLabel}','%')
+                <if test="_databaseId == 'mysql'">
+                    and queue_label like concat('%', #{yarnQueue.queueLabel},'%')
+                </if>
+                <if test="_databaseId == 'pgsql'">
+                    and queue_label like '%' || #{yarnQueue.queueLabel} || '%'
+                </if>
             </if>
             <if test="yarnQueue.createTimeFrom != null and yarnQueue.createTimeFrom !=''">
                 and create_time &gt; #{yarnQueue.createTimeFrom}
diff --git a/streampark-console/streampark-console-service/src/main/resources/mapper/system/MemberMapper.xml b/streampark-console/streampark-console-service/src/main/resources/mapper/system/MemberMapper.xml
index 3d79db840..643ebc206 100644
--- a/streampark-console/streampark-console-service/src/main/resources/mapper/system/MemberMapper.xml
+++ b/streampark-console/streampark-console-service/src/main/resources/mapper/system/MemberMapper.xml
@@ -51,7 +51,12 @@
         <where>
             tur.team_id = #{member.teamId}
             <if test="member.userName != null and member.userName != ''">
-                and u.username like concat('%','${member.userName}','%')
+                <if test="_databaseId == 'mysql'">
+                    and u.username like concat('%', #{member.userName},'%')
+                </if>
+                <if test="_databaseId == 'pgsql'">
+                    and u.username like '%' || #{member.userName} || '%'
+                </if>
             </if>
             <if test="member.roleName != null and member.roleName != ''">
                 and r.role_name = #{member.roleName}
diff --git a/streampark-console/streampark-console-service/src/main/resources/mapper/system/RoleMapper.xml b/streampark-console/streampark-console-service/src/main/resources/mapper/system/RoleMapper.xml
index c4c2bcaff..0904f6e47 100644
--- a/streampark-console/streampark-console-service/src/main/resources/mapper/system/RoleMapper.xml
+++ b/streampark-console/streampark-console-service/src/main/resources/mapper/system/RoleMapper.xml
@@ -29,7 +29,12 @@
         select * from t_role
         <where>
             <if test="role.roleName != null and role.roleName != ''">
-                and role_name like concat('%','${role.roleName}','%')
+                <if test="_databaseId == 'mysql'">
+                    and role_name like concat('%', #{role.roleName},'%')
+                </if>
+                <if test="_databaseId == 'pgsql'">
+                    and role_name like '%' || #{role.roleName} || '%'
+                </if>
             </if>
             <if test="role.createTimeFrom != null and role.createTimeFrom !=''">
                 and  create_time &gt; #{role.createTimeFrom}
diff --git a/streampark-console/streampark-console-service/src/main/resources/mapper/system/TeamMapper.xml b/streampark-console/streampark-console-service/src/main/resources/mapper/system/TeamMapper.xml
index 328842435..b2b39d8e0 100644
--- a/streampark-console/streampark-console-service/src/main/resources/mapper/system/TeamMapper.xml
+++ b/streampark-console/streampark-console-service/src/main/resources/mapper/system/TeamMapper.xml
@@ -29,7 +29,12 @@
         select * from t_team
         <where>
             <if test="team.teamName != null and team.teamName != ''">
-                and team_name like concat('%','${team.teamName}','%')
+                <if test="_databaseId == 'mysql'">
+                    and team_name like concat('%', #{team.teamName},'%')
+                </if>
+                <if test="_databaseId == 'pgsql'">
+                    and team_name like '%' || #{team.teamName} || '%'
+                </if>
             </if>
             <if test="team.createTimeFrom != null and team.createTimeFrom !=''">
                 and create_time &gt; #{team.createTimeFrom}
diff --git a/streampark-console/streampark-console-service/src/main/resources/mapper/system/UserMapper.xml b/streampark-console/streampark-console-service/src/main/resources/mapper/system/UserMapper.xml
index db459d626..e819aa114 100644
--- a/streampark-console/streampark-console-service/src/main/resources/mapper/system/UserMapper.xml
+++ b/streampark-console/streampark-console-service/src/main/resources/mapper/system/UserMapper.xml
@@ -38,7 +38,12 @@
         select * from t_user
         <where>
             <if test="user.username != null and user.username != ''">
-                and username like concat('%','${user.username}','%')
+                <if test="_databaseId == 'mysql'">
+                    and username like concat('%', #{user.username},'%')
+                </if>
+                <if test="_databaseId == 'pgsql'">
+                    and username like '%' || #{user.username} || '%'
+                </if>
             </if>
             <if test="user.createTimeFrom != null and user.createTimeFrom !=''">
                 and create_time &gt; #{user.createTimeFrom}