Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Imprpve] JDBC "like" syntax is compatible with mysql and pgsql #3557

Merged
merged 5 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.apache.streampark.console.base.mybatis.interceptor.PostgreSQLPrepareInterceptor;
import org.apache.streampark.console.base.mybatis.interceptor.PostgreSQLQueryInterceptor;

import org.apache.ibatis.mapping.DatabaseIdProvider;
import org.apache.ibatis.mapping.VendorDatabaseIdProvider;
import org.apache.ibatis.type.JdbcType;

import com.baomidou.mybatisplus.annotation.IdType;
Expand All @@ -34,6 +36,8 @@
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"})
Expand Down Expand Up @@ -89,4 +93,16 @@ public MybatisPlusPropertiesCustomizer mybatisPlusPropertiesCustomizer() {
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ export default {
lost: 'LOST',
},
release: {
releaseTitle: 'The current release of the application is in progress.',
releaseTitle: 'The current release of the job is in progress.',
releaseDesc: 'are you sure you want to force another build',
releaseFail: 'release application failed,',
releasing: 'Current Application is releasing',
releaseFail: 'release job failed,',
releasing: 'Current job is releasing',
},
detail: {
detailTitle: 'Application Info',
detailTitle: 'Job Info',
flinkWebUi: 'Flink Web UI',
compareConfig: 'Compare Config',
compareFlinkSql: 'Compare Flink SQL',
Expand Down Expand Up @@ -155,16 +155,16 @@ export default {
},
},
view: {
buildTitle: 'Application releasing Progress',
buildTitle: 'Job releasing Progress',
stepTitle: 'Steps Detail',
errorLog: 'Error Log',
errorSummary: 'Error Summary',
errorStack: 'Error Stack',
logTitle: 'Start Log : Job Name [ {0} ]',
refreshTime: 'last refresh time',
refresh: 'refresh',
start: 'Start Application',
stop: 'Stop application',
start: 'Start Job',
stop: 'Stop Job',
savepoint: 'Trigger Savepoint',
fromSavepoint: 'From savepoint',
savepointTip: 'Restore the job from savepoint or latest checkpoint',
Expand All @@ -174,8 +174,8 @@ export default {
ignoreRestored: 'Ignore failed',
ignoreRestoredTip:
'ignore savepoint then cannot be restored, Same as:-allowNonRestoredState(-n)',
recheck: 'the associated project has changed and this job need to be rechecked',
changed: 'the application has changed.',
recheck: 'the associated project has changed and this job need to be release',
changed: 'the job has been updated',
},
pod: {
choice: 'Choice',
Expand Down Expand Up @@ -203,17 +203,17 @@ export default {
sqlCheck: 'SQL check error',
},
operation: {
edit: 'Edit Application',
release: 'Release Application',
edit: 'Edit Job',
release: 'Release Job',
releaseDetail: 'Releasing Progress Detail',
start: 'Start Application',
cancel: 'Cancel Application',
start: 'Start Job',
cancel: 'Cancel Job',
savepoint: 'Trigger Savepoint',
detail: 'View Detail',
startLog: 'See Flink Start log',
force: 'Forced Stop Application',
copy: 'Copy Application',
remapping: 'Remapping Application',
force: 'Forced Stop Job',
copy: 'Copy Job',
remapping: 'Remapping Job',
deleteTip: 'Are you sure delete this job ?',
triggerSavePoint: 'Trigger savepoint',
enableSavePoint: 'Trigger savepoint before flink job cancel',
Expand Down Expand Up @@ -282,7 +282,7 @@ export default {
totalMemoryOptionsPlaceholder: 'Please select the resource parameters to set',
tmPlaceholder: 'Please select the resource parameters to set',
yarnQueuePlaceholder: 'Please enter yarn queue label',
descriptionPlaceholder: 'Please enter description for this application',
descriptionPlaceholder: 'Please enter description for this job',
serviceAccountPlaceholder: 'Please enter kubernetes service-account, e.g: default',
kubernetesNamespacePlaceholder: 'Please enter kubernetes Namespace, e.g: default',
kubernetesClusterIdPlaceholder: 'Please enter Kubernetes clusterId',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default {
terminated: '终止',
},
release: {
releaseTitle: '该应用程序的当前启动正在进行中.',
releaseTitle: '该作业正在启动中.',
releaseDesc: '您确定要强制进行另一次构建吗',
releaseFail: '发布作业失败',
releasing: '当前作业正在发布中',
Expand Down Expand Up @@ -145,7 +145,7 @@ export default {
},
},
view: {
buildTitle: '应用程序启动进度',
buildTitle: '作业启动进度',
stepTitle: '步骤详情',
errorLog: '错误日志',
errorSummary: '错误摘要',
Expand All @@ -156,8 +156,8 @@ export default {
start: '启动作业',
stop: '停止应用',
savepoint: '触发 Savepoint',
recheck: '关联的项目已更改,需要重新检查此作业',
changed: '应用程序已更改。',
recheck: '关联的项目已更新,需要重新发布此作业',
changed: '作业已更新',
fromSavepoint: 'Savepoint 恢复',
savepointTip: '作业从 savepoint 或 checkpoint 恢复状态',
savepointInput: '指定 savepoint/checkpoint 路径',
Expand Down Expand Up @@ -262,10 +262,10 @@ export default {
appNamePlaceholder: '请输入作业名称',
appNameIsRequiredMessage: '作业名称必填',
appNameNotUniqueMessage: '作业名称必须唯一, 输入的作业名称已经存在',
appNameExistsInYarnMessage: '应用程序名称已经在YARN集群中存在,不能重复。请检查',
appNameExistsInK8sMessage: '该应用程序名称已经在K8S集群中存在,不能重复。请检查',
appNameValid: '应用程序名称不合法',
appNameRole: '应用名称必须遵循以下规则:',
appNameExistsInYarnMessage: '该作业名称已经在YARN集群中存在,不能重复。请检查',
appNameExistsInK8sMessage: '该作业名称已经在K8S集群中存在,不能重复。请检查',
appNameValid: '作业名称不合法',
appNameRole: '作业必须遵循以下规则:',
K8sSessionClusterIdRole: 'K8S集群ID必要遵循以下规则:',
appNameK8sClusterIdRole:
'当前部署模式是 K8s Application模式,会将作业名称作为k8s的 clusterId,因此作业名称要遵循以下规则:',
Expand All @@ -283,7 +283,7 @@ export default {
totalMemoryOptionsPlaceholder: '请选择要设置的资源参数',
tmPlaceholder: '请选择要设置的资源参数',
yarnQueuePlaceholder: '请输入yarn队列标签名称',
descriptionPlaceholder: '请输入此应用程序的描述',
descriptionPlaceholder: '请输入此作业的描述',
serviceAccountPlaceholder: '请输入K8S服务账号(service-account)',
kubernetesNamespacePlaceholder: '请输入K8S命名空间, 如: default',
kubernetesClusterIdPlaceholder: '请选择K8S ClusterId',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ export const useAppTableAction = (

const formConfig = computed((): Partial<FormProps> => {
const tableFormConfig: FormProps = {
baseColProps: { span: 5, style: { paddingRight: '20px' } },
actionColOptions: { span: 4 },
baseColProps: { span: 4, style: { paddingRight: '30px' } },
actionColOptions: { style: { paddingRight: '0px' } },
showSubmitButton: false,
showResetButton: false,
async resetFunc() {
Expand Down Expand Up @@ -329,6 +329,7 @@ export const useAppTableAction = (
text: t('common.add'),
color: 'primary',
preIcon: 'ant-design:plus-outlined',
style: { float: 'right' },
},
});
}
Expand Down
Loading