View Javadoc
1 package org.apache.torque.map; 2 3 /* ==================================================================== 4 * The Apache Software License, Version 1.1 5 * 6 * Copyright (c) 2001 The Apache Software Foundation. All rights 7 * reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in 18 * the documentation and/or other materials provided with the 19 * distribution. 20 * 21 * 3. The end-user documentation included with the redistribution, 22 * if any, must include the following acknowledgment: 23 * "This product includes software developed by the 24 * Apache Software Foundation (http://www.apache.org/)." 25 * Alternately, this acknowledgment may appear in the software itself, 26 * if and wherever such third-party acknowledgments normally appear. 27 * 28 * 4. The names "Apache" and "Apache Software Foundation" and 29 * "Apache Turbine" must not be used to endorse or promote products 30 * derived from this software without prior written permission. For 31 * written permission, please contact apache@apache.org. 32 * 33 * 5. Products derived from this software may not be called "Apache", 34 * "Apache Turbine", nor may "Apache" appear in their name, without 35 * prior written permission of the Apache Software Foundation. 36 * 37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 48 * SUCH DAMAGE. 49 * ==================================================================== 50 * 51 * This software consists of voluntary contributions made by many 52 * individuals on behalf of the Apache Software Foundation. For more 53 * information on the Apache Software Foundation, please see 54 * <http://www.apache.org/>. 55 */ 56 57 /*** 58 * ColumnMap is used to model a column of a table in a database. 59 * 60 * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a> 61 * @version $Id: ColumnMap.java,v 1.7 2003/03/21 17:31:08 mpoeschl Exp $ 62 */ 63 public class ColumnMap implements java.io.Serializable 64 { 65 /*** Type of the column. */ 66 private Object type = null; 67 68 /*** Size of the column. */ 69 private int size = 0; 70 71 /*** Is it a primary key? */ 72 private boolean pk = false; 73 74 /*** Is null value allowed ?*/ 75 private boolean notNull = false; 76 77 /*** Name of the table that this column is related to. */ 78 private String relatedTableName = ""; 79 80 /*** Name of the column that this column is related to. */ 81 private String relatedColumnName = ""; 82 83 /*** The TableMap for this column. */ 84 private TableMap table; 85 86 /*** The name of the column. */ 87 private String columnName; 88 89 90 /*** 91 * Constructor. 92 * 93 * @param name The name of the column. 94 * @param containingTable TableMap of the table this column is in. 95 */ 96 public ColumnMap(String name, TableMap containingTable) 97 { 98 this.columnName = name; 99 table = containingTable; 100 } 101 102 /*** 103 * Get the name of a column. 104 * 105 * @return A String with the column name. 106 */ 107 public String getColumnName() 108 { 109 return columnName; 110 } 111 112 /*** 113 * Get the table name + column name. 114 * 115 * @return A String with the full column name. 116 */ 117 public String getFullyQualifiedName() 118 { 119 return table.getName() + "." + columnName; 120 } 121 122 /*** 123 * Get the name of the table this column is in. 124 * 125 * @return A String with the table name. 126 */ 127 public String getTableName() 128 { 129 return table.getName(); 130 } 131 132 /*** 133 * Set the type of this column. 134 * 135 * @param type An Object specifying the type. 136 */ 137 public void setType (Object type) 138 { 139 this.type = type; 140 } 141 142 /*** 143 * Set the size of this column. 144 * 145 * @param size An int specifying the size. 146 */ 147 public void setSize(int size) 148 { 149 this.size = size; 150 } 151 152 /*** 153 * Set if this column is a primary key or not. 154 * 155 * @param pk True if column is a primary key. 156 */ 157 public void setPrimaryKey(boolean pk) 158 { 159 this.pk = pk; 160 } 161 162 /*** 163 * Set if this column may be null. 164 * 165 * @param nn True if column may be null. 166 */ 167 public void setNotNull(boolean nn) 168 { 169 this.notNull = nn; 170 } 171 172 /*** 173 * Set the foreign key for this column. 174 * 175 * @param fullyQualifiedName The name of the table.column that is 176 * foreign. 177 */ 178 public void setForeignKey(String fullyQualifiedName) 179 { 180 if (fullyQualifiedName != null && fullyQualifiedName.length() > 0) 181 { 182 relatedTableName = fullyQualifiedName.substring( 183 0, fullyQualifiedName.indexOf('.')); 184 relatedColumnName = fullyQualifiedName.substring( 185 fullyQualifiedName.indexOf('.') + 1); 186 } 187 else 188 { 189 relatedTableName = ""; 190 relatedColumnName = ""; 191 } 192 } 193 194 /*** 195 * Set the foreign key for this column. 196 * 197 * @param tableName The name of the table that is foreign. 198 * @param columnName The name of the column that is foreign. 199 */ 200 public void setForeignKey(String tableName, String columnName) 201 { 202 if (tableName != null && tableName.length() > 0 && columnName != null 203 && columnName.length() > 0) 204 { 205 relatedTableName = tableName; 206 relatedColumnName = columnName; 207 } 208 else 209 { 210 relatedTableName = ""; 211 relatedColumnName = ""; 212 } 213 } 214 215 /*** 216 * Get the type of this column. 217 * 218 * @return An Object specifying the type. 219 */ 220 public Object getType() 221 { 222 return type; 223 } 224 225 /*** 226 * Get the size of this column. 227 * 228 * @return An int specifying the size. 229 */ 230 public int getSize() 231 { 232 return size; 233 } 234 235 /*** 236 * Is this column a primary key? 237 * 238 * @return True if column is a primary key. 239 */ 240 public boolean isPrimaryKey() 241 { 242 return pk; 243 } 244 245 /*** 246 * Is null value allowed ? 247 * 248 * @return True if column may be null. 249 */ 250 public boolean isNotNull() 251 { 252 return (notNull || isPrimaryKey()); 253 } 254 255 /*** 256 * Is this column a foreign key? 257 * 258 * @return True if column is a foreign key. 259 */ 260 public boolean isForeignKey() 261 { 262 return (relatedTableName != null && relatedTableName.length() > 0); 263 } 264 265 /*** 266 * Get the table.column that this column is related to. 267 * 268 * @return A String with the full name for the related column. 269 */ 270 public String getRelatedName() 271 { 272 return relatedTableName + "." + relatedColumnName; 273 } 274 275 /*** 276 * Get the table name that this column is related to. 277 * 278 * @return A String with the name for the related table. 279 */ 280 public String getRelatedTableName() 281 { 282 return relatedTableName; 283 } 284 285 /*** 286 * Get the column name that this column is related to. 287 * 288 * @return A String with the name for the related column. 289 */ 290 public String getRelatedColumnName() 291 { 292 return relatedColumnName; 293 } 294 }

This page was automatically generated by Maven