Unverified Commit 3f5b8da1 authored by Licho's avatar Licho Committed by GitHub

refactor: some trick modification (#1135)

* refactor: some trick modification

* refactor: some trick modification

* fix: checkstyle
Signed-off-by: 's avatarlicho <lecho.sun@gmail.com>
Signed-off-by: 's avatarlicho <lecho.sun@gmail.com>
parent b64a565f
...@@ -32,6 +32,9 @@ import java.util.Map; ...@@ -32,6 +32,9 @@ import java.util.Map;
*/ */
public class Asserts { public class Asserts {
private Asserts() {
}
public static boolean isNotNull(Object object) { public static boolean isNotNull(Object object) {
return object != null; return object != null;
} }
...@@ -88,25 +91,19 @@ public class Asserts { ...@@ -88,25 +91,19 @@ public class Asserts {
} }
} }
public static boolean isNullCollection(Collection collection) { public static boolean isNullCollection(Collection<?> collection) {
if (isNull(collection) || collection.size() == 0) { return isNull(collection) || collection.isEmpty();
return true;
}
return false;
} }
public static boolean isNotNullCollection(Collection collection) { public static boolean isNotNullCollection(Collection<?> collection) {
return !isNullCollection(collection); return !isNullCollection(collection);
} }
public static boolean isNullMap(Map map) { public static boolean isNullMap(Map<?, ?> map) {
if (isNull(map) || map.size() == 0) { return isNull(map) || map.size() == 0;
return true;
}
return false;
} }
public static boolean isNotNullMap(Map map) { public static boolean isNotNullMap(Map<?, ?> map) {
return !isNullMap(map); return !isNullMap(map);
} }
...@@ -128,13 +125,13 @@ public class Asserts { ...@@ -128,13 +125,13 @@ public class Asserts {
} }
} }
public static void checkNullCollection(Collection collection, String msg) { public static void checkNullCollection(Collection<?> collection, String msg) {
if (isNullCollection(collection)) { if (isNullCollection(collection)) {
throw new RunTimeException(msg); throw new RunTimeException(msg);
} }
} }
public static void checkNullMap(Map map, String msg) { public static void checkNullMap(Map<?, ?> map, String msg) {
if (isNullMap(map)) { if (isNullMap(map)) {
throw new RunTimeException(msg); throw new RunTimeException(msg);
} }
......
...@@ -41,7 +41,7 @@ public class SqlUtil { ...@@ -41,7 +41,7 @@ public class SqlUtil {
return new String[0]; return new String[0];
} }
String[] splits = sql.replaceAll(";\r\n", ";\n").split(sqlSeparator); String[] splits = sql.replace(";\r\n", ";\n").split(sqlSeparator);
String lastStatement = splits[splits.length - 1].trim(); String lastStatement = splits[splits.length - 1].trim();
if (lastStatement.endsWith(SEMICOLON)) { if (lastStatement.endsWith(SEMICOLON)) {
splits[splits.length - 1] = lastStatement.substring(0, lastStatement.length() - 1); splits[splits.length - 1] = lastStatement.substring(0, lastStatement.length() - 1);
......
...@@ -63,10 +63,7 @@ public enum SqlType { ...@@ -63,10 +63,7 @@ public enum SqlType {
} }
public boolean isInsert() { public boolean isInsert() {
if (type.equals("INSERT")) { return type.equals("INSERT");
return true;
}
return false;
} }
} }
...@@ -26,6 +26,8 @@ import com.dlink.trans.ddl.SetOperation; ...@@ -26,6 +26,8 @@ import com.dlink.trans.ddl.SetOperation;
import com.dlink.trans.ddl.ShowFragmentOperation; import com.dlink.trans.ddl.ShowFragmentOperation;
import com.dlink.trans.ddl.ShowFragmentsOperation; import com.dlink.trans.ddl.ShowFragmentsOperation;
import java.util.Arrays;
/** /**
* Operations * Operations
* *
...@@ -34,8 +36,10 @@ import com.dlink.trans.ddl.ShowFragmentsOperation; ...@@ -34,8 +36,10 @@ import com.dlink.trans.ddl.ShowFragmentsOperation;
**/ **/
public class Operations { public class Operations {
private static Operation[] operations = { private Operations() {
new CreateAggTableOperation() }
private static final Operation[] ALL_OPERATIONS = {new CreateAggTableOperation()
, new SetOperation() , new SetOperation()
, new CreateCDCSourceOperation() , new CreateCDCSourceOperation()
, new ShowFragmentsOperation() , new ShowFragmentsOperation()
...@@ -70,12 +74,15 @@ public class Operations { ...@@ -70,12 +74,15 @@ public class Operations {
} }
public static Operation buildOperation(String statement) { public static Operation buildOperation(String statement) {
String sql = statement.replace("\n", " ").replaceAll("\\s{1,}", " ").trim().toUpperCase(); String sql = statement.replace("\n", " ")
for (int i = 0; i < operations.length; i++) { .replaceAll("\\s+", " ")
if (sql.startsWith(operations[i].getHandle())) { .trim()
return operations[i].create(statement); .toUpperCase();
}
} return Arrays.stream(ALL_OPERATIONS)
return null; .filter(p -> sql.startsWith(p.getHandle()))
.findFirst()
.map(p -> p.create(statement))
.orElse(null);
} }
} }
...@@ -29,12 +29,16 @@ import com.dlink.assertion.Asserts; ...@@ -29,12 +29,16 @@ import com.dlink.assertion.Asserts;
**/ **/
public enum GatewayType { public enum GatewayType {
LOCAL("l", "local"), STANDALONE("s", "standalone"), LOCAL("l", "local"),
YARN_SESSION("ys", "yarn-session"), YARN_APPLICATION("ya", "yarn-application"), STANDALONE("s", "standalone"),
YARN_PER_JOB("ypj", "yarn-per-job"), KUBERNETES_SESSION("ks", "kubernetes-session"), KUBERNETES_APPLICATION("ka", "kubernetes-application"); YARN_SESSION("ys", "yarn-session"),
YARN_APPLICATION("ya", "yarn-application"),
YARN_PER_JOB("ypj", "yarn-per-job"),
KUBERNETES_SESSION("ks", "kubernetes-session"),
KUBERNETES_APPLICATION("ka", "kubernetes-application");
private String value; private final String value;
private String longValue; private final String longValue;
GatewayType(String value, String longValue) { GatewayType(String value, String longValue) {
this.value = value; this.value = value;
...@@ -59,10 +63,7 @@ public enum GatewayType { ...@@ -59,10 +63,7 @@ public enum GatewayType {
} }
public boolean equalsValue(String type) { public boolean equalsValue(String type) {
if (Asserts.isEquals(value, type) || Asserts.isEquals(longValue, type)) { return Asserts.isEquals(value, type) || Asserts.isEquals(longValue, type);
return true;
}
return false;
} }
public static boolean isDeployCluster(String type) { public static boolean isDeployCluster(String type) {
......
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