001: /*
002: * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/CompilableTag.java,v 1.5 2002/05/17 15:18:12 jstrachan Exp $
003: * $Revision: 1.5 $
004: * $Date: 2002/05/17 15:18:12 $
005: *
006: * ====================================================================
007: *
008: * The Apache Software License, Version 1.1
009: *
010: * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
011: * reserved.
012: *
013: * Redistribution and use in source and binary forms, with or without
014: * modification, are permitted provided that the following conditions
015: * are met:
016: *
017: * 1. Redistributions of source code must retain the above copyright
018: * notice, this list of conditions and the following disclaimer.
019: *
020: * 2. Redistributions in binary form must reproduce the above copyright
021: * notice, this list of conditions and the following disclaimer in
022: * the documentation and/or other materials provided with the
023: * distribution.
024: *
025: * 3. The end-user documentation included with the redistribution, if
026: * any, must include the following acknowlegement:
027: * "This product includes software developed by the
028: * Apache Software Foundation (http://www.apache.org/)."
029: * Alternately, this acknowlegement may appear in the software itself,
030: * if and wherever such third-party acknowlegements normally appear.
031: *
032: * 4. The names "The Jakarta Project", "Commons", and "Apache Software
033: * Foundation" must not be used to endorse or promote products derived
034: * from this software without prior written permission. For written
035: * permission, please contact apache@apache.org.
036: *
037: * 5. Products derived from this software may not be called "Apache"
038: * nor may "Apache" appear in their names without prior written
039: * permission of the Apache Group.
040: *
041: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
042: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
043: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
044: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
045: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
046: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
047: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
048: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
049: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
050: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
051: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
052: * SUCH DAMAGE.
053: * ====================================================================
054: *
055: * This software consists of voluntary contributions made by many
056: * individuals on behalf of the Apache Software Foundation. For more
057: * information on the Apache Software Foundation, please see
058: * <http://www.apache.org/>.
059: *
060: * $Id: CompilableTag.java,v 1.5 2002/05/17 15:18:12 jstrachan Exp $
061: */
062: package org.apache.commons.sql.model;
063:
064: import java.util.Iterator;
065: import java.util.ArrayList;
066: import java.util.List;
067:
068: public class Table {
069: private String catalog = null;
070:
071: private String name = null;
072:
073: private String schema = null;
074:
075: private String remarks = null;
076:
077: private String type = null;
078:
079: private List columns = new ArrayList();
080:
081: private List foreignKeys = new ArrayList();
082:
083: private List indexes = new ArrayList();
084:
085: public Table() {
086: }
087:
088: public String getCatalog() {
089: return this .catalog;
090: }
091:
092: public void setCatalog(String catalog) {
093: this .catalog = catalog;
094: }
095:
096: public String getRemarks() {
097: return this .remarks;
098: }
099:
100: public void setRemarks(String remarks) {
101: this .remarks = remarks;
102: }
103:
104: public String getSchema() {
105: return this .schema;
106: }
107:
108: public void setSchema(String schema) {
109: this .schema = schema;
110: }
111:
112: public String getType() {
113: return (type == null) ? "(null)" : type;
114: }
115:
116: public void setType(String type) {
117: this .type = type;
118: }
119:
120: public String getName() {
121: return name;
122: }
123:
124: public void setName(String name) {
125: this .name = name;
126: }
127:
128: public void addColumn(Column column) {
129: columns.add(column);
130: }
131:
132: public void addAll(List columns) {
133: if (columns != null && columns.size() > 0) {
134: int columnsSize = columns.size();
135: for (int i = 0; i < columnsSize; i++) {
136: Column column = (Column) columns.get(i);
137: if (column != null) {
138: this .addColumn(column);
139: }
140: }
141: }
142: }
143:
144: public List getColumns() {
145: return columns;
146: }
147:
148: public void addForeignKey(ForeignKey foreignKey) {
149: foreignKeys.add(foreignKey);
150: }
151:
152: public List getForeignKeys() {
153: return foreignKeys;
154: }
155:
156: public Column getColumn(int index) {
157: return (Column) columns.get(index);
158: }
159:
160: public ForeignKey getForeignKey(int index) {
161: return (ForeignKey) foreignKeys.get(index);
162: }
163:
164: public void addIndex(Index index) {
165: indexes.add(index);
166: }
167:
168: public List getIndexes() {
169: return indexes;
170: }
171:
172: public Index getIndex(int index) {
173: return (Index) indexes.get(index);
174: }
175:
176: // Helper methods
177: //-------------------------------------------------------------------------
178:
179: /**
180: * @return true if there is at least one primary key column
181: * on this table
182: */
183: public boolean hasPrimaryKey() {
184: for (Iterator iter = getColumns().iterator(); iter.hasNext();) {
185: Column column = (Column) iter.next();
186: if (column.isPrimaryKey()) {
187: return true;
188: }
189: }
190: return false;
191: }
192:
193: /**
194: * Finds the table with the specified name, using case insensitive matching.
195: * Note that this method is not called getColumn(String) to avoid introspection
196: * problems.
197: */
198: public Column findColumn(String name) {
199: for (Iterator iter = getColumns().iterator(); iter.hasNext();) {
200: Column column = (Column) iter.next();
201:
202: // column names are typically case insensitive
203: if (column.getName().equalsIgnoreCase(name)) {
204: return column;
205: }
206: }
207: return null;
208: }
209:
210: /**
211: * @return a List of primary key columns or an empty list if there are no
212: * primary key columns for this Table
213: */
214: public List getPrimaryKeyColumns() {
215: List answer = new ArrayList();
216: for (Iterator iter = getColumns().iterator(); iter.hasNext();) {
217: Column column = (Column) iter.next();
218: if (column.isPrimaryKey()) {
219: answer.add(column);
220: }
221: }
222: return answer;
223: }
224:
225: /**
226: * @return the auto increment column, if there is one, otherwise null is returned
227: */
228: public Column getAutoIncrementColumn() {
229: for (Iterator iter = getColumns().iterator(); iter.hasNext();) {
230: Column column = (Column) iter.next();
231: if (column.isAutoIncrement()) {
232: return column;
233: }
234: }
235: return null;
236: }
237: }
|