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