001: /*
002: * Copyright 2002-2005 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.jdbc.support.rowset;
018:
019: import java.sql.ResultSetMetaData;
020: import java.sql.SQLException;
021:
022: import org.springframework.jdbc.InvalidResultSetAccessException;
023:
024: /**
025: * Default implementation of Spring's SqlRowSetMetaData interface.
026: * Used by ResultSetWrappingSqlRowSet.
027: *
028: * <p>This implementation wraps a <code>javax.sql.ResultSetMetaData</code>
029: * instance, catching any SQLExceptions and translating them to the
030: * appropriate Spring DataAccessException.
031: *
032: * @author Thomas Risberg
033: * @author Juergen Hoeller
034: * @since 1.2
035: * @see ResultSetWrappingSqlRowSet#getMetaData
036: */
037: public class ResultSetWrappingSqlRowSetMetaData implements
038: SqlRowSetMetaData {
039:
040: private final ResultSetMetaData resultSetMetaData;
041:
042: private String[] columnNames;
043:
044: /**
045: * Create a new ResultSetWrappingSqlRowSetMetaData object
046: * for the given ResultSetMetaData instance.
047: * @param resultSetMetaData a disconnected ResultSetMetaData instance
048: * to wrap (usually a <code>javax.sql.RowSetMetaData</code> instance)
049: * @see java.sql.ResultSet#getMetaData
050: * @see javax.sql.RowSetMetaData
051: * @see ResultSetWrappingSqlRowSet#getMetaData
052: */
053: public ResultSetWrappingSqlRowSetMetaData(
054: ResultSetMetaData resultSetMetaData) {
055: this .resultSetMetaData = resultSetMetaData;
056: }
057:
058: public String getCatalogName(int column)
059: throws InvalidResultSetAccessException {
060: try {
061: return this .resultSetMetaData.getCatalogName(column);
062: } catch (SQLException se) {
063: throw new InvalidResultSetAccessException(se);
064: }
065: }
066:
067: public String getColumnClassName(int column)
068: throws InvalidResultSetAccessException {
069: try {
070: return this .resultSetMetaData.getColumnClassName(column);
071: } catch (SQLException se) {
072: throw new InvalidResultSetAccessException(se);
073: }
074: }
075:
076: public int getColumnCount() throws InvalidResultSetAccessException {
077: try {
078: return this .resultSetMetaData.getColumnCount();
079: } catch (SQLException se) {
080: throw new InvalidResultSetAccessException(se);
081: }
082: }
083:
084: public String[] getColumnNames()
085: throws InvalidResultSetAccessException {
086: if (this .columnNames == null) {
087: this .columnNames = new String[getColumnCount()];
088: for (int i = 0; i < getColumnCount(); i++) {
089: this .columnNames[i] = getColumnName(i + 1);
090: }
091: }
092: return this .columnNames;
093: }
094:
095: public int getColumnDisplaySize(int column)
096: throws InvalidResultSetAccessException {
097: try {
098: return this .resultSetMetaData.getColumnDisplaySize(column);
099: } catch (SQLException se) {
100: throw new InvalidResultSetAccessException(se);
101: }
102: }
103:
104: public String getColumnLabel(int column)
105: throws InvalidResultSetAccessException {
106: try {
107: return this .resultSetMetaData.getColumnLabel(column);
108: } catch (SQLException se) {
109: throw new InvalidResultSetAccessException(se);
110: }
111: }
112:
113: public String getColumnName(int column)
114: throws InvalidResultSetAccessException {
115: try {
116: return this .resultSetMetaData.getColumnName(column);
117: } catch (SQLException se) {
118: throw new InvalidResultSetAccessException(se);
119: }
120: }
121:
122: public int getColumnType(int column)
123: throws InvalidResultSetAccessException {
124: try {
125: return this .resultSetMetaData.getColumnType(column);
126: } catch (SQLException se) {
127: throw new InvalidResultSetAccessException(se);
128: }
129: }
130:
131: public String getColumnTypeName(int column)
132: throws InvalidResultSetAccessException {
133: try {
134: return this .resultSetMetaData.getColumnTypeName(column);
135: } catch (SQLException se) {
136: throw new InvalidResultSetAccessException(se);
137: }
138: }
139:
140: public int getPrecision(int column)
141: throws InvalidResultSetAccessException {
142: try {
143: return this .resultSetMetaData.getPrecision(column);
144: } catch (SQLException se) {
145: throw new InvalidResultSetAccessException(se);
146: }
147: }
148:
149: public int getScale(int column)
150: throws InvalidResultSetAccessException {
151: try {
152: return this .resultSetMetaData.getScale(column);
153: } catch (SQLException se) {
154: throw new InvalidResultSetAccessException(se);
155: }
156: }
157:
158: public String getSchemaName(int column)
159: throws InvalidResultSetAccessException {
160: try {
161: return this .resultSetMetaData.getSchemaName(column);
162: } catch (SQLException se) {
163: throw new InvalidResultSetAccessException(se);
164: }
165: }
166:
167: public String getTableName(int column)
168: throws InvalidResultSetAccessException {
169: try {
170: return this .resultSetMetaData.getTableName(column);
171: } catch (SQLException se) {
172: throw new InvalidResultSetAccessException(se);
173: }
174: }
175:
176: public boolean isCaseSensitive(int column)
177: throws InvalidResultSetAccessException {
178: try {
179: return this .resultSetMetaData.isCaseSensitive(column);
180: } catch (SQLException se) {
181: throw new InvalidResultSetAccessException(se);
182: }
183: }
184:
185: public boolean isCurrency(int column)
186: throws InvalidResultSetAccessException {
187: try {
188: return this .resultSetMetaData.isCurrency(column);
189: } catch (SQLException se) {
190: throw new InvalidResultSetAccessException(se);
191: }
192: }
193:
194: public boolean isSigned(int column)
195: throws InvalidResultSetAccessException {
196: try {
197: return this .resultSetMetaData.isSigned(column);
198: } catch (SQLException se) {
199: throw new InvalidResultSetAccessException(se);
200: }
201: }
202:
203: }
|