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

Generated by: LCOV version 1.10