| 1 | /* |
|---|
| 2 | * $Id$ |
|---|
| 3 | * |
|---|
| 4 | * Copyright 2006, The jCoderZ.org Project. All rights reserved. |
|---|
| 5 | * |
|---|
| 6 | * Redistribution and use in source and binary forms, with or without |
|---|
| 7 | * modification, are permitted provided that the following conditions are |
|---|
| 8 | * met: |
|---|
| 9 | * |
|---|
| 10 | * * Redistributions of source code must retain the above copyright |
|---|
| 11 | * notice, this list of conditions and the following disclaimer. |
|---|
| 12 | * * Redistributions in binary form must reproduce the above |
|---|
| 13 | * copyright notice, this list of conditions and the following |
|---|
| 14 | * disclaimer in the documentation and/or other materials |
|---|
| 15 | * provided with the distribution. |
|---|
| 16 | * * Neither the name of the jCoderZ.org Project nor the names of |
|---|
| 17 | * its contributors may be used to endorse or promote products |
|---|
| 18 | * derived from this software without specific prior written |
|---|
| 19 | * permission. |
|---|
| 20 | * |
|---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND |
|---|
| 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|---|
| 24 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS |
|---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
|---|
| 28 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|---|
| 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|---|
| 30 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|---|
| 31 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 32 | */ |
|---|
| 33 | package org.jcoderz.phoenix.sqlparser; |
|---|
| 34 | |
|---|
| 35 | import java.util.ArrayList; |
|---|
| 36 | import java.util.Iterator; |
|---|
| 37 | import java.util.List; |
|---|
| 38 | |
|---|
| 39 | /** |
|---|
| 40 | * @author Albrecht Messner |
|---|
| 41 | */ |
|---|
| 42 | public class CreateTableStatement extends SqlStatement |
|---|
| 43 | { |
|---|
| 44 | private final String mTableName; |
|---|
| 45 | private String mBeanName; |
|---|
| 46 | private String mAdditionalJavadoc; |
|---|
| 47 | private boolean mOptimisticVersionCount; |
|---|
| 48 | private boolean mSkipAppserverSupport; |
|---|
| 49 | |
|---|
| 50 | private final List mColumns = new ArrayList(); |
|---|
| 51 | |
|---|
| 52 | private final List mIndexes = new ArrayList(); |
|---|
| 53 | |
|---|
| 54 | private final List mFkConstraints = new ArrayList(); |
|---|
| 55 | |
|---|
| 56 | public CreateTableStatement (String tableName) |
|---|
| 57 | { |
|---|
| 58 | mTableName = tableName; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | /** |
|---|
| 62 | * Returns all columns of this table. |
|---|
| 63 | * @return a list of ColumnSpec objects describing the columns of this table |
|---|
| 64 | */ |
|---|
| 65 | public final List getColumns () |
|---|
| 66 | { |
|---|
| 67 | return mColumns; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | /** |
|---|
| 71 | * Returns the name of this table. |
|---|
| 72 | * @return the name of this table |
|---|
| 73 | */ |
|---|
| 74 | public final String getTableName () |
|---|
| 75 | { |
|---|
| 76 | return mTableName; |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | /** |
|---|
| 80 | * Adds a column definition to this table. |
|---|
| 81 | * @param column a column definition |
|---|
| 82 | */ |
|---|
| 83 | public final void addColumn (ColumnSpec column) |
|---|
| 84 | { |
|---|
| 85 | mColumns.add(column); |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | /** |
|---|
| 89 | * Retrieves a column by its name. |
|---|
| 90 | * @param colName the name of the column |
|---|
| 91 | * @return the column specification, or null |
|---|
| 92 | * if no column by that name is found |
|---|
| 93 | */ |
|---|
| 94 | public final ColumnSpec getColumnByName (String colName) |
|---|
| 95 | { |
|---|
| 96 | ColumnSpec result = null; |
|---|
| 97 | for (final Iterator it = mColumns.iterator(); it.hasNext(); ) |
|---|
| 98 | { |
|---|
| 99 | final ColumnSpec col = (ColumnSpec) it.next(); |
|---|
| 100 | if (col.getColumnName().equalsIgnoreCase(colName)) |
|---|
| 101 | { |
|---|
| 102 | result = col; |
|---|
| 103 | break; |
|---|
| 104 | } |
|---|
| 105 | } |
|---|
| 106 | return result; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | /** |
|---|
| 110 | * Returns a readable string representation. |
|---|
| 111 | * @return a readable string representation |
|---|
| 112 | */ |
|---|
| 113 | public final String toString () |
|---|
| 114 | { |
|---|
| 115 | final StringBuffer sbuf = new StringBuffer(); |
|---|
| 116 | sbuf.append("[CREATE TABLE Statement: name=").append(mTableName); |
|---|
| 117 | sbuf.append(", bean name=").append(mBeanName); |
|---|
| 118 | sbuf.append(", annotation=").append(getAnnotation()); |
|---|
| 119 | for (final Iterator it = mColumns.iterator(); it.hasNext();) |
|---|
| 120 | { |
|---|
| 121 | final ColumnSpec col = (ColumnSpec) it.next(); |
|---|
| 122 | sbuf.append(",\n col=").append(col); |
|---|
| 123 | } |
|---|
| 124 | sbuf.append(']'); |
|---|
| 125 | return sbuf.toString(); |
|---|
| 126 | } |
|---|
| 127 | /** |
|---|
| 128 | * @return Returns the beanName. |
|---|
| 129 | */ |
|---|
| 130 | public String getBeanName () |
|---|
| 131 | { |
|---|
| 132 | return mBeanName; |
|---|
| 133 | } |
|---|
| 134 | /** |
|---|
| 135 | * @param beanName The beanName to set. |
|---|
| 136 | */ |
|---|
| 137 | public void setBeanName (String beanName) |
|---|
| 138 | { |
|---|
| 139 | mBeanName = beanName; |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | public List getIndexes () |
|---|
| 143 | { |
|---|
| 144 | return mIndexes; |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | public void addIndex (CreateIndexStatement stmt) |
|---|
| 148 | { |
|---|
| 149 | mIndexes.add(stmt); |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | public void addFkConstraint (FkConstraint constraint) |
|---|
| 153 | { |
|---|
| 154 | mFkConstraints.add(constraint); |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | public List getFkConstraints () |
|---|
| 158 | { |
|---|
| 159 | return mFkConstraints; |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | /** |
|---|
| 163 | * @return Returns the additionalJavadoc. |
|---|
| 164 | */ |
|---|
| 165 | public String getAdditionalJavadoc () |
|---|
| 166 | { |
|---|
| 167 | return mAdditionalJavadoc; |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | /** |
|---|
| 171 | * @param additionalJavadoc The additionalJavadoc to set. |
|---|
| 172 | */ |
|---|
| 173 | public void setAdditionalJavadoc (String additionalJavadoc) |
|---|
| 174 | { |
|---|
| 175 | mAdditionalJavadoc = additionalJavadoc; |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | public void setOptimisticVersionCount (boolean b) |
|---|
| 179 | { |
|---|
| 180 | mOptimisticVersionCount = b; |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | public boolean isOptimisticVersionCount () |
|---|
| 184 | { |
|---|
| 185 | return mOptimisticVersionCount; |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | /** |
|---|
| 189 | * @param b |
|---|
| 190 | */ |
|---|
| 191 | public void setSkipAppserverSupport (boolean b) |
|---|
| 192 | { |
|---|
| 193 | mSkipAppserverSupport = b; |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | /** |
|---|
| 197 | * @return Returns the skipAppserverSupport. |
|---|
| 198 | */ |
|---|
| 199 | public boolean isSkipAppserverSupport () |
|---|
| 200 | { |
|---|
| 201 | return mSkipAppserverSupport; |
|---|
| 202 | } |
|---|
| 203 | } |
|---|