001: package org.dbbrowser.db.engine.model;
002:
003: /**
004: * This class holds information about a DB column
005: * @author amangat
006: *
007: */
008: public class ColumnInfo {
009: public static final String COLUMN_NULLABLE = "NULLABLE";
010: public static final String COLUMN_NOT_NULLABLE = "NOT_NULLABLE";
011: public static final String COLUMN_NULLABLE_NATURE_UNKNOWN = "UNKNOWN";
012:
013: public static final String COLUMN_TYPE_VARCHAR = "VARCHAR"; //String
014: public static final String COLUMN_TYPE_VARCHAR2 = "VARCHAR2"; //String
015: public static final String COLUMN_TYPE_NUMBER = "NUMBER"; //Integer
016: public static final String COLUMN_TYPE_BIG_DECIMAL = "BIG_DECIMAL"; //BigDecimal
017: public static final String COLUMN_TYPE_DATE = "DATE"; //Date
018: public static final String COLUMN_TYPE_DATE_TIME = "DATETIME"; //Date
019: public static final String COLUMN_TYPE_TIMESTAMP = "TIMESTAMP"; //Date
020: public static final String COLUMN_TYPE_BIG_INT = "BIG_INT"; //Long
021: public static final String COLUMN_TYPE_CHAR = "CHAR"; //String
022: public static final String COLUMN_TYPE_DECIMAL = "DECIMAL"; //BigDecimal
023: public static final String COLUMN_TYPE_FLOAT = "FLOAT"; //Float
024: public static final String COLUMN_TYPE_REAL = "REAL"; //Double
025: public static final String COLUMN_TYPE_SMALL_INT = "SMALL_INT"; //Integer
026: public static final String COLUMN_TYPE_TINY_INT = "TINY_INT"; //Integer
027:
028: private String columnName = null;
029: private String columnTypeName = null;
030: private String equivalentJavaClass = null;
031: private Integer columnDisplaySize = null;
032: private String nullableNature = null;
033: private Boolean isAutoIncrement = null;
034: private Boolean isPrimaryKeyColumn = null;
035: private Boolean editable = null;
036: private Integer columnType = null;
037:
038: /**
039: * Constructer
040: * @param columnName
041: * @param columnTypeName
042: * @param equivalentJavaClass
043: * @param columnDisplaySize
044: * @param nullableNature
045: * @param isPrimaryKeyColumn
046: * @param editable
047: * @param columnType
048: */
049: public ColumnInfo(String columnName, String columnTypeName,
050: String equivalentJavaClass, Integer columnDisplaySize,
051: String nullableNature, Boolean isAutoIncrement,
052: Boolean isPrimaryKeyColumn, Boolean editable,
053: Integer columnType) {
054: this .columnName = columnName;
055: this .columnTypeName = columnTypeName;
056: this .equivalentJavaClass = equivalentJavaClass;
057: this .columnDisplaySize = columnDisplaySize;
058: this .nullableNature = nullableNature;
059: this .isAutoIncrement = isAutoIncrement;
060: this .isPrimaryKeyColumn = isPrimaryKeyColumn;
061: this .editable = editable;
062: this .columnType = columnType;
063: }
064:
065: /**
066: * Get the column name
067: * @return
068: */
069: public String getColumnName() {
070: return this .columnName;
071: }
072:
073: /**
074: * Returns the column type name e.g. NUMBER, VARCHAR and DATE. The types come from java.sql.Types
075: * @return
076: */
077: public String getColumnTypeName() {
078: return this .columnTypeName;
079: }
080:
081: /**
082: * Get the equivalent java class to represent this column e.g. java.lang.Integer
083: * @return
084: */
085: public String getEquivalentJavaClass() {
086: return this .equivalentJavaClass;
087: }
088:
089: /**
090: * Returns the display size of the column
091: * @return
092: */
093: public Integer getColumnDisplaySize() {
094: return this .columnDisplaySize;
095: }
096:
097: /**
098: * Returns a String describing the nullable nature
099: * <ul>
100: * <li>ColumnInfo.NULLABLE - if the column is nullable</li>
101: * <li>ColumnInfo.NOT_NULLABLE - if the column is not nullable</li>
102: * <li>ColumnInfo.UNKNOWN - if the nature cannot be determined</li>
103: * </ul>
104: * @return
105: */
106: public String getNullableNature() {
107: return this .nullableNature;
108: }
109:
110: /**
111: * Returns true if this column is auto incremented
112: * @return
113: */
114: public Boolean isAutoIncrement() {
115: return this .isAutoIncrement;
116: }
117:
118: /**
119: * Returns true if it is a primary key column
120: * @return
121: */
122: public Boolean isPrimaryKeyColumn() {
123: return this .isPrimaryKeyColumn;
124: }
125:
126: /**
127: * Returns true if this column is editable
128: * @return
129: */
130: public Boolean isEditable() {
131: return this .editable;
132: }
133:
134: /**
135: * Returns the column type as defined in the java.sql.Types
136: * @return
137: */
138: public Integer getColumnType() {
139: return this .columnType;
140: }
141:
142: /**
143: * For debugging only
144: */
145: public String toString() {
146: StringBuffer buffer = new StringBuffer();
147: buffer.append("Column Info----------------\n");
148: buffer.append("Column name: " + this .getColumnName() + "\n");
149: buffer
150: .append("Column type: " + this .getColumnTypeName()
151: + "\n");
152: buffer.append("Java class: " + this .getEquivalentJavaClass()
153: + "\n");
154: buffer.append("Is primary key column: "
155: + this .isPrimaryKeyColumn() + "\n");
156: buffer.append("Is editable: " + this .isEditable() + "\n");
157: buffer.append("Column type: " + this .getColumnType() + "\n");
158:
159: return buffer.toString();
160: }
161: }
|