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.engine.type;
17  
18  import com.ibatis.sqlmap.client.extensions.ParameterSetter;
19  
20  import java.io.InputStream;
21  import java.io.Reader;
22  import java.math.BigDecimal;
23  import java.net.URL;
24  import java.sql.Array;
25  import java.sql.Blob;
26  import java.sql.Clob;
27  import java.sql.Date;
28  import java.sql.PreparedStatement;
29  import java.sql.Ref;
30  import java.sql.SQLException;
31  import java.sql.Time;
32  import java.sql.Timestamp;
33  import java.util.Calendar;
34  
35  /**
36   * A ParameterSetter implementation.
37   */
38  public class ParameterSetterImpl implements ParameterSetter {
39  
40    /** The ps. */
41    private PreparedStatement ps;
42  
43    /** The index. */
44    private int index;
45  
46    /**
47     * Creates an instance for a PreparedStatement and column index.
48     *
49     * @param statement
50     *          - the PreparedStatement
51     * @param columnIndex
52     *          - the column index
53     */
54    public ParameterSetterImpl(PreparedStatement statement, int columnIndex) {
55      this.ps = statement;
56      this.index = columnIndex;
57    }
58  
59    @Override
60    public void setArray(Array x) throws SQLException {
61      ps.setArray(index, x);
62    }
63  
64    @Override
65    public void setAsciiStream(InputStream x, int length) throws SQLException {
66      ps.setAsciiStream(index, x, length);
67    }
68  
69    @Override
70    public void setBigDecimal(BigDecimal x) throws SQLException {
71      ps.setBigDecimal(index, x);
72    }
73  
74    @Override
75    public void setBinaryStream(InputStream x, int length) throws SQLException {
76      ps.setBinaryStream(index, x, length);
77    }
78  
79    @Override
80    public void setBlob(Blob x) throws SQLException {
81      ps.setBlob(index, x);
82    }
83  
84    @Override
85    public void setBoolean(boolean x) throws SQLException {
86      ps.setBoolean(index, x);
87    }
88  
89    @Override
90    public void setByte(byte x) throws SQLException {
91      ps.setByte(index, x);
92    }
93  
94    @Override
95    public void setBytes(byte x[]) throws SQLException {
96      ps.setBytes(index, x);
97    }
98  
99    @Override
100   public void setCharacterStream(Reader reader, int length) throws SQLException {
101     ps.setCharacterStream(index, reader, length);
102   }
103 
104   @Override
105   public void setClob(Clob x) throws SQLException {
106     ps.setClob(index, x);
107   }
108 
109   @Override
110   public void setDate(Date x) throws SQLException {
111     ps.setDate(index, x);
112   }
113 
114   @Override
115   public void setDate(Date x, Calendar cal) throws SQLException {
116     ps.setDate(index, x, cal);
117   }
118 
119   @Override
120   public void setDouble(double x) throws SQLException {
121     ps.setDouble(index, x);
122   }
123 
124   @Override
125   public void setFloat(float x) throws SQLException {
126     ps.setFloat(index, x);
127   }
128 
129   @Override
130   public void setInt(int x) throws SQLException {
131     ps.setInt(index, x);
132   }
133 
134   @Override
135   public void setLong(long x) throws SQLException {
136     ps.setLong(index, x);
137   }
138 
139   @Override
140   public void setNull(int sqlType) throws SQLException {
141     ps.setNull(index, sqlType);
142   }
143 
144   @Override
145   public void setNull(int sqlType, String typeName) throws SQLException {
146     ps.setNull(index, sqlType, typeName);
147   }
148 
149   @Override
150   public void setObject(Object x) throws SQLException {
151     ps.setObject(index, x);
152   }
153 
154   @Override
155   public void setObject(Object x, int targetSqlType) throws SQLException {
156     ps.setObject(index, x, targetSqlType);
157   }
158 
159   @Override
160   public void setObject(Object x, int targetSqlType, int scale) throws SQLException {
161     ps.setObject(index, x, scale);
162   }
163 
164   @Override
165   public void setRef(Ref x) throws SQLException {
166     ps.setRef(index, x);
167   }
168 
169   @Override
170   public void setShort(short x) throws SQLException {
171     ps.setShort(index, x);
172   }
173 
174   @Override
175   public void setString(String x) throws SQLException {
176     ps.setString(index, x);
177   }
178 
179   @Override
180   public void setTime(Time x) throws SQLException {
181     ps.setTime(index, x);
182   }
183 
184   @Override
185   public void setTime(Time x, Calendar cal) throws SQLException {
186     ps.setTime(index, x, cal);
187   }
188 
189   @Override
190   public void setTimestamp(Timestamp x) throws SQLException {
191     ps.setTimestamp(index, x);
192   }
193 
194   @Override
195   public void setTimestamp(Timestamp x, Calendar cal) throws SQLException {
196     ps.setTimestamp(index, x, cal);
197   }
198 
199   @Override
200   public void setURL(URL x) throws SQLException {
201     ps.setURL(index, x);
202   }
203 
204   @Override
205   public PreparedStatement getPreparedStatement() {
206     return ps;
207   }
208 
209   @Override
210   public int getParameterIndex() {
211     return index;
212   }
213 }