📄 sqlcolumn.java
字号:
return charLength; } public void setCharLength(int charLength) { this.charLength = charLength; } public int getColSize() { return colSize; } public void setColSize(int colSize) { this.colSize = colSize; } public String getColDefault() { return this.colDefault; } public void setColDefault(String colDefault) { this.colDefault = colDefault; } public int getPos() { return pos; } public void setPos(int pos) { this.pos = pos; } public int getRadix() { return radix; } public void setRadix(int radix) { this.radix = radix; } public String getRemarks() { return remarks; } public void setRemarks(String remarks) { this.remarks = remarks; } public String getPkName() { return pkName; } public void setPkName(String pkName) { this.pkName = pkName; } public boolean isAutoInc() { return autoInc; } public void setAutoInc(boolean autoInc) { this.autoInc = autoInc; } public boolean isCaseSens() { return caseSens; } public void setCaseSens(boolean caseSens) { this.caseSens = caseSens; } public String getLabel() { return label; } public void setLabel(String label) { this.label = label; } public String getTypeName() { return typeName; } public void setTypeName(String typeName) { this.typeName = typeName; } public static String getSqlTypeAsText(int sqlType) { if (sqlType == Types.ARRAY) return "ARRAY"; if (sqlType == Types.BIGINT) return "BIGINT"; if (sqlType == Types.BINARY) return "BINARY"; if (sqlType == Types.BIT) return "BIT"; if (sqlType == Types.BLOB) return "BLOB"; if (sqlType == Types.BOOLEAN) return "BOOLEAN"; if (sqlType == Types.CHAR) return "CHAR"; if (sqlType == Types.CLOB) return "CLOB"; if (sqlType == Types.DATALINK) return "DATALINK"; if (sqlType == Types.DATE) return "DATE"; if (sqlType == Types.DECIMAL) return "DECIMAL"; if (sqlType == Types.DISTINCT) return "DISTINCT"; if (sqlType == Types.DOUBLE) return "DOUBLE"; if (sqlType == Types.FLOAT) return "FLOAT"; if (sqlType == Types.INTEGER) return "INTEGER"; if (sqlType == Types.JAVA_OBJECT) return "JAVA_OBJECT"; if (sqlType == Types.LONGVARBINARY) return "LONGVARBINARY"; if (sqlType == Types.LONGVARCHAR) return "LONGVARCHAR"; if (sqlType == Types.NULL) return "NULL"; if (sqlType == Types.NUMERIC) return "NUMERIC"; if (sqlType == Types.OTHER) return "OTHER"; if (sqlType == Types.REAL) return "REAL"; if (sqlType == Types.REF) return "REF"; if (sqlType == Types.SMALLINT) return "SMALLINT"; if (sqlType == Types.STRUCT) return "STRUCT"; if (sqlType == Types.TIME) return "TIME"; if (sqlType == Types.TIMESTAMP) return "TIMESTAMP"; if (sqlType == Types.TINYINT) return "TINYINT"; if (sqlType == Types.VARBINARY) return "VARBINARY"; if (sqlType == Types.VARCHAR) return "VARCHAR"; return "UNKNOWN"; } public static SqlColumn getComplete() { SqlColumn desc = new SqlColumn(new PropertiesInfo(new Properties())); desc.setColName("someName"); desc.setTable("tableName"); desc.setSchema("schemaName"); desc.setCatalog("catalogName"); desc.setType("typeName"); desc.setPrecision(4); desc.setScale(3); desc.setPrimaryKey(true); desc.setPkName("somePkName"); desc.setSqlType(2000); desc.setColSize(10); desc.setRadix(5); desc.setRemarks("Some remarks"); desc.setColDefault("someDef"); desc.setCharLength(29); desc.setPos(4); desc.setFkCatalog("someForCat"); desc.setFkSchema("ForeignSchema"); desc.setFkTable("ForeignTable"); desc.setFkCol("FkColumn"); desc.setFkSeq("FkSequence"); desc.setFkUpdRule("forUpdateRule"); desc.setFkDelRule("forDelRule"); desc.setFkDef("FkDef"); desc.setLabel("SomeLabel"); desc.setAutoInc(true); desc.setTypeName("VARCHAR"); desc.setCaseSens(true); desc.setReadOnly(true); desc.setNullable(4); desc.setSigned(true); return desc; } public static void main(String[] args) { System.out.println(SqlColumn.getComplete().toXml("")); System.out.println("\n\n\n"); System.out.println("THE java.sql.Types integer codes"); System.out.println("====================================="); System.out.println("ARRAY\t" + Types.ARRAY); System.out.println("BIGINT\t" + Types.BIGINT); System.out.println("BINARY\t" + Types.BINARY); System.out.println("BIT\t" + Types.BIT); System.out.println("BLOB\t" + Types.BLOB); System.out.println("BOOLEAN\t" + Types.BOOLEAN); System.out.println("CHAR\t" + Types.CHAR); System.out.println("CLOB\t" + Types.CLOB); System.out.println("DATALINK\t" + Types.DATALINK); System.out.println("DATE\t" + Types.DATE); System.out.println("DECIMAL\t" + Types.DECIMAL); System.out.println("DISTINCT\t" + Types.DISTINCT); System.out.println("DOUBLE\t" + Types.DOUBLE); System.out.println("FLOAT\t" + Types.FLOAT); System.out.println("INTEGER\t" + Types.INTEGER); System.out.println("JAVA_OBJECT\t" + Types.JAVA_OBJECT); System.out.println("LONGVARBINARY\t" + Types.LONGVARBINARY); System.out.println("LONGVARCHAR\t" + Types.LONGVARCHAR); System.out.println("NULL\t" + Types.NULL); System.out.println("NUMERIC\t" + Types.NUMERIC); System.out.println("OTHER\t" + Types.OTHER); System.out.println("REAL\t" + Types.REAL); System.out.println("REF\t" + Types.REF); System.out.println("SMALLINT\t" + Types.SMALLINT); System.out.println("STRUCT\t" + Types.STRUCT); System.out.println("TIME\t" + Types.TIME); System.out.println("TIMESTAMP\t" + Types.TIMESTAMP); System.out.println("TINYINT\t" + Types.TINYINT); System.out.println("VARBINARY\t" + Types.VARBINARY); System.out.println("VARCHAR\t" + Types.VARCHAR); System.out.println("====================================="); } private static boolean isSameString(String str1, String str2) { if (str1 == null) { if (str2 == null) return true; return false; } if (str2 == null) return false; return str1.equals(str2); } public boolean isSame(SqlColumn col) { if (!isSameString(getType(), col.getType())) return false; if (getPrecision() != col.getPrecision()) return false; if (getScale() != col.getScale()) return false; if (getNullable() != col.getNullable()) return false; if (isSearchable() != col.isSearchable()) return false; if (isSigned() != col.isSigned()) return false; if (isReadOnly() != col.isReadOnly()) return false; if (getSqlType() != col.getSqlType()) return false; if (getColSize() != col.getColSize()) return false; if (getRadix() != col.getRadix()) return false; if (getCharLength() != col.getCharLength()) return false; // if (getPos() != col.getPos()) // return false; if (getRemarks() != col.getRemarks()) return false; if (getColDefault() != col.getColDefault()) return false; if (!isSameString(getLabel(), col.getLabel())) return false; if (!isSameString(getTypeName(), col.getTypeName())) return false; if (isAutoInc() != col.isAutoInc()) return false; if (isCaseSens() != col.isCaseSens()) return false; if (isPrimaryKey() != col.isPrimaryKey()) return false; if (!isSameString(getPkName(), col.getPkName())) return false; if (isFk() != col.isFk()) return false; if (isFk()) { if (!isSameString(getFkCatalog(), col.getFkCatalog())) return false; if (!isSameString(getFkSchema(), col.getFkSchema())) return false; if (!isSameString(getFkTable(), col.getFkTable())) return false; if (!isSameString(getFkCol(), col.getFkCol())) return false; if (!isSameString(getFkSeq(), col.getFkSeq())) return false; if (!isSameString(getFkUpdRule(), col.getFkUpdRule())) return false; if (!isSameString(getFkDelRule(), col.getFkDelRule())) return false; if (!isSameString(getFkDef(), col.getFkDef())) return false; } return true; } private final ClientProperty nextChar(Random random, int numOfChars) { if (this.colSize < numOfChars) numOfChars = this.colSize; StringBuffer buf = new StringBuffer(numOfChars); for (int i=0; i < numOfChars; i++) { int val = 32 + random.nextInt(96); buf.append((char)val); } return new ClientProperty(this.colName, null, null, buf.toString()); } private final ClientProperty nextNumber(Random random, int max) { int val = random.nextInt(max); return new ClientProperty(this.colName, null, null, "" + val); } private final ClientProperty nextDate(Random random) { int val = random.nextInt(87600); long time = System.currentTimeMillis() - (5L*365*24*3600*1000L); time += (60000L * val); Timestamp ts = new Timestamp(time); return new ClientProperty(this.colName, null, null, ts.toString()); } public ClientProperty generateRandomObject() { if (sqlType == Types.ARRAY) return null; if (sqlType == Types.BIT) return null; if (sqlType == Types.DATALINK) return null; if (sqlType == Types.DISTINCT) return null; if (sqlType == Types.REF) return null; if (sqlType == Types.STRUCT) return null; if (sqlType == Types.JAVA_OBJECT) return null; if (sqlType == Types.NULL) return null; if (sqlType == Types.OTHER) return null; Random random = new Random(System.currentTimeMillis()); ClientProperty ret = new ClientProperty(this.colName, null, null); if (sqlType == Types.BOOLEAN) { ret.setValue("" + random.nextBoolean()); return ret; } if (sqlType == Types.CHAR) return nextChar(random, 1); if (sqlType == Types.BINARY) return nextChar(random, 24); if (sqlType == Types.BLOB) return nextChar(random, 24); if (sqlType == Types.CLOB) return nextChar(random, 24); if (sqlType == Types.LONGVARBINARY) return nextChar(random, 24); if (sqlType == Types.LONGVARCHAR) return nextChar(random, 24); if (sqlType == Types.VARBINARY) return nextChar(random, 24); if (sqlType == Types.VARCHAR) return nextChar(random, 24); if (sqlType == Types.DATE) return nextDate(random); if (sqlType == Types.TIME) return nextDate(random); if (sqlType == Types.TIMESTAMP) return nextDate(random); if (sqlType == Types.BIGINT) return nextNumber(random, 60000); if (sqlType == Types.DECIMAL) return nextNumber(random, 60000); if (sqlType == Types.DOUBLE) return nextNumber(random, 60000); if (sqlType == Types.FLOAT) return nextNumber(random, 60000); if (sqlType == Types.INTEGER) return nextNumber(random, 60000); if (sqlType == Types.NUMERIC) return nextNumber(random, 60000); if (sqlType == Types.REAL) return nextNumber(random, 60000); if (sqlType == Types.SMALLINT) return nextNumber(random, 256); if (sqlType == Types.TINYINT) return nextNumber(random, 256); return null; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -