| 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 ColumnSpec |
|---|
| 43 | { |
|---|
| 44 | private String mColumnName; |
|---|
| 45 | private String mColumnType; |
|---|
| 46 | |
|---|
| 47 | private String mJavaType; |
|---|
| 48 | private String mStoreMethod; |
|---|
| 49 | private String mLoadMethod; |
|---|
| 50 | private String mCurrencyColumn; |
|---|
| 51 | private String mPeriodFieldName; |
|---|
| 52 | private String mPeriodEndDateColumn; |
|---|
| 53 | private String mWeblogicColumnType; |
|---|
| 54 | private boolean mPeriodDefined = false; |
|---|
| 55 | private boolean mSkipInInterface = false; |
|---|
| 56 | |
|---|
| 57 | private final List mDatatypeAttributes = new ArrayList(); |
|---|
| 58 | private final List mAttributes = new ArrayList(); |
|---|
| 59 | |
|---|
| 60 | private boolean mIsNotNull = false; |
|---|
| 61 | private boolean mIsPrimaryKey = false; |
|---|
| 62 | private boolean mIsUnique = false; |
|---|
| 63 | |
|---|
| 64 | private String mAnnotation; |
|---|
| 65 | |
|---|
| 66 | /** |
|---|
| 67 | * Returns the name of this column. |
|---|
| 68 | * @return the name of this column |
|---|
| 69 | */ |
|---|
| 70 | public final String getColumnName () |
|---|
| 71 | { |
|---|
| 72 | return mColumnName; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | /** |
|---|
| 76 | * Sets the name of this column. |
|---|
| 77 | * @param string the name of this column |
|---|
| 78 | */ |
|---|
| 79 | public final void setColumnName (String string) |
|---|
| 80 | { |
|---|
| 81 | mColumnName = string; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | /** |
|---|
| 85 | * Returns the data type for this column. |
|---|
| 86 | * @return the data type for this column |
|---|
| 87 | */ |
|---|
| 88 | public final String getColumnType () |
|---|
| 89 | { |
|---|
| 90 | return mColumnType; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | /** |
|---|
| 95 | * Sets the data type for this column. |
|---|
| 96 | * @param string the data type |
|---|
| 97 | */ |
|---|
| 98 | public final void setColumnType (String string) |
|---|
| 99 | { |
|---|
| 100 | mColumnType = string; |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | /** |
|---|
| 105 | * Returns a list of all attributes of this colspec. |
|---|
| 106 | * The elements of this list are of type ColumnAttribute. |
|---|
| 107 | * @return a list of all attributes of this colspec |
|---|
| 108 | */ |
|---|
| 109 | public final List getAttributes () |
|---|
| 110 | { |
|---|
| 111 | return mAttributes; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | /** |
|---|
| 115 | * Adds an attribute to this column spec. |
|---|
| 116 | * @param attr the attribute to add |
|---|
| 117 | */ |
|---|
| 118 | public final void addAttribute (ColumnAttribute attr) |
|---|
| 119 | { |
|---|
| 120 | mAttributes.add(attr); |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | /** |
|---|
| 124 | * Adds an attribute to the datatype of this colspec. |
|---|
| 125 | * @param attr the datatype attribute that should be added |
|---|
| 126 | */ |
|---|
| 127 | public final void addDatatypeAttribute (ColumnAttribute attr) |
|---|
| 128 | { |
|---|
| 129 | mDatatypeAttributes.add(attr); |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | /** |
|---|
| 133 | * Returns the datatype attributes of this colspec. |
|---|
| 134 | * @return a list of datatype attributes |
|---|
| 135 | */ |
|---|
| 136 | public final List getDatatypeAttributes () |
|---|
| 137 | { |
|---|
| 138 | return mDatatypeAttributes; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | /** |
|---|
| 142 | * Returns the java type to which this column maps. |
|---|
| 143 | * @return the java type to which this column maps |
|---|
| 144 | */ |
|---|
| 145 | public final String getJavaType () |
|---|
| 146 | { |
|---|
| 147 | return mJavaType; |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | /** |
|---|
| 151 | * Sets the java type for this column. |
|---|
| 152 | * @param type the java type for this column |
|---|
| 153 | */ |
|---|
| 154 | public final void setJavaType (String type) |
|---|
| 155 | { |
|---|
| 156 | mJavaType = type; |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | /** |
|---|
| 160 | * Returns the method used when loading the custom type from the db. |
|---|
| 161 | * @return the method used when loading the custom type from the db |
|---|
| 162 | */ |
|---|
| 163 | public final String getLoadMethod () |
|---|
| 164 | { |
|---|
| 165 | return mLoadMethod; |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | /** |
|---|
| 169 | * Sets the method used when loading the custom type from the db. |
|---|
| 170 | * @param methodName the method used when loading the custom type from the db |
|---|
| 171 | */ |
|---|
| 172 | public final void setLoadMethod (String methodName) |
|---|
| 173 | { |
|---|
| 174 | mLoadMethod = methodName; |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | /** |
|---|
| 178 | * Returns the method used when storing the type to the db. |
|---|
| 179 | * @return the method used when storing the type to the db |
|---|
| 180 | */ |
|---|
| 181 | public final String getStoreMethod () |
|---|
| 182 | { |
|---|
| 183 | return mStoreMethod; |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | /** |
|---|
| 187 | * Sets the method used when storing the type to the db. |
|---|
| 188 | * @param methodName the method used when storing the type to the db |
|---|
| 189 | */ |
|---|
| 190 | public final void setStoreMethod (String methodName) |
|---|
| 191 | { |
|---|
| 192 | mStoreMethod = methodName; |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | /** |
|---|
| 196 | * Returns whether this column is not null. |
|---|
| 197 | * @return true if this column is not null, false otherwise |
|---|
| 198 | */ |
|---|
| 199 | public final boolean isNotNull () |
|---|
| 200 | { |
|---|
| 201 | return mIsNotNull; |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | /** |
|---|
| 205 | * Set whether this column is not null. |
|---|
| 206 | * @param b flag indicating whether this column is not null |
|---|
| 207 | */ |
|---|
| 208 | public final void setNotNull (boolean b) |
|---|
| 209 | { |
|---|
| 210 | mIsNotNull = b; |
|---|
| 211 | } |
|---|
| 212 | |
|---|
| 213 | /** |
|---|
| 214 | * Returns whether this column is primary key. |
|---|
| 215 | * @return true if this column is primary key, false otherwise |
|---|
| 216 | */ |
|---|
| 217 | public final boolean isPrimaryKey () |
|---|
| 218 | { |
|---|
| 219 | return mIsPrimaryKey; |
|---|
| 220 | } |
|---|
| 221 | |
|---|
| 222 | /** |
|---|
| 223 | * Set whether this column is primary key or not. |
|---|
| 224 | * @param b flag indicating whether this column is primary key |
|---|
| 225 | */ |
|---|
| 226 | public final void setPrimaryKey (boolean b) |
|---|
| 227 | { |
|---|
| 228 | mIsPrimaryKey = b; |
|---|
| 229 | } |
|---|
| 230 | |
|---|
| 231 | /** |
|---|
| 232 | * @return Returns the isUnique. |
|---|
| 233 | */ |
|---|
| 234 | public boolean isUnique () |
|---|
| 235 | { |
|---|
| 236 | return mIsUnique; |
|---|
| 237 | } |
|---|
| 238 | /** |
|---|
| 239 | * @param isUnique The isUnique to set. |
|---|
| 240 | */ |
|---|
| 241 | public void setUnique (boolean isUnique) |
|---|
| 242 | { |
|---|
| 243 | mIsUnique = isUnique; |
|---|
| 244 | } |
|---|
| 245 | |
|---|
| 246 | /** {@inheritDoc} */ |
|---|
| 247 | public final String toString () |
|---|
| 248 | { |
|---|
| 249 | final StringBuffer sbuf = new StringBuffer(); |
|---|
| 250 | sbuf.append("[ColumnSpec name=").append(mColumnName); |
|---|
| 251 | sbuf.append(", sqlType=").append(mColumnType); |
|---|
| 252 | sbuf.append(", javaType=").append(mJavaType); |
|---|
| 253 | sbuf.append(", storeMethod=").append(mStoreMethod); |
|---|
| 254 | sbuf.append(", loadMethod=").append(mLoadMethod); |
|---|
| 255 | if (mIsNotNull) |
|---|
| 256 | { |
|---|
| 257 | sbuf.append(", not null"); |
|---|
| 258 | } |
|---|
| 259 | if (mIsPrimaryKey) |
|---|
| 260 | { |
|---|
| 261 | sbuf.append(", primary key"); |
|---|
| 262 | } |
|---|
| 263 | if (mIsUnique) |
|---|
| 264 | { |
|---|
| 265 | sbuf.append(", unique"); |
|---|
| 266 | } |
|---|
| 267 | for (final Iterator it = mDatatypeAttributes.iterator(); it.hasNext(); ) |
|---|
| 268 | { |
|---|
| 269 | final ColumnAttribute attr = (ColumnAttribute) it.next(); |
|---|
| 270 | sbuf.append(",\n Data Type Attribute: ").append(attr); |
|---|
| 271 | } |
|---|
| 272 | for (final Iterator it = mAttributes.iterator(); it.hasNext(); ) |
|---|
| 273 | { |
|---|
| 274 | final ColumnAttribute attr = (ColumnAttribute) it.next(); |
|---|
| 275 | sbuf.append(",\n Column Attribute: ").append(attr); |
|---|
| 276 | } |
|---|
| 277 | return sbuf.toString(); |
|---|
| 278 | } |
|---|
| 279 | |
|---|
| 280 | public void setAnnotation (String annotation) |
|---|
| 281 | { |
|---|
| 282 | mAnnotation = annotation; |
|---|
| 283 | } |
|---|
| 284 | |
|---|
| 285 | public String getAnnotation () |
|---|
| 286 | { |
|---|
| 287 | return mAnnotation; |
|---|
| 288 | } |
|---|
| 289 | |
|---|
| 290 | /** |
|---|
| 291 | * @return Returns the currencyColumn. |
|---|
| 292 | */ |
|---|
| 293 | public String getCurrencyColumn () |
|---|
| 294 | { |
|---|
| 295 | return mCurrencyColumn; |
|---|
| 296 | } |
|---|
| 297 | |
|---|
| 298 | /** |
|---|
| 299 | * @param currencyColumn The currencyColumn to set. |
|---|
| 300 | */ |
|---|
| 301 | public void setCurrencyColumn (String currencyColumn) |
|---|
| 302 | { |
|---|
| 303 | mCurrencyColumn = currencyColumn; |
|---|
| 304 | } |
|---|
| 305 | |
|---|
| 306 | public boolean isPeriodDefined () |
|---|
| 307 | { |
|---|
| 308 | return mPeriodDefined; |
|---|
| 309 | } |
|---|
| 310 | |
|---|
| 311 | public void setIsPeriodDefined (boolean periodDefined) |
|---|
| 312 | { |
|---|
| 313 | mPeriodDefined = periodDefined; |
|---|
| 314 | } |
|---|
| 315 | |
|---|
| 316 | public String getPeriodFieldName () |
|---|
| 317 | { |
|---|
| 318 | return mPeriodFieldName; |
|---|
| 319 | } |
|---|
| 320 | |
|---|
| 321 | public void setPeriodFieldName (String periodFieldName) |
|---|
| 322 | { |
|---|
| 323 | mPeriodFieldName = periodFieldName; |
|---|
| 324 | } |
|---|
| 325 | |
|---|
| 326 | public String getPeriodEndDateColumn () |
|---|
| 327 | { |
|---|
| 328 | return mPeriodEndDateColumn; |
|---|
| 329 | } |
|---|
| 330 | |
|---|
| 331 | public void setPeriodEndDateColumn (String endDateColumn) |
|---|
| 332 | { |
|---|
| 333 | mPeriodEndDateColumn = endDateColumn; |
|---|
| 334 | } |
|---|
| 335 | |
|---|
| 336 | public boolean isSkipInInterface () |
|---|
| 337 | { |
|---|
| 338 | return mSkipInInterface; |
|---|
| 339 | } |
|---|
| 340 | |
|---|
| 341 | public void setSkipInInterface (boolean b) |
|---|
| 342 | { |
|---|
| 343 | mSkipInInterface = b; |
|---|
| 344 | } |
|---|
| 345 | |
|---|
| 346 | public String getWeblogicColumnType () |
|---|
| 347 | { |
|---|
| 348 | return mWeblogicColumnType; |
|---|
| 349 | } |
|---|
| 350 | |
|---|
| 351 | public void setWeblogicColumnType (String weblogicColumnType) |
|---|
| 352 | { |
|---|
| 353 | mWeblogicColumnType = weblogicColumnType; |
|---|
| 354 | } |
|---|
| 355 | |
|---|
| 356 | public boolean isWeblogicColumnTypeDefined () |
|---|
| 357 | { |
|---|
| 358 | return mWeblogicColumnType != null; |
|---|
| 359 | } |
|---|
| 360 | } |
|---|