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