SqlReplacer now using DB#isDb2
This commit is contained in:
parent
5dd1de4d58
commit
640ffb3a7e
|
|
@ -23,6 +23,11 @@
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>pro.taskana</groupId>
|
||||||
|
<artifactId>taskana-common</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- test dependencies -->
|
<!-- test dependencies -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import pro.taskana.common.internal.configuration.DB;
|
||||||
|
|
||||||
/** This class replaces boolean values with int values if the database is db2. */
|
/** This class replaces boolean values with int values if the database is db2. */
|
||||||
final class SqlReplacer {
|
final class SqlReplacer {
|
||||||
|
|
||||||
|
|
@ -18,16 +20,13 @@ final class SqlReplacer {
|
||||||
static final DateTimeFormatter DATE_TIME_FORMATTER =
|
static final DateTimeFormatter DATE_TIME_FORMATTER =
|
||||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
|
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
|
||||||
|
|
||||||
|
// to prevent initialization
|
||||||
private SqlReplacer() {}
|
private SqlReplacer() {}
|
||||||
|
|
||||||
static String getScriptAsSql(String dbProductName, ZonedDateTime now, String scriptPath) {
|
static String getScriptAsSql(String dbProductName, ZonedDateTime now, String scriptPath) {
|
||||||
return parseAndReplace(getScriptBufferedStream(scriptPath), now, dbProductName);
|
return parseAndReplace(getScriptBufferedStream(scriptPath), now, dbProductName);
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isDb2(String dbProductName) {
|
|
||||||
return dbProductName != null && dbProductName.contains("DB2");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method resolves the custom sql function defined through this regex: {@value
|
* This method resolves the custom sql function defined through this regex: {@value
|
||||||
* RELATIVE_DATE_REGEX}. Its parameter is a digit representing the relative offset of a given
|
* RELATIVE_DATE_REGEX}. Its parameter is a digit representing the relative offset of a given
|
||||||
|
|
@ -61,17 +60,13 @@ final class SqlReplacer {
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
static String getSanitizedTableName(String table) {
|
|
||||||
return table.replaceAll("[^a-zA-Z0-9_]", "__");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String replaceBooleanWithInteger(String sql) {
|
private static String replaceBooleanWithInteger(String sql) {
|
||||||
return sql.replaceAll("(?i)true", "1").replaceAll("(?i)false", "0");
|
return sql.replaceAll("(?i)true", "1").replaceAll("(?i)false", "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String parseAndReplace(
|
private static String parseAndReplace(
|
||||||
BufferedReader bufferedReader, ZonedDateTime now, String dbProductname) {
|
BufferedReader bufferedReader, ZonedDateTime now, String dbProductname) {
|
||||||
boolean isDb2 = isDb2(dbProductname);
|
boolean isDb2 = DB.isDb2(dbProductname);
|
||||||
String sql = bufferedReader.lines().collect(Collectors.joining(System.lineSeparator()));
|
String sql = bufferedReader.lines().collect(Collectors.joining(System.lineSeparator()));
|
||||||
if (isDb2) {
|
if (isDb2) {
|
||||||
sql = replaceBooleanWithInteger(sql);
|
sql = replaceBooleanWithInteger(sql);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue