LCOV - code coverage report
Current view: top level - connectivity/source/drivers/jdbc - CallableStatement.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 165 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 34 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/CallableStatement.hxx"
      21             : #include "java/tools.hxx"
      22             : #include "java/sql/Array.hxx"
      23             : #include "java/sql/Clob.hxx"
      24             : #include "java/sql/Blob.hxx"
      25             : #include "java/sql/Connection.hxx"
      26             : #include "java/sql/Ref.hxx"
      27             : #include "java/sql/Timestamp.hxx"
      28             : #include <cppuhelper/typeprovider.hxx>
      29             : #include <cppuhelper/queryinterface.hxx>
      30             : #include <comphelper/sequence.hxx>
      31             : 
      32             : #include <string.h>
      33             : 
      34             : using namespace connectivity;
      35             : using namespace ::com::sun::star::uno;
      36             : using namespace ::com::sun::star::beans;
      37             : using namespace ::com::sun::star::sdbc;
      38             : using namespace ::com::sun::star::container;
      39             : using namespace ::com::sun::star::lang;
      40             : 
      41             : 
      42           0 : IMPLEMENT_SERVICE_INFO(java_sql_CallableStatement,"com.sun.star.sdbcx.ACallableStatement","com.sun.star.sdbc.CallableStatement");
      43             : 
      44             : 
      45             : //************ Class: java.sql.CallableStatement
      46             : 
      47           0 : java_sql_CallableStatement::java_sql_CallableStatement( JNIEnv * pEnv, java_sql_Connection& _rCon,const OUString& sql )
      48           0 :     : java_sql_PreparedStatement( pEnv, _rCon, sql )
      49             : {
      50           0 : }
      51             : 
      52           0 : java_sql_CallableStatement::~java_sql_CallableStatement()
      53             : {
      54           0 : }
      55             : 
      56             : 
      57           0 : Any SAL_CALL java_sql_CallableStatement::queryInterface( const Type & rType ) throw(RuntimeException, std::exception)
      58             : {
      59           0 :     Any aRet = java_sql_PreparedStatement::queryInterface(rType);
      60           0 :     return aRet.hasValue() ? aRet : ::cppu::queryInterface(rType,static_cast< css::sdbc::XRow*>(this),static_cast< css::sdbc::XOutParameters*>(this));
      61             : }
      62             : 
      63           0 : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL java_sql_CallableStatement::getTypes(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
      64             : {
      65           0 :     ::cppu::OTypeCollection aTypes( cppu::UnoType<css::sdbc::XRow>::get(),
      66           0 :                                     cppu::UnoType<css::sdbc::XOutParameters>::get());
      67             : 
      68           0 :     return ::comphelper::concatSequences(aTypes.getTypes(),java_sql_PreparedStatement::getTypes());
      69             : }
      70             : 
      71           0 : sal_Bool SAL_CALL java_sql_CallableStatement::wasNull(  ) throw(css::sdbc::SQLException, RuntimeException, std::exception)
      72             : {
      73           0 :     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
      74           0 :     createStatement(t.pEnv);
      75             :     static jmethodID mID(NULL);
      76           0 :     return callBooleanMethod( "wasNull", mID );
      77             : }
      78             : 
      79           0 : sal_Bool SAL_CALL java_sql_CallableStatement::getBoolean( sal_Int32 columnIndex ) throw(css::sdbc::SQLException, RuntimeException, std::exception)
      80             : {
      81           0 :     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
      82           0 :     createStatement(t.pEnv);
      83             :     static jmethodID mID(NULL);
      84           0 :     return callBooleanMethodWithIntArg( "getBoolean", mID,columnIndex );
      85             : }
      86           0 : sal_Int8 SAL_CALL java_sql_CallableStatement::getByte( sal_Int32 columnIndex ) throw(css::sdbc::SQLException, RuntimeException, std::exception)
      87             : {
      88           0 :     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
      89           0 :     createStatement(t.pEnv);
      90             :     static jmethodID mID(NULL);
      91           0 :     jbyte (JNIEnv::*pCallMethod)( jobject obj, jmethodID methodID, ... ) = &JNIEnv::CallByteMethod;
      92           0 :     return callMethodWithIntArg<jbyte>(pCallMethod,"getByte","(I)B",mID,columnIndex);
      93             : }
      94           0 : Sequence< sal_Int8 > SAL_CALL java_sql_CallableStatement::getBytes( sal_Int32 columnIndex ) throw(css::sdbc::SQLException, RuntimeException, std::exception)
      95             : {
      96           0 :     ::osl::MutexGuard aGuard( m_aMutex );
      97           0 :     checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
      98           0 :     Sequence< sal_Int8 > aSeq;
      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 :     jbyteArray out = static_cast<jbyteArray>(callObjectMethodWithIntArg(t.pEnv,"getBytes","(I)[B", mID, columnIndex));
     104           0 :     if (out)
     105             :     {
     106           0 :         jboolean p = sal_False;
     107           0 :         aSeq.realloc(t.pEnv->GetArrayLength(out));
     108           0 :         memcpy(aSeq.getArray(),t.pEnv->GetByteArrayElements(out,&p),aSeq.getLength());
     109           0 :         t.pEnv->DeleteLocalRef(out);
     110             :     }
     111           0 :     return aSeq;
     112             : }
     113           0 : ::com::sun::star::util::Date SAL_CALL java_sql_CallableStatement::getDate( sal_Int32 columnIndex ) throw(css::sdbc::SQLException, RuntimeException, std::exception)
     114             : {
     115           0 :     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
     116           0 :     createStatement(t.pEnv);
     117             :     static jmethodID mID(NULL);
     118           0 :     jobject out = callObjectMethodWithIntArg(t.pEnv,"getDate","(I)Ljava/sql/Date;", mID, columnIndex);
     119           0 :     return out ? static_cast <com::sun::star::util::Date>(java_sql_Date( t.pEnv, out )) : ::com::sun::star::util::Date();
     120             : }
     121           0 : double SAL_CALL java_sql_CallableStatement::getDouble( sal_Int32 columnIndex ) throw(css::sdbc::SQLException, RuntimeException, std::exception)
     122             : {
     123           0 :     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
     124           0 :     createStatement(t.pEnv);
     125             :     static jmethodID mID(NULL);
     126           0 :     double (JNIEnv::*pCallMethod)( jobject obj, jmethodID methodID, ... ) = &JNIEnv::CallDoubleMethod;
     127           0 :     return callMethodWithIntArg<double>(pCallMethod,"getDouble","(I)D",mID,columnIndex);
     128             : }
     129             : 
     130           0 : float SAL_CALL java_sql_CallableStatement::getFloat( sal_Int32 columnIndex ) throw(css::sdbc::SQLException, RuntimeException, std::exception)
     131             : {
     132           0 :     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
     133           0 :     createStatement(t.pEnv);
     134             :     static jmethodID mID(NULL);
     135           0 :     jfloat (JNIEnv::*pCallMethod)( jobject obj, jmethodID methodID, ... ) = &JNIEnv::CallFloatMethod;
     136           0 :     return callMethodWithIntArg<jfloat>(pCallMethod,"getFloat","(I)F",mID,columnIndex);
     137             : }
     138             : 
     139           0 : sal_Int32 SAL_CALL java_sql_CallableStatement::getInt( sal_Int32 columnIndex ) throw(css::sdbc::SQLException, RuntimeException, std::exception)
     140             : {
     141           0 :     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
     142           0 :     createStatement(t.pEnv);
     143             :     static jmethodID mID(NULL);
     144           0 :     return callIntMethodWithIntArg_ThrowSQL("getInt",mID,columnIndex);
     145             : }
     146             : 
     147           0 : sal_Int64 SAL_CALL java_sql_CallableStatement::getLong( sal_Int32 columnIndex ) throw(css::sdbc::SQLException, RuntimeException, std::exception)
     148             : {
     149           0 :     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
     150           0 :     createStatement(t.pEnv);
     151             :     static jmethodID mID(NULL);
     152           0 :     jlong (JNIEnv::*pCallMethod)( jobject obj, jmethodID methodID, ... ) = &JNIEnv::CallLongMethod;
     153           0 :     return callMethodWithIntArg<jlong>(pCallMethod,"getLong","(I)J",mID,columnIndex);
     154             : }
     155             : 
     156           0 : Any SAL_CALL java_sql_CallableStatement::getObject( sal_Int32 columnIndex, const Reference< ::com::sun::star::container::XNameAccess >& /*typeMap*/ ) throw(css::sdbc::SQLException, RuntimeException, std::exception)
     157             : {
     158           0 :     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
     159           0 :     createStatement(t.pEnv);
     160             :     static jmethodID mID(NULL);
     161           0 :     callObjectMethodWithIntArg(t.pEnv,"getObject","(I)Ljava/lang/Object;", mID, columnIndex);
     162             :     // WARNING: the caller becomes the owner of the returned pointer
     163           0 :     return Any();
     164             : }
     165             : 
     166           0 : sal_Int16 SAL_CALL java_sql_CallableStatement::getShort( sal_Int32 columnIndex ) throw(css::sdbc::SQLException, RuntimeException, std::exception)
     167             : {
     168           0 :     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
     169           0 :     createStatement(t.pEnv);
     170             :     static jmethodID mID(NULL);
     171           0 :     jshort (JNIEnv::*pCallMethod)( jobject obj, jmethodID methodID, ... ) = &JNIEnv::CallShortMethod;
     172           0 :     return callMethodWithIntArg<jshort>(pCallMethod,"getShort","(I)S",mID,columnIndex);
     173             : }
     174             : 
     175           0 : OUString SAL_CALL java_sql_CallableStatement::getString( sal_Int32 columnIndex ) throw(css::sdbc::SQLException, RuntimeException, std::exception)
     176             : {
     177           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     178           0 :     checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
     179           0 :     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
     180           0 :     createStatement(t.pEnv);
     181             :     static jmethodID mID(NULL);
     182           0 :     return callStringMethodWithIntArg("getString",mID,columnIndex);
     183             : }
     184             : 
     185           0 :  ::com::sun::star::util::Time SAL_CALL java_sql_CallableStatement::getTime( sal_Int32 columnIndex ) throw(css::sdbc::SQLException, RuntimeException, std::exception)
     186             : {
     187           0 :     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
     188           0 :     createStatement(t.pEnv);
     189             :     static jmethodID mID(NULL);
     190           0 :     jobject out = callObjectMethodWithIntArg(t.pEnv,"getTime","(I)Ljava/sql/Time;", mID, columnIndex);
     191             :     // WARNING: the caller becomes the owner of the returned pointer
     192           0 :     return out ? static_cast <com::sun::star::util::Time> (java_sql_Time( t.pEnv, out )) : ::com::sun::star::util::Time();
     193             : }
     194             : 
     195           0 :  ::com::sun::star::util::DateTime SAL_CALL java_sql_CallableStatement::getTimestamp( sal_Int32 columnIndex ) throw(css::sdbc::SQLException, RuntimeException, std::exception)
     196             : {
     197           0 :     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
     198           0 :     createStatement(t.pEnv);
     199             :     static jmethodID mID(NULL);
     200           0 :     jobject out = callObjectMethodWithIntArg(t.pEnv,"getTimestamp","(I)Ljava/sql/Timestamp;", mID, columnIndex);
     201             :     // WARNING: the caller becomes the owner of the returned pointer
     202           0 :     return out ? static_cast <com::sun::star::util::DateTime> (java_sql_Timestamp( t.pEnv, out )) : ::com::sun::star::util::DateTime();
     203             : }
     204             : 
     205           0 : void SAL_CALL java_sql_CallableStatement::registerOutParameter( sal_Int32 parameterIndex, sal_Int32 sqlType, const OUString& typeName ) throw(css::sdbc::SQLException, RuntimeException, std::exception)
     206             : {
     207           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     208           0 :     checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
     209           0 :     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
     210             : 
     211             :     {
     212           0 :         createStatement(t.pEnv);
     213             : 
     214             :         // initialize temporary variable
     215             :         static const char * cSignature = "(IILjava/lang/String;)V";
     216             :         static const char * cMethodName = "registerOutParameter";
     217             :         // execute Java-Call
     218             :         static jmethodID mID(NULL);
     219           0 :         obtainMethodId_throwSQL(t.pEnv, cMethodName,cSignature, mID);
     220             :         // Convert Parameter
     221           0 :         jdbc::LocalRef< jstring > str( t.env(),convertwchar_tToJavaString(t.pEnv,typeName));
     222           0 :         t.pEnv->CallVoidMethod( object, mID, parameterIndex,sqlType,str.get());
     223           0 :         ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
     224           0 :     }
     225           0 : }
     226           0 : void SAL_CALL java_sql_CallableStatement::registerNumericOutParameter( sal_Int32 parameterIndex, sal_Int32 sqlType, sal_Int32 scale ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
     227             : {
     228           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     229           0 :     checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
     230           0 :     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
     231             : 
     232             :     {
     233           0 :         createStatement(t.pEnv);
     234             :         // initialize temporary variable
     235             :         static const char * cSignature = "(III)V";
     236             :         static const char * cMethodName = "registerOutParameter";
     237             :         // execute Java-Call
     238             :         static jmethodID mID(NULL);
     239           0 :         obtainMethodId_throwSQL(t.pEnv, cMethodName,cSignature, mID);
     240           0 :         t.pEnv->CallVoidMethod( object, mID, parameterIndex,sqlType,scale);
     241           0 :         ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
     242           0 :     }
     243           0 : }
     244             : 
     245             : jclass java_sql_CallableStatement::theClass = 0;
     246             : 
     247           0 : jclass java_sql_CallableStatement::getMyClass() const
     248             : {
     249             :     // the class must be fetched only once, therefore static
     250           0 :     if( !theClass )
     251           0 :         theClass = findMyClass("java/sql/CallableStatement");
     252           0 :     return theClass;
     253             : }
     254             : 
     255           0 : Reference< ::com::sun::star::io::XInputStream > SAL_CALL java_sql_CallableStatement::getBinaryStream( sal_Int32 columnIndex ) throw(css::sdbc::SQLException, RuntimeException, std::exception)
     256             : {
     257           0 :     Reference< css::sdbc::XBlob > xBlob = getBlob(columnIndex);
     258           0 :     return xBlob.is() ? xBlob->getBinaryStream() : Reference< ::com::sun::star::io::XInputStream >();
     259             : }
     260           0 : Reference< ::com::sun::star::io::XInputStream > SAL_CALL java_sql_CallableStatement::getCharacterStream( sal_Int32 columnIndex ) throw(css::sdbc::SQLException, RuntimeException, std::exception)
     261             : {
     262           0 :     Reference< css::sdbc::XClob > xClob = getClob(columnIndex);
     263           0 :     return xClob.is() ? xClob->getCharacterStream() : Reference< ::com::sun::star::io::XInputStream >();
     264             : }
     265             : 
     266           0 : Reference< css::sdbc::XArray > SAL_CALL java_sql_CallableStatement::getArray( sal_Int32 columnIndex ) throw(css::sdbc::SQLException, RuntimeException, std::exception)
     267             : {
     268           0 :     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
     269           0 :     createStatement(t.pEnv);
     270             :     static jmethodID mID(NULL);
     271           0 :     jobject out = callObjectMethodWithIntArg(t.pEnv,"getArray","(I)Ljava/sql/Array;", mID, columnIndex);
     272             :     // WARNING: the caller becomes the owner of the returned pointer
     273           0 :     return out==0 ? 0 : new java_sql_Array( t.pEnv, out );
     274             : }
     275             : 
     276           0 : Reference< css::sdbc::XClob > SAL_CALL java_sql_CallableStatement::getClob( sal_Int32 columnIndex ) throw(css::sdbc::SQLException, RuntimeException, std::exception)
     277             : {
     278           0 :     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
     279           0 :     createStatement(t.pEnv);
     280             :     static jmethodID mID(NULL);
     281           0 :     jobject out = callObjectMethodWithIntArg(t.pEnv,"getClob","(I)Ljava/sql/Clob;", mID, columnIndex);
     282             :     // WARNING: the caller becomes the owner of the returned pointer
     283           0 :     return out==0 ? 0 : new java_sql_Clob( t.pEnv, out );
     284             : }
     285           0 : Reference< css::sdbc::XBlob > SAL_CALL java_sql_CallableStatement::getBlob( sal_Int32 columnIndex ) throw(css::sdbc::SQLException, RuntimeException, std::exception)
     286             : {
     287           0 :     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
     288           0 :     createStatement(t.pEnv);
     289             :     static jmethodID mID(NULL);
     290           0 :     jobject out = callObjectMethodWithIntArg(t.pEnv,"getBlob","(I)Ljava/sql/Blob;", mID, columnIndex);
     291             :     // WARNING: the caller becomes the owner of the returned pointer
     292           0 :     return out==0 ? 0 : new java_sql_Blob( t.pEnv, out );
     293             : }
     294             : 
     295           0 : Reference< css::sdbc::XRef > SAL_CALL java_sql_CallableStatement::getRef( sal_Int32 columnIndex ) throw(css::sdbc::SQLException, RuntimeException, std::exception)
     296             : {
     297           0 :     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
     298           0 :     createStatement(t.pEnv);
     299             :     static jmethodID mID(NULL);
     300           0 :     jobject out = callObjectMethodWithIntArg(t.pEnv,"getRef","(I)Ljava/sql/Ref;", mID, columnIndex);
     301             :     // WARNING: the caller becomes the owner of the returned pointer
     302           0 :     return out==0 ? 0 : new java_sql_Ref( t.pEnv, out );
     303             : }
     304             : 
     305           0 : void SAL_CALL java_sql_CallableStatement::acquire() throw()
     306             : {
     307           0 :     java_sql_PreparedStatement::acquire();
     308           0 : }
     309             : 
     310           0 : void SAL_CALL java_sql_CallableStatement::release() throw()
     311             : {
     312           0 :     java_sql_PreparedStatement::release();
     313           0 : }
     314             : 
     315           0 : void java_sql_CallableStatement::createStatement(JNIEnv* /*_pEnv*/)
     316             : {
     317           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     318           0 :     checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
     319             : 
     320             : 
     321           0 :     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
     322           0 :     if( t.pEnv && !object ){
     323             :         // initialize temporary variable
     324             :         static const char * cMethodName = "prepareCall";
     325             :         // execute Java-Call
     326           0 :         jobject out = NULL;
     327             :         // convert Parameter
     328           0 :         jdbc::LocalRef< jstring > str( t.env(),convertwchar_tToJavaString(t.pEnv,m_sSqlStatement));
     329             : 
     330             :         static jmethodID mID(NULL);
     331           0 :         if ( !mID  )
     332             :         {
     333             :             static const char * cSignature = "(Ljava/lang/String;II)Ljava/sql/CallableStatement;";
     334           0 :             mID  = t.pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature );
     335             :         }
     336           0 :         if( mID ){
     337           0 :             out = t.pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID, str.get() ,m_nResultSetType,m_nResultSetConcurrency);
     338             :         } //mID
     339             :         else
     340             :         {
     341             :             static const char * cSignature2 = "(Ljava/lang/String;)Ljava/sql/CallableStatement;";
     342           0 :             static jmethodID mID2 = t.pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature2 );OSL_ENSURE(mID2,"Unknown method id!");
     343           0 :             if( mID2 ){
     344           0 :                 out = t.pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID2, str.get() );
     345             :             } //mID
     346             :         }
     347           0 :         ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
     348             : 
     349           0 :         if ( out )
     350           0 :             object = t.pEnv->NewGlobalRef( out );
     351           0 :     } //t.pEnv
     352           0 : }
     353             : 
     354             : 
     355             : 
     356             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11