001 /*
002 * JBoss DNA (http://www.jboss.org/dna)
003 * See the COPYRIGHT.txt file distributed with this work for information
004 * regarding copyright ownership. Some portions may be licensed
005 * to Red Hat, Inc. under one or more contributor license agreements.
006 * See the AUTHORS.txt file in the distribution for a full listing of
007 * individual contributors.
008 *
009 * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
010 * is licensed to you under the terms of the GNU Lesser General Public License as
011 * published by the Free Software Foundation; either version 2.1 of
012 * the License, or (at your option) any later version.
013 *
014 * JBoss DNA is distributed in the hope that it will be useful,
015 * but WITHOUT ANY WARRANTY; without even the implied warranty of
016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017 * Lesser General Public License for more details.
018 *
019 * You should have received a copy of the GNU Lesser General Public
020 * License along with this software; if not, write to the Free
021 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
022 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
023 */
024 package org.jboss.dna.common.jdbc.model.spi;
025
026 import java.util.Set;
027 import java.util.HashSet;
028 import org.jboss.dna.common.jdbc.model.api.Column;
029 import org.jboss.dna.common.jdbc.model.api.NullabilityType;
030 import org.jboss.dna.common.jdbc.model.api.SqlType;
031 import org.jboss.dna.common.jdbc.model.api.Privilege;
032 import org.jboss.dna.common.jdbc.model.api.SchemaObject;
033
034 /**
035 * Provides all column specific metadata.
036 *
037 * @author <a href="mailto:litsenko_sergey@yahoo.com">Sergiy Litsenko</a>
038 */
039 public class ColumnBean extends DatabaseNamedObjectBean implements Column {
040 private static final long serialVersionUID = 4797227922671541353L;
041 private SchemaObject owner;
042 private NullabilityType nullabilityType;
043 private SqlType sqlType;
044 private String typeName;
045 private Integer size;
046 private Integer precision;
047 private Integer radix;
048 private String defaultValue;
049 private Integer ordinalPosition;
050 private Integer charOctetLength;
051 private Set<Privilege> privileges = new HashSet<Privilege>();
052
053 /**
054 * Default constructor
055 */
056 public ColumnBean() {
057 }
058
059 /**
060 * Returns owner of ColumnMetaData such as Table, or Stored Procedure, UDT, PK, FK, Index, etc. May return NULL
061 *
062 * @return owner of ColumnMetaData such as Table, or Stored Procedure, or UDT, PK, FK, Index, etc. May return NULL
063 */
064 public SchemaObject getOwner() {
065 return owner;
066 }
067
068 /**
069 * Sets the owner of ColumnMetaData
070 *
071 * @param owner the owner of ColumnMetaData
072 */
073 public void setOwner( SchemaObject owner ) {
074 this.owner = owner;
075 }
076
077 /**
078 * Gets column nullability
079 *
080 * @return column nullability
081 */
082 public NullabilityType getNullabilityType() {
083 return nullabilityType;
084 }
085
086 /**
087 * Sets column nullability
088 *
089 * @param nullabilityType the column nullability
090 */
091 public void setNullabilityType( NullabilityType nullabilityType ) {
092 this.nullabilityType = nullabilityType;
093 }
094
095 /**
096 * Gets SQL type from java.sql.Types
097 *
098 * @return SQL type from java.sql.Types
099 */
100 public SqlType getSqlType() {
101 return sqlType;
102 }
103
104 /**
105 * Sets SQL type from java.sql.Types
106 *
107 * @param sqlType the SQL type from java.sql.Types
108 */
109 public void setSqlType( SqlType sqlType ) {
110 this.sqlType = sqlType;
111 }
112
113 /**
114 * Data source dependent type name. For a UDT, the type name is fully qualified. For a REF, the type name is fully qualified
115 * and represents the target type of the reference type.
116 *
117 * @return data source dependent type name
118 */
119 public String getTypeName() {
120 return typeName;
121 }
122
123 /**
124 * Data source dependent type name. For a UDT, the type name is fully qualified. For a REF, the type name is fully qualified
125 * and represents the target type of the reference type.
126 *
127 * @param typeName data source dependent type name
128 */
129 public void setTypeName( String typeName ) {
130 this.typeName = typeName;
131 }
132
133 /**
134 * Gets column size. For char or date types this is the maximum number of characters, for numeric or decimal types this is
135 * precision. For Stored procedure columns it is length in bytes of data
136 *
137 * @return column size
138 */
139 public Integer getSize() {
140 return size;
141 }
142
143 /**
144 * Sets column size. For char or date types this is the maximum number of characters, for numeric or decimal types this is
145 * precision. For Stored procedure columns it is length in bytes of data
146 *
147 * @param size the column size
148 */
149 public void setSize( Integer size ) {
150 this.size = size;
151 }
152
153 /**
154 * Gets precision if applicable otherwise 0. For table columns return the number of fractional digits; for stored procedure
155 * column - scale.
156 *
157 * @return precision if applicable otherwise 0
158 */
159 public Integer getPrecision() {
160 return precision;
161 }
162
163 /**
164 * Sets precision if applicable otherwise 0. For table columns return the number of fractional digits; for stored procedure
165 * column - scale.
166 *
167 * @param precision the precision if applicable otherwise 0
168 */
169 public void setPrecision( Integer precision ) {
170 this.precision = precision;
171 }
172
173 /**
174 * Gets radix if applicable
175 *
176 * @return radix if applicable
177 */
178 public Integer getRadix() {
179 return radix;
180 }
181
182 /**
183 * Sets radix if applicable
184 *
185 * @param radix if applicable
186 */
187 public void setRadix( Integer radix ) {
188 this.radix = radix;
189 }
190
191 /**
192 * Gets default value (may be <code>null</code>)
193 *
194 * @return default value (may be <code>null</code>)
195 */
196 public String getDefaultValue() {
197 return defaultValue;
198 }
199
200 /**
201 * Sets default value (may be <code>null</code>)
202 *
203 * @param defaultValue the default value (may be <code>null</code>)
204 */
205 public void setDefaultValue( String defaultValue ) {
206 this.defaultValue = defaultValue;
207 }
208
209 /**
210 * Returns index of column starting at 1 - if applicable. Otherwise returns -1.
211 *
212 * @return index of column starting at 1 - if applicable. Otherwise returns -1.
213 */
214 public Integer getOrdinalPosition() {
215 return ordinalPosition;
216 }
217
218 /**
219 * Sets index of column starting at 1 - if applicable. Otherwise returns -1.
220 *
221 * @param ordinalPosition the index of column starting at 1 - if applicable. Otherwise returns -1.
222 */
223 public void setOrdinalPosition( Integer ordinalPosition ) {
224 this.ordinalPosition = ordinalPosition;
225 }
226
227 /**
228 * For char types returns the maximum number of bytes in the column. Otherwise returns -1.
229 *
230 * @return For char types returns the maximum number of bytes in the column. Otherwise returns -1.
231 */
232 public Integer getCharOctetLength() {
233 return charOctetLength;
234 }
235
236 /**
237 * For char types sets the maximum number of bytes in the column. Otherwise -1.
238 *
239 * @param charOctetLength For char types sets the maximum number of bytes in the column. Otherwise -1.
240 */
241 public void setCharOctetLength( Integer charOctetLength ) {
242 this.charOctetLength = charOctetLength;
243 }
244
245 /**
246 * Gets table column privileges.
247 *
248 * @return set of table column privileges
249 */
250 public Set<Privilege> getPrivileges() {
251 return privileges;
252 }
253
254 /**
255 * Adds table column priviledge
256 *
257 * @param privilege the table column priviledge
258 */
259 public void addPrivilege( Privilege privilege ) {
260 privileges.add(privilege);
261 }
262
263 /**
264 * Deletes table column priviledge
265 *
266 * @param privilege the table column priviledge
267 */
268 public void deletePrivilege( Privilege privilege ) {
269 privileges.remove(privilege);
270 }
271
272 /**
273 * Searches priviledge by name
274 *
275 * @param priviledgeName the priviledge name to search
276 * @return priviledge if found, otherwise return null
277 */
278 public Privilege findPriviledgeByName( String priviledgeName ) {
279 for (Privilege p : privileges) {
280 if (p.getName().equals(priviledgeName)) {
281 return p;
282 }
283 }
284 // return nothing
285 return null;
286 }
287 }