001: /* Copyright (C) 2003 Finalist IT Group
002: *
003: * This file is part of JAG - the Java J2EE Application Generator
004: *
005: * JAG is free software; you can redistribute it and/or modify
006: * it under the terms of the GNU General Public License as published by
007: * the Free Software Foundation; either version 2 of the License, or
008: * (at your option) any later version.
009: * JAG is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: * You should have received a copy of the GNU General Public License
014: * along with JAG; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
016: */
017:
018: package com.finalist.jaggenerator;
019:
020: import org.apache.commons.logging.Log;
021: import org.apache.commons.logging.LogFactory;
022:
023: import java.io.Serializable;
024:
025: /**
026: *
027: * @author hillebrand
028: */
029: public class Column implements Serializable {
030: static Log log = LogFactory.getLog(Column.class);
031: /** Holds value of property name. */
032: private String name;
033:
034: /** Holds value of property sqlType. */
035: private String sqlType;
036:
037: /** Holds value of property precision. */
038: private int precision;
039:
040: /** Holds value of property scale. */
041: private int scale;
042:
043: /** Holds value of property length. */
044: private int length;
045:
046: /** Set to true if columns is primary key column. */
047: private boolean primaryKey;
048:
049: /** True if the column may be null. */
050: private boolean nullable;
051:
052: /** Creates a new instance of Column */
053: public Column() {
054: }
055:
056: /** Getter for property name.
057: * @return Value of property name.
058: *
059: */
060: public String getName() {
061: return this .name;
062: }
063:
064: /** Setter for property name.
065: * @param name New value of property name.
066: *
067: */
068: public void setName(String name) {
069: this .name = name;
070: }
071:
072: /** Setter for property sqlType.
073: * @param sqlType New value of property sqlType.
074: *
075: */
076: public void setSqlType(String sqlType) {
077:
078: // Check if a precision and / or scale have been passed.
079: if (sqlType != null) {
080: int index = sqlType.indexOf("(");
081: if (index != -1) {
082: this .sqlType = sqlType.substring(0, index);
083: // Now als set the scale and precision...
084: int index2 = sqlType.indexOf(")");
085: if (index2 != -1) {
086: // There is a scale and / or precsions.
087: int index3 = sqlType.indexOf(",");
088: if (index3 != -1) {
089: // Scale AND precision!
090: String scale = sqlType.substring(index + 1,
091: index3).trim();
092: String precision = sqlType.substring(
093: index3 + 1, index2).trim();
094: int sc = 0;
095: int pr = 0;
096: try {
097: sc = Integer.parseInt(scale);
098: pr = Integer.parseInt(precision);
099: } catch (Exception e) {
100: log
101: .warn("Error while parsing scale or precision for type "
102: + sqlType);
103: }
104: setScale(sc);
105: setPrecision(pr);
106: } else {
107: // Only a scale..
108: String scale = sqlType.substring(index + 1,
109: index2).trim();
110: int sc = 0;
111: try {
112: sc = Integer.parseInt(scale);
113: } catch (Exception e) {
114: log
115: .warn("Error while parsing scale for type "
116: + sqlType);
117: }
118: setScale(sc);
119:
120: }
121: }
122: } else {
123: this .sqlType = sqlType;
124: }
125:
126: }
127: }
128:
129: /** Getter for property precision.
130: * @return Value of property precision.
131: *
132: */
133: public int getPrecision() {
134: return this .precision;
135: }
136:
137: /** Setter for property precision.
138: * @param precision New value of property precision.
139: *
140: */
141: public void setPrecision(int precision) {
142: this .precision = precision;
143: }
144:
145: /** Getter for property scale.
146: * @return Value of property scale.
147: *
148: */
149: public int getScale() {
150: return this .scale;
151: }
152:
153: /** Setter for property scale.
154: * @param scale New value of property scale.
155: *
156: */
157: public void setScale(int scale) {
158: this .scale = scale;
159: }
160:
161: /** Getter for property length.
162: * @return Value of property length.
163: *
164: */
165: public int getLength() {
166: return this .length;
167: }
168:
169: /** Setter for property length.
170: * @param length New value of property length.
171: *
172: */
173: public void setLength(int length) {
174: this .length = length;
175: }
176:
177: /** Getter for property sqlType.
178: * @return Value of property sqlType.
179: *
180: */
181: public String getSqlType() {
182: return this .sqlType;
183: }
184:
185: /** Getter for property primary Key
186: * @return Value of primary key.
187: *
188: */
189: public boolean isPrimaryKey() {
190: return this .primaryKey;
191: }
192:
193: /** Setter for the primary key.
194: * @param value to true if column is a primary key column
195: *
196: */
197: public void setPrimaryKey(boolean value) {
198: this .primaryKey = value;
199: }
200:
201: /**
202: * Gets the 'nullableString' property as a boolean.
203: *
204: * @return the boolean interpretation of the 'nullableString' property.
205: */
206: public boolean isNullable() {
207: return nullable;
208: }
209:
210: /**
211: * Sets the 'nullable' property with a value from a database columns dumo.
212: * @param nullable set to <code>true</code> if the column is nullable.
213: */
214: public void setNullable(boolean nullable) {
215: this .nullable = nullable;
216: }
217:
218: /** @see {@link java.lang.Object#toString()}. */
219: public String toString() {
220: return "Column(name=" + name + ", sqlType=" + sqlType
221: + ", precision=" + precision + ", scale=" + scale
222: + ", length=" + length + ", primaryKey=" + primaryKey
223: + ", nullable=" + nullable + ")";
224: }
225:
226: }
|