KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jdbc > support > rowset > ResultSetWrappingSqlRowSetMetaData


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.jdbc.support.rowset;
18
19 import java.sql.ResultSetMetaData JavaDoc;
20 import java.sql.SQLException JavaDoc;
21
22 import org.springframework.jdbc.InvalidResultSetAccessException;
23
24 /**
25  * Default implementation of Spring's SqlRowSetMetaData interface.
26  * Used by ResultSetWrappingSqlRowSet.
27  *
28  * <p>This implementation wraps a <code>javax.sql.ResultSetMetaData</code>
29  * instance, catching any SQLExceptions and translating them to the
30  * appropriate Spring DataAccessException.
31  *
32  * @author Thomas Risberg
33  * @author Juergen Hoeller
34  * @since 1.2
35  * @see ResultSetWrappingSqlRowSet#getMetaData
36  */

37 public class ResultSetWrappingSqlRowSetMetaData implements SqlRowSetMetaData {
38
39     private final ResultSetMetaData JavaDoc resultSetMetaData;
40
41     private String JavaDoc[] columnNames;
42
43
44     /**
45      * Create a new ResultSetWrappingSqlRowSetMetaData object
46      * for the given ResultSetMetaData instance.
47      * @param resultSetMetaData a disconnected ResultSetMetaData instance
48      * to wrap (usually a <code>javax.sql.RowSetMetaData</code> instance)
49      * @see java.sql.ResultSet#getMetaData
50      * @see javax.sql.RowSetMetaData
51      * @see ResultSetWrappingSqlRowSet#getMetaData
52      */

53     public ResultSetWrappingSqlRowSetMetaData(ResultSetMetaData JavaDoc resultSetMetaData) {
54         this.resultSetMetaData = resultSetMetaData;
55     }
56
57
58     public String JavaDoc getCatalogName(int column) throws InvalidResultSetAccessException {
59         try {
60             return this.resultSetMetaData.getCatalogName(column);
61         }
62         catch (SQLException JavaDoc se) {
63             throw new InvalidResultSetAccessException(se);
64         }
65     }
66     
67     public String JavaDoc getColumnClassName(int column) throws InvalidResultSetAccessException {
68         try {
69             return this.resultSetMetaData.getColumnClassName(column);
70         }
71         catch (SQLException JavaDoc se) {
72             throw new InvalidResultSetAccessException(se);
73         }
74     }
75
76     public int getColumnCount() throws InvalidResultSetAccessException {
77         try {
78             return this.resultSetMetaData.getColumnCount();
79         }
80         catch (SQLException JavaDoc se) {
81             throw new InvalidResultSetAccessException(se);
82         }
83     }
84
85     public String JavaDoc[] getColumnNames() throws InvalidResultSetAccessException {
86         if (this.columnNames == null) {
87             this.columnNames = new String JavaDoc[getColumnCount()];
88             for (int i = 0; i < getColumnCount(); i++) {
89                 this.columnNames[i] = getColumnName(i + 1);
90             }
91         }
92         return this.columnNames;
93     }
94
95     public int getColumnDisplaySize(int column) throws InvalidResultSetAccessException {
96         try {
97             return this.resultSetMetaData.getColumnDisplaySize(column);
98         }
99         catch (SQLException JavaDoc se) {
100             throw new InvalidResultSetAccessException(se);
101         }
102     }
103
104     public String JavaDoc getColumnLabel(int column) throws InvalidResultSetAccessException {
105         try {
106             return this.resultSetMetaData.getColumnLabel(column);
107         }
108         catch (SQLException JavaDoc se) {
109             throw new InvalidResultSetAccessException(se);
110         }
111     }
112
113     public String JavaDoc getColumnName(int column) throws InvalidResultSetAccessException {
114         try {
115             return this.resultSetMetaData.getColumnName(column);
116         }
117         catch (SQLException JavaDoc se) {
118             throw new InvalidResultSetAccessException(se);
119         }
120     }
121
122     public int getColumnType(int column) throws InvalidResultSetAccessException {
123         try {
124             return this.resultSetMetaData.getColumnType(column);
125         }
126         catch (SQLException JavaDoc se) {
127             throw new InvalidResultSetAccessException(se);
128         }
129     }
130
131     public String JavaDoc getColumnTypeName(int column) throws InvalidResultSetAccessException {
132         try {
133             return this.resultSetMetaData.getColumnTypeName(column);
134         }
135         catch (SQLException JavaDoc se) {
136             throw new InvalidResultSetAccessException(se);
137         }
138     }
139
140     public int getPrecision(int column) throws InvalidResultSetAccessException {
141         try {
142             return this.resultSetMetaData.getPrecision(column);
143         }
144         catch (SQLException JavaDoc se) {
145             throw new InvalidResultSetAccessException(se);
146         }
147     }
148
149     public int getScale(int column) throws InvalidResultSetAccessException {
150         try {
151             return this.resultSetMetaData.getScale(column);
152         }
153         catch (SQLException JavaDoc se) {
154             throw new InvalidResultSetAccessException(se);
155         }
156     }
157
158     public String JavaDoc getSchemaName(int column) throws InvalidResultSetAccessException {
159         try {
160             return this.resultSetMetaData.getSchemaName(column);
161         }
162         catch (SQLException JavaDoc se) {
163             throw new InvalidResultSetAccessException(se);
164         }
165     }
166
167     public String JavaDoc getTableName(int column) throws InvalidResultSetAccessException {
168         try {
169             return this.resultSetMetaData.getTableName(column);
170         }
171         catch (SQLException JavaDoc se) {
172             throw new InvalidResultSetAccessException(se);
173         }
174     }
175
176     public boolean isCaseSensitive(int column) throws InvalidResultSetAccessException {
177         try {
178             return this.resultSetMetaData.isCaseSensitive(column);
179         }
180         catch (SQLException JavaDoc se) {
181             throw new InvalidResultSetAccessException(se);
182         }
183     }
184
185     public boolean isCurrency(int column) throws InvalidResultSetAccessException {
186         try {
187             return this.resultSetMetaData.isCurrency(column);
188         }
189         catch (SQLException JavaDoc se) {
190             throw new InvalidResultSetAccessException(se);
191         }
192     }
193
194     public boolean isSigned(int column) throws InvalidResultSetAccessException {
195         try {
196             return this.resultSetMetaData.isSigned(column);
197         }
198         catch (SQLException JavaDoc se) {
199             throw new InvalidResultSetAccessException(se);
200         }
201     }
202     
203 }
204
Popular Tags