KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mockobjects > eziba > sql > CallableStatement


1 /*
2  * Copyright (C) 2001 eZiba.com, Inc.
3  * All Rights Reserved
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * Redistributions in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following
13  * disclaimer in the documentation and/or other materials provided
14  * with the distribution. Neither the name of eZiba.com nor the
15  * names of its contributors may be used to endorse or promote
16  * products derived from this software without specific prior
17  * written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23  * eZiba.com OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30  * OF THE POSSIBILITY OF SUCH DAMAGE.
31  */

32
33 package com.mockobjects.eziba.sql;
34 import java.math.BigDecimal JavaDoc;
35 import java.sql.SQLException JavaDoc;
36 import java.util.Calendar JavaDoc;
37 import java.util.Map JavaDoc;
38 import java.util.Iterator JavaDoc;
39 import java.util.SortedMap JavaDoc;
40 import java.util.TreeMap JavaDoc;public class CallableStatement
41   extends PreparedStatement
42   implements java.sql.CallableStatement JavaDoc
43 {
44
45     CallableStatement(Connection p_connection, String JavaDoc p_sql)
46     {
47         super(p_connection,p_sql);
48     }
49
50     private Object JavaDoc [] m_results;
51
52     private SortedMap JavaDoc m_outs = new TreeMap JavaDoc();
53
54     public boolean execute()
55         throws SQLException JavaDoc
56     {
57         m_results = connection.getRegisteredCall(sql,getArguments());
58         return m_results.length > 0;
59     }
60
61     public void registerOutParameter(int parameterIndex, int sqlType)
62     {
63         m_outs.put(new Integer JavaDoc(parameterIndex), new Integer JavaDoc(sqlType));
64         setArg(parameterIndex,Connection.WILDCARD);
65     }
66
67     private Object JavaDoc getOutParameter(int i)
68         throws SQLException JavaDoc
69     {
70         if (m_results == null)
71         {
72             throw new SQLException JavaDoc("Attempt to get OUT param before execute");
73         }
74         if (m_results.length != m_outs.size())
75         {
76             throw new SQLException JavaDoc( "# of result values supplied ("
77                                     + m_results.length
78                                     + ") not equal to # of OUT parameters ("
79                                     + m_outs.size()
80                                     + ")") ;
81         }
82         if (! m_outs.containsKey(new Integer JavaDoc(i)))
83         {
84             throw new SQLException JavaDoc("No OUT param registered at position " + i);
85         }
86         Iterator JavaDoc keys = m_outs.keySet().iterator();
87         int k = 0;
88         while (keys.hasNext())
89         {
90             int j = ((Integer JavaDoc) keys.next()).intValue();
91             if (j == i)
92             {
93                 return m_results[k];
94             }
95             k++;
96         }
97         throw new SQLException JavaDoc("No OUT parameter registered at position " + i);
98     }
99
100     public int getInt(int parameterIndex)
101         throws SQLException JavaDoc
102     {
103         return ((Integer JavaDoc) getOutParameter(parameterIndex)).intValue();
104     }
105
106     public BigDecimal JavaDoc getBigDecimal(int parameterIndex)
107         throws SQLException JavaDoc
108     {
109         return (BigDecimal JavaDoc) getOutParameter(parameterIndex);
110     }
111
112     public String JavaDoc getString(int parameterIndex)
113         throws SQLException JavaDoc
114     {
115         Object JavaDoc o = getOutParameter(parameterIndex);
116         if ( o == null )
117         {
118             return null;
119         }
120         else
121         {
122             return o.toString();
123         }
124     }
125
126     // be afraid, be very afraid, for below this line
127
// all methods throw the dreaded NotImplementedException ...
128

129
130
131
132     public java.sql.Array JavaDoc getArray(int i)
133     {
134         throw new NotImplementedException();
135     }
136
137     /**
138      * @deprecated
139      */

140     public BigDecimal JavaDoc getBigDecimal(int parameterIndex, int scale)
141     {
142         throw new NotImplementedException();
143     }
144
145     public java.sql.Blob JavaDoc getBlob(int i)
146     {
147         throw new NotImplementedException();
148     }
149
150     public boolean getBoolean(int parameterIndex)
151     {
152         throw new NotImplementedException();
153     }
154
155     public byte getByte(int parameterIndex)
156     {
157         throw new NotImplementedException();
158     }
159
160     public byte[] getBytes(int parameterIndex)
161     {
162         throw new NotImplementedException();
163     }
164
165     public java.sql.Clob JavaDoc getClob(int i)
166     {
167         throw new NotImplementedException();
168     }
169
170     public java.sql.Date JavaDoc getDate(int parameterIndex)
171     {
172         throw new NotImplementedException();
173     }
174
175     public java.sql.Date JavaDoc getDate(int parameterIndex, Calendar JavaDoc cal)
176     {
177         throw new NotImplementedException();
178     }
179
180     public double getDouble(int parameterIndex)
181     {
182         throw new NotImplementedException();
183     }
184
185     public float getFloat(int parameterIndex)
186     {
187         throw new NotImplementedException();
188     }
189
190     public long getLong(int parameterIndex)
191     {
192         throw new NotImplementedException();
193     }
194
195     public Object JavaDoc getObject(int parameterIndex)
196     {
197         throw new NotImplementedException();
198     }
199
200     public Object JavaDoc getObject(int i, Map JavaDoc map)
201     {
202         throw new NotImplementedException();
203     }
204
205     public java.sql.Ref JavaDoc getRef(int i)
206     {
207         throw new NotImplementedException();
208     }
209
210     public short getShort(int parameterIndex)
211     {
212         throw new NotImplementedException();
213     }
214
215     public java.sql.Time JavaDoc getTime(int parameterIndex)
216     {
217         throw new NotImplementedException();
218     }
219
220     public java.sql.Time JavaDoc getTime(int parameterIndex, Calendar JavaDoc cal)
221     {
222         throw new NotImplementedException();
223     }
224
225     public java.sql.Timestamp JavaDoc getTimestamp(int parameterIndex)
226     {
227         throw new NotImplementedException();
228     }
229
230     public java.sql.Timestamp JavaDoc getTimestamp(int parameterIndex, Calendar JavaDoc cal)
231     {
232         throw new NotImplementedException();
233     }
234
235     public void registerOutParameter(int parameterIndex, int sqlType, int scale)
236     {
237         throw new NotImplementedException();
238     }
239
240     public void registerOutParameter(int paramIndex, int sqlType, String JavaDoc typeName)
241     {
242         throw new NotImplementedException();
243     }
244
245     public boolean wasNull()
246     {
247         throw new NotImplementedException();
248     }
249 }
Popular Tags