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

Generated by: LCOV version 1.10