📄 column.java
字号:
public boolean requiresTransactionInPostgres() { return needsTransactionInPostgres; } /** * Utility method to determine if this column is a foreign key. */ public boolean isForeignKey() { return (getForeignKey() != null); } /** * Determine if this column is a foreign key that refers to the * same table as another foreign key column in this table. */ public boolean isMultipleFK() { ForeignKey fk = getForeignKey(); if (fk != null) { ForeignKey[] fks = parentTable.getForeignKeys(); for (int i = 0; i < fks.length; i++) { if (fks[i].getForeignTableName() .equals(fk.getForeignTableName()) && !fks[i].getLocalColumns().contains(this.name)) { return true; } } } // No multiple foreign keys. return false; } /** * get the foreign key object for this column * if it is a foreign key or part of a foreign key */ public ForeignKey getForeignKey() { return parentTable.getForeignKey (this.name); } /** * Utility method to get the related table of this column if it is a foreign * key or part of a foreign key */ public String getRelatedTableName() { ForeignKey fk = getForeignKey(); return (fk == null ? null : fk.getForeignTableName()); } /** * Utility method to get the related column of this local column if this * column is a foreign key or part of a foreign key. */ public String getRelatedColumnName() { ForeignKey fk = getForeignKey(); if (fk == null) { return null; } else { return fk.getLocalForeignMapping().get(this.name).toString(); } } /** * Adds the foreign key from another table that refers to this column. */ public void addReferrer(ForeignKey fk) { if (referrers == null) { referrers = new ArrayList(5); } referrers.add(fk); } /** * Get list of references to this column. */ public List getReferrers() { if (referrers == null) { referrers = new ArrayList(5); } return referrers; } /** * Returns the colunm type */ public void setType(String torqueType) { this.torqueType = torqueType; if (torqueType.equals("VARBINARY") || torqueType.equals("BLOB")) { needsTransactionInPostgres = true; } } /** * Returns the column jdbc type as an object */ public Object getType() { return TypeMap.getJdbcType(torqueType); } /** * Returns the column type as given in the schema as an object */ public Object getTorqueType() { return torqueType; } /** * Utility method to see if the column is a string */ public boolean isString() { return (columnType instanceof String); } /** * Utility method to return the value as an element to be usable * in an SQL insert statement. This is used from the SQL loader task */ public boolean needEscapedValue() { return (torqueType != null) && ( torqueType.equals("VARCHAR") || torqueType.equals("LONGVARCHAR") || torqueType.equals("DATE") || torqueType.equals("DATETIME") || torqueType.equals("TIMESTAMP") || torqueType.equals("CHAR")); } /** * String representation of the column. This is an xml representation. * * @return string representation in xml */ public String toString() { StringBuffer result = new StringBuffer(); result.append(" <column name=\"").append(name).append('"'); if (javaName != null) { result.append(" javaName=\"").append(javaName).append('"'); } if (isPrimaryKey) { result.append(" primaryKey=\"").append(isPrimaryKey).append('"'); } if (isNotNull) { result.append(" required=\"true\""); } else { result.append(" required=\"false\""); } result.append(" type=\"").append (torqueType).append('"'); if (size != null) { result.append(" size=\"").append(size).append('"'); } if (defaultValue != null) { result.append(" default=\"").append(defaultValue).append('"'); } if (isInheritance()) { result.append(" inheritance=\"").append(inheritanceType) .append('"'); } // Close the column. result.append(" />\n"); return result.toString(); } /** * Returns the size of the column */ public String getSize() { return size; } /** * Set the size of the column */ public void setSize(String newSize) { size = newSize; } /** * Return the size in brackets for use in an sql * schema if the type is String. Otherwise return an empty string */ public String printSize() { return (size == null ? "" : '(' + size + ')'); } /** * Return a string that will give this column a default value. * <p> * TODO: Properly SQL-escape text values. */ public String getDefaultSetting() { StringBuffer dflt = new StringBuffer(0); if (defaultValue != null) { dflt.append("default "); if (TypeMap.isTextType(torqueType)) { // TODO: Properly SQL-escape the text. dflt.append('\'').append(defaultValue).append('\''); } else { dflt.append(defaultValue); } } return dflt.toString(); } /** * Set a string that will give this column a default value. */ public void setDefaultValue(String def) { defaultValue = def; } /** * Get a string that will give this column a default value. */ public String getDefaultValue() { return defaultValue; } /** * Returns the class name to do input validation */ public String getInputValidator() { return this.inputValidator; } /** * Return auto increment/sequence string for the target database. We need to * pass in the props for the target database! */ public boolean isAutoIncrement() { return isAutoIncrement; } /** * Set the auto increment value. * Use isAutoIncrement() to find out if it is set or not. */ public void setAutoIncrement(boolean value) { isAutoIncrement = value; } /** * Set the column type from a string property * (normally a string from an sql input file) */ public void setTypeFromString (String typeName, String size) { String tn = typeName.toUpperCase(); setType(tn); if (size != null) { this.size = size; } if (tn.indexOf ("CHAR") != -1) { torqueType = "VARCHAR"; columnType = ""; } else if (tn.indexOf ("INT") != -1) { torqueType = "INTEGER"; columnType = new Integer (0); } else if (tn.indexOf ("FLOAT") != -1) { torqueType = "FLOAT"; columnType = new Float (0); } else if (tn.indexOf ("DATE") != -1) { torqueType = "DATE"; columnType = new Date(); } else if (tn.indexOf ("TIME") != -1) { torqueType = "TIMESTAMP"; columnType = new Date(); } else if (tn.indexOf ("BINARY") != -1) { torqueType = "LONGVARBINARY"; columnType = new Hashtable(); } else { torqueType = "VARCHAR"; columnType = ""; } } /** * Return a string representation of the * Java object which corresponds to the JDBC * type of this column. Use in the generation * of MapBuilders. */ public String getJavaObject() { return TypeMap.getJavaObject(torqueType); } /** * Return a string representation of the primitive java type which * corresponds to the JDBC type of this column. * * @return string representation of the primitive java type */ public String getJavaPrimitive() { return TypeMap.getJavaNative(torqueType); } /** * Return a string representation of the native java type which corresponds * to the JDBC type of this column. Use in the generation of Base objects. * This method is used by torque, so it returns Key types for primaryKey and * foreignKey columns * * @return java datatype used by torque */ public String getJavaNative() { String jtype = TypeMap.getJavaNativeObject(torqueType); if (isUsePrimitive()) { jtype = TypeMap.getJavaNative(torqueType); } return jtype; } /** * Return Village asX() method which corresponds to the JDBC type * which represents this column. */ public String getVillageMethod() { String vmethod = TypeMap.getVillageObjectMethod(torqueType); if (isUsePrimitive()) { vmethod = TypeMap.getVillageMethod(torqueType); } return vmethod; } /** * Return ParameterParser getX() method which * corresponds to the JDBC type which represents this column. */ public String getParameterParserMethod() { return TypeMap.getPPMethod(torqueType); } /** * Returns true if the column type is boolean in the * java object and a numeric (1 or 0) in the db. */ public boolean isBooleanInt() { return TypeMap.isBooleanInt(torqueType); } /** * Returns true if the column type is boolean in the * java object and a String ("Y" or "N") in the db. */ public boolean isBooleanChar() { return TypeMap.isBooleanChar(torqueType); } /** * returns true, if the columns java native type is an * boolean, byte, short, int, long, float, double, char */ public boolean isPrimitive() { String t = getJavaNative(); return "boolean".equals(t) || "byte".equals(t) || "short".equals(t) || "int".equals(t) || "long".equals(t) || "float".equals(t) || "double".equals(t) || "char".equals(t); } public boolean isUsePrimitive() { String s = getJavaType(); return (s != null && s.equals("primitive")) || (s == null && !"object".equals( getTable().getDatabase().getDefaultJavaType())); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -