LCOV - code coverage report
Current view: top level - connectivity/source/drivers/jdbc - tools.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 90 135 66.7 %
Date: 2014-11-03 Functions: 9 12 75.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             : 
      21             : #include <string.h>
      22             : #include <cstdarg>
      23             : #include "java/tools.hxx"
      24             : #include "java/lang/String.hxx"
      25             : #include "java/lang/Class.hxx"
      26             : #include "java/util/Property.hxx"
      27             : #include <com/sun/star/sdbc/DriverPropertyInfo.hpp>
      28             : #include <com/sun/star/container/XNameAccess.hpp>
      29             : #include <connectivity/dbexception.hxx>
      30             : 
      31             : using namespace connectivity;
      32             : using namespace ::com::sun::star::uno;
      33             : using namespace ::com::sun::star::beans;
      34             : using namespace ::com::sun::star::sdbc;
      35             : using namespace ::com::sun::star::container;
      36             : using namespace ::com::sun::star::lang;
      37             : 
      38          16 : void java_util_Properties::setProperty(const OUString& key, const OUString& value)
      39             : {
      40          16 :     SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
      41          16 :     jobject out(0);
      42             : 
      43             :     {
      44             :         jvalue args[2];
      45             :         // Convert Parameter
      46          16 :         args[0].l = convertwchar_tToJavaString(t.pEnv,key);
      47          16 :         args[1].l = convertwchar_tToJavaString(t.pEnv,value);
      48             :         // Initialize temporary Variables
      49             :         static const char * cSignature = "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;";
      50             :         static const char * cMethodName = "setProperty";
      51             :         // Turn off Java-Call
      52             :         static jmethodID mID(NULL);
      53          16 :         obtainMethodId_throwSQL(t.pEnv, cMethodName,cSignature, mID);
      54          16 :         out = t.pEnv->CallObjectMethod(object, mID, args[0].l,args[1].l);
      55          16 :         ThrowSQLException(t.pEnv,NULL);
      56          16 :         t.pEnv->DeleteLocalRef(static_cast<jstring>(args[1].l));
      57          16 :         t.pEnv->DeleteLocalRef(static_cast<jstring>(args[0].l));
      58          16 :         ThrowSQLException(t.pEnv,0);
      59          16 :         if(out)
      60           0 :             t.pEnv->DeleteLocalRef(out);
      61          16 :     } //t.pEnv
      62             :     // WARNING: The caller will be owner of the returned pointers!!!
      63          16 : }
      64             : jclass java_util_Properties::theClass = 0;
      65             : 
      66           8 : java_util_Properties::~java_util_Properties()
      67           8 : {}
      68             : 
      69          12 : jclass java_util_Properties::getMyClass() const
      70             : {
      71             :     // the class needs only be called once, that is why it is static
      72          12 :     if( !theClass )
      73           4 :         theClass = findMyClass("java/util/Properties");
      74          12 :     return theClass;
      75             : }
      76             : 
      77             : 
      78           4 : java_util_Properties::java_util_Properties( ): java_lang_Object( NULL, (jobject)NULL )
      79             : {
      80           4 :     SDBThreadAttach t;
      81           4 :     if( !t.pEnv )
      82           4 :         return;
      83             :     // Turn off Java-Call for the constructor
      84             :     // Initialize temperary Variables
      85             :     static const char * cSignature = "()V";
      86             :     jobject tempObj;
      87             :     static jmethodID mID(NULL);
      88           4 :     obtainMethodId_throwSQL(t.pEnv, "<init>",cSignature, mID);
      89           4 :     tempObj = t.pEnv->NewObject( getMyClass(), mID);
      90           4 :     saveRef( t.pEnv, tempObj );
      91           4 :     t.pEnv->DeleteLocalRef( tempObj );
      92             : }
      93             : 
      94             : 
      95         114 : jstring connectivity::convertwchar_tToJavaString(JNIEnv *pEnv,const OUString& _rTemp)
      96             : {
      97             :     OSL_ENSURE(pEnv,"Environment is NULL!");
      98         114 :     jstring pStr = pEnv->NewString(_rTemp.getStr(), _rTemp.getLength());
      99         114 :     pEnv->ExceptionClear();
     100             :     OSL_ENSURE(pStr,"Could not create a jsstring object!");
     101         114 :     return pStr;
     102             : }
     103             : 
     104             : 
     105           4 : java_util_Properties* connectivity::createStringPropertyArray(const Sequence< PropertyValue >& info )  throw(SQLException, RuntimeException)
     106             : {
     107           4 :     java_util_Properties* pProps = new java_util_Properties();
     108           4 :     const PropertyValue* pBegin = info.getConstArray();
     109           4 :     const PropertyValue* pEnd   = pBegin + info.getLength();
     110             : 
     111          44 :     for(;pBegin != pEnd;++pBegin)
     112             :     {
     113             :         // these are properties used internally by LibreOffice,
     114             :         // and should not be passed to the JDBC driver
     115             :         // (which probably does not know anything about them anyway).
     116          80 :         if  (   pBegin->Name != "JavaDriverClass"
     117          36 :             &&  pBegin->Name != "JavaDriverClassPath"
     118          32 :             &&  pBegin->Name != "SystemProperties"
     119          28 :             &&  pBegin->Name != "CharSet"
     120          28 :             &&  pBegin->Name != "AppendTableAliasName"
     121          28 :             &&  pBegin->Name != "AddIndexAppendix"
     122          28 :             &&  pBegin->Name != "FormsCheckRequiredFields"
     123          28 :             &&  pBegin->Name != "GenerateASBeforeCorrelationName"
     124          28 :             &&  pBegin->Name != "EscapeDateTime"
     125          28 :             &&  pBegin->Name != "ParameterNameSubstitution"
     126          28 :             &&  pBegin->Name != "IsPasswordRequired"
     127          28 :             &&  pBegin->Name != "IsAutoRetrievingEnabled"
     128          24 :             &&  pBegin->Name != "AutoRetrievingStatement"
     129          20 :             &&  pBegin->Name != "UseCatalogInSelect"
     130          20 :             &&  pBegin->Name != "UseSchemaInSelect"
     131          20 :             &&  pBegin->Name != "AutoIncrementCreation"
     132          20 :             &&  pBegin->Name != "Extension"
     133          20 :             &&  pBegin->Name != "NoNameLengthLimit"
     134          20 :             &&  pBegin->Name != "EnableSQL92Check"
     135          20 :             &&  pBegin->Name != "EnableOuterJoinEscape"
     136          20 :             &&  pBegin->Name != "BooleanComparisonMode"
     137          20 :             &&  pBegin->Name != "IgnoreCurrency"
     138          20 :             &&  pBegin->Name != "TypeInfoSettings"
     139          20 :             &&  pBegin->Name != "IgnoreDriverPrivileges"
     140          16 :             &&  pBegin->Name != "ImplicitCatalogRestriction"
     141          16 :             &&  pBegin->Name != "ImplicitSchemaRestriction"
     142          16 :             &&  pBegin->Name != "SupportsTableCreation"
     143          16 :             &&  pBegin->Name != "UseJava"
     144          16 :             &&  pBegin->Name != "Authentication"
     145          16 :             &&  pBegin->Name != "PreferDosLikeLineEnds"
     146          16 :             &&  pBegin->Name != "PrimaryKeySupport"
     147          56 :             &&  pBegin->Name != "RespectDriverResultSetType"
     148             :             )
     149             :         {
     150          16 :             OUString aStr;
     151          16 :             OSL_VERIFY( pBegin->Value >>= aStr );
     152          16 :             pProps->setProperty(pBegin->Name,aStr);
     153             :         }
     154             :     }
     155           4 :     return pProps;
     156             : }
     157             : 
     158        8206 : OUString connectivity::JavaString2String(JNIEnv *pEnv,jstring _Str)
     159             : {
     160        8206 :     OUString aStr;
     161        8206 :     if(_Str)
     162             :     {
     163        8190 :         jboolean bCopy(sal_True);
     164        8190 :         const jchar* pChar = pEnv->GetStringChars(_Str,&bCopy);
     165        8190 :         jsize len = pEnv->GetStringLength(_Str);
     166        8190 :         aStr = OUString(pChar,len);
     167             : 
     168        8190 :         if(bCopy)
     169        8190 :             pEnv->ReleaseStringChars(_Str,pChar);
     170        8190 :         pEnv->DeleteLocalRef(_Str);
     171             :     }
     172        8206 :     return aStr;
     173             : }
     174             : 
     175           0 : jobject connectivity::convertTypeMapToJavaMap(JNIEnv* /*pEnv*/,const Reference< ::com::sun::star::container::XNameAccess > & _rMap)
     176             : {
     177           0 :     if ( _rMap.is() )
     178             :     {
     179           0 :         ::com::sun::star::uno::Sequence< OUString > aNames = _rMap->getElementNames();
     180           0 :         if ( aNames.getLength() > 0 )
     181           0 :             ::dbtools::throwFeatureNotImplementedSQLException( "Type maps", NULL );
     182             :     }
     183           0 :     return 0;
     184             : }
     185             : 
     186          52 : bool connectivity::isExceptionOccurred(JNIEnv *pEnv,bool _bClear)
     187             : {
     188          52 :     if ( !pEnv )
     189           0 :         return false;
     190             : 
     191          52 :     jthrowable pThrowable = pEnv->ExceptionOccurred();
     192          52 :     bool bRet = pThrowable != NULL;
     193          52 :     if ( pThrowable )
     194             :     {
     195           0 :         if ( _bClear )
     196           0 :             pEnv->ExceptionClear();
     197             : #if OSL_DEBUG_LEVEL > 1
     198             :         if(pEnv->IsInstanceOf(pThrowable,java_sql_SQLException_BASE::st_getMyClass()))
     199             :         {
     200             : 
     201             :             java_sql_SQLException_BASE* pException = new java_sql_SQLException_BASE(pEnv,pThrowable);
     202             :             OUString sError = pException->getMessage();
     203             :             delete pException;
     204             :         }
     205             : #else
     206           0 :         pEnv->DeleteLocalRef(pThrowable);
     207             : #endif
     208             : 
     209             :     }
     210             : 
     211          52 :     return bRet;
     212             : }
     213             : 
     214           0 : jobject connectivity::createByteInputStream(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& x,sal_Int32 length)
     215             : {
     216           0 :     SDBThreadAttach t;
     217           0 :     if( !t.pEnv || !x.is() )
     218           0 :         return NULL;
     219             :     // Turn off Java-Call for the constructor
     220             :     // Initialize temperary variables
     221           0 :     jclass clazz = java_lang_Object::findMyClass("java/io/ByteArrayInputStream");
     222             :     static jmethodID mID(NULL);
     223           0 :     if  ( !mID )
     224             :     {
     225             :         static const char * cSignature = "([B)V";
     226           0 :         mID  = t.pEnv->GetMethodID( clazz, "<init>", cSignature );
     227             :         OSL_ENSURE( mID, cSignature );
     228           0 :         if  ( !mID )
     229           0 :             throw SQLException();
     230             :     } // if  ( !_inout_MethodID )
     231           0 :     jbyteArray pByteArray = t.pEnv->NewByteArray(length);
     232           0 :     Sequence< sal_Int8 > aData;
     233           0 :     x->readBytes(aData,length);
     234           0 :     jboolean p = sal_False;
     235           0 :     memcpy(t.pEnv->GetByteArrayElements(pByteArray,&p),aData.getArray(),aData.getLength());
     236           0 :     jobject out = t.pEnv->NewObject( clazz, mID,pByteArray);
     237           0 :     t.pEnv->DeleteLocalRef((jbyteArray)pByteArray);
     238           0 :     return out;
     239             : }
     240             : 
     241           0 : jobject connectivity::createCharArrayReader(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& x,sal_Int32 length)
     242             : {
     243           0 :     SDBThreadAttach t;
     244           0 :     if( !t.pEnv || !x.is() )
     245           0 :         return NULL;
     246             :     // Turn off Java-Call for the constructor
     247             :     // Initialize temperary Variables
     248           0 :     jclass clazz = java_lang_Object::findMyClass("java/io/CharArrayReader");
     249             :     static jmethodID mID(NULL);
     250           0 :     if  ( !mID )
     251             :     {
     252             :         static const char * cSignature = "([C)V";
     253           0 :         mID  = t.pEnv->GetMethodID( clazz, "<init>", cSignature );
     254             :         OSL_ENSURE( mID, cSignature );
     255           0 :         if  ( !mID )
     256           0 :             throw SQLException();
     257             :     } // if  ( !_inout_MethodID )
     258           0 :     jcharArray pCharArray = t.pEnv->NewCharArray(length);
     259           0 :     Sequence< sal_Int8 > aData;
     260           0 :     x->readBytes(aData,length);
     261           0 :     jboolean p = sal_False;
     262           0 :     memcpy(t.pEnv->GetCharArrayElements(pCharArray,&p),aData.getArray(),aData.getLength());
     263           0 :     jobject out = t.pEnv->NewObject( clazz, mID,pCharArray);
     264           0 :     t.pEnv->DeleteLocalRef((jcharArray)pCharArray);
     265           0 :     return out;
     266             : }
     267             : 
     268             : 
     269             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10