001: /*
002: * Copyright 2004 Clinton Begin
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: package com.ibatis.sqlmap.engine.type;
017:
018: import com.ibatis.sqlmap.client.extensions.ResultGetter;
019:
020: import java.math.BigDecimal;
021: import java.net.URL;
022: import java.sql.*;
023: import java.util.Calendar;
024: import java.util.Map;
025:
026: /**
027: * A ResultGetter implementation
028: */
029: public class ResultGetterImpl implements ResultGetter {
030:
031: private ResultSet rs;
032: private String name;
033: private int index;
034:
035: /**
036: * Creates an instance for a PreparedStatement and column index
037: *
038: * @param resultSet - the result set
039: * @param columnIndex - the column index
040: */
041: public ResultGetterImpl(ResultSet resultSet, int columnIndex) {
042: this .rs = resultSet;
043: this .index = columnIndex;
044: }
045:
046: /**
047: * Creates an instance for a PreparedStatement and column name
048: *
049: * @param resultSet - the result set
050: * @param columnName - the column index
051: */
052: public ResultGetterImpl(ResultSet resultSet, String columnName) {
053: this .rs = resultSet;
054: this .name = columnName;
055: }
056:
057: public Array getArray() throws SQLException {
058: if (name != null) {
059: return rs.getArray(name);
060: } else {
061: return rs.getArray(index);
062: }
063: }
064:
065: public BigDecimal getBigDecimal() throws SQLException {
066: if (name != null) {
067: return rs.getBigDecimal(name);
068: } else {
069: return rs.getBigDecimal(index);
070: }
071: }
072:
073: public Blob getBlob() throws SQLException {
074: if (name != null) {
075: return rs.getBlob(name);
076: } else {
077: return rs.getBlob(index);
078: }
079: }
080:
081: public boolean getBoolean() throws SQLException {
082: if (name != null) {
083: return rs.getBoolean(name);
084: } else {
085: return rs.getBoolean(index);
086: }
087: }
088:
089: public byte getByte() throws SQLException {
090: if (name != null) {
091: return rs.getByte(name);
092: } else {
093: return rs.getByte(index);
094: }
095: }
096:
097: public byte[] getBytes() throws SQLException {
098: if (name != null) {
099: return rs.getBytes(name);
100: } else {
101: return rs.getBytes(index);
102: }
103: }
104:
105: public Clob getClob() throws SQLException {
106: if (name != null) {
107: return rs.getClob(name);
108: } else {
109: return rs.getClob(index);
110: }
111: }
112:
113: public Date getDate() throws SQLException {
114: if (name != null) {
115: return rs.getDate(name);
116: } else {
117: return rs.getDate(index);
118: }
119: }
120:
121: public Date getDate(Calendar cal) throws SQLException {
122: if (name != null) {
123: return rs.getDate(name, cal);
124: } else {
125: return rs.getDate(index, cal);
126: }
127: }
128:
129: public double getDouble() throws SQLException {
130: if (name != null) {
131: return rs.getDouble(name);
132: } else {
133: return rs.getDouble(index);
134: }
135: }
136:
137: public float getFloat() throws SQLException {
138: if (name != null) {
139: return rs.getFloat(name);
140: } else {
141: return rs.getFloat(index);
142: }
143: }
144:
145: public int getInt() throws SQLException {
146: if (name != null) {
147: return rs.getInt(name);
148: } else {
149: return rs.getInt(index);
150: }
151: }
152:
153: public long getLong() throws SQLException {
154: if (name != null) {
155: return rs.getLong(name);
156: } else {
157: return rs.getLong(index);
158: }
159: }
160:
161: public Object getObject() throws SQLException {
162: if (name != null) {
163: return rs.getObject(name);
164: } else {
165: return rs.getObject(index);
166: }
167: }
168:
169: public Object getObject(Map map) throws SQLException {
170: if (name != null) {
171: return rs.getObject(name, map);
172: } else {
173: return rs.getObject(index, map);
174: }
175: }
176:
177: public Ref getRef() throws SQLException {
178: if (name != null) {
179: return rs.getRef(name);
180: } else {
181: return rs.getRef(index);
182: }
183: }
184:
185: public short getShort() throws SQLException {
186: if (name != null) {
187: return rs.getShort(name);
188: } else {
189: return rs.getShort(index);
190: }
191: }
192:
193: public String getString() throws SQLException {
194: if (name != null) {
195: return rs.getString(name);
196: } else {
197: return rs.getString(index);
198: }
199: }
200:
201: public Time getTime() throws SQLException {
202: if (name != null) {
203: return rs.getTime(name);
204: } else {
205: return rs.getTime(index);
206: }
207: }
208:
209: public Time getTime(Calendar cal) throws SQLException {
210: if (name != null) {
211: return rs.getTime(name);
212: } else {
213: return rs.getTime(index);
214: }
215: }
216:
217: public Timestamp getTimestamp() throws SQLException {
218: if (name != null) {
219: return rs.getTimestamp(name);
220: } else {
221: return rs.getTimestamp(index);
222: }
223: }
224:
225: public Timestamp getTimestamp(Calendar cal) throws SQLException {
226: if (name != null) {
227: return rs.getTimestamp(name, cal);
228: } else {
229: return rs.getTimestamp(index, cal);
230: }
231: }
232:
233: public URL getURL() throws SQLException {
234: if (name != null) {
235: return rs.getURL(name);
236: } else {
237: return rs.getURL(index);
238: }
239: }
240:
241: public boolean wasNull() throws SQLException {
242: return rs.wasNull();
243: }
244:
245: public ResultSet getResultSet() {
246: return rs;
247: }
248:
249: public int getColumnIndex() {
250: return index;
251: }
252:
253: public String getColumnName() {
254: return name;
255: }
256: }
|