KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibatis > sqlmap > engine > type > ResultGetterImpl


1 /*
2  * Copyright 2004 Clinton Begin
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 package com.ibatis.sqlmap.engine.type;
17
18 import com.ibatis.sqlmap.client.extensions.ResultGetter;
19
20 import java.math.BigDecimal JavaDoc;
21 import java.net.URL JavaDoc;
22 import java.sql.*;
23 import java.util.Calendar JavaDoc;
24 import java.util.Map JavaDoc;
25
26 /**
27  * A ResultGetter implementation
28  */

29 public class ResultGetterImpl implements ResultGetter {
30
31   private ResultSet rs;
32   private String JavaDoc name;
33   private int index;
34
35   /**
36    * Creates an instance for a PreparedStatement and column index
37    *
38    * @param resultSet - the result set
39    * @param columnIndex - the column index
40    */

41   public ResultGetterImpl(ResultSet resultSet, int columnIndex) {
42     this.rs = resultSet;
43     this.index = columnIndex;
44   }
45
46   /**
47    * Creates an instance for a PreparedStatement and column name
48    *
49    * @param resultSet - the result set
50    * @param columnName - the column index
51    */

52   public ResultGetterImpl(ResultSet resultSet, String JavaDoc columnName) {
53     this.rs = resultSet;
54     this.name = columnName;
55   }
56
57
58   public Array getArray() throws SQLException {
59     if (name != null) {
60       return rs.getArray(name);
61     } else {
62       return rs.getArray(index);
63     }
64   }
65
66   public BigDecimal JavaDoc getBigDecimal() throws SQLException {
67     if (name != null) {
68       return rs.getBigDecimal(name);
69     } else {
70       return rs.getBigDecimal(index);
71     }
72   }
73
74   public Blob getBlob() throws SQLException {
75     if (name != null) {
76       return rs.getBlob(name);
77     } else {
78       return rs.getBlob(index);
79     }
80   }
81
82   public boolean getBoolean() throws SQLException {
83     if (name != null) {
84       return rs.getBoolean(name);
85     } else {
86       return rs.getBoolean(index);
87     }
88   }
89
90   public byte getByte() throws SQLException {
91     if (name != null) {
92       return rs.getByte(name);
93     } else {
94       return rs.getByte(index);
95     }
96   }
97
98   public byte[] getBytes() throws SQLException {
99     if (name != null) {
100       return rs.getBytes(name);
101     } else {
102       return rs.getBytes(index);
103     }
104   }
105
106   public Clob getClob() throws SQLException {
107     if (name != null) {
108       return rs.getClob(name);
109     } else {
110       return rs.getClob(index);
111     }
112   }
113
114   public Date getDate() throws SQLException {
115     if (name != null) {
116       return rs.getDate(name);
117     } else {
118       return rs.getDate(index);
119     }
120   }
121
122   public Date getDate(Calendar JavaDoc cal) throws SQLException {
123     if (name != null) {
124       return rs.getDate(name, cal);
125     } else {
126       return rs.getDate(index, cal);
127     }
128   }
129
130   public double getDouble() throws SQLException {
131     if (name != null) {
132       return rs.getDouble(name);
133     } else {
134       return rs.getDouble(index);
135     }
136   }
137
138   public float getFloat() throws SQLException {
139     if (name != null) {
140       return rs.getFloat(name);
141     } else {
142       return rs.getFloat(index);
143     }
144   }
145
146   public int getInt() throws SQLException {
147     if (name != null) {
148       return rs.getInt(name);
149     } else {
150       return rs.getInt(index);
151     }
152   }
153
154   public long getLong() throws SQLException {
155     if (name != null) {
156       return rs.getLong(name);
157     } else {
158       return rs.getLong(index);
159     }
160   }
161
162   public Object JavaDoc getObject() throws SQLException {
163     if (name != null) {
164       return rs.getObject(name);
165     } else {
166       return rs.getObject(index);
167     }
168   }
169
170   public Object JavaDoc getObject(Map JavaDoc map) throws SQLException {
171     if (name != null) {
172       return rs.getObject(name, map);
173     } else {
174       return rs.getObject(index, map);
175     }
176   }
177
178   public Ref getRef() throws SQLException {
179     if (name != null) {
180       return rs.getRef(name);
181     } else {
182       return rs.getRef(index);
183     }
184   }
185
186   public short getShort() throws SQLException {
187     if (name != null) {
188       return rs.getShort(name);
189     } else {
190       return rs.getShort(index);
191     }
192   }
193
194   public String JavaDoc getString() throws SQLException {
195     if (name != null) {
196       return rs.getString(name);
197     } else {
198       return rs.getString(index);
199     }
200   }
201
202   public Time getTime() throws SQLException {
203     if (name != null) {
204       return rs.getTime(name);
205     } else {
206       return rs.getTime(index);
207     }
208   }
209
210   public Time getTime(Calendar JavaDoc cal) throws SQLException {
211     if (name != null) {
212       return rs.getTime(name);
213     } else {
214       return rs.getTime(index);
215     }
216   }
217
218   public Timestamp getTimestamp() throws SQLException {
219     if (name != null) {
220       return rs.getTimestamp(name);
221     } else {
222       return rs.getTimestamp(index);
223     }
224   }
225
226   public Timestamp getTimestamp(Calendar JavaDoc cal) throws SQLException {
227     if (name != null) {
228       return rs.getTimestamp(name, cal);
229     } else {
230       return rs.getTimestamp(index, cal);
231     }
232   }
233
234   public URL JavaDoc getURL() throws SQLException {
235     if (name != null) {
236       return rs.getURL(name);
237     } else {
238       return rs.getURL(index);
239     }
240   }
241
242   public boolean wasNull() throws SQLException {
243     return rs.wasNull();
244   }
245
246   public ResultSet getResultSet() {
247     return rs;
248   }
249 }
250
Popular Tags