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

Generated by: LCOV version 1.10