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 : :
21 : : #include "java/sql/JStatement.hxx"
22 : : #include "java/sql/ResultSet.hxx"
23 : : #include "java/sql/Connection.hxx"
24 : : #include "java/sql/SQLWarning.hxx"
25 : : #include "java/tools.hxx"
26 : : #include "java/ContextClassLoader.hxx"
27 : : #include <comphelper/property.hxx>
28 : : #include <com/sun/star/lang/DisposedException.hpp>
29 : : #include <cppuhelper/typeprovider.hxx>
30 : : #include <comphelper/sequence.hxx>
31 : : #include "TConnection.hxx"
32 : : #include <comphelper/types.hxx>
33 : : #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
34 : : #include <com/sun/star/sdbc/ResultSetType.hpp>
35 : : #include <com/sun/star/sdbc/FetchDirection.hpp>
36 : :
37 : : #include "resource/jdbc_log.hrc"
38 : :
39 : : #include <algorithm>
40 : : #include <string.h>
41 : :
42 : : using namespace ::comphelper;
43 : : using namespace connectivity;
44 : : using namespace ::cppu;
45 : : //------------------------------------------------------------------------------
46 : : using namespace ::com::sun::star::uno;
47 : : using namespace ::com::sun::star::beans;
48 : : using namespace ::com::sun::star::sdbc;
49 : : using namespace ::com::sun::star::container;
50 : : using namespace ::com::sun::star::lang;
51 : :
52 : : //------------------------------------------------------------------------------
53 : : //**************************************************************
54 : : //************ Class: java.sql.Statement
55 : : //**************************************************************
56 : :
57 : : jclass java_sql_Statement_Base::theClass = 0;
58 : :
59 : : // -------------------------------------------------------------------------
60 : 0 : java_sql_Statement_Base::java_sql_Statement_Base( JNIEnv * pEnv, java_sql_Connection& _rCon )
61 : : :java_sql_Statement_BASE(m_aMutex)
62 : : ,java_lang_Object( pEnv, NULL )
63 : : ,OPropertySetHelper(java_sql_Statement_BASE::rBHelper)
64 : : ,m_pConnection( &_rCon )
65 : 0 : ,m_aLogger( _rCon.getLogger(), java::sql::ConnectionLog::STATEMENT )
66 : : ,m_nResultSetConcurrency(ResultSetConcurrency::READ_ONLY)
67 : : ,m_nResultSetType(ResultSetType::FORWARD_ONLY)
68 : : ,m_bEscapeProcessing(sal_True)
69 : 0 : ,rBHelper(java_sql_Statement_BASE::rBHelper)
70 : : {
71 : 0 : m_pConnection->acquire();
72 : 0 : }
73 : :
74 : : //------------------------------------------------------------------------------
75 : 0 : java_sql_Statement_Base::~java_sql_Statement_Base()
76 : : {
77 : 0 : }
78 : :
79 : : //------------------------------------------------------------------------------
80 : 0 : void SAL_CALL OStatement_BASE2::disposing()
81 : : {
82 : 0 : ::osl::MutexGuard aGuard(m_aMutex);
83 : :
84 : 0 : if ( object )
85 : : {
86 : : static jmethodID mID(NULL);
87 : 0 : callVoidMethod("close",mID);
88 : : }
89 : :
90 : 0 : ::comphelper::disposeComponent(m_xGeneratedStatement);
91 : 0 : if (m_pConnection)
92 : 0 : m_pConnection->release();
93 : 0 : m_pConnection = NULL;
94 : :
95 : 0 : dispose_ChildImpl();
96 : 0 : java_sql_Statement_Base::disposing();
97 : 0 : }
98 : : // -------------------------------------------------------------------------
99 : 0 : jclass java_sql_Statement_Base::getMyClass() const
100 : : {
101 : : // the class must be fetched only once, therefore static
102 : 0 : if( !theClass )
103 : 0 : theClass = findMyClass("java/sql/Statement");
104 : 0 : return theClass;
105 : : }
106 : : // -----------------------------------------------------------------------------
107 : 0 : void SAL_CALL java_sql_Statement_Base::disposing(void)
108 : : {
109 : 0 : m_aLogger.log( LogLevel::FINE, STR_LOG_CLOSING_STATEMENT );
110 : 0 : java_sql_Statement_BASE::disposing();
111 : 0 : clearObject();
112 : 0 : }
113 : : // -------------------------------------------------------------------------
114 : :
115 : 0 : void SAL_CALL OStatement_BASE2::release() throw()
116 : : {
117 : 0 : relase_ChildImpl();
118 : 0 : }
119 : :
120 : : // -------------------------------------------------------------------------
121 : 0 : Any SAL_CALL java_sql_Statement_Base::queryInterface( const Type & rType ) throw(RuntimeException)
122 : : {
123 : 0 : if ( m_pConnection && !m_pConnection->isAutoRetrievingEnabled() && rType == ::getCppuType( (const Reference< XGeneratedResultSet > *)0 ) )
124 : 0 : return Any();
125 : 0 : Any aRet( java_sql_Statement_BASE::queryInterface(rType) );
126 : 0 : return aRet.hasValue() ? aRet : OPropertySetHelper::queryInterface(rType);
127 : : }
128 : : // -------------------------------------------------------------------------
129 : 0 : Sequence< Type > SAL_CALL java_sql_Statement_Base::getTypes( ) throw(RuntimeException)
130 : : {
131 : 0 : ::cppu::OTypeCollection aTypes( ::getCppuType( (const Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ),
132 : 0 : ::getCppuType( (const Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ),
133 : 0 : ::getCppuType( (const Reference< ::com::sun::star::beans::XPropertySet > *)0 ));
134 : :
135 : 0 : Sequence< Type > aOldTypes = java_sql_Statement_BASE::getTypes();
136 : 0 : if ( m_pConnection && !m_pConnection->isAutoRetrievingEnabled() )
137 : : {
138 : 0 : ::std::remove(aOldTypes.getArray(),aOldTypes.getArray() + aOldTypes.getLength(),
139 : 0 : ::getCppuType( (const Reference< XGeneratedResultSet > *)0 ));
140 : 0 : aOldTypes.realloc(aOldTypes.getLength() - 1);
141 : : }
142 : :
143 : 0 : return ::comphelper::concatSequences(aTypes.getTypes(),aOldTypes);
144 : : }
145 : : // -----------------------------------------------------------------------------
146 : 0 : Reference< XResultSet > SAL_CALL java_sql_Statement_Base::getGeneratedValues( ) throw (SQLException, RuntimeException)
147 : : {
148 : 0 : m_aLogger.log( LogLevel::FINE, STR_LOG_GENERATED_VALUES );
149 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
150 : 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
151 : :
152 : 0 : jobject out(0);
153 : 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
154 : 0 : createStatement(t.pEnv);
155 : : // initialize temporary Variable
156 : : try
157 : : {
158 : : static jmethodID mID(NULL);
159 : 0 : out = callResultSetMethod(t.env(),"getGeneratedKeys",mID);
160 : : }
161 : 0 : catch(const SQLException&)
162 : : {
163 : : // ignore
164 : : }
165 : :
166 : 0 : Reference< XResultSet > xRes;
167 : 0 : if ( !out )
168 : : {
169 : : OSL_ENSURE( m_pConnection && m_pConnection->isAutoRetrievingEnabled(),"Illegal call here. isAutoRetrievingEnabled is false!");
170 : 0 : if ( m_pConnection )
171 : : {
172 : 0 : ::rtl::OUString sStmt = m_pConnection->getTransformedGeneratedStatement(m_sSqlStatement);
173 : 0 : if ( !sStmt.isEmpty() )
174 : : {
175 : 0 : m_aLogger.log( LogLevel::FINER, STR_LOG_GENERATED_VALUES_FALLBACK, sStmt );
176 : 0 : ::comphelper::disposeComponent(m_xGeneratedStatement);
177 : 0 : m_xGeneratedStatement = m_pConnection->createStatement();
178 : 0 : xRes = m_xGeneratedStatement->executeQuery(sStmt);
179 : 0 : }
180 : : }
181 : : }
182 : : else
183 : 0 : xRes = new java_sql_ResultSet( t.pEnv, out, m_aLogger,*m_pConnection, this );
184 : 0 : return xRes;
185 : : }
186 : :
187 : : // -------------------------------------------------------------------------
188 : :
189 : 0 : void SAL_CALL java_sql_Statement_Base::cancel( ) throw(RuntimeException)
190 : : {
191 : 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
192 : 0 : createStatement(t.pEnv);
193 : : static jmethodID mID(NULL);
194 : 0 : callVoidMethod("cancel",mID);
195 : 0 : }
196 : : // -------------------------------------------------------------------------
197 : :
198 : 0 : void SAL_CALL java_sql_Statement_Base::close( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
199 : : {
200 : : {
201 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
202 : 0 : if (java_sql_Statement_BASE::rBHelper.bDisposed)
203 : 0 : throw DisposedException();
204 : : }
205 : 0 : dispose();
206 : 0 : }
207 : : // -------------------------------------------------------------------------
208 : :
209 : 0 : void SAL_CALL java_sql_Statement::clearBatch( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
210 : : {
211 : 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
212 : : {
213 : :
214 : 0 : createStatement(t.pEnv);
215 : : static jmethodID mID(NULL);
216 : 0 : callVoidMethod("clearBatch",mID);
217 : 0 : } //t.pEnv
218 : 0 : }
219 : : // -------------------------------------------------------------------------
220 : :
221 : 0 : sal_Bool SAL_CALL java_sql_Statement_Base::execute( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
222 : : {
223 : 0 : m_aLogger.log( LogLevel::FINE, STR_LOG_EXECUTE_STATEMENT, sql );
224 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
225 : 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
226 : :
227 : 0 : jboolean out(sal_False);
228 : 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
229 : : {
230 : 0 : createStatement(t.pEnv);
231 : 0 : m_sSqlStatement = sql;
232 : : // initialize temporary Variable
233 : : static const char * cSignature = "(Ljava/lang/String;)Z";
234 : : static const char * cMethodName = "execute";
235 : : // Java-Call
236 : : static jmethodID mID(NULL);
237 : 0 : obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
238 : : // convert Parameter
239 : 0 : jdbc::LocalRef< jstring > str( t.env(), convertwchar_tToJavaString( t.pEnv, sql ) );
240 : : {
241 : 0 : jdbc::ContextClassLoaderScope ccl( t.env(),
242 : 0 : m_pConnection ? m_pConnection->getDriverClassLoader() : jdbc::GlobalRef< jobject >(),
243 : : m_aLogger,
244 : : *this
245 : 0 : );
246 : :
247 : 0 : out = t.pEnv->CallBooleanMethod( object, mID, str.get() );
248 : 0 : ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
249 : 0 : }
250 : : } //t.pEnv
251 : 0 : return out;
252 : : }
253 : : // -------------------------------------------------------------------------
254 : :
255 : 0 : Reference< XResultSet > SAL_CALL java_sql_Statement_Base::executeQuery( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
256 : : {
257 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
258 : 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
259 : 0 : m_aLogger.log( LogLevel::FINE, STR_LOG_EXECUTE_QUERY, sql );
260 : :
261 : 0 : jobject out(0);
262 : 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
263 : :
264 : : {
265 : 0 : createStatement(t.pEnv);
266 : 0 : m_sSqlStatement = sql;
267 : : // initialize temporary variable
268 : : static const char * cSignature = "(Ljava/lang/String;)Ljava/sql/ResultSet;";
269 : : static const char * cMethodName = "executeQuery";
270 : : // Java-Call
271 : : static jmethodID mID(NULL);
272 : 0 : obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
273 : : // convert Parameter
274 : 0 : jdbc::LocalRef< jstring > str( t.env(), convertwchar_tToJavaString( t.pEnv, sql ) );
275 : : {
276 : 0 : jdbc::ContextClassLoaderScope ccl( t.env(),
277 : 0 : m_pConnection ? m_pConnection->getDriverClassLoader() : jdbc::GlobalRef< jobject >(),
278 : : m_aLogger,
279 : : *this
280 : 0 : );
281 : :
282 : 0 : out = t.pEnv->CallObjectMethod( object, mID, str.get() );
283 : 0 : ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
284 : 0 : }
285 : : } //t.pEnv
286 : : // WARNING: the caller becomes the owner of the returned pointer
287 : 0 : return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out, m_aLogger, *m_pConnection,this );
288 : : }
289 : : // -------------------------------------------------------------------------
290 : 0 : Reference< XConnection > SAL_CALL java_sql_Statement_Base::getConnection( ) throw(SQLException, RuntimeException)
291 : : {
292 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
293 : 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
294 : 0 : return (Reference< XConnection >)m_pConnection;
295 : : }
296 : : // -------------------------------------------------------------------------
297 : :
298 : 0 : Any SAL_CALL java_sql_Statement::queryInterface( const Type & rType ) throw(RuntimeException)
299 : : {
300 : 0 : Any aRet = ::cppu::queryInterface(rType,static_cast< XBatchExecution*> (this));
301 : 0 : return aRet.hasValue() ? aRet : java_sql_Statement_Base::queryInterface(rType);
302 : : }
303 : : // -------------------------------------------------------------------------
304 : :
305 : 0 : void SAL_CALL java_sql_Statement::addBatch( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
306 : : {
307 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
308 : 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
309 : 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
310 : : {
311 : 0 : createStatement(t.pEnv);
312 : : static jmethodID mID(NULL);
313 : 0 : callVoidMethodWithStringArg("addBatch",mID,sql);
314 : 0 : } //t.pEnv
315 : 0 : }
316 : : // -------------------------------------------------------------------------
317 : :
318 : 0 : Sequence< sal_Int32 > SAL_CALL java_sql_Statement::executeBatch( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
319 : : {
320 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
321 : 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
322 : 0 : Sequence< sal_Int32 > aSeq;
323 : 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
324 : 0 : createStatement(t.pEnv);
325 : : static jmethodID mID(NULL);
326 : 0 : jintArray out = (jintArray)callObjectMethod(t.pEnv,"executeBatch","()[I", mID);
327 : 0 : if (out)
328 : : {
329 : 0 : jboolean p = sal_False;
330 : 0 : aSeq.realloc(t.pEnv->GetArrayLength(out));
331 : 0 : memcpy(aSeq.getArray(),t.pEnv->GetIntArrayElements(out,&p),aSeq.getLength());
332 : 0 : t.pEnv->DeleteLocalRef(out);
333 : : }
334 : 0 : return aSeq;
335 : : }
336 : : // -------------------------------------------------------------------------
337 : :
338 : :
339 : 0 : sal_Int32 SAL_CALL java_sql_Statement_Base::executeUpdate( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
340 : : {
341 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
342 : 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
343 : 0 : m_aLogger.log( LogLevel::FINE, STR_LOG_EXECUTE_UPDATE, sql );
344 : :
345 : 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
346 : 0 : createStatement(t.pEnv);
347 : 0 : m_sSqlStatement = sql;
348 : : static jmethodID mID(NULL);
349 : 0 : return callIntMethodWithStringArg("executeUpdate",mID,sql);
350 : : }
351 : : // -------------------------------------------------------------------------
352 : :
353 : 0 : Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL java_sql_Statement_Base::getResultSet( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
354 : : {
355 : 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
356 : 0 : createStatement(t.pEnv);
357 : : static jmethodID mID(NULL);
358 : 0 : jobject out = callResultSetMethod(t.env(),"getResultSet",mID);
359 : :
360 : : // WARNING: the caller becomes the owner of the returned pointer
361 : 0 : return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out, m_aLogger, *m_pConnection,this );
362 : : }
363 : : // -------------------------------------------------------------------------
364 : :
365 : 0 : sal_Int32 SAL_CALL java_sql_Statement_Base::getUpdateCount( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
366 : : {
367 : 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
368 : 0 : createStatement(t.pEnv);
369 : : static jmethodID mID(NULL);
370 : 0 : sal_Int32 out = callIntMethod("getUpdateCount",mID);
371 : 0 : m_aLogger.log( LogLevel::FINER, STR_LOG_UPDATE_COUNT, (sal_Int32)out );
372 : 0 : return out;
373 : : }
374 : : // -------------------------------------------------------------------------
375 : :
376 : 0 : sal_Bool SAL_CALL java_sql_Statement_Base::getMoreResults( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
377 : : {
378 : : static jmethodID mID(NULL);
379 : 0 : return callBooleanMethod( "getMoreResults", mID );
380 : : }
381 : : // -------------------------------------------------------------------------
382 : :
383 : : // -------------------------------------------------------------------------
384 : 0 : Any SAL_CALL java_sql_Statement_Base::getWarnings( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
385 : : {
386 : 0 : SDBThreadAttach t;
387 : 0 : createStatement(t.pEnv);
388 : : static jmethodID mID(NULL);
389 : 0 : jobject out = callObjectMethod(t.pEnv,"getWarnings","()Ljava/sql/SQLWarning;", mID);
390 : : // WARNING: the caller becomes the owner of the returned pointer
391 : 0 : if( out )
392 : : {
393 : 0 : java_sql_SQLWarning_BASE warn_base( t.pEnv, out );
394 : : return makeAny(
395 : : static_cast< starsdbc::SQLException >(
396 : 0 : java_sql_SQLWarning(warn_base,*(::cppu::OWeakObject*)this)));
397 : : }
398 : :
399 : 0 : return Any();
400 : : }
401 : : // -------------------------------------------------------------------------
402 : 0 : void SAL_CALL java_sql_Statement_Base::clearWarnings( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
403 : : {
404 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
405 : 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
406 : 0 : SDBThreadAttach t;
407 : :
408 : : {
409 : 0 : createStatement(t.pEnv);
410 : : static jmethodID mID(NULL);
411 : 0 : callVoidMethod("clearWarnings",mID);
412 : 0 : }
413 : 0 : }
414 : : //------------------------------------------------------------------------------
415 : 0 : sal_Int32 java_sql_Statement_Base::getQueryTimeOut() throw(SQLException, RuntimeException)
416 : : {
417 : : static jmethodID mID(NULL);
418 : 0 : return impl_getProperty("getQueryTimeOut",mID);
419 : : }
420 : : //------------------------------------------------------------------------------
421 : 0 : sal_Int32 java_sql_Statement_Base::getMaxRows() throw(SQLException, RuntimeException)
422 : : {
423 : : static jmethodID mID(NULL);
424 : 0 : return impl_getProperty("getMaxRows",mID);
425 : : }
426 : : //------------------------------------------------------------------------------
427 : 0 : sal_Int32 java_sql_Statement_Base::getResultSetConcurrency() throw(SQLException, RuntimeException)
428 : : {
429 : : static jmethodID mID(NULL);
430 : 0 : return impl_getProperty("getResultSetConcurrency",mID,m_nResultSetConcurrency);
431 : : }
432 : :
433 : : //------------------------------------------------------------------------------
434 : 0 : sal_Int32 java_sql_Statement_Base::getResultSetType() throw(SQLException, RuntimeException)
435 : : {
436 : : static jmethodID mID(NULL);
437 : 0 : return impl_getProperty("getResultSetType",mID,m_nResultSetType);
438 : : }
439 : : //------------------------------------------------------------------------------
440 : 0 : sal_Int32 java_sql_Statement_Base::impl_getProperty(const char* _pMethodName, jmethodID& _inout_MethodID,sal_Int32 _nDefault)
441 : : {
442 : 0 : sal_Int32 out = _nDefault;
443 : 0 : if ( object )
444 : 0 : out = callIntMethod(_pMethodName,_inout_MethodID,true);
445 : :
446 : 0 : return out;
447 : : }
448 : : //------------------------------------------------------------------------------
449 : 0 : sal_Int32 java_sql_Statement_Base::impl_getProperty(const char* _pMethodName, jmethodID& _inout_MethodID)
450 : : {
451 : 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
452 : 0 : createStatement(t.pEnv);
453 : 0 : return callIntMethod(_pMethodName,_inout_MethodID,true);
454 : : }
455 : :
456 : : //------------------------------------------------------------------------------
457 : 0 : sal_Int32 java_sql_Statement_Base::getFetchDirection() throw(SQLException, RuntimeException)
458 : : {
459 : : static jmethodID mID(NULL);
460 : 0 : return impl_getProperty("getFetchDirection",mID);
461 : : }
462 : : //------------------------------------------------------------------------------
463 : 0 : sal_Int32 java_sql_Statement_Base::getFetchSize() throw(SQLException, RuntimeException)
464 : : {
465 : : static jmethodID mID(NULL);
466 : 0 : return impl_getProperty("getFetchSize",mID);
467 : : }
468 : : //------------------------------------------------------------------------------
469 : 0 : sal_Int32 java_sql_Statement_Base::getMaxFieldSize() throw(SQLException, RuntimeException)
470 : : {
471 : : static jmethodID mID(NULL);
472 : 0 : return impl_getProperty("getMaxFieldSize",mID);
473 : : }
474 : : //------------------------------------------------------------------------------
475 : 0 : ::rtl::OUString java_sql_Statement_Base::getCursorName() throw(SQLException, RuntimeException)
476 : : {
477 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
478 : 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
479 : 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
480 : 0 : createStatement(t.pEnv);
481 : : static jmethodID mID(NULL);
482 : : try
483 : : {
484 : 0 : return callStringMethod("getCursorName",mID);
485 : : }
486 : 0 : catch(const SQLException&)
487 : : {
488 : : }
489 : 0 : return ::rtl::OUString();
490 : : }
491 : : //------------------------------------------------------------------------------
492 : 0 : void java_sql_Statement_Base::setQueryTimeOut(sal_Int32 _par0) throw(SQLException, RuntimeException)
493 : : {
494 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
495 : 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
496 : 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
497 : 0 : createStatement(t.pEnv);
498 : : static jmethodID mID(NULL);
499 : 0 : callVoidMethodWithIntArg("setQueryTimeOut",mID,_par0,true);
500 : 0 : }
501 : :
502 : : //------------------------------------------------------------------------------
503 : 0 : void java_sql_Statement_Base::setEscapeProcessing(sal_Bool _par0) throw(SQLException, RuntimeException)
504 : : {
505 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
506 : 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
507 : 0 : m_aLogger.log( LogLevel::FINE, STR_LOG_SET_ESCAPE_PROCESSING, _par0 );
508 : :
509 : 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
510 : 0 : m_bEscapeProcessing = _par0;
511 : 0 : createStatement( t.pEnv );
512 : : static jmethodID mID(NULL);
513 : 0 : callVoidMethodWithBoolArg("setEscapeProcessing",mID,_par0,true);
514 : 0 : }
515 : :
516 : : //------------------------------------------------------------------------------
517 : 0 : void java_sql_Statement_Base::setMaxRows(sal_Int32 _par0) throw(SQLException, RuntimeException)
518 : : {
519 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
520 : 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
521 : 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
522 : 0 : createStatement(t.pEnv);
523 : : static jmethodID mID(NULL);
524 : 0 : callVoidMethodWithIntArg("setMaxRows",mID,_par0,true);
525 : 0 : }
526 : : //------------------------------------------------------------------------------
527 : 0 : void java_sql_Statement_Base::setResultSetConcurrency(sal_Int32 _par0) throw(SQLException, RuntimeException)
528 : : {
529 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
530 : 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
531 : 0 : m_aLogger.log( LogLevel::FINE, STR_LOG_RESULT_SET_CONCURRENCY, (sal_Int32)_par0 );
532 : 0 : m_nResultSetConcurrency = _par0;
533 : :
534 : 0 : clearObject();
535 : 0 : }
536 : : //------------------------------------------------------------------------------
537 : 0 : void java_sql_Statement_Base::setResultSetType(sal_Int32 _par0) throw(SQLException, RuntimeException)
538 : : {
539 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
540 : 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
541 : 0 : m_aLogger.log( LogLevel::FINE, STR_LOG_RESULT_SET_TYPE, (sal_Int32)_par0 );
542 : 0 : m_nResultSetType = _par0;
543 : :
544 : 0 : clearObject();
545 : 0 : }
546 : : //------------------------------------------------------------------------------
547 : 0 : void java_sql_Statement_Base::setFetchDirection(sal_Int32 _par0) throw(SQLException, RuntimeException)
548 : : {
549 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
550 : 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
551 : 0 : m_aLogger.log( LogLevel::FINER, STR_LOG_FETCH_DIRECTION, (sal_Int32)_par0 );
552 : 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
553 : 0 : createStatement(t.pEnv);
554 : : static jmethodID mID(NULL);
555 : 0 : callVoidMethodWithIntArg("setFetchDirection",mID,_par0,true);
556 : 0 : }
557 : : //------------------------------------------------------------------------------
558 : 0 : void java_sql_Statement_Base::setFetchSize(sal_Int32 _par0) throw(SQLException, RuntimeException)
559 : : {
560 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
561 : 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
562 : 0 : m_aLogger.log( LogLevel::FINER, STR_LOG_FETCH_SIZE, (sal_Int32)_par0 );
563 : :
564 : 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
565 : 0 : createStatement(t.pEnv);
566 : : static jmethodID mID(NULL);
567 : 0 : callVoidMethodWithIntArg("setFetchSize",mID,_par0,true);
568 : 0 : }
569 : : //------------------------------------------------------------------------------
570 : 0 : void java_sql_Statement_Base::setMaxFieldSize(sal_Int32 _par0) throw(SQLException, RuntimeException)
571 : : {
572 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
573 : 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
574 : 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
575 : 0 : createStatement(t.pEnv);
576 : : static jmethodID mID(NULL);
577 : 0 : callVoidMethodWithIntArg("setMaxFieldSize",mID,_par0,true);
578 : 0 : }
579 : : //------------------------------------------------------------------------------
580 : 0 : void java_sql_Statement_Base::setCursorName(const ::rtl::OUString &_par0) throw(SQLException, RuntimeException)
581 : : {
582 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
583 : 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
584 : 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
585 : : {
586 : 0 : createStatement(t.pEnv);
587 : : static jmethodID mID(NULL);
588 : 0 : callVoidMethodWithStringArg("setCursorName",mID,_par0);
589 : 0 : } //t.pEnv
590 : 0 : }
591 : :
592 : : // -------------------------------------------------------------------------
593 : 0 : ::cppu::IPropertyArrayHelper* java_sql_Statement_Base::createArrayHelper( ) const
594 : : {
595 : 0 : Sequence< Property > aProps(10);
596 : 0 : Property* pProperties = aProps.getArray();
597 : 0 : sal_Int32 nPos = 0;
598 : 0 : DECL_PROP0(CURSORNAME, ::rtl::OUString);
599 : 0 : DECL_BOOL_PROP0(ESCAPEPROCESSING);
600 : 0 : DECL_PROP0(FETCHDIRECTION,sal_Int32);
601 : 0 : DECL_PROP0(FETCHSIZE, sal_Int32);
602 : 0 : DECL_PROP0(MAXFIELDSIZE,sal_Int32);
603 : 0 : DECL_PROP0(MAXROWS, sal_Int32);
604 : 0 : DECL_PROP0(QUERYTIMEOUT,sal_Int32);
605 : 0 : DECL_PROP0(RESULTSETCONCURRENCY,sal_Int32);
606 : 0 : DECL_PROP0(RESULTSETTYPE,sal_Int32);
607 : 0 : DECL_BOOL_PROP0(USEBOOKMARKS);
608 : :
609 : 0 : return new ::cppu::OPropertyArrayHelper(aProps);
610 : : }
611 : :
612 : : // -------------------------------------------------------------------------
613 : 0 : ::cppu::IPropertyArrayHelper & java_sql_Statement_Base::getInfoHelper()
614 : :
615 : : {
616 : 0 : return *const_cast<java_sql_Statement_Base*>(this)->getArrayHelper();
617 : : }
618 : : // -------------------------------------------------------------------------
619 : 0 : sal_Bool java_sql_Statement_Base::convertFastPropertyValue(
620 : : Any & rConvertedValue,
621 : : Any & rOldValue,
622 : : sal_Int32 nHandle,
623 : : const Any& rValue )
624 : : throw (::com::sun::star::lang::IllegalArgumentException)
625 : : {
626 : 0 : switch(nHandle)
627 : : {
628 : : case PROPERTY_ID_QUERYTIMEOUT:
629 : 0 : return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getQueryTimeOut());
630 : : case PROPERTY_ID_MAXFIELDSIZE:
631 : 0 : return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getMaxFieldSize());
632 : : case PROPERTY_ID_MAXROWS:
633 : 0 : return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getMaxRows());
634 : : case PROPERTY_ID_CURSORNAME:
635 : 0 : return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getCursorName());
636 : : case PROPERTY_ID_RESULTSETCONCURRENCY:
637 : 0 : return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetConcurrency());
638 : : case PROPERTY_ID_RESULTSETTYPE:
639 : 0 : return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetType());
640 : : case PROPERTY_ID_FETCHDIRECTION:
641 : 0 : return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection());
642 : : case PROPERTY_ID_FETCHSIZE:
643 : 0 : return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize());
644 : : case PROPERTY_ID_ESCAPEPROCESSING:
645 : 0 : return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bEscapeProcessing );
646 : : case PROPERTY_ID_USEBOOKMARKS:
647 : : // return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAsLink);
648 : : default:
649 : : ;
650 : : }
651 : 0 : return sal_False;
652 : : }
653 : : // -------------------------------------------------------------------------
654 : 0 : void java_sql_Statement_Base::setFastPropertyValue_NoBroadcast(
655 : : sal_Int32 nHandle,
656 : : const Any& rValue
657 : : )
658 : : throw (Exception)
659 : : {
660 : 0 : switch(nHandle)
661 : : {
662 : : case PROPERTY_ID_QUERYTIMEOUT:
663 : 0 : setQueryTimeOut(comphelper::getINT32(rValue));
664 : 0 : break;
665 : : case PROPERTY_ID_MAXFIELDSIZE:
666 : 0 : setMaxFieldSize(comphelper::getINT32(rValue));
667 : 0 : break;
668 : : case PROPERTY_ID_MAXROWS:
669 : 0 : setMaxRows(comphelper::getINT32(rValue));
670 : 0 : break;
671 : : case PROPERTY_ID_CURSORNAME:
672 : 0 : setCursorName(comphelper::getString(rValue));
673 : 0 : break;
674 : : case PROPERTY_ID_RESULTSETCONCURRENCY:
675 : 0 : setResultSetConcurrency(comphelper::getINT32(rValue));
676 : 0 : break;
677 : : case PROPERTY_ID_RESULTSETTYPE:
678 : 0 : setResultSetType(comphelper::getINT32(rValue));
679 : 0 : break;
680 : : case PROPERTY_ID_FETCHDIRECTION:
681 : 0 : setFetchDirection(comphelper::getINT32(rValue));
682 : 0 : break;
683 : : case PROPERTY_ID_FETCHSIZE:
684 : 0 : setFetchSize(comphelper::getINT32(rValue));
685 : 0 : break;
686 : : case PROPERTY_ID_ESCAPEPROCESSING:
687 : 0 : setEscapeProcessing( ::comphelper::getBOOL( rValue ) );
688 : 0 : break;
689 : : case PROPERTY_ID_USEBOOKMARKS:
690 : : // return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAsLink);
691 : : default:
692 : : ;
693 : : }
694 : 0 : }
695 : : // -------------------------------------------------------------------------
696 : 0 : void java_sql_Statement_Base::getFastPropertyValue(
697 : : Any& rValue,
698 : : sal_Int32 nHandle
699 : : ) const
700 : : {
701 : 0 : java_sql_Statement_Base* THIS = const_cast<java_sql_Statement_Base*>(this);
702 : : try
703 : : {
704 : 0 : switch(nHandle)
705 : : {
706 : : case PROPERTY_ID_QUERYTIMEOUT:
707 : 0 : rValue <<= THIS->getQueryTimeOut();
708 : 0 : break;
709 : : case PROPERTY_ID_MAXFIELDSIZE:
710 : 0 : rValue <<= THIS->getMaxFieldSize();
711 : 0 : break;
712 : : case PROPERTY_ID_MAXROWS:
713 : 0 : rValue <<= THIS->getMaxRows();
714 : 0 : break;
715 : : case PROPERTY_ID_CURSORNAME:
716 : 0 : rValue <<= THIS->getCursorName();
717 : 0 : break;
718 : : case PROPERTY_ID_RESULTSETCONCURRENCY:
719 : 0 : rValue <<= THIS->getResultSetConcurrency();
720 : 0 : break;
721 : : case PROPERTY_ID_RESULTSETTYPE:
722 : 0 : rValue <<= THIS->getResultSetType();
723 : 0 : break;
724 : : case PROPERTY_ID_FETCHDIRECTION:
725 : 0 : rValue <<= THIS->getFetchDirection();
726 : 0 : break;
727 : : case PROPERTY_ID_FETCHSIZE:
728 : 0 : rValue <<= THIS->getFetchSize();
729 : 0 : break;
730 : : case PROPERTY_ID_ESCAPEPROCESSING:
731 : 0 : rValue <<= (sal_Bool)m_bEscapeProcessing;
732 : 0 : break;
733 : : case PROPERTY_ID_USEBOOKMARKS:
734 : : default:
735 : : ;
736 : : }
737 : : }
738 : 0 : catch(const Exception&)
739 : : {
740 : : }
741 : 0 : }
742 : : // -------------------------------------------------------------------------
743 : : jclass java_sql_Statement::theClass = 0;
744 : :
745 : 0 : java_sql_Statement::~java_sql_Statement()
746 : 0 : {}
747 : :
748 : 0 : jclass java_sql_Statement::getMyClass() const
749 : : {
750 : : // the class must be fetched only once, therefore static
751 : 0 : if( !theClass )
752 : 0 : theClass = findMyClass("java/sql/Statement");
753 : 0 : return theClass;
754 : : }
755 : :
756 : : // -----------------------------------------------------------------------------
757 : 0 : void java_sql_Statement::createStatement(JNIEnv* _pEnv)
758 : : {
759 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
760 : 0 : checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
761 : :
762 : 0 : if( _pEnv && !object ){
763 : : // initialize temporary variable
764 : : static const char * cSignature = "(II)Ljava/sql/Statement;";
765 : : static const char * cMethodName = "createStatement";
766 : : // Java-Call
767 : 0 : jobject out = NULL;
768 : : static jmethodID mID(NULL);
769 : 0 : if ( !mID )
770 : 0 : mID = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature );
771 : 0 : if( mID ){
772 : 0 : out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID,m_nResultSetType,m_nResultSetConcurrency );
773 : : } //mID
774 : : else
775 : : {
776 : : static const char * cSignature2 = "()Ljava/sql/Statement;";
777 : 0 : static jmethodID mID2 = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature2 );OSL_ENSURE(mID2,"Unknown method id!");
778 : 0 : if( mID2 ){
779 : 0 : out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID2);
780 : : } //mID
781 : : }
782 : 0 : ThrowLoggedSQLException( m_aLogger, _pEnv, *this );
783 : :
784 : 0 : if ( out )
785 : 0 : object = _pEnv->NewGlobalRef( out );
786 : 0 : } //_pEnv
787 : 0 : }
788 : : // -----------------------------------------------------------------------------
789 : :
790 : :
791 : 0 : IMPLEMENT_SERVICE_INFO(java_sql_Statement,"com.sun.star.sdbcx.JStatement","com.sun.star.sdbc.Statement");
792 : : // -----------------------------------------------------------------------------
793 : 0 : void SAL_CALL java_sql_Statement_Base::acquire() throw()
794 : : {
795 : 0 : java_sql_Statement_BASE::acquire();
796 : 0 : }
797 : : // -----------------------------------------------------------------------------
798 : 0 : void SAL_CALL java_sql_Statement_Base::release() throw()
799 : : {
800 : 0 : java_sql_Statement_BASE::release();
801 : 0 : }
802 : : // -----------------------------------------------------------------------------
803 : 0 : void SAL_CALL java_sql_Statement::acquire() throw()
804 : : {
805 : 0 : OStatement_BASE2::acquire();
806 : 0 : }
807 : : // -----------------------------------------------------------------------------
808 : 0 : void SAL_CALL java_sql_Statement::release() throw()
809 : : {
810 : 0 : OStatement_BASE2::release();
811 : 0 : }
812 : : // -----------------------------------------------------------------------------
813 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL java_sql_Statement_Base::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException)
814 : : {
815 : 0 : return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
816 : : }
817 : : // -----------------------------------------------------------------------------
818 : :
819 : :
820 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|