LCOV - code coverage report
Current view: top level - connectivity/source/drivers/jdbc - JStatement.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 145 405 35.8 %
Date: 2014-11-03 Functions: 22 61 36.1 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10