View Javadoc
1   /*
2    * Copyright 2004-2025 the original author or authors.
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    *    https://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.client.extensions;
17  
18  import java.io.InputStream;
19  import java.io.Reader;
20  import java.math.BigDecimal;
21  import java.net.URL;
22  import java.sql.Array;
23  import java.sql.Blob;
24  import java.sql.Clob;
25  import java.sql.Date;
26  import java.sql.PreparedStatement;
27  import java.sql.Ref;
28  import java.sql.SQLException;
29  import java.sql.Time;
30  import java.sql.Timestamp;
31  import java.util.Calendar;
32  
33  /**
34   * Allows parameters to be set on the underlying prepared statement. TypeHandlerCallback implementations use this
35   * interface to process values before they are set on the prepared statement. Each of these methods has a corresponding
36   * method on the PreparedStatement class, the only difference being that there is no need to specify the parameter index
37   * with these methods.
38   * <p>
39   * <b>NOTE:</b> There is no need to implement this. The implementation will be passed into the TypeHandlerCallback
40   * automatically.
41   */
42  public interface ParameterSetter {
43  
44    /**
45     * Set an array on the underlying prepared statement.
46     *
47     * @param x
48     *          - the array to set
49     *
50     * @throws SQLException
51     *           - thrown if the underlying prepared statement throws it
52     */
53    void setArray(Array x) throws SQLException;
54  
55    /**
56     * Set an InputStream on the underlying prepared statement.
57     *
58     * @param x
59     *          - the InputStream
60     * @param length
61     *          - the length of the InputStream
62     *
63     * @throws SQLException
64     *           - thrown if the underlying prepared statement throws it
65     */
66    void setAsciiStream(InputStream x, int length) throws SQLException;
67  
68    /**
69     * Set an on the underlying prepared statement.
70     *
71     * @param x
72     *          the new big decimal
73     *
74     * @throws SQLException
75     *           - thrown if the underlying prepared statement throws it
76     */
77    void setBigDecimal(BigDecimal x) throws SQLException;
78  
79    /**
80     * Set an InputStream on the underlying prepared statement.
81     *
82     * @param x
83     *          - the InputStream
84     * @param length
85     *          - the length of the InputStream
86     *
87     * @throws SQLException
88     *           - thrown if the underlying prepared statement throws it
89     */
90    void setBinaryStream(InputStream x, int length) throws SQLException;
91  
92    /**
93     * Set a blob on the underlying prepared statement.
94     *
95     * @param x
96     *          - the blob
97     *
98     * @throws SQLException
99     *           - thrown if the underlying prepared statement throws it
100    */
101   void setBlob(Blob x) throws SQLException;
102 
103   /**
104    * Set a boolean on the underlying prepared statement.
105    *
106    * @param x
107    *          - the boolean
108    *
109    * @throws SQLException
110    *           - thrown if the underlying prepared statement throws it
111    */
112   void setBoolean(boolean x) throws SQLException;
113 
114   /**
115    * Set a byte on the underlying prepared statement.
116    *
117    * @param x
118    *          - the byte
119    *
120    * @throws SQLException
121    *           - thrown if the underlying prepared statement throws it
122    */
123   void setByte(byte x) throws SQLException;
124 
125   /**
126    * Set a byte array on the underlying prepared statement.
127    *
128    * @param x
129    *          - the byte[]
130    *
131    * @throws SQLException
132    *           - thrown if the underlying prepared statement throws it
133    */
134   void setBytes(byte[] x) throws SQLException;
135 
136   /**
137    * Set a character stream on the underlying prepared statement.
138    *
139    * @param reader
140    *          - the reader
141    * @param length
142    *          - the length of the reader
143    *
144    * @throws SQLException
145    *           - thrown if the underlying prepared statement throws it
146    */
147   void setCharacterStream(Reader reader, int length) throws SQLException;
148 
149   /**
150    * Set a clob on the underlying prepared statement.
151    *
152    * @param x
153    *          - the clob
154    *
155    * @throws SQLException
156    *           - thrown if the underlying prepared statement throws it
157    */
158   void setClob(Clob x) throws SQLException;
159 
160   /**
161    * Set a date on the underlying prepared statement.
162    *
163    * @param x
164    *          - the date
165    *
166    * @throws SQLException
167    *           - thrown if the underlying prepared statement throws it
168    */
169   void setDate(Date x) throws SQLException;
170 
171   /**
172    * Set a date with a calendar on the underlying prepared statement.
173    *
174    * @param x
175    *          - the date
176    * @param cal
177    *          - the calendar
178    *
179    * @throws SQLException
180    *           - thrown if the underlying prepared statement throws it
181    */
182   void setDate(Date x, Calendar cal) throws SQLException;
183 
184   /**
185    * Set a double on the underlying prepared statement.
186    *
187    * @param x
188    *          - the double
189    *
190    * @throws SQLException
191    *           - thrown if the underlying prepared statement throws it
192    */
193   void setDouble(double x) throws SQLException;
194 
195   /**
196    * Set a float on the underlying prepared statement.
197    *
198    * @param x
199    *          the float
200    *
201    * @throws SQLException
202    *           - thrown if the underlying prepared statement throws it
203    */
204   void setFloat(float x) throws SQLException;
205 
206   /**
207    * Set an integer on the underlying prepared statement.
208    *
209    * @param x
210    *          - the int
211    *
212    * @throws SQLException
213    *           - thrown if the underlying prepared statement throws it
214    */
215   void setInt(int x) throws SQLException;
216 
217   /**
218    * Set a long on the underlying prepared statement.
219    *
220    * @param x
221    *          - the long
222    *
223    * @throws SQLException
224    *           - thrown if the underlying prepared statement throws it
225    */
226   void setLong(long x) throws SQLException;
227 
228   /**
229    * Set a null on the underlying prepared statement.
230    *
231    * @param sqlType
232    *          - the type for the null value
233    *
234    * @throws SQLException
235    *           - thrown if the underlying prepared statement throws it
236    */
237   void setNull(int sqlType) throws SQLException;
238 
239   /**
240    * Set a null on the underlying prepared statement.
241    *
242    * @param sqlType
243    *          - the type for the null value
244    * @param typeName
245    *          - the name of the type
246    *
247    * @throws SQLException
248    *           - thrown if the underlying prepared statement throws it
249    */
250   void setNull(int sqlType, String typeName) throws SQLException;
251 
252   /**
253    * Set an object on the underlying prepared statement.
254    *
255    * @param x
256    *          - the object to set
257    *
258    * @throws SQLException
259    *           - thrown if the underlying prepared statement throws it
260    */
261   void setObject(Object x) throws SQLException;
262 
263   /**
264    * Set an object on the underlying prepared statement.
265    *
266    * @param x
267    *          - the object to set
268    * @param targetSqlType
269    *          - the sql type of the object
270    *
271    * @throws SQLException
272    *           - thrown if the underlying prepared statement throws it
273    */
274   void setObject(Object x, int targetSqlType) throws SQLException;
275 
276   /**
277    * Set an object on the underlying prepared statement.
278    *
279    * @param x
280    *          - the object to set
281    * @param targetSqlType
282    *          - the sql type of the object
283    * @param scale
284    *          - the scale of the object
285    *
286    * @throws SQLException
287    *           - thrown if the underlying prepared statement throws it
288    */
289   void setObject(Object x, int targetSqlType, int scale) throws SQLException;
290 
291   /**
292    * Set a reference on the underlying prepared statement.
293    *
294    * @param x
295    *          - the reference to set
296    *
297    * @throws SQLException
298    *           - thrown if the underlying prepared statement throws it
299    */
300   void setRef(Ref x) throws SQLException;
301 
302   /**
303    * Set a short on the underlying prepared statement.
304    *
305    * @param x
306    *          - the short to set
307    *
308    * @throws SQLException
309    *           - thrown if the underlying prepared statement throws it
310    */
311   void setShort(short x) throws SQLException;
312 
313   /**
314    * Set a string on the underlying prepared statement.
315    *
316    * @param x
317    *          - the string to set
318    *
319    * @throws SQLException
320    *           - thrown if the underlying prepared statement throws it
321    */
322   void setString(String x) throws SQLException;
323 
324   /**
325    * Set a time on the underlying prepared statement.
326    *
327    * @param x
328    *          - the time to set
329    *
330    * @throws SQLException
331    *           - thrown if the underlying prepared statement throws it
332    */
333   void setTime(Time x) throws SQLException;
334 
335   /**
336    * Set a time with a calendar on the underlying prepared statement.
337    *
338    * @param x
339    *          - the time to set
340    * @param cal
341    *          - the calendar to use
342    *
343    * @throws SQLException
344    *           - thrown if the underlying prepared statement throws it
345    */
346   void setTime(Time x, Calendar cal) throws SQLException;
347 
348   /**
349    * Set a timestamp on the underlying prepared statement.
350    *
351    * @param x
352    *          - the timestamp to set
353    *
354    * @throws SQLException
355    *           - thrown if the underlying prepared statement throws it
356    */
357   void setTimestamp(Timestamp x) throws SQLException;
358 
359   /**
360    * Set a timestamp on the underlying prepared statement.
361    *
362    * @param x
363    *          - the timestamp to set
364    * @param cal
365    *          - the calendar to use
366    *
367    * @throws SQLException
368    *           - thrown if the underlying prepared statement throws it
369    */
370   void setTimestamp(Timestamp x, Calendar cal) throws SQLException;
371 
372   /**
373    * Set a URL on the underlying prepared statement.
374    *
375    * @param x
376    *          - the url to set
377    *
378    * @throws SQLException
379    *           - thrown if the underlying prepared statement throws it
380    */
381   void setURL(URL x) throws SQLException;
382 
383   /**
384    * Returns the underlying prepared statement...be careful!
385    *
386    * @return the prepared statement
387    */
388   PreparedStatement getPreparedStatement();
389 
390   /**
391    * Returns the index of the parameter being set.
392    *
393    * @return the parameter index used to set the value in the underlying PreparedStatement
394    */
395   int getParameterIndex();
396 }