Commit 0d5e7e57 authored by wenmo's avatar wenmo

common format

parent f6d81b81
...@@ -13,44 +13,44 @@ import java.util.Map; ...@@ -13,44 +13,44 @@ import java.util.Map;
*/ */
public class Asserts { public class Asserts {
public static boolean isNotNull(Object object){ public static boolean isNotNull(Object object) {
return object!=null; return object != null;
} }
public static boolean isNull(Object object){ public static boolean isNull(Object object) {
return object==null; return object == null;
} }
public static boolean isNullString(String str){ public static boolean isNullString(String str) {
return isNull(str)||"".equals(str); return isNull(str) || "".equals(str);
} }
public static boolean isNotNullString(String str){ public static boolean isNotNullString(String str) {
return !isNullString(str); return !isNullString(str);
} }
public static boolean isEquals(String str1,String str2){ public static boolean isEquals(String str1, String str2) {
if(isNull(str1)&&isNull(str2)){ if (isNull(str1) && isNull(str2)) {
return true; return true;
}else if(isNull(str1)||isNull(str2)){ } else if (isNull(str1) || isNull(str2)) {
return false; return false;
}else{ } else {
return str1.equals(str2); return str1.equals(str2);
} }
} }
public static boolean isEqualsIgnoreCase(String str1,String str2){ public static boolean isEqualsIgnoreCase(String str1, String str2) {
if(isNull(str1)&&isNull(str2)){ if (isNull(str1) && isNull(str2)) {
return true; return true;
}else if(isNull(str1)||isNull(str2)){ } else if (isNull(str1) || isNull(str2)) {
return false; return false;
}else{ } else {
return str1.equalsIgnoreCase(str2); return str1.equalsIgnoreCase(str2);
} }
} }
public static boolean isNullCollection(Collection collection) { public static boolean isNullCollection(Collection collection) {
if (isNull(collection)||collection.size()==0) { if (isNull(collection) || collection.size() == 0) {
return true; return true;
} }
return false; return false;
...@@ -61,7 +61,7 @@ public class Asserts { ...@@ -61,7 +61,7 @@ public class Asserts {
} }
public static boolean isNullMap(Map map) { public static boolean isNullMap(Map map) {
if (isNull(map)||map.size()==0) { if (isNull(map) || map.size() == 0) {
return true; return true;
} }
return false; return false;
...@@ -71,32 +71,32 @@ public class Asserts { ...@@ -71,32 +71,32 @@ public class Asserts {
return !isNullMap(map); return !isNullMap(map);
} }
public static void checkNull(Object key,String msg) { public static void checkNull(Object key, String msg) {
if (key == null) { if (key == null) {
throw new RunTimeException(msg); throw new RunTimeException(msg);
} }
} }
public static void checkNotNull(Object object,String msg) { public static void checkNotNull(Object object, String msg) {
if (isNull(object)) { if (isNull(object)) {
throw new RunTimeException(msg); throw new RunTimeException(msg);
} }
} }
public static void checkNullString(String key,String msg) { public static void checkNullString(String key, String msg) {
if (isNull(key)||isEquals("",key)) { if (isNull(key) || isEquals("", key)) {
throw new RunTimeException(msg); throw new RunTimeException(msg);
} }
} }
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);
} }
} }
......
package com.dlink.model; package com.dlink.model;
import com.dlink.assertion.Asserts;
/** /**
* JobLifeCycle * JobLifeCycle
* *
...@@ -9,13 +7,13 @@ import com.dlink.assertion.Asserts; ...@@ -9,13 +7,13 @@ import com.dlink.assertion.Asserts;
* @since 2022/2/1 16:37 * @since 2022/2/1 16:37
*/ */
public enum JobLifeCycle { public enum JobLifeCycle {
UNKNOWN(0,"未知"), UNKNOWN(0, "未知"),
CREATE(1,"创建"), CREATE(1, "创建"),
DEVELOP(2,"开发"), DEVELOP(2, "开发"),
DEBUG(3,"调试"), DEBUG(3, "调试"),
RELEASE(4,"发布"), RELEASE(4, "发布"),
ONLINE(5,"上线"), ONLINE(5, "上线"),
CANCEL(6,"注销"); CANCEL(6, "注销");
private Integer value; private Integer value;
private String label; private String label;
...@@ -34,17 +32,17 @@ public enum JobLifeCycle { ...@@ -34,17 +32,17 @@ public enum JobLifeCycle {
} }
public static JobLifeCycle get(Integer value){ public static JobLifeCycle get(Integer value) {
for (JobLifeCycle item : JobLifeCycle.values()) { for (JobLifeCycle item : JobLifeCycle.values()) {
if(item.getValue() == value){ if (item.getValue() == value) {
return item; return item;
} }
} }
return JobLifeCycle.UNKNOWN; return JobLifeCycle.UNKNOWN;
} }
public boolean equalsValue(Integer step){ public boolean equalsValue(Integer step) {
if(value == step){ if (value == step) {
return true; return true;
} }
return false; return false;
......
...@@ -16,10 +16,12 @@ import java.util.Map; ...@@ -16,10 +16,12 @@ import java.util.Map;
public class SystemConfiguration { public class SystemConfiguration {
private static volatile SystemConfiguration systemConfiguration = new SystemConfiguration(); private static volatile SystemConfiguration systemConfiguration = new SystemConfiguration();
public static SystemConfiguration getInstances() { public static SystemConfiguration getInstances() {
return systemConfiguration; return systemConfiguration;
} }
private static final List<Configuration> CONFIGURATION_LIST = new ArrayList<Configuration>(){{
private static final List<Configuration> CONFIGURATION_LIST = new ArrayList<Configuration>() {{
add(systemConfiguration.sqlSubmitJarPath); add(systemConfiguration.sqlSubmitJarPath);
add(systemConfiguration.sqlSubmitJarParas); add(systemConfiguration.sqlSubmitJarParas);
add(systemConfiguration.sqlSubmitJarMainAppClass); add(systemConfiguration.sqlSubmitJarMainAppClass);
...@@ -63,12 +65,12 @@ public class SystemConfiguration { ...@@ -63,12 +65,12 @@ public class SystemConfiguration {
"Flink SQL 的语句分割符" "Flink SQL 的语句分割符"
); );
public void setConfiguration(JsonNode jsonNode){ public void setConfiguration(JsonNode jsonNode) {
for(Configuration item : CONFIGURATION_LIST){ for (Configuration item : CONFIGURATION_LIST) {
if(!jsonNode.has(item.getName())){ if (!jsonNode.has(item.getName())) {
continue; continue;
} }
switch (item.getType()){ switch (item.getType()) {
case BOOLEAN: case BOOLEAN:
item.setValue(jsonNode.get(item.getName()).asBoolean()); item.setValue(jsonNode.get(item.getName()).asBoolean());
break; break;
...@@ -81,12 +83,12 @@ public class SystemConfiguration { ...@@ -81,12 +83,12 @@ public class SystemConfiguration {
} }
} }
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)){ if (map.containsKey(item.getName()) && item.getType().equals(ValueType.BOOLEAN)) {
map.put(item.getName(), Asserts.isEqualsIgnoreCase("true",map.get(item.getName()).toString())); map.put(item.getName(), Asserts.isEqualsIgnoreCase("true", map.get(item.getName()).toString()));
} }
if(!map.containsKey(item.getName())) { if (!map.containsKey(item.getName())) {
map.put(item.getName(), item.getValue()); map.put(item.getName(), item.getValue());
} }
} }
...@@ -132,11 +134,11 @@ public class SystemConfiguration { ...@@ -132,11 +134,11 @@ public class SystemConfiguration {
this.sqlSeparator.setValue(sqlSeparator); this.sqlSeparator.setValue(sqlSeparator);
} }
enum ValueType{ enum ValueType {
STRING,INT,DOUBLE,FLOAT,BOOLEAN,DATE STRING, INT, DOUBLE, FLOAT, BOOLEAN, DATE
} }
public class Configuration{ public class Configuration {
private String name; private String name;
private String label; private String label;
private ValueType type; private ValueType type;
......
...@@ -83,9 +83,9 @@ public class Table implements Serializable, Comparable<Table> { ...@@ -83,9 +83,9 @@ public class Table implements Serializable, Comparable<Table> {
} }
sb.append("`" + columns.get(i).getName() + "` " + type); sb.append("`" + columns.get(i).getName() + "` " + type);
if (Asserts.isNotNullString(columns.get(i).getComment())) { if (Asserts.isNotNullString(columns.get(i).getComment())) {
if(columns.get(i).getComment().contains("\'") | columns.get(i).getComment().contains("\"")) { if (columns.get(i).getComment().contains("\'") | columns.get(i).getComment().contains("\"")) {
sb.append(" COMMENT '" + columns.get(i).getComment().replaceAll("\"|'","") + "'"); sb.append(" COMMENT '" + columns.get(i).getComment().replaceAll("\"|'", "") + "'");
}else { } else {
sb.append(" COMMENT '" + columns.get(i).getComment() + "'"); sb.append(" COMMENT '" + columns.get(i).getComment() + "'");
} }
} }
...@@ -99,7 +99,7 @@ public class Table implements Serializable, Comparable<Table> { ...@@ -99,7 +99,7 @@ public class Table implements Serializable, Comparable<Table> {
if (i > 0) { if (i > 0) {
pksb.append(","); pksb.append(",");
} }
pksb.append("`"+pks.get(i)+"`"); pksb.append("`" + pks.get(i) + "`");
} }
pksb.append(" ) NOT ENFORCED\n"); pksb.append(" ) NOT ENFORCED\n");
if (pks.size() > 0) { if (pks.size() > 0) {
...@@ -107,10 +107,10 @@ public class Table implements Serializable, Comparable<Table> { ...@@ -107,10 +107,10 @@ public class Table implements Serializable, Comparable<Table> {
sb.append(pksb); sb.append(pksb);
} }
sb.append(")"); sb.append(")");
if(Asserts.isNotNullString(comment)){ if (Asserts.isNotNullString(comment)) {
if(comment.contains("\'") | comment.contains("\"")) { if (comment.contains("\'") | comment.contains("\"")) {
sb.append(" COMMENT '" + comment.replaceAll("\"|'","") + "'\n"); sb.append(" COMMENT '" + comment.replaceAll("\"|'", "") + "'\n");
}else { } else {
sb.append(" COMMENT '" + comment + "'\n"); sb.append(" COMMENT '" + comment + "'\n");
} }
} }
...@@ -128,21 +128,21 @@ public class Table implements Serializable, Comparable<Table> { ...@@ -128,21 +128,21 @@ public class Table implements Serializable, Comparable<Table> {
if (i > 0) { if (i > 0) {
sb.append(","); sb.append(",");
} }
String columnComment= columns.get(i).getComment(); String columnComment = columns.get(i).getComment();
if(Asserts.isNotNullString(columnComment)){ if (Asserts.isNotNullString(columnComment)) {
if (columnComment.contains("\'") | columnComment.contains("\"")) { if (columnComment.contains("\'") | columnComment.contains("\"")) {
columnComment = columnComment.replaceAll("\"|'", ""); columnComment = columnComment.replaceAll("\"|'", "");
} }
sb.append("`"+columns.get(i).getName() + "` -- " + columnComment + " \n"); sb.append("`" + columns.get(i).getName() + "` -- " + columnComment + " \n");
}else { } else {
sb.append("`"+columns.get(i).getName() + "` \n"); sb.append("`" + columns.get(i).getName() + "` \n");
} }
} }
if(Asserts.isNotNullString(comment)){ if (Asserts.isNotNullString(comment)) {
sb.append(" FROM " + schema + "." + name + ";" + " -- " + comment + "\n"); sb.append(" FROM " + schema + "." + name + ";" + " -- " + comment + "\n");
}else { } else {
sb.append(" FROM " + schema + "." + name +";\n"); sb.append(" FROM " + schema + "." + name + ";\n");
} }
return sb.toString(); return sb.toString();
} }
......
...@@ -28,14 +28,14 @@ public class ClassEntity { ...@@ -28,14 +28,14 @@ public class ClassEntity {
this.classByte = classByte; this.classByte = classByte;
} }
public static ClassEntity build(String name, String code){ public static ClassEntity build(String name, String code) {
return new ClassEntity(name,code); return new ClassEntity(name, code);
} }
public boolean equals(ClassEntity entity) { public boolean equals(ClassEntity entity) {
if (Asserts.isEquals(name, entity.getName()) && Asserts.isEquals(code, entity.getCode())){ if (Asserts.isEquals(name, entity.getName()) && Asserts.isEquals(code, entity.getCode())) {
return true; return true;
}else{ } else {
return false; return false;
} }
} }
......
...@@ -31,8 +31,8 @@ public class ClassPool { ...@@ -31,8 +31,8 @@ public class ClassPool {
return false; return false;
} }
public static Integer push(ClassEntity executorEntity){ public static Integer push(ClassEntity executorEntity) {
if(exist(executorEntity.getName())){ if (exist(executorEntity.getName())) {
remove(executorEntity.getName()); remove(executorEntity.getName());
} }
classList.add(executorEntity); classList.add(executorEntity);
......
...@@ -17,12 +17,12 @@ public class AbstractResult { ...@@ -17,12 +17,12 @@ public class AbstractResult {
protected long time; protected long time;
protected String error; protected String error;
public void success(){ public void success() {
this.setEndTime(LocalDateTime.now()); this.setEndTime(LocalDateTime.now());
this.setSuccess(true); this.setSuccess(true);
} }
public void error(String error){ public void error(String error) {
this.setEndTime(LocalDateTime.now()); this.setEndTime(LocalDateTime.now());
this.setSuccess(false); this.setSuccess(false);
this.setError(error); this.setError(error);
......
package com.dlink.result; package com.dlink.result;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Date;
/** /**
* 解释结果 * 解释结果
...@@ -35,12 +34,12 @@ public class SqlExplainResult { ...@@ -35,12 +34,12 @@ public class SqlExplainResult {
this.explainTime = explainTime; this.explainTime = explainTime;
} }
public static SqlExplainResult success(String type,String sql,String explain){ public static SqlExplainResult success(String type, String sql, String explain) {
return new SqlExplainResult(1,type,sql,null,explain,null,true,true,LocalDateTime.now()); return new SqlExplainResult(1, type, sql, null, explain, null, true, true, LocalDateTime.now());
} }
public static SqlExplainResult fail(String sql,String error){ public static SqlExplainResult fail(String sql, String error) {
return new SqlExplainResult(1,null,sql,null,null,error,false,false,LocalDateTime.now()); return new SqlExplainResult(1, null, sql, null, null, error, false, false, LocalDateTime.now());
} }
public Integer getIndex() { public Integer getIndex() {
......
...@@ -3,12 +3,7 @@ package com.dlink.utils; ...@@ -3,12 +3,7 @@ package com.dlink.utils;
import com.dlink.assertion.Asserts; import com.dlink.assertion.Asserts;
import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode; import com.fasterxml.jackson.databind.node.TextNode;
...@@ -17,15 +12,9 @@ import org.slf4j.Logger; ...@@ -17,15 +12,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.*;
import java.util.Collections;
import java.util.List; import static com.fasterxml.jackson.databind.DeserializationFeature.*;
import java.util.Map;
import java.util.TimeZone;
import static com.fasterxml.jackson.databind.DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT;
import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
import static com.fasterxml.jackson.databind.DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL;
import static com.fasterxml.jackson.databind.MapperFeature.REQUIRE_SETTERS_FOR_GETTERS; import static com.fasterxml.jackson.databind.MapperFeature.REQUIRE_SETTERS_FOR_GETTERS;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
...@@ -124,7 +113,7 @@ public class JSONUtil { ...@@ -124,7 +113,7 @@ public class JSONUtil {
} }
public static String toJsonString(Object object) { public static String toJsonString(Object object) {
if(Asserts.isNull(object)){ if (Asserts.isNull(object)) {
return null; return null;
} }
try { try {
......
...@@ -18,33 +18,33 @@ public class LogUtil { ...@@ -18,33 +18,33 @@ public class LogUtil {
private static final Logger logger = LoggerFactory.getLogger(LogUtil.class); private static final Logger logger = LoggerFactory.getLogger(LogUtil.class);
public static String getError(Exception e){ public static String getError(Exception e) {
// e.printStackTrace(); // e.printStackTrace();
String error = null; String error = null;
try(StringWriter sw = new StringWriter(); try (StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw)){ PrintWriter pw = new PrintWriter(sw)) {
e.printStackTrace(pw); e.printStackTrace(pw);
error = sw.toString(); error = sw.toString();
logger.error(error); logger.error(error);
} catch (IOException ioe) { } catch (IOException ioe) {
ioe.printStackTrace(); ioe.printStackTrace();
}finally { } finally {
return error; return error;
} }
} }
public static String getError(String msg,Exception e){ public static String getError(String msg, Exception e) {
// e.printStackTrace(); // e.printStackTrace();
String error = null; String error = null;
try(StringWriter sw = new StringWriter(); try (StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw)){ PrintWriter pw = new PrintWriter(sw)) {
e.printStackTrace(pw); e.printStackTrace(pw);
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
error = now.toString() + ": " + msg + " \nError message:\n " + sw.toString(); error = now.toString() + ": " + msg + " \nError message:\n " + sw.toString();
logger.error(error); logger.error(error);
} catch (IOException ioe) { } catch (IOException ioe) {
ioe.printStackTrace(); ioe.printStackTrace();
}finally { } finally {
return error; return error;
} }
} }
......
...@@ -8,7 +8,7 @@ package com.dlink.utils; ...@@ -8,7 +8,7 @@ package com.dlink.utils;
**/ **/
public class RunTimeUtil { public class RunTimeUtil {
public static void recovery(Object obj){ public static void recovery(Object obj) {
obj = null; obj = null;
System.gc(); System.gc();
} }
......
...@@ -25,6 +25,6 @@ public class SqlUtil { ...@@ -25,6 +25,6 @@ public class SqlUtil {
} }
public static String replaceAllParam(String sql, String name, String value) { public static String replaceAllParam(String sql, String name, String value) {
return sql.replaceAll("\\$\\{"+name+"\\}",value); return sql.replaceAll("\\$\\{" + name + "\\}", value);
} }
} }
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