📄 sqlcolumn.java
字号:
/*------------------------------------------------------------------------------Name: DbInfoUpdateColDescription.javaProject: xmlBlaster.orgCopyright: xmlBlaster.org, see xmlBlaster-LICENSE file------------------------------------------------------------------------------*/package org.xmlBlaster.contrib.dbwriter.info;import java.sql.Timestamp;import java.sql.Types;import java.util.Properties;import java.util.Random;import org.xmlBlaster.contrib.I_Info;import org.xmlBlaster.contrib.PropertiesInfo;import org.xmlBlaster.util.def.Constants;import org.xmlBlaster.util.qos.ClientProperty;public class SqlColumn { public final static String COLNAME_TAG = "colname"; public final static String SCHEMA_ATTR = "schema"; public final static String CATALOG_ATTR = "catalog"; public final static String TABLE_ATTR = "table"; public final static String TYPE_ATTR = "type"; public final static String PRECISION_ATTR = "precision"; public final static String SCALE_ATTR = "scale"; public final static String NULLABLE_ATTR = "nullable"; public final static String SIGNED_ATTR = "signed"; public final static String SEARCHABLE_ATTR = "searchable"; public final static String RO_ATTR = "readOnly"; public final static String DATA_TYPE = "datatype"; // new attributes public final static String PK_ATTR = "pk"; // primary key public final static String PK_NAME_ATTR = "pkName"; // primary key public final static String FK_TABLE_CAT_ATTR = "fkCatalog"; public final static String FK_TABLE_SCHEM_ATTR = "fkSchema"; public final static String FK_TABLE_NAME_ATTR = "fkTable"; public final static String FK_COLUMN_NAME_ATTR = "fkCol"; public final static String FK_KEY_SEQ_ATTR = "fkSeq"; public final static String FK_UPDATE_RULE_ATTR = "fkUpdRule"; public final static String FK_DELETE_RULE_ATTR = "fkDelRule"; public final static String FK_DEFERRABILITY_ATTR = "fkDef"; public final static String DATA_TYPE_ATTR = "sqlType"; // position(05) public final static String COLUMN_SIZE_ATTR = "colSize"; // position(07) public final static String DECIMAL_DIGITS_ATTR = "digits"; // position(09) public final static String NUM_PREC_RADIX_ATTR = "radix"; // position(10); public final static String REMARKS_ATTR = "remarks"; // position(12) public final static String COLUMN_DEF_ATTR = "colDefault"; // position(13) this is the default public final static String CHAR_OCTET_LENGTH_ATTR = "charLength"; // position(16) public final static String ORDINAL_POSITION_ATTR = "pos"; // position(17) public final static String LABEL_ATTR = "label"; public final static String AUTO_INCREMENT_ATTR = "autoInc"; public final static String CASE_SENSITIVE_ATTR = "caseSens"; public final static String TYPE_NAME_ATTR = "typeName"; /* System.out.println(rs.getString(1) + "1. PKTABLE_CAT String => primary key table catalog being imported (may be null)"); System.out.println(rs.getString(2) + "2. PKTABLE_SCHEM String => primary key table schema being imported (may be null)"); System.out.println(rs.getString(3) + "3. PKTABLE_NAME String => primary key table name being imported"); System.out.println(rs.getString(4) + "4. PKCOLUMN_NAME String => primary key column name being imported"); System.out.println(rs.getString(9) + "9. KEY_SEQ short => sequence number within a foreign key"); System.out.println(rs.getString(10) + "10. UPDATE_RULE short => What happens to a foreign key when the primary key is updated:"); System.out.println(" * importedNoAction - do not allow update of primary key if it has been imported"); System.out.println(" * importedKeyCascade - change imported key to agree with primary key update"); System.out.println(" * importedKeySetNull - change imported key to NULL if its primary key has been updated"); System.out.println(" * importedKeySetDefault - change imported key to default values if its primary key has been updated"); System.out.println(" * importedKeyRestrict - same as importedKeyNoAction (for ODBC 2.x compatibility) "); System.out.println(rs.getString(11) + "11. DELETE_RULE short => What happens to the foreign key when primary is deleted."); System.out.println(" * importedKeyNoAction - do not allow delete of primary key if it has been imported"); System.out.println(" * importedKeyCascade - delete rows that import a deleted key"); System.out.println(" * importedKeySetNull - change imported key to NULL if its primary key has been deleted"); System.out.println(" * importedKeyRestrict - same as importedKeyNoAction (for ODBC 2.x compatibility)"); System.out.println(" * importedKeySetDefault - change imported key to default if its primary key has been deleted "); System.out.println(rs.getString(14) + "14. DEFERRABILITY short => can the evaluation of foreign key constraints be deferred until commit"); System.out.println(" * importedKeyInitiallyDeferred - see SQL92 for definition"); System.out.println(" * importedKeyInitiallyImmediate - see SQL92 for definition"); System.out.println(" * importedKeyNotDeferrable - see SQL92 for definition ");*/ private String colName; private String table; private String schema; private String catalog; private String type; private int precision; // DECIMAL_DIGITS position (9) private int scale; // <-- not used in replication private int nullable; // no default: is always written out private boolean searchable = true; // defaults to true private boolean signed = true; // defaults to true <-- not used in replication private boolean readOnly; // defaults to false <-- not used in replication private boolean primaryKey; // defaults to false (but unknown) private String pkName; // private boolean primaryKeyKnown; // on first write it will be known // additional variables not defined in original DbWatcher private int sqlType; // DATA_TYPE (position 5) private int colSize; // COLUMN_SIZE (position 7) private int radix; // NUM_PREC_RADIX position(10); private String remarks; // REMARKS position(12) private String colDefault; // COLUMN_DEF position(13) this is the default private int charLength; // CHAR_OCTET_LENGTH position(16) private int pos; // ORDINAL_POSITION position(17) private String fkCatalog; private String fkSchema; private String fkTable; // if this is set, then it is a foreign key private String fkCol; private String fkSeq; private String fkUpdRule; private String fkDelRule; private String fkDef; // new additions 2005-10-10 private String label; private boolean autoInc; private boolean caseSens; private String typeName; public SqlColumn(I_Info info) { } public String getCatalog() { return this.catalog; } public void setCatalog(String catalog) { this.catalog = catalog; } public int getPrecision() { return this.precision; } public void setPrecision(int precision) { this.precision = precision; } public boolean isReadOnly() { return this.readOnly; } public boolean isSearchable() { return this.searchable; } public void setSearchable(boolean searchable) { this.searchable = searchable; } public void setReadOnly(boolean readOnly) { this.readOnly = readOnly; } public int getScale() { return this.scale; } public void setScale(int scale) { this.scale = scale; } public String getSchema() { return this.schema; } public void setSchema(String schema) { this.schema = schema; } public boolean isSigned() { return this.signed; } public String getFkCatalog() { return fkCatalog; } public void setFkCatalog(String fkCatalog) { this.fkCatalog = fkCatalog; } public String getFkCol() { return fkCol; } public void setFkCol(String fkCol) { this.fkCol = fkCol; } public String getFkDef() { return fkDef; } public void setFkDef(String fkDef) { this.fkDef = fkDef; } public String getFkDelRule() { return fkDelRule; } public void setFkDelRule(String fkDelRule) { this.fkDelRule = fkDelRule; } public String getFkSchema() { return fkSchema; } public void setFkSchema(String fkSchema) { this.fkSchema = fkSchema; } public String getFkSeq() { return fkSeq; } public void setFkSeq(String fkSeq) { this.fkSeq = fkSeq; } public String getFkTable() { return fkTable; } public void setFkTable(String fkTable) { this.fkTable = fkTable; } public String getFkUpdRule() { return fkUpdRule; } public void setFkUpdRule(String fkUpdRule) { this.fkUpdRule = fkUpdRule; } public void setSigned(boolean signed) { this.signed = signed; } public String getTable() { return this.table; } public void setTable(String table) { this.table = table; } public String getType() { return this.type; } public void setSqlType(int sqlType) { this.sqlType = sqlType; } public int getSqlType() { return this.sqlType; } public void setType(String type) { this.type = type; } public String getColName() { return this.colName; } public void setColName(String colName) { this.colName = colName; } private boolean stringExists(String str) { return str != null && str.length() > 0; } public boolean isPrimaryKey() { return this.primaryKey; } public void setPrimaryKey(boolean primaryKey) { // this.primaryKeyKnown = true; this.primaryKey = primaryKey; } public int getNullable() { return this.nullable; } public void setNullable(int nullable) { this.nullable = nullable; } public String toXml(String extraOffset) { StringBuffer buf = new StringBuffer(256); if (extraOffset == null) extraOffset = ""; String offset = Constants.OFFSET + extraOffset; buf.append(offset).append("<").append(COLNAME_TAG); if (stringExists(this.table)) buf.append(" ").append(TABLE_ATTR).append("='").append(this.table).append("'"); if (stringExists(this.schema)) buf.append(" ").append(SCHEMA_ATTR).append("='").append(this.schema).append("'"); if (stringExists(this.catalog)) buf.append(" ").append(CATALOG_ATTR).append("='").append(this.catalog).append("'"); if (stringExists(this.type)) buf.append(" ").append(TYPE_ATTR).append("='").append(this.type).append("'"); if (this.precision != 0) buf.append(" ").append(PRECISION_ATTR).append("='").append(this.precision).append("'"); if (this.scale != 0) buf.append(" ").append(SCALE_ATTR).append("='").append(this.scale).append("'"); // always write this out since there is no default defined. buf.append(" ").append(NULLABLE_ATTR).append("='").append(this.nullable).append("'"); if (!this.searchable) // don't write the default which is 'true' (also check the parser) buf.append(" ").append(SEARCHABLE_ATTR).append("='").append(this.searchable).append("'"); if (!this.signed) // don't write the default which is 'true' (also check the parser) buf.append(" ").append(SIGNED_ATTR).append("='").append(this.signed).append("'"); if (this.readOnly) // don't write the default which is 'false' (also check the parser) buf.append(" ").append(RO_ATTR).append("='").append(this.readOnly).append("'"); if (this.sqlType != 0) buf.append(" ").append(DATA_TYPE_ATTR).append("='").append(this.sqlType).append("'"); if (this.colSize != 0) buf.append(" ").append(COLUMN_SIZE_ATTR).append("='").append(this.colSize).append("'"); if (this.radix != 0) buf.append(" ").append(NUM_PREC_RADIX_ATTR).append("='").append(this.radix).append("'"); if (this.charLength != 0) buf.append(" ").append(CHAR_OCTET_LENGTH_ATTR).append("='").append(this.charLength).append("'"); if (this.pos != 0) buf.append(" ").append(ORDINAL_POSITION_ATTR).append("='").append(this.pos).append("'"); if (this.remarks != null) buf.append(" ").append(REMARKS_ATTR).append("='").append(this.remarks).append("'"); if (this.colDefault != null) buf.append(" ").append(COLUMN_DEF_ATTR).append("='").append(this.colDefault).append("'"); if (this.label != null) buf.append(" ").append(LABEL_ATTR).append("='").append(this.label).append("'"); if (this.typeName != null) buf.append(" ").append(TYPE_NAME_ATTR).append("='").append(this.typeName).append("'"); if (this.autoInc) buf.append(" ").append(AUTO_INCREMENT_ATTR).append("='").append(this.autoInc).append("'"); if (this.caseSens) buf.append(" ").append(CASE_SENSITIVE_ATTR).append("='").append(this.caseSens).append("'"); if (this.primaryKey) { buf.append(" ").append(PK_ATTR).append("='").append(this.primaryKey).append("'"); if (this.pkName != null) { buf.append(" ").append(PK_NAME_ATTR).append("='").append(this.pkName).append("'"); } } if (isFk()) { if (this.fkCatalog != null) buf.append(" ").append(FK_TABLE_CAT_ATTR).append("='").append(this.fkCatalog).append("'"); if (this.fkSchema != null) buf.append(" ").append(FK_TABLE_SCHEM_ATTR).append("='").append(this.fkSchema).append("'"); if (this.fkTable != null) buf.append(" ").append(FK_TABLE_NAME_ATTR).append("='").append(this.fkTable).append("'"); if (this.fkCol != null) buf.append(" ").append(FK_COLUMN_NAME_ATTR).append("='").append(this.fkCol).append("'"); if (this.fkSeq != null) buf.append(" ").append(FK_KEY_SEQ_ATTR).append("='").append(this.fkSeq).append("'"); if (this.fkUpdRule != null) buf.append(" ").append(FK_UPDATE_RULE_ATTR).append("='").append(this.fkUpdRule).append("'"); if (this.fkDelRule != null) buf.append(" ").append(FK_DELETE_RULE_ATTR).append("='").append(this.fkDelRule).append("'"); if (this.fkDef != null) buf.append(" ").append(FK_DEFERRABILITY_ATTR).append("='").append(this.fkDef).append("'"); } // this will not be parsed. String tmp = getSqlTypeAsText(this.getSqlType()); if (tmp != null && !"NULL".equals(tmp)) buf.append(" ").append(DATA_TYPE).append("='").append(tmp).append("'"); buf.append(">"); buf.append(this.colName); buf.append("</").append(COLNAME_TAG).append(">"); return buf.toString(); } public boolean isFk() { return this.fkTable != null; } public int getCharLength() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -