Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "java/sql/PreparedStatement.hxx"
21 : #include "java/sql/ResultSet.hxx"
22 : #include "java/sql/ResultSetMetaData.hxx"
23 : #include "java/sql/Connection.hxx"
24 : #include "java/sql/Timestamp.hxx"
25 : #include "java/math/BigDecimal.hxx"
26 : #include "java/tools.hxx"
27 : #include <cppuhelper/typeprovider.hxx>
28 : #include <cppuhelper/queryinterface.hxx>
29 : #include <comphelper/sequence.hxx>
30 : #include <connectivity/dbtools.hxx>
31 : #include <connectivity/FValue.hxx>
32 : #include <connectivity/dbexception.hxx>
33 : #include "resource/jdbc_log.hrc"
34 : #include "resource/common_res.hrc"
35 : #include "resource/sharedresources.hxx"
36 : #include "java/LocalRef.hxx"
37 : #include <string.h>
38 : #include <boost/scoped_ptr.hpp>
39 :
40 : using namespace connectivity;
41 : using namespace ::com::sun::star::uno;
42 : using namespace ::com::sun::star::beans;
43 : using namespace ::com::sun::star::sdbc;
44 : using namespace ::com::sun::star::container;
45 : using namespace ::com::sun::star::lang;
46 :
47 :
48 : //************ Class: java.sql.PreparedStatement
49 :
50 0 : IMPLEMENT_SERVICE_INFO(java_sql_PreparedStatement,"com.sun.star.sdbcx.JPreparedStatement","com.sun.star.sdbc.PreparedStatement");
51 :
52 55 : java_sql_PreparedStatement::java_sql_PreparedStatement( JNIEnv * pEnv, java_sql_Connection& _rCon, const OUString& sql )
53 55 : : OStatement_BASE2( pEnv, _rCon )
54 : {
55 55 : m_sSqlStatement = sql;
56 55 : }
57 :
58 : jclass java_sql_PreparedStatement::theClass = 0;
59 :
60 110 : java_sql_PreparedStatement::~java_sql_PreparedStatement()
61 : {
62 110 : }
63 :
64 :
65 13 : jclass java_sql_PreparedStatement::getMyClass() const
66 : {
67 : // the class must be fetched only once, therefore static
68 13 : if( !theClass )
69 2 : theClass = findMyClass("java/sql/PreparedStatement");
70 13 : return theClass;
71 : }
72 :
73 :
74 890 : ::com::sun::star::uno::Any SAL_CALL java_sql_PreparedStatement::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException, std::exception)
75 : {
76 890 : ::com::sun::star::uno::Any aRet = OStatement_BASE2::queryInterface(rType);
77 890 : return aRet.hasValue() ? aRet : ::cppu::queryInterface( rType,
78 : static_cast< XPreparedStatement*>(this),
79 : static_cast< XParameters*>(this),
80 : static_cast< XResultSetMetaDataSupplier*>(this),
81 890 : static_cast< XPreparedBatchExecution*>(this));
82 : }
83 :
84 0 : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL java_sql_PreparedStatement::getTypes( ) throw(::com::sun::star::uno::RuntimeException, std::exception)
85 : {
86 0 : ::cppu::OTypeCollection aTypes( cppu::UnoType<XPreparedStatement>::get(),
87 0 : cppu::UnoType<XParameters>::get(),
88 0 : cppu::UnoType<XResultSetMetaDataSupplier>::get(),
89 0 : cppu::UnoType<XPreparedBatchExecution>::get());
90 :
91 0 : return ::comphelper::concatSequences(aTypes.getTypes(),OStatement_BASE2::getTypes());
92 : }
93 :
94 :
95 0 : sal_Bool SAL_CALL java_sql_PreparedStatement::execute( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
96 : {
97 0 : m_aLogger.log( LogLevel::FINE, STR_LOG_EXECUTING_PREPARED );
98 0 : ::osl::MutexGuard aGuard( m_aMutex );
99 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
100 :
101 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
102 0 : createStatement(t.pEnv);
103 : static jmethodID mID(NULL);
104 0 : return callBooleanMethod( "execute", mID );
105 : }
106 :
107 :
108 622 : sal_Int32 SAL_CALL java_sql_PreparedStatement::executeUpdate( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
109 : {
110 622 : ::osl::MutexGuard aGuard( m_aMutex );
111 622 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
112 622 : m_aLogger.log( LogLevel::FINE, STR_LOG_EXECUTING_PREPARED_UPDATE );
113 :
114 1244 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
115 622 : createStatement(t.pEnv);
116 : static jmethodID mID(NULL);
117 1244 : return callIntMethod_ThrowSQL("executeUpdate", mID);
118 : }
119 :
120 :
121 604 : void SAL_CALL java_sql_PreparedStatement::setString( sal_Int32 parameterIndex, const OUString& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
122 : {
123 604 : ::osl::MutexGuard aGuard( m_aMutex );
124 604 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
125 604 : m_aLogger.log( LogLevel::FINER, STR_LOG_STRING_PARAMETER, parameterIndex, x );
126 :
127 1208 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
128 : { // initialize temporary Variable
129 604 : createStatement(t.pEnv);
130 : static const char * cSignature = "(ILjava/lang/String;)V";
131 : static const char * cMethodName = "setString";
132 : // Java-Call
133 : static jmethodID mID(NULL);
134 604 : obtainMethodId_throwSQL(t.pEnv, cMethodName,cSignature, mID);
135 604 : jdbc::LocalRef< jstring > str( t.env(),convertwchar_tToJavaString(t.pEnv,x));
136 604 : t.pEnv->CallVoidMethod( object, mID, parameterIndex,str.get());
137 : // and clean up
138 604 : ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
139 604 : } //t.pEnv
140 604 : }
141 :
142 :
143 0 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL java_sql_PreparedStatement::getConnection( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
144 : {
145 0 : return Reference< XConnection >(m_pConnection);
146 : }
147 :
148 :
149 13487 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL java_sql_PreparedStatement::executeQuery( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
150 : {
151 13487 : m_aLogger.log( LogLevel::FINE, STR_LOG_EXECUTING_PREPARED_QUERY );
152 13487 : ::osl::MutexGuard aGuard( m_aMutex );
153 13487 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
154 :
155 26974 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
156 13487 : createStatement(t.pEnv);
157 : static jmethodID mID(NULL);
158 13487 : jobject out = callResultSetMethod(t.env(),"executeQuery",mID);
159 :
160 26974 : return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out, m_aLogger, *m_pConnection,this);
161 : }
162 :
163 :
164 0 : void SAL_CALL java_sql_PreparedStatement::setBoolean( sal_Int32 parameterIndex, sal_Bool x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
165 : {
166 0 : m_aLogger.log( LogLevel::FINER, STR_LOG_BOOLEAN_PARAMETER, parameterIndex, bool(x) );
167 0 : ::osl::MutexGuard aGuard( m_aMutex );
168 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
169 :
170 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
171 0 : createStatement(t.pEnv);
172 : static jmethodID mID(NULL);
173 0 : callVoidMethod_ThrowSQL("setBoolean", "(IZ)V", mID, parameterIndex, x);
174 0 : }
175 :
176 :
177 0 : void SAL_CALL java_sql_PreparedStatement::setByte( sal_Int32 parameterIndex, sal_Int8 x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
178 : {
179 0 : m_aLogger.log( LogLevel::FINER, STR_LOG_BYTE_PARAMETER, parameterIndex, (sal_Int32)x );
180 0 : ::osl::MutexGuard aGuard( m_aMutex );
181 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
182 :
183 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
184 0 : createStatement(t.pEnv);
185 : static jmethodID mID(NULL);
186 0 : callVoidMethod_ThrowSQL("setByte", "(IB)V", mID, parameterIndex, x);
187 0 : }
188 :
189 :
190 0 : void SAL_CALL java_sql_PreparedStatement::setDate( sal_Int32 parameterIndex, const ::com::sun::star::util::Date& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
191 : {
192 0 : m_aLogger.log( LogLevel::FINER, STR_LOG_DATE_PARAMETER, parameterIndex, x );
193 0 : ::osl::MutexGuard aGuard( m_aMutex );
194 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
195 :
196 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
197 0 : createStatement(t.pEnv);
198 0 : java_sql_Date aT(x);
199 : static jmethodID mID(NULL);
200 0 : callVoidMethod_ThrowSQL("setDate", "(ILjava/sql/Date;)V", mID, parameterIndex, aT.getJavaObject());
201 0 : }
202 :
203 :
204 :
205 0 : void SAL_CALL java_sql_PreparedStatement::setTime( sal_Int32 parameterIndex, const ::com::sun::star::util::Time& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
206 : {
207 0 : m_aLogger.log( LogLevel::FINER, STR_LOG_TIME_PARAMETER, parameterIndex, x );
208 0 : ::osl::MutexGuard aGuard( m_aMutex );
209 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
210 :
211 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
212 0 : createStatement(t.pEnv);
213 0 : java_sql_Time aT(x);
214 : static jmethodID mID(NULL);
215 0 : callVoidMethod_ThrowSQL("setTime", "(ILjava/sql/Time;)V", mID, parameterIndex, aT.getJavaObject());
216 0 : }
217 :
218 :
219 0 : void SAL_CALL java_sql_PreparedStatement::setTimestamp( sal_Int32 parameterIndex, const ::com::sun::star::util::DateTime& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
220 : {
221 0 : m_aLogger.log( LogLevel::FINER, STR_LOG_TIMESTAMP_PARAMETER, parameterIndex, x );
222 0 : ::osl::MutexGuard aGuard( m_aMutex );
223 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
224 :
225 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
226 0 : createStatement(t.pEnv);
227 : static jmethodID mID(NULL);
228 0 : java_sql_Timestamp aD(x);
229 0 : callVoidMethod_ThrowSQL("setTimestamp", "(ILjava/sql/Timestamp;)V", mID, parameterIndex, aD.getJavaObject());
230 0 : }
231 :
232 0 : void SAL_CALL java_sql_PreparedStatement::setDouble( sal_Int32 parameterIndex, double x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
233 : {
234 0 : m_aLogger.log( LogLevel::FINER, STR_LOG_DOUBLE_PARAMETER, parameterIndex, x );
235 0 : ::osl::MutexGuard aGuard( m_aMutex );
236 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
237 :
238 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
239 0 : createStatement(t.pEnv);
240 : static jmethodID mID(NULL);
241 0 : callVoidMethod_ThrowSQL("setDouble", "(ID)V", mID, parameterIndex, x);
242 0 : }
243 :
244 :
245 0 : void SAL_CALL java_sql_PreparedStatement::setFloat( sal_Int32 parameterIndex, float x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
246 : {
247 0 : m_aLogger.log( LogLevel::FINER, STR_LOG_FLOAT_PARAMETER, parameterIndex, x );
248 0 : ::osl::MutexGuard aGuard( m_aMutex );
249 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
250 :
251 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
252 0 : createStatement(t.pEnv);
253 : static jmethodID mID(NULL);
254 0 : callVoidMethod_ThrowSQL("setFloat", "(IF)V", mID, parameterIndex, x);
255 0 : }
256 :
257 :
258 14101 : void SAL_CALL java_sql_PreparedStatement::setInt( sal_Int32 parameterIndex, sal_Int32 x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
259 : {
260 14101 : m_aLogger.log( LogLevel::FINER, STR_LOG_INT_PARAMETER, parameterIndex, x );
261 14101 : ::osl::MutexGuard aGuard( m_aMutex );
262 14101 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
263 :
264 28202 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
265 14101 : createStatement(t.pEnv);
266 : static jmethodID mID(NULL);
267 28202 : callVoidMethod_ThrowSQL("setInt", "(II)V", mID, parameterIndex, x);
268 14101 : }
269 :
270 :
271 0 : void SAL_CALL java_sql_PreparedStatement::setLong( sal_Int32 parameterIndex, sal_Int64 x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
272 : {
273 0 : m_aLogger.log( LogLevel::FINER, STR_LOG_LONG_PARAMETER, parameterIndex, x );
274 0 : ::osl::MutexGuard aGuard( m_aMutex );
275 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
276 :
277 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
278 0 : createStatement(t.pEnv);
279 : static jmethodID mID(NULL);
280 0 : callVoidMethod_ThrowSQL("setLong", "(IJ)V", mID, parameterIndex, x);
281 0 : }
282 :
283 :
284 0 : void SAL_CALL java_sql_PreparedStatement::setNull( sal_Int32 parameterIndex, sal_Int32 sqlType ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
285 : {
286 0 : m_aLogger.log( LogLevel::FINER, STR_LOG_NULL_PARAMETER, parameterIndex, sqlType );
287 0 : ::osl::MutexGuard aGuard( m_aMutex );
288 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
289 :
290 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
291 0 : createStatement(t.pEnv);
292 : static jmethodID mID(NULL);
293 0 : callVoidMethod_ThrowSQL("setNull", "(II)V", mID, parameterIndex, sqlType);
294 0 : }
295 :
296 :
297 0 : void SAL_CALL java_sql_PreparedStatement::setClob( sal_Int32 /*parameterIndex*/, const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XClob >& /*x*/ ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
298 : {
299 0 : ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setClob", *this );
300 0 : }
301 :
302 :
303 0 : void SAL_CALL java_sql_PreparedStatement::setBlob( sal_Int32 /*parameterIndex*/, const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XBlob >& /*x*/ ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
304 : {
305 0 : ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setBlob", *this );
306 0 : }
307 :
308 :
309 0 : void SAL_CALL java_sql_PreparedStatement::setArray( sal_Int32 /*parameterIndex*/, const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XArray >& /*x*/ ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
310 : {
311 0 : ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setArray", *this );
312 0 : }
313 :
314 :
315 0 : void SAL_CALL java_sql_PreparedStatement::setRef( sal_Int32 /*parameterIndex*/, const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRef >& /*x*/ ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
316 : {
317 0 : ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setRef", *this );
318 0 : }
319 :
320 :
321 0 : void SAL_CALL java_sql_PreparedStatement::setObjectWithInfo( sal_Int32 parameterIndex, const ::com::sun::star::uno::Any& x, sal_Int32 targetSqlType, sal_Int32 scale ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
322 : {
323 0 : m_aLogger.log( LogLevel::FINER, STR_LOG_OBJECT_NULL_PARAMETER, parameterIndex );
324 0 : ::osl::MutexGuard aGuard( m_aMutex );
325 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
326 :
327 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
328 : {
329 0 : createStatement(t.pEnv);
330 :
331 : // initialize temporary Variable
332 : static const char * cSignature = "(ILjava/lang/Object;II)V";
333 : static const char * cMethodName = "setObject";
334 : // Java-Call
335 : static jmethodID mID(NULL);
336 0 : obtainMethodId_throwSQL(t.pEnv, cMethodName,cSignature, mID);
337 : {
338 0 : jobject obj = NULL;
339 0 : switch(targetSqlType)
340 : {
341 : case DataType::DECIMAL:
342 : case DataType::NUMERIC:
343 : {
344 0 : double nTemp = 0.0;
345 :
346 0 : boost::scoped_ptr<java_math_BigDecimal> pBigDecimal;
347 0 : if ( x >>= nTemp)
348 : {
349 0 : pBigDecimal.reset(new java_math_BigDecimal(nTemp));
350 : //setDouble(parameterIndex,nTemp);
351 : //return;
352 : }
353 : else
354 : {
355 0 : ORowSetValue aValue;
356 0 : aValue.fill(x);
357 0 : const OUString sValue = aValue;
358 0 : if ( !sValue.isEmpty() )
359 0 : pBigDecimal.reset(new java_math_BigDecimal(sValue));
360 : else
361 0 : pBigDecimal.reset(new java_math_BigDecimal(0.0));
362 : }
363 : //obj = convertwchar_tToJavaString(t.pEnv,::comphelper::getString(x));
364 0 : t.pEnv->CallVoidMethod( object, mID, parameterIndex,pBigDecimal->getJavaObject(),targetSqlType,scale);
365 0 : ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
366 0 : return;
367 : }
368 : default:
369 0 : obj = convertwchar_tToJavaString(t.pEnv,::comphelper::getString(x));
370 0 : break;
371 : }
372 0 : t.pEnv->CallVoidMethod( object, mID, parameterIndex,obj,targetSqlType,scale);
373 0 : t.pEnv->DeleteLocalRef(obj);
374 0 : ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
375 : // and clean up
376 : } //mID
377 0 : } //t.pEnv
378 : }
379 :
380 :
381 0 : void SAL_CALL java_sql_PreparedStatement::setObjectNull( sal_Int32 parameterIndex, sal_Int32 /*sqlType*/, const OUString& /*typeName*/ ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
382 : {
383 0 : m_aLogger.log( LogLevel::FINER, STR_LOG_OBJECT_NULL_PARAMETER, parameterIndex );
384 0 : ::osl::MutexGuard aGuard( m_aMutex );
385 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
386 :
387 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
388 0 : createStatement(t.pEnv);
389 : static jmethodID mID(NULL);
390 0 : callVoidMethod_ThrowSQL<jobject>("setObject", "(ILjava/lang/Object;)V", mID, parameterIndex, NULL);
391 0 : }
392 :
393 :
394 0 : void SAL_CALL java_sql_PreparedStatement::setObject( sal_Int32 parameterIndex, const ::com::sun::star::uno::Any& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
395 : {
396 0 : if(!::dbtools::implSetObject(this,parameterIndex,x))
397 : {
398 0 : const OUString sError( m_pConnection->getResources().getResourceStringWithSubstitution(
399 : STR_UNKNOWN_PARA_TYPE,
400 : "$position$", OUString::number(parameterIndex)
401 0 : ) );
402 0 : ::dbtools::throwGenericSQLException(sError,*this);
403 : }
404 0 : }
405 :
406 :
407 0 : void SAL_CALL java_sql_PreparedStatement::setShort( sal_Int32 parameterIndex, sal_Int16 x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
408 : {
409 0 : m_aLogger.log( LogLevel::FINER, STR_LOG_SHORT_PARAMETER, parameterIndex, x );
410 0 : ::osl::MutexGuard aGuard( m_aMutex );
411 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
412 :
413 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
414 0 : createStatement(t.pEnv);
415 : static jmethodID mID(NULL);
416 0 : callVoidMethod_ThrowSQL("setShort", "(IS)V", mID, parameterIndex, x);
417 0 : }
418 :
419 :
420 0 : void SAL_CALL java_sql_PreparedStatement::setBytes( sal_Int32 parameterIndex, const ::com::sun::star::uno::Sequence< sal_Int8 >& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
421 : {
422 0 : m_aLogger.log( LogLevel::FINER, STR_LOG_BYTES_PARAMETER, parameterIndex );
423 0 : ::osl::MutexGuard aGuard( m_aMutex );
424 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
425 :
426 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
427 : {
428 0 : createStatement(t.pEnv);
429 :
430 : // initialize temporary Variable
431 : static const char * cSignature = "(I[B)V";
432 : static const char * cMethodName = "setBytes";
433 : // Java-Call
434 : static jmethodID mID(NULL);
435 0 : obtainMethodId_throwSQL(t.pEnv, cMethodName,cSignature, mID);
436 0 : jbyteArray pByteArray = t.pEnv->NewByteArray(x.getLength());
437 0 : t.pEnv->SetByteArrayRegion(pByteArray,0,x.getLength(),x.getConstArray());
438 0 : t.pEnv->CallVoidMethod( object, mID, parameterIndex,pByteArray);
439 0 : t.pEnv->DeleteLocalRef(pByteArray);
440 0 : ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
441 0 : } //t.pEnv
442 0 : }
443 :
444 :
445 0 : void SAL_CALL java_sql_PreparedStatement::setCharacterStream( sal_Int32 parameterIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
446 : {
447 0 : m_aLogger.log( LogLevel::FINER, STR_LOG_CHARSTREAM_PARAMETER, parameterIndex );
448 0 : ::osl::MutexGuard aGuard( m_aMutex );
449 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
450 :
451 0 : SDBThreadAttach t;
452 : assert(t.pEnv && "Java Enviroment geloescht worden!");
453 : {
454 0 : createStatement(t.pEnv);
455 :
456 : // initialize temporary variable
457 : static const char * cSignature = "(ILjava/io/InputStream;I)V";
458 : static const char * cMethodName = "setCharacterStream";
459 : // Java-Call
460 : static jmethodID mID(NULL);
461 0 : obtainMethodId_throwSQL(t.pEnv, cMethodName,cSignature, mID);
462 0 : Sequence< sal_Int8 > aSeq;
463 0 : if ( x.is() )
464 0 : x->readBytes( aSeq, length );
465 0 : sal_Int32 actualLength = aSeq.getLength();
466 :
467 : jvalue args2[3];
468 0 : jbyteArray pByteArray = t.pEnv->NewByteArray( actualLength );
469 0 : t.pEnv->SetByteArrayRegion(pByteArray,0,actualLength,aSeq.getConstArray());
470 0 : args2[0].l = pByteArray;
471 0 : args2[1].i = 0;
472 0 : args2[2].i = actualLength;
473 : // Java-Call
474 0 : jclass aClass = t.pEnv->FindClass("java/io/CharArrayInputStream");
475 : static jmethodID mID2 = NULL;
476 0 : if ( !mID2 )
477 : {
478 : // initialize temporary variable
479 0 : const char * cSignatureStream = "([BII)V";
480 0 : mID2 = t.pEnv->GetMethodID( aClass, "<init>", cSignatureStream );
481 : }
482 0 : jobject tempObj = NULL;
483 0 : if(mID2)
484 0 : tempObj = t.pEnv->NewObjectA( aClass, mID2, args2 );
485 :
486 0 : t.pEnv->CallVoidMethod( object, mID, parameterIndex,tempObj,actualLength);
487 : // and clean up
488 0 : t.pEnv->DeleteLocalRef(pByteArray);
489 0 : t.pEnv->DeleteLocalRef(tempObj);
490 0 : t.pEnv->DeleteLocalRef(aClass);
491 0 : ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
492 0 : } //t.pEnv
493 0 : }
494 :
495 :
496 0 : void SAL_CALL java_sql_PreparedStatement::setBinaryStream( sal_Int32 parameterIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
497 : {
498 0 : m_aLogger.log( LogLevel::FINER, STR_LOG_BINARYSTREAM_PARAMETER, parameterIndex );
499 0 : ::osl::MutexGuard aGuard( m_aMutex );
500 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
501 :
502 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
503 : {
504 0 : createStatement(t.pEnv);
505 : // initialize temporary variable
506 : static const char * cSignature = "(ILjava/io/InputStream;I)V";
507 : static const char * cMethodName = "setBinaryStream";
508 : // Java-Call
509 : static jmethodID mID(NULL);
510 0 : obtainMethodId_throwSQL(t.pEnv, cMethodName,cSignature, mID);
511 : {
512 0 : Sequence< sal_Int8 > aSeq;
513 0 : if ( x.is() )
514 0 : x->readBytes( aSeq, length );
515 0 : sal_Int32 actualLength = aSeq.getLength();
516 :
517 : jvalue args2[3];
518 0 : jbyteArray pByteArray = t.pEnv->NewByteArray(actualLength);
519 0 : t.pEnv->SetByteArrayRegion(pByteArray,0,actualLength,aSeq.getConstArray());
520 0 : args2[0].l = pByteArray;
521 0 : args2[1].i = 0;
522 0 : args2[2].i = (sal_Int32)actualLength;
523 :
524 : // Java-Call
525 0 : jclass aClass = t.pEnv->FindClass("java/io/ByteArrayInputStream");
526 : static jmethodID mID2 = NULL;
527 0 : if ( !mID2 )
528 : {
529 : // initialize temporary variable
530 0 : const char * cSignatureStream = "([BII)V";
531 0 : mID2 = t.pEnv->GetMethodID( aClass, "<init>", cSignatureStream );
532 : }
533 0 : jobject tempObj = NULL;
534 0 : if(mID2)
535 0 : tempObj = t.pEnv->NewObjectA( aClass, mID2, args2 );
536 0 : t.pEnv->CallVoidMethod( object, mID, parameterIndex,tempObj,(sal_Int32)actualLength);
537 : // and clean up
538 0 : t.pEnv->DeleteLocalRef(pByteArray);
539 0 : t.pEnv->DeleteLocalRef(tempObj);
540 0 : t.pEnv->DeleteLocalRef(aClass);
541 0 : ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
542 : }
543 0 : } //t.pEnv
544 0 : }
545 :
546 :
547 13478 : void SAL_CALL java_sql_PreparedStatement::clearParameters( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
548 : {
549 13478 : m_aLogger.log( LogLevel::FINER, STR_LOG_CLEAR_PARAMETERS );
550 13478 : ::osl::MutexGuard aGuard( m_aMutex );
551 13478 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
552 :
553 26956 : SDBThreadAttach t;
554 : {
555 13478 : createStatement(t.pEnv);
556 :
557 : static jmethodID mID(NULL);
558 13478 : callVoidMethod_ThrowSQL("clearParameters",mID);
559 13478 : } //t.pEnv
560 13478 : }
561 :
562 0 : void SAL_CALL java_sql_PreparedStatement::clearBatch( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
563 : {
564 0 : ::osl::MutexGuard aGuard( m_aMutex );
565 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
566 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
567 : {
568 0 : createStatement(t.pEnv);
569 : static jmethodID mID(NULL);
570 0 : callVoidMethod_ThrowSQL("clearBatch",mID);
571 0 : } //t.pEnv
572 0 : }
573 :
574 :
575 0 : void SAL_CALL java_sql_PreparedStatement::addBatch( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
576 : {
577 0 : ::osl::MutexGuard aGuard( m_aMutex );
578 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
579 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
580 : {
581 0 : createStatement(t.pEnv);
582 : static jmethodID mID(NULL);
583 0 : callVoidMethod_ThrowSQL("addBatch", mID);
584 0 : } //t.pEnv
585 0 : }
586 :
587 :
588 0 : ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL java_sql_PreparedStatement::executeBatch( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
589 : {
590 0 : ::osl::MutexGuard aGuard( m_aMutex );
591 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
592 0 : ::com::sun::star::uno::Sequence< sal_Int32 > aSeq;
593 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
594 0 : createStatement(t.pEnv);
595 : static jmethodID mID(NULL);
596 0 : jintArray out = static_cast<jintArray>(callObjectMethod(t.pEnv,"executeBatch","()[I", mID));
597 0 : if(out)
598 : {
599 0 : jboolean p = sal_False;
600 0 : aSeq.realloc(t.pEnv->GetArrayLength(out));
601 0 : memcpy(aSeq.getArray(),t.pEnv->GetIntArrayElements(out,&p),aSeq.getLength());
602 0 : t.pEnv->DeleteLocalRef(out);
603 : }
604 0 : return aSeq;
605 : }
606 :
607 13 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData > SAL_CALL java_sql_PreparedStatement::getMetaData( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
608 : {
609 13 : ::osl::MutexGuard aGuard( m_aMutex );
610 13 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
611 26 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
612 13 : createStatement(t.pEnv);
613 : static jmethodID mID(NULL);
614 13 : jobject out = callObjectMethod(t.pEnv,"getMetaData","()Ljava/sql/ResultSetMetaData;", mID);
615 :
616 26 : return out==0 ? 0 : new java_sql_ResultSetMetaData( t.pEnv, out, m_aLogger,*m_pConnection );
617 : }
618 :
619 31124 : void SAL_CALL java_sql_PreparedStatement::acquire() throw()
620 : {
621 31124 : OStatement_BASE2::acquire();
622 31124 : }
623 :
624 31124 : void SAL_CALL java_sql_PreparedStatement::release() throw()
625 : {
626 31124 : OStatement_BASE2::release();
627 31124 : }
628 :
629 42315 : void java_sql_PreparedStatement::createStatement(JNIEnv* _pEnv)
630 : {
631 42315 : ::osl::MutexGuard aGuard( m_aMutex );
632 42315 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
633 :
634 42315 : if( !object && _pEnv ){
635 : // initialize temporary variable
636 : static const char * cMethodName = "prepareStatement";
637 :
638 : jvalue args[1];
639 : // convert Parameter
640 64 : args[0].l = convertwchar_tToJavaString(_pEnv,m_sSqlStatement);
641 : // Java-Call
642 64 : jobject out = NULL;
643 : static jmethodID mID(NULL);
644 64 : if ( !mID )
645 : {
646 : static const char * cSignature = "(Ljava/lang/String;II)Ljava/sql/PreparedStatement;";
647 2 : mID = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature );
648 : }
649 64 : if( mID )
650 : {
651 64 : out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID, args[0].l ,m_nResultSetType,m_nResultSetConcurrency);
652 : }
653 : else
654 : {
655 : static jmethodID mID2 = NULL;
656 0 : if ( !mID2 )
657 : {
658 : static const char * cSignature2 = "(Ljava/lang/String;)Ljava/sql/PreparedStatement;";
659 0 : mID2 = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature2 );
660 : }
661 0 : if ( mID2 )
662 0 : out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID2, args[0].l );
663 : }
664 64 : _pEnv->DeleteLocalRef(static_cast<jstring>(args[0].l));
665 64 : ThrowLoggedSQLException( m_aLogger, _pEnv, *this );
666 64 : if ( out )
667 64 : object = _pEnv->NewGlobalRef( out );
668 42315 : } //t.pEnv
669 42315 : }
670 :
671 :
672 :
673 :
674 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|