Tag: cws_src680_dba24c User: fs Date: 2007-10-29 10:59:22+0000 Modified: dba/connectivity/source/drivers/jdbc/JConnection.cxx
Log: #i83097# additional setting specifying Java methods allowed to call from inside HSQL File Changes: Directory: /dba/connectivity/source/drivers/jdbc/ ================================================= File [changed]: JConnection.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/jdbc/JConnection.cxx?r1=1.6.2.4&r2=1.6.2.5 Delta lines: +63 -2 -------------------- --- JConnection.cxx 2007-10-29 09:44:13+0000 1.6.2.4 +++ JConnection.cxx 2007-10-29 10:59:19+0000 1.6.2.5 @@ -4,9 +4,9 @@ * * $RCSfile: JConnection.cxx,v $ * - * $Revision: 1.6.2.4 $ + * $Revision: 1.6.2.5 $ * - * last change: $Author: fs $ $Date: 2007/10/29 09:44:13 $ + * last change: $Author: fs $ $Date: 2007/10/29 10:59:19 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -65,6 +65,12 @@ #ifndef _COM_SUN_STAR_SDBC_SQLWARNING_HPP_ #include <com/sun/star/sdbc/SQLWarning.hpp> #endif +#ifndef _COM_SUN_STAR_SDBC_SQLWARNING_HPP_ +#include <com/sun/star/sdbc/SQLWarning.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_NAMEDVALUE_HPP_ +#include <com/sun/star/beans/NamedValue.hpp> +#endif #ifndef _CONNECTIVITY_SQLPARSE_HXX #include "connectivity/sqlparse.hxx" #endif @@ -72,6 +78,7 @@ #include "connectivity/dbexception.hxx" #endif #include "java/util/Property.hxx" +#include "java/LocalRef.hxx" #include "resource/jdbc_log.hrc" #include "com/sun/star/uno/XComponentContext.hpp" #include "jvmaccess/classpath.hxx" @@ -907,6 +914,52 @@ return Any(); } // ----------------------------------------------------------------------------- +namespace +{ + bool lcl_setSystemProperties_nothrow( const java::sql::ConnectionLog& _rLogger, + JNIEnv& _rEnv, const Sequence< NamedValue >& _rSystemProperties ) + { + if ( _rSystemProperties.getLength() == 0 ) + // nothing to do + return true; + + LocalRef< jclass > systemClass( _rEnv ); + jmethodID nSetPropertyMethodID = 0; + // retrieve the java.lang.System class + systemClass.set( _rEnv.FindClass( "java/lang/System" ) ); + if ( systemClass.is() ) + { + nSetPropertyMethodID = _rEnv.GetStaticMethodID( + systemClass.get(), "setProperty", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;" ); + } + + if ( nSetPropertyMethodID == 0 ) + return false; + + for ( const NamedValue* pSystemProp = _rSystemProperties.getConstArray(); + pSystemProp != _rSystemProperties.getConstArray() + _rSystemProperties.getLength(); + ++pSystemProp + ) + { + ::rtl::OUString sValue; + OSL_VERIFY( pSystemProp->Value >>= sValue ); + + _rLogger.log( LogLevel::FINER, STR_LOG_SETTING_SYSTEM_PROPERTY, pSystemProp->Name, sValue ); + + LocalRef< jstring > jName( _rEnv, convertwchar_tToJavaString( &_rEnv, pSystemProp->Name ) ); + LocalRef< jstring > jValue( _rEnv, convertwchar_tToJavaString( &_rEnv, sValue ) ); + + _rEnv.CallStaticObjectMethod( systemClass.get(), nSetPropertyMethodID, jName.get(), jValue.get() ); + LocalRef< jthrowable > throwable( _rEnv, _rEnv.ExceptionOccurred() ); + if ( throwable.is() ) + return false; + } + + return true; + } +} + +// ----------------------------------------------------------------------------- void java_sql_Connection::loadDriverFromProperties( const Sequence< PropertyValue >& info ) { // contains the statement which should be used when query for automatically generated values @@ -918,6 +971,7 @@ SDBThreadAttach t; try { + Sequence< NamedValue > aSystemProperties; const PropertyValue* pJavaDriverClass = 0; const PropertyValue* pJavaDriverClassPath = 0; const PropertyValue* pBegin = info.getConstArray(); @@ -948,9 +1002,16 @@ { OSL_VERIFY( pBegin->Value >>= m_bIgnoreDriverPrivileges ); } + else if(!pBegin->Name.compareToAscii("SystemProperties")) + { + OSL_VERIFY( pBegin->Value >>= aSystemProperties ); + } } if ( !object && pJavaDriverClass != 0 ) { + if ( !lcl_setSystemProperties_nothrow( getLogger(), *t.pEnv, aSystemProperties ) ) + ThrowLoggedSQLException( getLogger(), t.pEnv, *this ); + m_pDriverClassLoader.reset(); // here I try to find the class for jdbc driver --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
