Tag: mws_oog680 User: kz Date: 2007-10-30 14:03:03+0000 Modified: dba/connectivity/source/drivers/jdbc/JConnection.cxx
Log: INTEGRATION: CWS hsql1808 (1.5.14); FILE MERGED 2007/10/16 13:11:20 fs 1.5.14.2: support additional setting 'SystemProperties', which denotes properties to the set via java.lang.System.setProperty 2007/07/30 07:22:06 fs 1.5.14.1: getWarning should return a warning, not an error 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.5&r2=1.5.22.1 Delta lines: +73 -3 -------------------- --- JConnection.cxx 2007-06-27 14:35:59+0000 1.5 +++ JConnection.cxx 2007-10-30 14:03:00+0000 1.5.22.1 @@ -63,6 +63,12 @@ #ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ #include <com/sun/star/lang/DisposedException.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 @@ -70,6 +76,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" @@ -80,6 +87,7 @@ #include <memory> using namespace connectivity; +using namespace connectivity::jdbc; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbc; @@ -797,14 +805,68 @@ if( out ) { java_sql_SQLWarning_BASE warn_base(t.pEnv, out); - return makeAny( - static_cast< starsdbc::SQLException >( - java_sql_SQLWarning(warn_base,*this))); + SQLException aAsException( static_cast< starsdbc::SQLException >( java_sql_SQLWarning( warn_base, *this ) ) ); + + // translate to warning + SQLWarning aWarning; + aWarning.Context = aAsException.Context; + aWarning.Message = aAsException.Message; + aWarning.SQLState = aAsException.SQLState; + aWarning.ErrorCode = aAsException.ErrorCode; + aWarning.NextException = aAsException.NextException; + + return makeAny( aWarning ); } 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, ::rtl::OUString& _rsGeneratedValueStatement, sal_Bool& _rbAutoRetrievingEnabled, sal_Bool& _bParameterSubstitution, sal_Bool& _bIgnoreDriverPrivileges ) @@ -813,6 +875,7 @@ SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); try { + Sequence< NamedValue > aSystemProperties; const PropertyValue* pJavaDriverClass = 0; const PropertyValue* pJavaDriverClassPath = 0; const PropertyValue* pBegin = info.getConstArray(); @@ -843,9 +906,16 @@ { OSL_VERIFY( pBegin->Value >>= _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 ); + // here I try to find the class for jdbc driver java_sql_SQLException_BASE::getMyClass(); java_lang_Throwable::getMyClass(); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
