Unverified Commit 8a40fbfc authored by Licho's avatar Licho Committed by GitHub

refactor: dinky-common (#1551)

* refacotr: dinky-common Signed-off-by: 's avatarLicho <chinabhsun@gmail.com> * chore: splotless * fix: flink other version rename absence Signed-off-by: 's avatarLicho <chinabhsun@gmail.com> Signed-off-by: 's avatarLicho <chinabhsun@gmail.com>
parent 291da9dc
...@@ -307,9 +307,9 @@ public abstract class AbstractSinkBuilder implements SinkBuilder { ...@@ -307,9 +307,9 @@ public abstract class AbstractSinkBuilder implements SinkBuilder {
case INTEGER: case INTEGER:
return new IntType(); return new IntType();
case DATE: case DATE:
case LOCALDATE: case LOCAL_DATE:
return new DateType(); return new DateType();
case LOCALDATETIME: case LOCAL_DATETIME:
case TIMESTAMP: case TIMESTAMP:
return new TimestampType(); return new TimestampType();
case BYTES: case BYTES:
......
...@@ -306,9 +306,9 @@ public abstract class AbstractSinkBuilder implements SinkBuilder { ...@@ -306,9 +306,9 @@ public abstract class AbstractSinkBuilder implements SinkBuilder {
case INTEGER: case INTEGER:
return new IntType(); return new IntType();
case DATE: case DATE:
case LOCALDATE: case LOCAL_DATE:
return new DateType(); return new DateType();
case LOCALDATETIME: case LOCAL_DATETIME:
case TIMESTAMP: case TIMESTAMP:
return new TimestampType(); return new TimestampType();
case BYTES: case BYTES:
......
...@@ -326,9 +326,9 @@ public class KafkaSinkJsonBuilder extends AbstractSinkBuilder implements SinkBui ...@@ -326,9 +326,9 @@ public class KafkaSinkJsonBuilder extends AbstractSinkBuilder implements SinkBui
case INTEGER: case INTEGER:
return new IntType(); return new IntType();
case DATE: case DATE:
case LOCALDATE: case LOCAL_DATE:
return new DateType(); return new DateType();
case LOCALDATETIME: case LOCAL_DATETIME:
case TIMESTAMP: case TIMESTAMP:
return new TimestampType(); return new TimestampType();
case BYTES: case BYTES:
......
...@@ -317,9 +317,9 @@ public abstract class AbstractSinkBuilder implements SinkBuilder { ...@@ -317,9 +317,9 @@ public abstract class AbstractSinkBuilder implements SinkBuilder {
case INTEGER: case INTEGER:
return new IntType(); return new IntType();
case DATE: case DATE:
case LOCALDATE: case LOCAL_DATE:
return new DateType(); return new DateType();
case LOCALDATETIME: case LOCAL_DATETIME:
case TIMESTAMP: case TIMESTAMP:
return new TimestampType(); return new TimestampType();
case BYTES: case BYTES:
......
...@@ -317,9 +317,9 @@ public abstract class AbstractSinkBuilder implements SinkBuilder { ...@@ -317,9 +317,9 @@ public abstract class AbstractSinkBuilder implements SinkBuilder {
case INTEGER: case INTEGER:
return new IntType(); return new IntType();
case DATE: case DATE:
case LOCALDATE: case LOCAL_DATE:
return new DateType(); return new DateType();
case LOCALDATETIME: case LOCAL_DATETIME:
case TIMESTAMP: case TIMESTAMP:
return new TimestampType(); return new TimestampType();
case BYTES: case BYTES:
......
...@@ -311,9 +311,9 @@ public abstract class AbstractSinkBuilder implements SinkBuilder { ...@@ -311,9 +311,9 @@ public abstract class AbstractSinkBuilder implements SinkBuilder {
case INTEGER: case INTEGER:
return new IntType(); return new IntType();
case DATE: case DATE:
case LOCALDATE: case LOCAL_DATE:
return new DateType(); return new DateType();
case LOCALDATETIME: case LOCAL_DATETIME:
case TIMESTAMP: case TIMESTAMP:
return new TimestampType(); return new TimestampType();
case BYTES: case BYTES:
......
...@@ -54,14 +54,14 @@ public class Column implements Serializable { ...@@ -54,14 +54,14 @@ public class Column implements Serializable {
public String getFlinkType() { public String getFlinkType() {
String flinkType = javaType.getFlinkType(); String flinkType = javaType.getFlinkType();
if (flinkType.equals("DECIMAL")) { if (!flinkType.equals("DECIMAL")) {
if (precision == null || precision == 0) {
return flinkType + "(" + 38 + "," + scale + ")";
} else {
return flinkType + "(" + precision + "," + scale + ")";
}
} else {
return flinkType; return flinkType;
} }
if (precision == null || precision == 0) {
return String.format("%s(%d,%d)", flinkType, 38, scale);
}
return String.format("%s(%d,%d)", flinkType, precision, scale);
} }
} }
...@@ -42,12 +42,12 @@ public enum ColumnType { ...@@ -42,12 +42,12 @@ public enum ColumnType {
JAVA_LANG_DOUBLE("java.lang.Double", "DOUBLE"), JAVA_LANG_DOUBLE("java.lang.Double", "DOUBLE"),
DOUBLE("double", "DOUBLE NOT NULL"), DOUBLE("double", "DOUBLE NOT NULL"),
DATE("java.sql.Date", "DATE"), DATE("java.sql.Date", "DATE"),
LOCALDATE("java.time.LocalDate", "DATE"), LOCAL_DATE("java.time.LocalDate", "DATE"),
TIME("java.sql.Time", "TIME"), TIME("java.sql.Time", "TIME"),
LOCALTIME("java.time.LocalTime", "TIME"), LOCALTIME("java.time.LocalTime", "TIME"),
TIMESTAMP("java.sql.Timestamp", "TIMESTAMP"), TIMESTAMP("java.sql.Timestamp", "TIMESTAMP"),
LOCALDATETIME("java.time.LocalDateTime", "TIMESTAMP"), LOCAL_DATETIME("java.time.LocalDateTime", "TIMESTAMP"),
OFFSETDATETIME("java.time.OffsetDateTime", "TIMESTAMP WITH TIME ZONE"), OFFSET_DATETIME("java.time.OffsetDateTime", "TIMESTAMP WITH TIME ZONE"),
INSTANT("java.time.Instant", "TIMESTAMP_LTZ"), INSTANT("java.time.Instant", "TIMESTAMP_LTZ"),
DURATION("java.time.Duration", "INVERVAL SECOND"), DURATION("java.time.Duration", "INVERVAL SECOND"),
PERIOD("java.time.Period", "INTERVAL YEAR TO MONTH"), PERIOD("java.time.Period", "INTERVAL YEAR TO MONTH"),
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
package org.dinky.model; package org.dinky.model;
import java.util.Arrays;
/** /**
* JobLifeCycle * JobLifeCycle
* *
...@@ -51,18 +53,13 @@ public enum JobLifeCycle { ...@@ -51,18 +53,13 @@ public enum JobLifeCycle {
} }
public static JobLifeCycle get(Integer value) { public static JobLifeCycle get(Integer value) {
for (JobLifeCycle item : JobLifeCycle.values()) { return Arrays.stream(values())
if (item.getValue().equals(value)) { .filter(item -> item.getValue().equals(value))
return item; .findFirst()
} .orElse(JobLifeCycle.UNKNOWN);
}
return JobLifeCycle.UNKNOWN;
} }
public boolean equalsValue(Integer step) { public boolean equalsValue(Integer step) {
if (value.equals(step)) { return value.equals(step);
return true;
}
return false;
} }
} }
...@@ -21,9 +21,11 @@ package org.dinky.model; ...@@ -21,9 +21,11 @@ package org.dinky.model;
import org.dinky.assertion.Asserts; import org.dinky.assertion.Asserts;
import java.util.ArrayList; import java.util.Arrays;
import java.util.List; import java.util.List;
import com.google.common.collect.Lists;
/** /**
* JobState * JobState
* *
...@@ -85,12 +87,10 @@ public enum JobStatus { ...@@ -85,12 +87,10 @@ public enum JobStatus {
} }
public static JobStatus get(String value) { public static JobStatus get(String value) {
for (JobStatus type : JobStatus.values()) { return Arrays.stream(JobStatus.values())
if (Asserts.isEqualsIgnoreCase(type.getValue(), value)) { .filter(type -> Asserts.isEqualsIgnoreCase(type.getValue(), value))
return type; .findFirst()
} .orElse(JobStatus.UNKNOWN);
}
return JobStatus.UNKNOWN;
} }
public static boolean isDone(String value) { public static boolean isDone(String value) {
...@@ -118,11 +118,6 @@ public enum JobStatus { ...@@ -118,11 +118,6 @@ public enum JobStatus {
} }
public static List<JobStatus> getAllDoneStatus() { public static List<JobStatus> getAllDoneStatus() {
final List<JobStatus> list = new ArrayList<>(4); return Lists.newArrayList(FAILED, CANCELED, FINISHED, UNKNOWN);
list.add(FAILED);
list.add(CANCELED);
list.add(FINISHED);
list.add(UNKNOWN);
return list;
} }
} }
...@@ -21,11 +21,11 @@ package org.dinky.model; ...@@ -21,11 +21,11 @@ package org.dinky.model;
import org.dinky.assertion.Asserts; import org.dinky.assertion.Asserts;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.Lists;
/** /**
* SystemConfiguration * SystemConfiguration
...@@ -42,17 +42,13 @@ public class SystemConfiguration { ...@@ -42,17 +42,13 @@ public class SystemConfiguration {
} }
private static final List<Configuration> CONFIGURATION_LIST = private static final List<Configuration> CONFIGURATION_LIST =
new ArrayList<Configuration>() { Lists.newArrayList(
systemConfiguration.sqlSubmitJarPath,
{ systemConfiguration.sqlSubmitJarParas,
add(systemConfiguration.sqlSubmitJarPath); systemConfiguration.sqlSubmitJarMainAppClass,
add(systemConfiguration.sqlSubmitJarParas); systemConfiguration.useRestAPI,
add(systemConfiguration.sqlSubmitJarMainAppClass); systemConfiguration.sqlSeparator,
add(systemConfiguration.useRestAPI); systemConfiguration.jobIdWait);
add(systemConfiguration.sqlSeparator);
add(systemConfiguration.jobIdWait);
}
};
private Configuration sqlSubmitJarPath = private Configuration sqlSubmitJarPath =
new Configuration( new Configuration(
...@@ -94,32 +90,34 @@ public class SystemConfiguration { ...@@ -94,32 +90,34 @@ public class SystemConfiguration {
"提交 Application 或 PerJob 任务时获取 Job ID 的最大等待时间(秒)"); "提交 Application 或 PerJob 任务时获取 Job ID 的最大等待时间(秒)");
public void setConfiguration(JsonNode jsonNode) { public void setConfiguration(JsonNode jsonNode) {
for (Configuration item : CONFIGURATION_LIST) { CONFIGURATION_LIST.stream()
if (!jsonNode.has(item.getName())) { .filter(t -> jsonNode.has(t.getName()))
continue; .forEach(
} item -> {
switch (item.getType()) { final JsonNode value = jsonNode.get(item.getName());
case BOOLEAN: switch (item.getType()) {
item.setValue(jsonNode.get(item.getName()).asBoolean()); case BOOLEAN:
break; item.setValue(value.asBoolean());
case INT: break;
item.setValue(jsonNode.get(item.getName()).asInt()); case INT:
break; item.setValue(value.asInt());
default: break;
item.setValue(jsonNode.get(item.getName()).asText()); default:
} item.setValue(value.asText());
} }
});
} }
public void addConfiguration(Map<String, Object> map) { public void addConfiguration(Map<String, Object> map) {
for (Configuration item : CONFIGURATION_LIST) { for (Configuration item : CONFIGURATION_LIST) {
if (map.containsKey(item.getName()) && item.getType().equals(ValueType.BOOLEAN)) { final String name = item.getName();
map.put( if (!map.containsKey(name)) {
item.getName(), map.put(name, item.getValue());
Asserts.isEqualsIgnoreCase("true", map.get(item.getName()).toString())); continue;
} }
if (!map.containsKey(item.getName())) {
map.put(item.getName(), item.getValue()); if (item.getType().equals(ValueType.BOOLEAN)) {
map.put(name, Asserts.isEqualsIgnoreCase("true", map.get(name).toString()));
} }
} }
} }
...@@ -183,12 +181,13 @@ public class SystemConfiguration { ...@@ -183,12 +181,13 @@ public class SystemConfiguration {
public class Configuration { public class Configuration {
private final String label;
private final Object defaultValue;
private final String note;
private String name; private String name;
private String label;
private ValueType type; private ValueType type;
private Object defaultValue;
private Object value; private Object value;
private String note;
public Configuration( public Configuration(
String name, String label, ValueType type, Object defaultValue, String note) { String name, String label, ValueType type, Object defaultValue, String note) {
......
...@@ -36,12 +36,15 @@ public enum TableType { ...@@ -36,12 +36,15 @@ public enum TableType {
if (splitDatabase && splitTable) { if (splitDatabase && splitTable) {
return TableType.SPLIT_DATABASE_AND_TABLE; return TableType.SPLIT_DATABASE_AND_TABLE;
} }
if (splitTable) { if (splitTable) {
return TableType.SINGLE_DATABASE_AND_SPLIT_TABLE; return TableType.SINGLE_DATABASE_AND_SPLIT_TABLE;
} }
if (!splitDatabase) {
return TableType.SINGLE_DATABASE_AND_TABLE; if (splitDatabase) {
return TableType.SPLIT_DATABASE_AND_SINGLE_TABLE;
} }
return TableType.SPLIT_DATABASE_AND_SINGLE_TABLE;
return TableType.SINGLE_DATABASE_AND_TABLE;
} }
} }
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
package org.dinky.model; package org.dinky.model;
import java.util.Arrays;
/** /**
* @author csz * @author csz
* @version 1.0 * @version 1.0
...@@ -53,11 +55,9 @@ public enum TaskOperatingSavepointSelect { ...@@ -53,11 +55,9 @@ public enum TaskOperatingSavepointSelect {
} }
public static TaskOperatingSavepointSelect valueByCode(Integer code) { public static TaskOperatingSavepointSelect valueByCode(Integer code) {
for (TaskOperatingSavepointSelect savepointSelect : TaskOperatingSavepointSelect.values()) { return Arrays.stream(values())
if (savepointSelect.getCode().equals(code)) { .filter(savepointSelect -> savepointSelect.getCode().equals(code))
return savepointSelect; .findFirst()
} .orElse(null);
}
return null;
} }
} }
...@@ -42,7 +42,7 @@ public class OracleTypeConvert implements ITypeConvert { ...@@ -42,7 +42,7 @@ public class OracleTypeConvert implements ITypeConvert {
if (t.contains("char")) { if (t.contains("char")) {
columnType = ColumnType.STRING; columnType = ColumnType.STRING;
} else if (t.contains("date")) { } else if (t.contains("date")) {
columnType = ColumnType.LOCALDATETIME; columnType = ColumnType.LOCAL_DATETIME;
} else if (t.contains("timestamp")) { } else if (t.contains("timestamp")) {
columnType = ColumnType.TIMESTAMP; columnType = ColumnType.TIMESTAMP;
} else if (t.contains("number")) { } else if (t.contains("number")) {
......
...@@ -86,7 +86,7 @@ public class SqlServerTypeConvert implements ITypeConvert { ...@@ -86,7 +86,7 @@ public class SqlServerTypeConvert implements ITypeConvert {
// 这里应该是纳秒 // 这里应该是纳秒
columnType = ColumnType.TIMESTAMP; columnType = ColumnType.TIMESTAMP;
} else if (t.equalsIgnoreCase("date")) { } else if (t.equalsIgnoreCase("date")) {
columnType = ColumnType.LOCALDATE; columnType = ColumnType.LOCAL_DATE;
} else if (t.equalsIgnoreCase("time")) { } else if (t.equalsIgnoreCase("time")) {
columnType = ColumnType.LOCALTIME; columnType = ColumnType.LOCALTIME;
} else if (t.contains("timestamp") } else if (t.contains("timestamp")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment