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