User: hr      
Date: 2007-06-27 14:36:46+0000
Modified:
   dba/connectivity/source/drivers/jdbc/Object.cxx

Log:
 INTEGRATION: CWS sdblogging (1.22.84); FILE MERGED
 2007/04/12 09:03:15 fs 1.22.84.1: #i76119# +ThrowLoggedSQLException

File Changes:

Directory: /dba/connectivity/source/drivers/jdbc/
=================================================

File [changed]: Object.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/jdbc/Object.cxx?r1=1.22&r2=1.23
Delta lines:  +60 -32
---------------------
--- Object.cxx  2006-09-17 02:47:32+0000        1.22
+++ Object.cxx  2007-06-27 14:36:43+0000        1.23
@@ -63,10 +63,15 @@
 #include <com/sun/star/uno/Sequence.hxx>
 #endif
 
+#include "resource/jdbc_log.hrc"
+
+#include <comphelper/logging.hxx>
+
+#include <memory>
+
 using namespace connectivity;
 using namespace ::com::sun::star::uno;
 using namespace ::com::sun::star::beans;
-//     using namespace ::com::sun::star::sdbcx;
 using namespace ::com::sun::star::sdbc;
 using namespace ::com::sun::star::container;
 using namespace ::com::sun::star::lang;
@@ -240,39 +245,62 @@
        } //pEnv
        return  aStr;
 }
+
 // 
--------------------------------------------------------------------------------
-void java_lang_Object::ThrowSQLException(JNIEnv * pEnv,const Reference< 
XInterface> & _rContext) throw(SQLException, RuntimeException)
+namespace
 {
-    jthrowable jThrow = pEnv ? pEnv->ExceptionOccurred() : NULL;
-       if ( jThrow )
+    bool    lcl_translateJNIExceptionToUNOException(
+        JNIEnv* _pEnvironment, const Reference< XInterface >& _rxContext, 
SQLException& _out_rException )
        {
-               pEnv->ExceptionClear();// we have to clear the exception here 
because we want to handle it itself
-               
if(pEnv->IsInstanceOf(jThrow,java_sql_SQLException_BASE::getMyClass()))
-               {
-                       java_sql_SQLException_BASE* pException = new 
java_sql_SQLException_BASE(pEnv,jThrow);
-                       SQLException e( pException->getMessage(),
-                                                               _rContext,
-                                                               
pException->getSQLState(),
-                                                               
pException->getErrorCode(),
-                                                               Any()
-                                                       );
-                       delete pException;
-                       throw  e;
-               }
-               else 
if(pEnv->IsInstanceOf(jThrow,java_lang_Throwable::getMyClass()))
-               {
-                       java_lang_Throwable *pThrow = new 
java_lang_Throwable(pEnv,jThrow);
-                       ::rtl::OUString aMsg = pThrow->getMessage();
-                       if(!aMsg.getLength())
-                               aMsg = pThrow->getLocalizedMessage();
-                       if(!aMsg.getLength())
-                               aMsg = pThrow->toString();
-                       delete pThrow;
-                       throw 
SQLException(aMsg,_rContext,::rtl::OUString(),-1,Any());
+        jthrowable jThrow = _pEnvironment ? _pEnvironment->ExceptionOccurred() 
: NULL;
+        if ( !jThrow )
+            return false;
+
+        _pEnvironment->ExceptionClear();
+            // we have to clear the exception here because we want to handle 
it itself
+
+        if ( _pEnvironment->IsInstanceOf( jThrow, 
java_sql_SQLException_BASE::getMyClass() ) )
+        {
+            ::std::auto_ptr< java_sql_SQLException_BASE > pException( new 
java_sql_SQLException_BASE( _pEnvironment, jThrow ) );
+            _out_rException = SQLException( pException->getMessage(), 
_rxContext,
+                pException->getSQLState(), pException->getErrorCode(), Any() );
+            return true;
+        }
+        else if ( _pEnvironment->IsInstanceOf( jThrow, 
java_lang_Throwable::getMyClass() ) )
+        {
+            ::std::auto_ptr< java_lang_Throwable > pThrow( new 
java_lang_Throwable( _pEnvironment, jThrow ) );
+            ::rtl::OUString sMessage = pThrow->getMessage();
+            if ( !sMessage.getLength() )
+                sMessage = pThrow->getLocalizedMessage();
+            if(  !sMessage.getLength() )
+                sMessage = pThrow->toString();
+            _out_rException = SQLException( sMessage, _rxContext, 
::rtl::OUString(), -1, Any() );
+            return true;
                }
                else
-                       pEnv->DeleteLocalRef( jThrow );
+            _pEnvironment->DeleteLocalRef( jThrow );
+        return false;
        }
 }
 
+// 
--------------------------------------------------------------------------------
+void java_lang_Object::ThrowLoggedSQLException( const 
::comphelper::ResourceBasedEventLogger& _rLogger, JNIEnv* _pEnvironment,
+    const Reference< XInterface >& _rxContext )
+{
+    SQLException aException;
+    if ( lcl_translateJNIExceptionToUNOException( _pEnvironment, _rxContext, 
aException ) )
+    {
+        _rLogger.log( ::com::sun::star::logging::LogLevel::SEVERE, 
STR_LOG_THROWING_EXCEPTION, aException.Message, aException.SQLState, 
aException.ErrorCode );
+        throw aException;
+    }
+}
+
+// 
--------------------------------------------------------------------------------
+void java_lang_Object::ThrowSQLException( JNIEnv* _pEnvironment, const 
Reference< XInterface>& _rxContext )
+{
+    SQLException aException;
+    if ( lcl_translateJNIExceptionToUNOException( _pEnvironment, _rxContext, 
aException ) )
+        throw aException;
+}
+
 




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to