001: /*
002: * JFolder, Copyright 2001-2006 Gary Steinmetz
003: *
004: * Distributable under LGPL license.
005: * See terms of license at gnu.org.
006: */
007:
008: package org.jfolder.platforms.stores.base;
009:
010: //base classes
011: import java.math.BigDecimal;
012: import java.sql.PreparedStatement;
013: import java.sql.ResultSet;
014: import java.sql.SQLException;
015: import java.util.ArrayList;
016: import java.util.HashMap;
017:
018: //project specific classes
019: import org.jfolder.common.UnexpectedSystemException;
020: import org.jfolder.platforms.stores.base.SystemStatement;
021:
022: //other classes
023:
024: public class CreateStatement extends SystemStatement {
025:
026: //
027: //private int type = 0;
028: private String name = null;
029: private boolean idPresent = false;
030: private boolean seriesSequencePresent = false;
031: private SequenceStatement wss = null;
032: //private boolean shadow = false;
033: //
034: private ArrayList columnNames = null;
035: private ArrayList columnTypes = null;
036: private ArrayList columnNulls = null;
037: private ArrayList columnForeignKeys = null;
038: //
039: //private HashMap foreignTables = null;
040: //private HashMap foreignColumns = null;
041: //
042: private ArrayList uniqueColumns = null;
043: //
044: private ArrayList groupByNames = null;
045: private ArrayList groupByTypes = null;
046:
047: //
048: public int hashCode() {
049: return this .name.hashCode();
050: }
051:
052: public boolean equals(Object inObject) {
053:
054: boolean outValue = false;
055:
056: if (inObject instanceof CreateStatement) {
057: CreateStatement wcs = (CreateStatement) inObject;
058: outValue = this .name.equals(wcs.name);
059: }
060:
061: return outValue;
062: }
063:
064: //
065: protected CreateStatement(String inName) {
066: //
067: //super();
068: //
069: this .name = inName;
070: //
071: this .wss = newSequenceStatement(inName);
072: //
073: this .columnNames = new ArrayList();
074: this .columnTypes = new ArrayList();
075: this .columnNulls = new ArrayList();
076: this .columnForeignKeys = new ArrayList();
077: //
078: //this.foreignTables = new HashMap();
079: //
080: this .uniqueColumns = new ArrayList();
081: //
082: this .groupByNames = new ArrayList();
083: this .groupByTypes = new ArrayList();
084: }
085:
086: //
087: //public void setName(String inName) {
088: // this.name = inName;
089: //}
090: public String getName() {
091: return this .name;
092: }
093:
094: public Integer getColumnDataType(String inName) {
095:
096: Integer outValue = null;
097:
098: int columnIndex = this .columnNames.indexOf(inName);
099: outValue = getColumnDataType(columnIndex);
100:
101: return outValue;
102: }
103:
104: public boolean verifyColumnAndType(String inName, Integer inType,
105: boolean inThrow) {
106:
107: boolean outValue = false;
108:
109: int columnIndex = this .columnNames.indexOf(inName);
110:
111: if (columnIndex != -1) {
112: Integer columnType = getColumnDataType(columnIndex);
113: if (inType.equals(columnType)) {
114: outValue = true;
115: } else if (inThrow) {
116: throw new UnexpectedSystemException("Column '" + inName
117: + "' has a different type");
118: }
119: } else if (inThrow) {
120: throw new UnexpectedSystemException("Column '" + inName
121: + "' does not exist");
122: }
123:
124: return outValue;
125: }
126:
127: private void verifyAvailableColumn(String inName) {
128: if (this .columnNames.indexOf(inName) != -1) {
129: throw new UnexpectedSystemException("Column '" + inName
130: + "' is already defined");
131: }
132: }
133:
134: //
135: //public void setShadowTableAttached(boolean inShadow) {
136: // this.shadow = inShadow;
137: //}
138:
139: //
140: public boolean isIdColumnPresent() {
141: return this .idPresent;
142: }
143:
144: public void addIdColumn() {
145: this .idPresent = true;
146: }
147:
148: //
149: public boolean isSeriesSequenceColumnPresent() {
150: return this .seriesSequencePresent;
151: }
152:
153: public void addSeriesSequenceColumn() {
154: this .seriesSequencePresent = true;
155: }
156:
157: public SequenceStatement getSequenceSeries() {
158: return this .wss;
159: }
160:
161: public void addSeriesSequenceGroupByColumn(String inName,
162: Integer inType) {
163: this .groupByNames.add(inName);
164: this .groupByTypes.add(inType);
165: }
166:
167: public int getGroupByColumnCount() {
168: return this .groupByNames.size();
169: }
170:
171: public String getGroupByColumnName(int inIndex) {
172: return (String) this .groupByNames.get(inIndex);
173: }
174:
175: public Integer getGroupByColumnType(int inIndex) {
176: return (Integer) this .groupByTypes.get(inIndex);
177: }
178:
179: //
180: public int getColumnCount() {
181: return this .columnNames.size();
182: }
183:
184: public String getColumnName(int inIndex) {
185: return (String) this .columnNames.get(inIndex);
186: }
187:
188: public Integer getColumnDataType(int inIndex) {
189: return (Integer) this .columnTypes.get(inIndex);
190: }
191:
192: public boolean getColumnNull(int inIndex) {
193: return ((Boolean) this .columnNulls.get(inIndex)).booleanValue();
194: }
195:
196: public String getColumnForeignKey(int inIndex) {
197: return (String) this .columnForeignKeys.get(inIndex);
198: }
199:
200: //
201: public void addDecimalColumn(String inName, boolean inNull,
202: String inForeignTable) {
203: //
204: verifyAvailableColumn(inName);
205: //
206: this .columnNames.add(inName);
207: this .columnTypes.add(DECIMAL);
208: this .columnNulls.add(new Boolean(inNull));
209: this .columnForeignKeys.add(inForeignTable);
210: }
211:
212: public void addSStringColumn(String inName, boolean inNull,
213: String inForeignTable) {
214: //
215: verifyAvailableColumn(inName);
216: //
217: this .columnNames.add(inName);
218: this .columnTypes.add(SHORT_STRING);
219: this .columnNulls.add(new Boolean(inNull));
220: this .columnForeignKeys.add(inForeignTable);
221: }
222:
223: //null must be permitted
224: public void addLStringColumn(String inName, String inForeignTable) {
225: //
226: verifyAvailableColumn(inName);
227: //
228: this .columnNames.add(inName);
229: this .columnTypes.add(LONG_STRING);
230: this .columnNulls.add(new Boolean(true));
231: this .columnForeignKeys.add(inForeignTable);
232: }
233:
234: public void addBooleanColumn(String inName, boolean inNull,
235: String inForeignTable) {
236: //
237: verifyAvailableColumn(inName);
238: //
239: this .columnNames.add(inName);
240: this .columnTypes.add(BOOLEAN);
241: this .columnNulls.add(new Boolean(inNull));
242: this .columnForeignKeys.add(inForeignTable);
243: }
244:
245: //null must be permitted
246: public void addBObjectColumn(String inName, String inForeignTable) {
247: //
248: verifyAvailableColumn(inName);
249: //
250: this .columnNames.add(inName);
251: this .columnTypes.add(BINARY_OBJECT);
252: this .columnNulls.add(new Boolean(true));
253: this .columnForeignKeys.add(inForeignTable);
254: }
255:
256: //public void addBStreamColumn(String inName, boolean inNull,
257: // String inForeignTable) {
258: // this.columnNames.add(inName);
259: // this.columnTypes.add(BINARY_STREAM);
260: // this.columnNulls.add(new Boolean(inNull));
261: // this.columnForeignKeys.add(inForeignTable);
262: //}
263:
264: //
265: //public void assignForeignKey(String inName, String inForeignTable) {
266: // this.foreignTables.put(inName, inForeignTable);
267: //}
268:
269: //
270: public void assignUnique(ArrayList inColumns) {
271: this .uniqueColumns.add(inColumns);
272: }
273:
274: //
275: public int getUniqueConstraintCount() {
276: return this .uniqueColumns.size();
277: }
278:
279: public ArrayList getUniqueConstraint(int inIndex) {
280: return ((ArrayList) this.uniqueColumns.get(inIndex));
281: }
282: }
|