View Javadoc

1   /*
2    * ModeShape (http://www.modeshape.org)
3    * See the COPYRIGHT.txt file distributed with this work for information
4    * regarding copyright ownership.  Some portions may be licensed
5    * to Red Hat, Inc. under one or more contributor license agreements.
6    * See the AUTHORS.txt file in the distribution for a full listing of 
7    * individual contributors. 
8    *
9    * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
10   * is licensed to you under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation; either version 2.1 of
12   * the License, or (at your option) any later version.
13   *
14   * ModeShape is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this software; if not, write to the Free
21   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23   */
24  package org.modeshape.connector.meta.jdbc;
25  
26  import java.sql.DatabaseMetaData;
27  import java.sql.Types;
28  import net.jcip.annotations.Immutable;
29  
30  /**
31   * Container for column-level metadata. The fields in this class roughly parallel the information returned from the
32   * {@link DatabaseMetaData#getColumns(String, String, String, String)} method.
33   */
34  @Immutable
35  public class ColumnMetadata {
36  
37      private final String name;
38      private final int jdbcDataType;
39      private final String typeName;
40      private final int columnSize;
41      private final int decimalDigits;
42      private final int radix;
43      private final Boolean nullable;
44      private final String description;
45      private final String defaultValue;
46      private final int length;
47      private final int ordinalPosition;
48      private final String scopeCatalogName;
49      private final String scopeSchemaName;
50      private final String scopeTableName;
51      private final Integer sourceJdbcDataType;
52  
53      public ColumnMetadata( String name,
54                             int jdbcDataType,
55                             String typeName,
56                             int columnSize,
57                             int decimalDigits,
58                             int radix,
59                             Boolean nullable,
60                             String description,
61                             String defaultValue,
62                             int length,
63                             int ordinalPosition,
64                             String scopeCatalogName,
65                             String scopeSchemaName,
66                             String scopeTableName,
67                             Integer sourceJdbcDataType ) {
68          super();
69          this.name = name;
70          this.jdbcDataType = jdbcDataType;
71          this.typeName = typeName;
72          this.columnSize = columnSize;
73          this.decimalDigits = decimalDigits;
74          this.radix = radix;
75          this.nullable = nullable;
76          this.description = description;
77          this.defaultValue = defaultValue;
78          this.length = length;
79          this.ordinalPosition = ordinalPosition;
80          this.scopeCatalogName = scopeCatalogName;
81          this.scopeSchemaName = scopeSchemaName;
82          this.scopeTableName = scopeTableName;
83          this.sourceJdbcDataType = sourceJdbcDataType;
84      }
85  
86      /**
87       * @return the column name (COLUMN_NAME in the {@link DatabaseMetaData#getColumns(String, String, String, String)} result
88       *         set).
89       */
90      public String getName() {
91          return name;
92      }
93  
94      /**
95       * @return the JDBC data type (from {@link Types}) (DATA_TYPE in the
96       *         {@link DatabaseMetaData#getColumns(String, String, String, String)} result set).
97       */
98      public int getJdbcDataType() {
99          return jdbcDataType;
100     }
101 
102     /**
103      * @return the database-dependent type name (TYPENAME in the
104      *         {@link DatabaseMetaData#getColumns(String, String, String, String)} result set).
105      */
106     public String getTypeName() {
107         return typeName;
108     }
109 
110     /**
111      * @return the column size (length for character data types, precision for numeric data types) (COLUMN_SIZE in the
112      *         {@link DatabaseMetaData#getColumns(String, String, String, String)} result set).
113      */
114     public int getColumnSize() {
115         return columnSize;
116     }
117 
118     /**
119      * @return the number of fractional digits in the column (DECIMAL_DIGITS in the
120      *         {@link DatabaseMetaData#getColumns(String, String, String, String)} result set).
121      */
122     public int getDecimalDigits() {
123         return decimalDigits;
124     }
125 
126     /**
127      * @return the radix for the column (NUM_PREC_RADIX in the {@link DatabaseMetaData#getColumns(String, String, String, String)}
128      *         result set).
129      */
130     public int getRadix() {
131         return radix;
132     }
133 
134     /**
135      * @return whether the column allows NULLs or not (NULLABLE in the
136      *         {@link DatabaseMetaData#getColumns(String, String, String, String)} result set); null indicates that it cannot be
137      *         determined if the column allows NULLs.
138      */
139     public Boolean getNullable() {
140         return nullable;
141     }
142 
143     /**
144      * @return the column description (REMARKS in the {@link DatabaseMetaData#getColumns(String, String, String, String)} result
145      *         set).
146      */
147     public String getDescription() {
148         return description;
149     }
150 
151     /**
152      * @return the default value for the column, if any (COLUMN_DEF in the
153      *         {@link DatabaseMetaData#getColumns(String, String, String, String)} result set).
154      */
155     public String getDefaultValue() {
156         return defaultValue;
157     }
158 
159     /**
160      * @return the number of bytes in the column (for char types) (CHAR_OCTECT_LENGTH in the
161      *         {@link DatabaseMetaData#getColumns(String, String, String, String)} result set).
162      */
163     public int getLength() {
164         return length;
165     }
166 
167     /**
168      * @return the 1-based index of the column within its table (ORDINAL_POSITION in the
169      *         {@link DatabaseMetaData#getColumns(String, String, String, String)} result set).
170      */
171     public int getOrdinalPosition() {
172         return ordinalPosition;
173     }
174 
175     /**
176      * @return for columns of type REF, the catalog name of the target table (SCOPE_CATALOG in the
177      *         {@link DatabaseMetaData#getColumns(String, String, String, String)} result set).
178      */
179     public String getScopeCatalogName() {
180         return scopeCatalogName;
181     }
182 
183     /**
184      * @return for columns of type REF, the schema name of the target table (SCOPE_SCHEMA in the
185      *         {@link DatabaseMetaData#getColumns(String, String, String, String)} result set).
186      */
187     public String getScopeSchemaName() {
188         return scopeSchemaName;
189     }
190 
191     /**
192      * @return for columns of type REF, the name of the target table (SCOPE_TABLE in the
193      *         {@link DatabaseMetaData#getColumns(String, String, String, String)} result set).
194      */
195     public String getScopeTableName() {
196         return scopeTableName;
197     }
198 
199     /**
200      * @return the source type of the referred type (from {@link Types}) for REF columns (SOURCE_DATA_TYPE in the
201      *         {@link DatabaseMetaData#getColumns(String, String, String, String)} result set).
202      */
203     public Integer getSourceJdbcDataType() {
204         return sourceJdbcDataType;
205     }
206 
207 }