add
This commit is contained in:
@ -0,0 +1,62 @@
|
||||
package com.qiaoba.common.base.enums;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 数据库类型
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/5/22 16:41
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum DataBaseEnum {
|
||||
|
||||
/**
|
||||
* MySQL
|
||||
*/
|
||||
MY_SQL("MySQL",
|
||||
"jdbc:mysql://localhost:3306/{}?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true",
|
||||
"com.mysql.cj.jdbc.Driver"),
|
||||
|
||||
/**
|
||||
* Oracle
|
||||
*/
|
||||
ORACLE("Oracle",
|
||||
"jdbc:oracle:thin:@//localhost:1521/{}",
|
||||
"oracle.jdbc.OracleDriver"),
|
||||
|
||||
/**
|
||||
* PostgreSQL
|
||||
*/
|
||||
POSTGRE_SQL("PostgreSQL",
|
||||
"jdbc:postgresql://localhost:5432/{}?useUnicode=true&characterEncoding=utf8&useSSL=true&autoReconnect=true&reWriteBatchedInserts=true",
|
||||
"org.postgresql.Driver"),
|
||||
|
||||
/**
|
||||
* SQL Server
|
||||
*/
|
||||
SQL_SERVER("Microsoft SQL Server",
|
||||
"jdbc:sqlserver://localhost:1433;DatabaseName={};SelectMethod=cursor;encrypt=false;rewriteBatchedStatements=true",
|
||||
"com.microsoft.sqlserver.jdbc.SQLServerDriver");
|
||||
|
||||
private final String type;
|
||||
private final String url;
|
||||
private final String driver;
|
||||
|
||||
public static DataBaseEnum find(String databaseProductName) {
|
||||
if (StrUtil.isBlank(databaseProductName)) {
|
||||
return null;
|
||||
}
|
||||
for (DataBaseEnum type : values()) {
|
||||
if (type.getType().equals(databaseProductName)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package com.qiaoba.common.base.enums;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 数据库类型
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/5/22 16:41
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum DataBaseTypeEnum {
|
||||
|
||||
/**
|
||||
* MySQL
|
||||
*/
|
||||
MY_SQL("MySQL"),
|
||||
|
||||
/**
|
||||
* Oracle
|
||||
*/
|
||||
ORACLE("Oracle"),
|
||||
|
||||
/**
|
||||
* PostgreSQL
|
||||
*/
|
||||
POSTGRE_SQL("PostgreSQL"),
|
||||
|
||||
/**
|
||||
* SQL Server
|
||||
*/
|
||||
SQL_SERVER("Microsoft SQL Server");
|
||||
|
||||
private final String type;
|
||||
|
||||
public static DataBaseTypeEnum find(String databaseProductName) {
|
||||
if (StrUtil.isBlank(databaseProductName)) {
|
||||
return null;
|
||||
}
|
||||
for (DataBaseTypeEnum type : values()) {
|
||||
if (type.getType().equals(databaseProductName)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -2,7 +2,7 @@ package com.qiaoba.common.base.utils;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.qiaoba.common.base.context.BaseContext;
|
||||
import com.qiaoba.common.base.enums.DataBaseTypeEnum;
|
||||
import com.qiaoba.common.base.enums.DataBaseEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
@ -23,15 +23,15 @@ public class DatabaseUtil {
|
||||
* @return 处理后的sql
|
||||
*/
|
||||
public static String handleFindInSet(Object var1, String var2) {
|
||||
DataBaseTypeEnum dataBaseType = DataBaseTypeEnum.find(BaseContext.getDatabaseType());
|
||||
DataBaseEnum dataBaseType = DataBaseEnum.find(BaseContext.getDatabaseType());
|
||||
String var = Convert.toStr(var1);
|
||||
if (dataBaseType == DataBaseTypeEnum.SQL_SERVER) {
|
||||
if (dataBaseType == DataBaseEnum.SQL_SERVER) {
|
||||
// charindex(',100,' , ',0,100,101,') <> 0
|
||||
return "charindex('," + var + ",' , ','+" + var2 + "+',') <> 0";
|
||||
} else if (dataBaseType == DataBaseTypeEnum.POSTGRE_SQL) {
|
||||
} else if (dataBaseType == DataBaseEnum.POSTGRE_SQL) {
|
||||
// (select position(',100,' in ',0,100,101,')) <> 0
|
||||
return "(select position('," + var + ",' in ','||" + var2 + "||',')) <> 0";
|
||||
} else if (dataBaseType == DataBaseTypeEnum.ORACLE) {
|
||||
} else if (dataBaseType == DataBaseEnum.ORACLE) {
|
||||
// instr(',0,100,101,' , ',100,') <> 0
|
||||
return "instr(','||" + var2 + "||',' , '," + var + ",') <> 0";
|
||||
}
|
||||
|
Reference in New Issue
Block a user