KickJava   Java API By Example, From Geeks To Geeks.

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


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.sql.SQLException JavaDoc;
35 import java.util.Map JavaDoc;public class Connection
36   implements java.sql.Connection JavaDoc
37 {
38
39     Connection()
40     {
41     }
42
43
44     public static final Object JavaDoc WILDCARD = Wildcard.WILDCARD;
45
46     java.sql.ResultSet JavaDoc getRegisteredResult(String JavaDoc p_sql, Object JavaDoc [] p_args)
47         throws SQLException JavaDoc
48     {
49         java.sql.ResultSet JavaDoc rs =
50             (java.sql.ResultSet JavaDoc) m_resultMap.get(p_sql, p_args);
51         rs.first();
52         return rs;
53     }
54
55     int getRegisteredUpdate(String JavaDoc p_sql, Object JavaDoc [] p_args)
56         throws SQLException JavaDoc
57     {
58         Integer JavaDoc r = (Integer JavaDoc) m_updateMap.get(p_sql, p_args);
59         return r.intValue();
60     }
61
62     Object JavaDoc [] getRegisteredCall(String JavaDoc p_sql, Object JavaDoc [] p_args)
63         throws SQLException JavaDoc
64     {
65         Object JavaDoc [] rv = (Object JavaDoc [] ) m_callMap.get(p_sql, p_args);
66         return rv;
67     }
68
69     public String JavaDoc getRegistryContents()
70     {
71         return m_resultMap + "\n"
72             + m_callMap + "\n"
73             + m_updateMap;
74     }
75
76     public int getRegisteredResultCount()
77     {
78         return m_resultMap.size();
79     }
80
81     public int getRegisteredCallCount()
82     {
83         return m_callMap.size();
84     }
85
86     public int getRegisteredUpdateCount()
87     {
88         return m_updateMap.size();
89     }
90
91     public int getRegisteredCount()
92     {
93         return ( getRegisteredResultCount()
94                  + getRegisteredCallCount()
95                  + getRegisteredUpdateCount() );
96     }
97
98     public void registerResult(String JavaDoc p_sql,
99                                Object JavaDoc [] p_args,
100                                java.sql.ResultSet JavaDoc p_resultSet)
101     {
102         if (p_resultSet == null)
103         {
104             throw new IllegalArgumentException JavaDoc("ResultSet can't be null");
105         }
106         if (p_args == null)
107         {
108             throw new IllegalArgumentException JavaDoc("Argument array can't be null");
109         }
110         m_resultMap.put(p_sql, p_args, p_resultSet);
111     }
112
113     public void registerCall(String JavaDoc p_sql,
114                              Object JavaDoc [] p_args,
115                              Object JavaDoc [] p_output)
116     {
117         if (p_args == null)
118         {
119             throw new IllegalArgumentException JavaDoc("Argument array can't be null");
120         }
121         if (p_output == null)
122         {
123             throw new IllegalArgumentException JavaDoc("Output array can't be null");
124         }
125         m_callMap.put(p_sql,p_args, p_output);
126     }
127
128     public void registerUpdate(String JavaDoc p_sql,
129                                Object JavaDoc [] p_args,
130                                int p_result)
131     {
132         if (p_args == null)
133         {
134             throw new IllegalArgumentException JavaDoc("Argument array can't be null");
135         }
136         m_updateMap.put(p_sql, p_args,new Integer JavaDoc(p_result));
137     }
138
139     public void close()
140         throws SQLException JavaDoc
141     {
142         m_closed = true;
143     }
144
145     public boolean isClosed()
146     {
147         return m_closed;
148     }
149
150     private boolean m_closed = false;
151
152     public java.sql.CallableStatement JavaDoc prepareCall(String JavaDoc p_sql)
153         throws SQLException JavaDoc
154     {
155         if ( isClosed() )
156         {
157             throw new SQLException JavaDoc("Attempt to use a closed connection");
158         }
159         return new CallableStatement(this,p_sql);
160     }
161
162     public java.sql.PreparedStatement JavaDoc prepareStatement(String JavaDoc p_sql)
163         throws SQLException JavaDoc
164     {
165         if ( isClosed() )
166         {
167             throw new SQLException JavaDoc("Attempt to use a closed connection");
168         }
169         return new PreparedStatement(this,p_sql);
170     }
171
172
173
174     private ConnectionMap m_resultMap = new ConnectionMap("result set");
175     private ConnectionMap m_callMap = new ConnectionMap("call");
176     private ConnectionMap m_updateMap = new ConnectionMap("update");
177
178     // be afraid, be very afraid, for below this line
179
// all methods throw the dreaded NotImplementedException ...
180

181     public void clearWarnings()
182     {
183         throw new NotImplementedException();
184     }
185
186     public void commit()
187     {
188         throw new NotImplementedException();
189     }
190
191     public java.sql.Statement JavaDoc createStatement()
192     {
193         throw new NotImplementedException();
194     }
195
196     public java.sql.Statement JavaDoc createStatement(int p_resultSetType,
197                                               int p_resultSetConcurrency)
198     {
199         throw new NotImplementedException();
200     }
201
202     public boolean getAutoCommit()
203     {
204         throw new NotImplementedException();
205     }
206
207     public String JavaDoc getCatalog()
208     {
209         throw new NotImplementedException();
210     }
211
212     public java.sql.DatabaseMetaData JavaDoc getMetaData()
213     {
214         throw new NotImplementedException();
215     }
216
217     public int getTransactionIsolation()
218     {
219         throw new NotImplementedException();
220     }
221
222     public Map JavaDoc getTypeMap()
223     {
224         throw new NotImplementedException();
225     }
226
227     public java.sql.SQLWarning JavaDoc getWarnings()
228     {
229         throw new NotImplementedException();
230     }
231
232     public boolean isReadOnly()
233     {
234         throw new NotImplementedException();
235     }
236
237     public String JavaDoc nativeSQL(String JavaDoc p_sql)
238     {
239         throw new NotImplementedException();
240     }
241
242     public java.sql.CallableStatement JavaDoc prepareCall(String JavaDoc p_sql,
243                                                   int rsType,
244                                                   int rsConcurrency)
245     {
246         throw new NotImplementedException();
247     }
248
249     public java.sql.PreparedStatement JavaDoc prepareStatement(String JavaDoc p_sql,
250                                                        int rsType,
251                                                        int rsConcurrency)
252     {
253         throw new NotImplementedException();
254     }
255
256     public void rollback()
257     {
258         throw new NotImplementedException();
259     }
260
261     public void setAutoCommit(boolean p_autoCommit)
262     {
263         throw new NotImplementedException();
264     }
265
266     public void setCatalog(String JavaDoc p_catalog)
267     {
268         throw new NotImplementedException();
269     }
270
271     public void setReadOnly(boolean p_readOnly)
272     {
273         throw new NotImplementedException();
274     }
275
276     public void setTransactionIsolation(int p_level)
277     {
278         throw new NotImplementedException();
279     }
280
281     public void setTypeMap(Map JavaDoc p_map)
282     {
283         throw new NotImplementedException();
284     }
285 }
Popular Tags