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