package com.boman.system.common; import com.alibaba.fastjson.JSONException; import com.alibaba.fastjson.JSONObject; import io.seata.rm.datasource.sql.struct.ColumnMeta; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.*; import java.util.regex.Pattern; /** * @author shiqian * @description * @date 2021年03月22日 16:17 **/ public class ColumnImpl implements Column { private static final Logger log = LoggerFactory.getLogger(ColumnImpl.class); private static final long serialVersionUID = -5809782578272943999L; private static Pattern msgKeyPattern = Pattern.compile("\\p{Punct}"); private static Pattern spaceKeyPattern = Pattern.compile(" "); private int id = -1; private String name; private String description; private String description2 = null; private boolean isNullable; private String limit = null; private String money = null; private boolean modifiable; private String obtainManner; private String defaultValue; private String refColumnName; private String tableColumnName; private Table objectTable; private String regExpression; private String errorMessage; private String comment = null; private String filter; // private DisplaySetting displaySetting; private boolean isUpperCase; private int sqltype; private int type; private boolean isAlternateKey; private boolean isAlternateKey2; private boolean isDisplayKey; private String mask; private boolean isValueLimited; // private PairTable values = null; private int length; private Table rTable = null; private Column rColumn = null; private Table table = null; private int displayOrder; private String valueInterpreter = null; private boolean isVirtual = false; private String sumMethod = null; private String sumMethodDesc = ""; private int scale = 0; private String sequenceHead = null; private String command = null; private String valueGroupName; private boolean isIndexed = false; private int onDeleteAction = 0; private int statSize = -1; private boolean isFilteredByWildcard = false; private List referenceColumnsInWildcardFilter = null; private Properties props = null; private boolean isAutoComplete = false; private JSONObject jsonProps = null; private String strProps = null; private String showcomment; private int securityGrade = 0; private Boolean showtitle; private boolean isorder = false; private String fkdisplay = null; private String querydefval = null; // private LimitvalueGroup limitvalueGroup; private String searchtype; private Boolean isremote; private String searchmodel; private String commentstp; private Boolean isagfilter; private String agfilter; private boolean isRowspan = false; private Locale defaultlocal = new Locale("zh", "CN"); private ColumnMeta columnMeta; // public ColumnMeta getColumnMeta() { // return this.columnMeta; // } // // public void setColumnMeta(ColumnMeta columnMeta) { // this.columnMeta = columnMeta; // } // // public ColumnImpl() { // } // // public ColumnImpl(int id, Table table, String columnName, String desc, int sqltype, boolean isNull) { // this.id = id; // this.table = table; // this.name = columnName; // this.description = desc; // this.sqltype = sqltype; // this.type = toGrossType(sqltype); // this.isNullable = isNull; // this.isVirtual = this.checkVirtual(); // } // // public static int toGrossType(int type) { // byte jType; // switch(type) { // case 1: // case 12: // case 13: // case 22: // case 24: // case 25: // jType = 2; // break; // case 2: // case 3: // case 4: // case 5: // case 6: // case 7: // case 8: // case 9: // case 10: // case 16: // jType = 0; // break; // case 11: // case 14: // jType = 1; // break; // case 15: // jType = 4; // break; // case 17: // case 18: // case 19: // case 20: // case 21: // default: // jType = 9; // break; // case 23: // jType = 3; // } // // return jType; // } // // public void setIsIndexed(boolean b) { // this.isIndexed = b; // } // // public boolean isFilteredByWildcard() { // return this.isFilteredByWildcard; // } // // public final Properties getProperties() { // return this.props; // } // // public boolean isIndexed() { // return this.isIndexed; // } // // public boolean isAutoComplete() { // return this.isAutoComplete; // } // // public boolean setIsAutoComplete(boolean b) { // return this.isAutoComplete = b; // } // // /** @deprecated */ // @Deprecated // public int getOnDeleteAction() { // return this.onDeleteAction; // } // // /** @deprecated */ // @Deprecated // public void setOnDeleteAction(String s) { // if ("SETNULL".equalsIgnoreCase(s)) { // this.onDeleteAction = 1; // } else if ("CASCADE".equalsIgnoreCase(s)) { // this.onDeleteAction = 2; // } // // } // // public void setIsNullable(boolean n) { // this.isNullable = n; // } // // public String getLimitValueGroupName() { // return this.valueGroupName; // } // // public int getScale() { // return this.scale; // } // // public void setScale(int scale) { // this.scale = scale; // } // // private boolean checkVirtual() { // char[] cs = this.name.toCharArray(); // // for(int i = 0; i < cs.length; ++i) { // if ((cs[i] < '0' || cs[i] > '9') && cs[i] != '_' && cs[i] != '-' && (cs[i] < 'a' || cs[i] > 'z') && (cs[i] < 'A' || cs[i] > 'Z')) { // return true; // } // } // // return false; // } // // public int getStatSize() { // return this.statSize; // } // // public void setStatSize(int size) { // this.statSize = size; // } // // public String getComment() { // return this.comment; // } // // public void setComment(String s) { // this.comment = s; // } // // public void setIsAlternateKey(boolean ak) { // this.isAlternateKey = ak; // } // // public void setIsAlternateKey2(boolean ak2) { // this.isAlternateKey2 = ak2; // } // // public void setIsDisplayKey(boolean dk) { // this.isDisplayKey = dk; // } // // public boolean isDisplayKey() { // return this.isDisplayKey; // } // // public void setMask(String mask) { // this.mask = mask; // } // // public void setIsValueLimited(boolean limit) { // this.isValueLimited = limit; // } // // public void setValues(String valueGroupName, PairTable vs, Locale locale) { // this.valueGroupName = valueGroupName.toLowerCase(); // if (this.values == null) { // this.values = new PairTable(); // } // // this.values.put(locale, vs); // } // // public void setValueInterpreter(String interpreter) { // if (interpreter == null) { // this.valueInterpreter = null; // } else { // this.valueInterpreter = interpreter; // } // } // // public boolean isAlternateKey() { // return this.isAlternateKey; // } // // public boolean isAlternateKey2() { // return this.isAlternateKey2; // } // // public boolean isNullable() { // return this.isNullable || this.displaySetting.getObjectType() == 5; // } // // public boolean isMaskSet(int maskPosition) { // if (maskPosition >= 0 && maskPosition < this.mask.length()) { // try { // return this.mask.charAt(maskPosition) == '1'; // } catch (IndexOutOfBoundsException var3) { // throw new IllegalArgumentException("mask position out of range:" + maskPosition + ",mask:" + this.mask); // } // } else { // return false; // } // } // // public boolean isMaskequls(int maskPosition) { // if (maskPosition >= 0 && maskPosition < this.mask.length()) { // try { // return this.mask.equals(Tools.replaceCharAt("0000000000", maskPosition, '1')); // } catch (IndexOutOfBoundsException var3) { // throw new IllegalArgumentException("mask position out of range:" + maskPosition + ",mask:" + this.mask); // } // } else { // return false; // } // } // // public boolean isShowable(int action) { // char c = true; // char c; // switch(action) { // case 0: // c = this.mask.charAt(0); // break; // case 1: // c = this.mask.charAt(2); // break; // case 2: // c = this.mask.charAt(4); // break; // case 3: // c = this.mask.charAt(5); // break; // case 4: // c = this.mask.charAt(6); // break; // case 5: // c = this.mask.charAt(7); // break; // case 6: // c = this.mask.charAt(8); // break; // case 7: // c = this.mask.charAt(9); // break; // default: // throw new IllegalArgumentException("action is not valid:" + action); // } // // return c == '1'; // } // // public boolean isModifiable(int action) { // char c = true; // char c; // switch(action) { // case 0: // c = this.mask.charAt(1); // break; // case 1: // c = this.mask.charAt(3); // break; // case 2: // c = this.mask.charAt(1); // break; // case 3: // c = this.mask.charAt(3); // break; // case 4: // c = '0'; // break; // default: // throw new IllegalArgumentException("action is not valid:" + action); // } // // return c == '1'; // } // // public boolean isValueLimited() { // return this.isValueLimited; // } // // public PairTable getValues(Locale locale) { // if (this.values == null) { // return null; // } else { // PairTable pt = (PairTable)this.values.get(locale); // if (pt == null) { // pt = new PairTable(); // Iterator it = this.getValues(this.defaultlocal).keys(); // // while(it.hasNext()) { // Object value = it.next(); // pt.put(value, Resources.getMessage("lmt_" + this.valueGroupName + "_" + value, new Object[0]).toLowerCase()); // } // // this.values.put(locale, pt); // } // // return pt; // } // } // // public int getLength() { // return this.length; // } // // public void setLength(int leng) { // this.length = leng; // } // // public Table getReferenceTable() { // return this.rTable; // } // // public void setReferenceTable(Table rt) { // this.rTable = rt; // } // // public Column getReferenceColumn() { // return this.rColumn; // } // // public void setReferenceColumn(Column rc) { // this.rColumn = rc; // } // // public Table getReferenceTable(boolean tryDateNumberAsFK, TableManager tm) { // if (this.rTable != null) { // return this.rTable; // } else { // return tryDateNumberAsFK && this.type == 3 ? tm.getDateTable() : null; // } // } // // public Column getReferenceColumn(boolean tryDateNumberAsFK, TableManager tm) { // if (this.rColumn != null) { // return this.rColumn; // } else { // if (tryDateNumberAsFK && this.type == 3) { // Table tb = tm.getDateTable(); // if (tb != null) { // return tb.getPrimaryKey(); // } // } // // return null; // } // } // // public int getDisplayOrder() { // return this.displayOrder; // } // // public void setDisplayOrder(int order) { // this.displayOrder = order; // } // // public String getValueInterpeter() { // return this.valueInterpreter; // } // // public int getId() { // return this.id; // } // // public String getName() { // return this.name; // } // // public String getDescription() { // return this.description; // } // // public String getDescription(Locale locale) { // try { // return Resources.getMessage("adcolumn_" + this.id, locale, new Object[]{this.description}); // } catch (MissingResourceException var3) { // return this.description; // } // } // // public void setDescription(String desc) { // this.description = desc; // } // // private String toMessageKey(String s) { // return spaceKeyPattern.matcher(msgKeyPattern.matcher(s).replaceAll("_")).replaceAll(""); // } // // public void setDescription2(String desc2) { // this.description2 = desc2; // } // // public int getSQLType() { // return this.sqltype; // } // // public void setSQLType(int sqlType) { // this.sqltype = sqlType; // this.type = toGrossType(this.sqltype); // } // // public int getType() { // return this.type; // } // // public Table getTable() { // return this.table; // } // // public int hashCode() { // return this.id; // } // // public boolean equals(Object c) { // return c instanceof Column && ((Column)c).getId() == this.id; // } // // public String toString() { // return this.table.toString() + "." + this.name; // } // // public void clone(Object obj) { // if (!(obj instanceof ColumnImpl)) { // throw new IllegalArgumentException("Not a ColumnImpl"); // } else { // ColumnImpl ci = (ColumnImpl)obj; // this.description = ci.description; // this.description2 = ci.description2; // this.displayOrder = ci.displayOrder; // this.id = ci.id; // this.isAlternateKey = ci.isAlternateKey; // this.isAlternateKey2 = ci.isAlternateKey2; // this.mask = ci.mask; // this.isValueLimited = ci.isValueLimited; // this.length = ci.length; // this.name = ci.name; // this.rTable = ci.rTable; // this.sqltype = ci.sqltype; // this.table = ci.table; // this.type = ci.type; // this.valueInterpreter = ci.valueInterpreter; // this.values = ci.values; // this.obtainManner = ci.obtainManner; // this.modifiable = ci.modifiable; // this.refColumnName = ci.refColumnName; // this.tableColumnName = ci.tableColumnName; // this.objectTable = ci.objectTable; // this.jsonProps = ci.jsonProps; // } // } // // public String getLimit() { // return this.limit; // } // // public void setLimit(String limit) { // this.limit = limit; // } // // public String getMoney() { // return this.money; // } // // public void setMoney(String money) { // this.money = money; // } // // public boolean getModifiable() { // return this.modifiable; // } // // public void setModifiable(boolean modifiable) { // this.modifiable = modifiable; // } // // public String getObtainManner() { // return this.obtainManner; // } // // public void setObtainManner(String obtainManner) { // this.obtainManner = obtainManner; // } // // public String getDefaultValue() { // return this.getDefaultValue(true); // } // // public void setDefaultValue(String defaultValue) { // this.defaultValue = defaultValue; // } // // public String getDefaultValue(boolean eval) { // if (eval && this.defaultValue != null && "=".equals(this.defaultValue.substring(0, 1))) { // } // // return this.defaultValue; // } // // public String getReferenceColumnName() { // return this.refColumnName; // } // // public void setReferenceColumnName(String columnName) { // this.refColumnName = columnName; // } // // public String getTableColumnName() { // return this.tableColumnName; // } // // public void setTableColumnName(String columnName) { // this.tableColumnName = columnName; // } // // public Table getObjectTable() { // return this.objectTable; // } // // public void setObjectTable(Table objectTable) { // this.objectTable = objectTable; // } // // public void setRegExpresion(String regExpression) { // if (Validator.isNotNull(regExpression)) { // if (this.displaySetting == null) { // throw new NDSRuntimeException("Must call setDisplaySetting before setRegExpresion for Column"); // } // // if (this.displaySetting.getObjectType() == 12) { // try { // JSONObject jo = JSONObject.parseObject(regExpression); // this.props = new Properties(); // Iterator var3 = jo.keySet().iterator(); // // while(var3.hasNext()) { // String key = (String)var3.next(); // this.props.setProperty(key, jo.getString(key)); // } // } catch (Throwable var5) { // throw new NDSRuntimeException("Could not load regExpression as json object:" + var5, var5); // } // } else { // this.regExpression = regExpression; // } // } // // } // // public String getRegExpression() { // return this.regExpression; // } // // public String getErrorMessage() { // return this.errorMessage; // } // // public void setErrorMessage(String errorMessage) { // this.errorMessage = errorMessage; // } // // public boolean isVirtual() { // return this.isVirtual; // } // // public String getSubTotalMethod() { // return this.sumMethod; // } // // public void setSubTotalMethod(String method) { // this.sumMethod = method; // } // // public String getSubTotalDesc() { // return this.sumMethodDesc; // } // // void setIsFilteredByWildcard(boolean b) { // this.isFilteredByWildcard = b; // } // // public List getReferenceColumnsInWildcardFilter() { // return this.referenceColumnsInWildcardFilter; // } // // public void setReferenceColumnsInWildcardFilter(List columns) { // this.referenceColumnsInWildcardFilter = columns; // } // // public String getFilter() { // return this.filter; // } // // public void setFilter(String filter) { // this.filter = filter; // if (Validator.isNotNull(filter) && (this.getReferenceTable() != null || this.getDisplaySetting().getObjectType() == 12) && filter.indexOf(64) > -1) { // this.isFilteredByWildcard = true; // } // // } // // public DisplaySetting getDisplaySetting() { // return this.displaySetting; // } // // public void setDisplaySetting(DisplaySetting setting) { // this.displaySetting = setting; // } // // public String getSequenceHead() { // return this.sequenceHead; // } // // public void setSequenceHead(String s) { // this.sequenceHead = s; // } // // public boolean isColumnLink(TableManager tm) { // if (this.name.indexOf(";") > -1) { // try { // this.getColumnLink(tm); // return true; // } catch (Exception var3) { // return false; // } // } else { // return false; // } // } // // public ColumnLink getColumnLink(TableManager tm) throws QueryException { // return new ColumnLink(this.table.getName() + "." + this.name, tm); // } // // public Object getUIConstructor() { // Object uiConstructor = null; // if (this.getDisplaySetting().getObjectType() == 10) { // if (Validator.isNull(this.getValueInterpeter())) { // throw new NDSRuntimeException("Not found interpreter of button column " + this); // } // // try { // uiConstructor = ApplicationContextHandle.getBean(this.getValueInterpeter()); // } catch (Exception var5) { // try { // uiConstructor = ApplicationContextHandle.getBean(InstanceUtil.getClass(this.getValueInterpeter())); // } catch (Exception var4) { // log.debug("Found error in get ui constructor:" + var4); // } // } // } // // return uiConstructor; // } // // public Object getUIAlerter() { // Object uiAlerter = null; // if (Validator.isNotNull(this.getValueInterpeter())) { // try { // uiAlerter = ApplicationContextHandle.getBean(this.getValueInterpeter()); // } catch (Exception var5) { // try { // uiAlerter = ApplicationContextHandle.getBean(InstanceUtil.getClass(this.getValueInterpeter())); // } catch (Exception var4) { // log.debug("Found error in get ui alerter:" + var4); // } // } // } // // return uiAlerter; // } // // public void setIsUpperCase(boolean b) { // this.isUpperCase = b; // } // // public boolean isUpperCase() { // return this.isUpperCase; // } // // public int getSecurityGrade() { // return this.securityGrade; // } // // public JSONObject toJSONSimpleObject() throws JSONException { // JSONObject jo = new JSONObject(); // jo.put("id", this.id); // jo.put("description", this.getDescription()); // jo.put("isNullable", this.isNullable); // jo.put("refColumnId", this.getReferenceColumn() == null ? -1 : this.getReferenceColumn().getId()); // if (this.getReferenceColumn() != null) { // jo.put("refTableAK", this.getReferenceTable().getAlternateKey().toJSONSimpleObject()); // } // // jo.put("mask", this.mask); // jo.put("isValueLimited", this.isValueLimited); // jo.put("type", this.type); // return jo; // } // // public JSONObject toJSONObject(Locale locale) throws JSONException { // JSONObject jo = new JSONObject(); // jo.put("id", this.id); // jo.put("name", this.name); // jo.put("description", this.getDescription()); // jo.put("isNullable", this.isNullable); // jo.put("obtainManner", this.obtainManner); // jo.put("defaultValue", this.defaultValue); // jo.put("refColumnId", this.getReferenceColumn() == null ? -1 : this.getReferenceColumn().getId()); // if (this.getReferenceColumn() != null) { // jo.put("refTableAK", this.getReferenceTable().getAlternateKey().toJSONObject(locale)); // } // // jo.put("refTableId", this.getReferenceTable() == null ? -1 : this.getReferenceTable().getId()); // jo.put("isAlternateKey", this.isAlternateKey); // jo.put("mask", this.mask); // jo.put("isValueLimited", this.isValueLimited); // jo.put("values", this.values); // jo.put("isUpperCase", this.isUpperCase); // jo.put("filter", this.filter); // jo.put("displaySetting", this.displaySetting.getObjectTypeString()); // jo.put("type", this.type); // jo.put("length", this.length); // jo.put("scale", this.scale); // jo.put("valueInterpreter", this.valueInterpreter); // jo.put("table", this.table.getId()); // jo.put("isVirtual", this.isVirtual); // jo.put("isIndexed", this.isIndexed); // jo.put("isAutoComplete", this.isAutoComplete); // jo.put("props", this.jsonProps); // return jo; // } // // public JSONObject getJSONProps() { // return this.jsonProps; // } // // public void setJSONProps(JSONObject jo) { // this.jsonProps = jo; // if (jo != null) { // this.securityGrade = jo.getIntValue("sgrade"); // } // // } // // public String getStrProps() { // if (this.jsonProps == null) { // this.jsonProps = new JSONObject(); // } // // return this.jsonProps.toString(); // } // // public String getShowcomment() { // return this.showcomment; // } // // public Boolean getIsorder() { // return this.isorder; // } // // public void setIsorder(Boolean isorder) { // this.isorder = isorder; // } // // public void setShowcomment(String shcomment) { // this.showcomment = shcomment; // } // // public Boolean getShowtitle() { // return this.showtitle; // } // // public void setShowtitle(Boolean ishowtite) { // this.showtitle = ishowtite; // } // // public Boolean getRowspan() { // return this.isRowspan; // } // // public void setRowspan(Boolean isRowspan) { // this.isRowspan = isRowspan; // } // // public String getFkdisplay() { // return this.fkdisplay; // } // // public void setFkdisplay(String fkdisplay) { // this.fkdisplay = fkdisplay; // } // // public String getQuerydefval() { // return this.querydefval; // } // // public void setQuerydefval(String querydefval) { // this.querydefval = querydefval; // } // // public boolean isComputed() { // return "computed".equals(this.obtainManner); // } // // public LimitvalueGroup getLimitvalueGroup() { // return this.limitvalueGroup; // } // // public void setLimitvalueGroup(LimitvalueGroup limitvalueGroup) { // this.limitvalueGroup = limitvalueGroup; // } // // public String getSearchtype() { // return this.searchtype; // } // // public void setSearchtype(String searchtype) { // this.searchtype = searchtype; // } // // public boolean getIsremote() { // return this.isremote; // } // // public void setIsremote(Boolean isremote) { // this.isremote = isremote; // } // // public String getSearchmodel() { // return this.searchmodel; // } // // public void setSearchmodel(String searchmodel) { // this.searchmodel = searchmodel; // } // // public String getCommentstp() { // return Tools.nvl(this.commentstp, "list"); // } // // public void setCommentstp(String commentstp) { // this.commentstp = commentstp; // } // // public Boolean getIsagfilter() { // return this.isagfilter; // } // // public void setIsagfilter(Boolean isagfilter) { // this.isagfilter = isagfilter; // } // // public String getAgfilter() { // return this.agfilter; // } // // public void setAgfilter(String agfilter) { // this.agfilter = agfilter; // } }