Newer
Older
/* **************************************************************************
*
* Copyright (C) 2002-2005 Octet String, Inc. All Rights Reserved.
*
* THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND
* TREATIES. USE, MODIFICATION, AND REDISTRIBUTION OF THIS WORK IS SUBJECT
* TO VERSION 2.0.1 OF THE OPENLDAP PUBLIC LICENSE, A COPY OF WHICH IS
* AVAILABLE AT HTTP://WWW.OPENLDAP.ORG/LICENSE.HTML OR IN THE FILE "LICENSE"
* IN THE TOP-LEVEL DIRECTORY OF THE DISTRIBUTION. ANY USE OR EXPLOITATION
* OF THIS WORK OTHER THAN AS AUTHORIZED IN VERSION 2.0.1 OF THE OPENLDAP
* PUBLIC LICENSE, OR OTHER PRIOR WRITTEN CONSENT FROM OCTET STRING, INC.,
* COULD SUBJECT THE PERPETRATOR TO CRIMINAL AND CIVIL LIABILITY.
******************************************************************************/
/*
* JdbcLdapPreparedStatement.java
*
* Created on March 19, 2002, 11:48 PM
*/
package com.octetstring.jdbcLdap.sql;
import java.sql.*;
import com.novell.ldap.LDAPMessageQueue;
import com.novell.ldap.LDAPSearchResults;
import com.octetstring.jdbcLdap.jndi.*;
import com.octetstring.jdbcLdap.jndi.UnpackResults;
import com.octetstring.jdbcLdap.sql.statements.*;
import com.octetstring.jdbcLdap.sql.*;
import javax.naming.*;
import java.io.*;
/**
*Parses and manages a prepared statement to the directory
*@author Marc Boorshtein, OctetString
* @version
*/
public class JdbcLdapPreparedStatement extends JdbcLdapStatement implements java.sql.PreparedStatement {
/** Creates new JdbcLdapPreparedStatement */
public JdbcLdapPreparedStatement(String sql, JndiLdapConnection con) throws SQLException {
super(con);
loadSQL(sql);
}
/**
*Reloads a sql statement based on a sql store
*@param store the sql store to re-load
*/
void loadSQL(SqlStore store) throws SQLException {
loadSQL(store.getSQL());
}
/**
*Used to set the caorrect parameter
*@param pos Position where to insert plus one
*@param val Value to insert
*/
void setVal(int pos, String val) throws SQLException {
@Deprecated
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
public void setUnicodeStream(int param, java.io.InputStream inputStream, int param2) throws java.sql.SQLException {
char[] c = new char[param2];
try {
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
in.read(c,0,param2);
in.close();
}
catch (IOException e) {
throw new SQLException(e.toString());
}
setVal(param,String.valueOf(c));
}
public void setTime(int param, java.sql.Time time) throws java.sql.SQLException {
setVal(param,time.toString());
}
public void setBigDecimal(int param, java.math.BigDecimal bigDecimal) throws java.sql.SQLException {
setVal(param,bigDecimal.toString());
}
public boolean execute() throws java.sql.SQLException {
if (stmt.isUpdate()) {
executeUpdate();
return false;
}
else {
executeQuery();
return true;
}
}
public void setURL(int param, java.net.URL uRL) throws java.sql.SQLException {
setVal(param,uRL.toString());
}
public void setAsciiStream(int param, java.io.InputStream inputStream, int param2) throws java.sql.SQLException {
char[] c = new char[param2];
try {
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
in.read(c,0,param2);
in.close();
}
catch (IOException e) {
throw new SQLException(e.toString());
}
setVal(param,String.valueOf(c));
}
public void setByte(int param, byte param1) throws java.sql.SQLException {
setVal(param,Byte.toString(param1));
}
public void setDouble(int param, double param1) throws java.sql.SQLException {
setVal(param,Double.toString(param1));
}
public void setLong(int param, long param1) throws java.sql.SQLException {
setVal(param,Long.toString(param1));
}
public void setDate(int param, java.sql.Date date) throws java.sql.SQLException {
setVal(param,date.toString());
}
public void setBinaryStream(int param, java.io.InputStream inputStream, int param2) throws java.sql.SQLException {
char[] c = new char[param2];
try {
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
in.read(c,0,param2);
in.close();
}
catch (IOException e) {
throw new SQLException(e.toString());
}
setVal(param,String.valueOf(c));
}
public java.sql.ParameterMetaData getParameterMetaData() throws java.sql.SQLException {
return null;
}
public void setTime(int param, java.sql.Time time, java.util.Calendar calendar) throws java.sql.SQLException {
setVal(param,time.toString());
}
public void setBlob(int param, java.sql.Blob blob) throws java.sql.SQLException {
}
public java.sql.ResultSet executeQuery() throws java.sql.SQLException {
res.unpackJldap((LDAPSearchResults) stmt.executeQuery(),stmt.getRetrieveDN(),this.stmt.getSqlStore().getFrom(),con.getBaseDN(),this.stmt.getSqlStore().getRevFieldMap());
res.unpackJldap((LDAPMessageQueue) stmt.executeQuery(),stmt.getRetrieveDN(),this.stmt.getSqlStore().getFrom(),con.getBaseDN(),this.stmt.getSqlStore().getRevFieldMap());
this.rs = new LdapResultSet(con,this,res,((JdbcLdapSelect) stmt).getBaseContext());
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
return rs;
}
public void setCharacterStream(int param, java.io.Reader reader, int param2) throws java.sql.SQLException {
char[] c = new char[param2];
try {
BufferedReader in = new BufferedReader(reader);
in.read(c,0,param2);
in.close();
}
catch (IOException e) {
throw new SQLException(e.toString());
}
setVal(param,String.valueOf(c));
}
public java.sql.ResultSetMetaData getMetaData() throws java.sql.SQLException {
return rs.getMetaData();
}
public void setTimestamp(int param, java.sql.Timestamp timestamp, java.util.Calendar calendar) throws java.sql.SQLException {
setVal(param,timestamp.toString());
}
public void setObject(int param, java.lang.Object obj, int param2, int param3) throws java.sql.SQLException {
setVal(param,obj.toString());
}
public void setObject(int param, java.lang.Object obj, int param2) throws java.sql.SQLException {
setVal(param,obj.toString());
}
public void setObject(int param, java.lang.Object obj) throws java.sql.SQLException {
setVal(param,obj.toString());
}
public void setRef(int param, java.sql.Ref ref) throws java.sql.SQLException {
}
public void setArray(int param, java.sql.Array array) throws java.sql.SQLException {
}
public void setTimestamp(int param, java.sql.Timestamp timestamp) throws java.sql.SQLException {
setVal(param,timestamp.toString());
}
public void setInt(int param, int param1) throws java.sql.SQLException {
setVal(param,Integer.toString(param1));
}
public void setBytes(int param, byte[] values) throws java.sql.SQLException {
this.setCharacterStream(param,new InputStreamReader(new ByteArrayInputStream(values)),values.length);
}
public void setShort(int param, short param1) throws java.sql.SQLException {
setVal(param,Short.toString(param1));
}
public void setFloat(int param, float param1) throws java.sql.SQLException {
setVal(param,Float.toString(param1));
}
public void setBoolean(int param, boolean param1) throws java.sql.SQLException {
setVal(param,Boolean.toString(param1));
}
public void setDate(int param, java.sql.Date date, java.util.Calendar calendar) throws java.sql.SQLException {
setVal(param,date.toString());
}
public int executeUpdate() throws java.sql.SQLException {
return ((Integer) stmt.executeUpdate()).intValue();
}
public void setString(int param, java.lang.String str) throws java.sql.SQLException {
setVal(param,str);
}
public void setClob(int param, java.sql.Clob clob) throws java.sql.SQLException {
}
public void addBatch() throws java.sql.SQLException {
statements.add(stmt);
loadSQL(stmt.getSqlStore());
}
public void clearParameters() throws java.sql.SQLException {
}
public void setNull(int param, int param1) throws java.sql.SQLException {
setVal(param,null);
}
public void setNull(int param, int param1, java.lang.String str) throws java.sql.SQLException {
setVal(param,null);
}
}