diff options
author | Ocke Janssen <oj@openoffice.org> | 2002-11-01 09:58:49 +0000 |
---|---|---|
committer | Ocke Janssen <oj@openoffice.org> | 2002-11-01 09:58:49 +0000 |
commit | 11fc9bd38fe690edc1a5db3ca8b0f385489e953e (patch) | |
tree | e6dab7ec756c6284fcaa9e587b414d6e85402d09 /connectivity | |
parent | 0b9e50e2b5f04a943ce673042251bf79f0e79572 (diff) |
#104636# correct exception handling
Diffstat (limited to 'connectivity')
-rw-r--r-- | connectivity/source/drivers/jdbc/DatabaseMetaData.cxx | 48 | ||||
-rw-r--r-- | connectivity/source/drivers/jdbc/Object.cxx | 27 | ||||
-rw-r--r-- | connectivity/source/drivers/jdbc/ResultSet.cxx | 27 | ||||
-rw-r--r-- | connectivity/source/drivers/jdbc/tools.cxx | 30 | ||||
-rw-r--r-- | connectivity/source/inc/java/tools.hxx | 14 |
5 files changed, 94 insertions, 52 deletions
diff --git a/connectivity/source/drivers/jdbc/DatabaseMetaData.cxx b/connectivity/source/drivers/jdbc/DatabaseMetaData.cxx index 48707b0e2a40..84921dfc5701 100644 --- a/connectivity/source/drivers/jdbc/DatabaseMetaData.cxx +++ b/connectivity/source/drivers/jdbc/DatabaseMetaData.cxx @@ -2,9 +2,9 @@ * * $RCSfile: DatabaseMetaData.cxx,v $ * - * $Revision: 1.12 $ + * $Revision: 1.13 $ * - * last change: $Author: oj $ $Date: 2002-10-25 09:07:21 $ + * last change: $Author: oj $ $Date: 2002-11-01 10:58:36 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -301,8 +301,7 @@ Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getTables( char * cMethodName = "getTables"; // Java-Call absetzen jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature );OSL_ENSURE(mID,"Unknown method id!"); - t.pEnv->ExceptionClear(); - OSL_ENSURE(!t.pEnv->ExceptionOccurred(),"Exception occured!"); + sal_Bool bExcepOccured = isExceptionOccured(t.pEnv,sal_True); OSL_ENSURE(!bExcepOccured,"Exception occured!"); if( mID ) { jvalue args[4]; @@ -310,16 +309,16 @@ Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getTables( if(len) { jobjectArray pObjArray = t.pEnv->NewObjectArray((jsize) len, java_lang_String::getMyClass(), 0); - OSL_ENSURE(!t.pEnv->ExceptionOccurred(),"Exception occured!"); - t.pEnv->ExceptionClear(); + sal_Bool bExcepOccured = isExceptionOccured(t.pEnv,sal_True); OSL_ENSURE(!bExcepOccured,"Exception occured!"); + const ::rtl::OUString* pBegin = types.getConstArray(); for(sal_Int32 i=0;i<len;i++,++pBegin) { jstring aT = convertwchar_tToJavaString(t.pEnv,*pBegin); //jstring aT = t.pEnv->NewStringUTF(_par3.GetToken(i)); t.pEnv->SetObjectArrayElement(pObjArray,(jsize)i,aT); - OSL_ENSURE(!t.pEnv->ExceptionOccurred(),"Exception occured!"); - t.pEnv->ExceptionClear(); + sal_Bool bExcepOccured = isExceptionOccured(t.pEnv,sal_True); OSL_ENSURE(!bExcepOccured,"Exception occured!"); + } args[3].l = pObjArray; }else @@ -329,27 +328,46 @@ Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getTables( args[1].l = schemaPattern.toChar() == '%' ? NULL : convertwchar_tToJavaString(t.pEnv,schemaPattern); args[2].l = convertwchar_tToJavaString(t.pEnv,tableNamePattern); out = t.pEnv->CallObjectMethod( object, mID, args[0].l, args[1].l,args[2].l,args[3].l); - OSL_ENSURE(!t.pEnv->ExceptionOccurred(),"Exception occured!"); - t.pEnv->ExceptionClear(); + jthrowable jThrow = t.pEnv->ExceptionOccurred(); + if ( jThrow ) + t.pEnv->ExceptionClear();// we have to clear the exception here because we want to handle it itself + + sal_Bool bExcepOccured; + if(catalog.hasValue()) { t.pEnv->DeleteLocalRef((jstring)args[0].l); - OSL_ENSURE(!t.pEnv->ExceptionOccurred(),"Exception occured!"); + bExcepOccured = isExceptionOccured(t.pEnv,sal_True); OSL_ENSURE(!bExcepOccured,"Exception occured!"); } if(args[1].l) { t.pEnv->DeleteLocalRef((jstring)args[1].l); - OSL_ENSURE(!t.pEnv->ExceptionOccurred(),"Exception occured!"); + bExcepOccured = isExceptionOccured(t.pEnv,sal_True); OSL_ENSURE(!bExcepOccured,"Exception occured!"); } if(tableNamePattern.getLength()) { t.pEnv->DeleteLocalRef((jstring)args[2].l); - OSL_ENSURE(!t.pEnv->ExceptionOccurred(),"Exception occured!"); + bExcepOccured = isExceptionOccured(t.pEnv,sal_True); OSL_ENSURE(!bExcepOccured,"Exception occured!"); } //for(INT16 i=0;i<len;i++) t.pEnv->DeleteLocalRef((jobjectArray)args[3].l); - OSL_ENSURE(!t.pEnv->ExceptionOccurred(),"Exception occured!"); - ThrowSQLException(t.pEnv,*this); + bExcepOccured = isExceptionOccured(t.pEnv,sal_True); OSL_ENSURE(!bExcepOccured,"Exception occured!"); + + if ( jThrow ) + { + if(t.pEnv->IsInstanceOf(jThrow,java_sql_SQLException_BASE::getMyClass())) + { + java_sql_SQLException_BASE* pException = new java_sql_SQLException_BASE(t.pEnv,jThrow); + SQLException e( pException->getMessage(), + *this, + pException->getSQLState(), + pException->getErrorCode(), + Any() + ); + delete pException; + throw e; + } + } } //mID } //t.pEnv diff --git a/connectivity/source/drivers/jdbc/Object.cxx b/connectivity/source/drivers/jdbc/Object.cxx index 5332b3944109..30738b07263f 100644 --- a/connectivity/source/drivers/jdbc/Object.cxx +++ b/connectivity/source/drivers/jdbc/Object.cxx @@ -2,9 +2,9 @@ * * $RCSfile: Object.cxx,v $ * - * $Revision: 1.10 $ + * $Revision: 1.11 $ * - * last change: $Author: oj $ $Date: 2001-10-19 11:14:28 $ + * last change: $Author: oj $ $Date: 2002-11-01 10:58:36 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -168,14 +168,9 @@ int SDB_JRE_InitJava(const Reference<XMultiServiceFactory >& _rxFactory) // } } - catch (Exception e) + catch (Exception& e) { - if (pEnv && pEnv->ExceptionOccurred()) - { - pEnv->ExceptionDescribe(); - pEnv->ExceptionClear(); - } - + isExceptionOccured(pEnv,sal_True); result = -1; } @@ -194,25 +189,19 @@ int SDB_JRE_InitJava(const Reference<XMultiServiceFactory >& _rxFactory) SDBThreadAttach::SDBThreadAttach() : bDetach(sal_False), pEnv(NULL) { attachThread(pEnv); - if(pEnv && pEnv->ExceptionOccurred()) - pEnv->ExceptionClear(); + isExceptionOccured(pEnv,sal_True); } SDBThreadAttach::SDBThreadAttach(const Reference<XMultiServiceFactory >& _rxFactory) : bDetach(sal_False), pEnv(NULL) { attachThread(pEnv,_rxFactory); - if(pEnv && pEnv->ExceptionOccurred()) - pEnv->ExceptionClear(); + isExceptionOccured(pEnv,sal_True); } SDBThreadAttach::~SDBThreadAttach() { - if(pEnv && pEnv->ExceptionOccurred()) - { - OSL_ENSURE(0,"Exception occured in JNI!"); - pEnv->ExceptionClear(); - } - + sal_Bool bOk = isExceptionOccured(pEnv,sal_True); + OSL_ENSURE(!bOk,"Exception occured in JNI!"); detachThread(); } diff --git a/connectivity/source/drivers/jdbc/ResultSet.cxx b/connectivity/source/drivers/jdbc/ResultSet.cxx index 6a6ddff6cc6a..548c3b2f4e3b 100644 --- a/connectivity/source/drivers/jdbc/ResultSet.cxx +++ b/connectivity/source/drivers/jdbc/ResultSet.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ResultSet.cxx,v $ * - * $Revision: 1.15 $ + * $Revision: 1.16 $ * - * last change: $Author: vg $ $Date: 2001-11-13 15:07:00 $ + * last change: $Author: oj $ $Date: 2002-11-01 10:58:36 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -1518,8 +1518,8 @@ sal_Int32 java_sql_ResultSet::getResultSetConcurrency() const throw(::com::sun:: if( mID ){ out = t.pEnv->CallIntMethod( object, mID); // special case here most JDBC 1.x doesn't support this feature so we just clear the exception when they occured - if(t.pEnv->ExceptionOccurred()) - t.pEnv->ExceptionClear(); + isExceptionOccured(t.pEnv,sal_True); + } //mID } //t.pEnv return (sal_Int32)out; @@ -1539,8 +1539,8 @@ sal_Int32 java_sql_ResultSet::getResultSetType() const throw(::com::sun::star::s if( mID ){ out = t.pEnv->CallIntMethod( object, mID); // special case here most JDBC 1.x doesn't support this feature so we just clear the exception when they occured - if(t.pEnv->ExceptionOccurred()) - t.pEnv->ExceptionClear(); + isExceptionOccured(t.pEnv,sal_True); + } //mID } //t.pEnv return (sal_Int32)out; @@ -1559,8 +1559,8 @@ sal_Int32 java_sql_ResultSet::getFetchDirection() const throw(::com::sun::star:: if( mID ){ out = t.pEnv->CallIntMethod( object, mID); // special case here most JDBC 1.x doesn't support this feature so we just clear the exception when they occured - if(t.pEnv->ExceptionOccurred()) - t.pEnv->ExceptionClear(); + isExceptionOccured(t.pEnv,sal_True); + } //mID } //t.pEnv return (sal_Int32)out; @@ -1579,8 +1579,8 @@ sal_Int32 java_sql_ResultSet::getFetchSize() const throw(::com::sun::star::sdbc: if( mID ){ out = t.pEnv->CallIntMethod( object, mID); // special case here most JDBC 1.x doesn't support this feature so we just clear the exception when they occured - if(t.pEnv->ExceptionOccurred()) - t.pEnv->ExceptionClear(); + isExceptionOccured(t.pEnv,sal_True); + } //mID } //t.pEnv return (sal_Int32)out; @@ -1621,8 +1621,8 @@ void java_sql_ResultSet::setFetchDirection(sal_Int32 _par0) throw(::com::sun::st if( mID ){ t.pEnv->CallVoidMethod( object, mID,_par0); // special case here most JDBC 1.x doesn't support this feature so we just clear the exception when they occured - if(t.pEnv->ExceptionOccurred()) - t.pEnv->ExceptionClear(); + isExceptionOccured(t.pEnv,sal_True); + } //mID } //t.pEnv @@ -1658,8 +1658,7 @@ void java_sql_ResultSet::setFetchSize(sal_Int32 _par0) throw(::com::sun::star::s if( mID ){ t.pEnv->CallVoidMethod( object, mID,_par0); // special case here most JDBC 1.x doesn't support this feature so we just clear the exception when they occured - if(t.pEnv->ExceptionOccurred()) - t.pEnv->ExceptionClear(); + isExceptionOccured(t.pEnv,sal_True); } //mID } //t.pEnv diff --git a/connectivity/source/drivers/jdbc/tools.cxx b/connectivity/source/drivers/jdbc/tools.cxx index 4baf83a2c482..605cbf0e60fd 100644 --- a/connectivity/source/drivers/jdbc/tools.cxx +++ b/connectivity/source/drivers/jdbc/tools.cxx @@ -2,9 +2,9 @@ * * $RCSfile: tools.cxx,v $ * - * $Revision: 1.10 $ + * $Revision: 1.11 $ * - * last change: $Author: oj $ $Date: 2002-08-01 07:15:16 $ + * last change: $Author: oj $ $Date: 2002-11-01 10:58:36 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -224,5 +224,31 @@ jobject connectivity::XNameAccess2Map(JNIEnv *pEnv,const Reference< ::com::sun:: } return 0; } +// ----------------------------------------------------------------------------- +sal_Bool connectivity::isExceptionOccured(JNIEnv *pEnv,sal_Bool _bClear) +{ + OSL_ENSURE(pEnv,"Java env not valid! Prepare for GPF. For performace reason there is not check for NULL here. :-("); + jthrowable pThrowable = pEnv->ExceptionOccurred(); + sal_Bool bRet = pThrowable != NULL; + if ( pThrowable ) + { + if ( _bClear ) + pEnv->ExceptionClear(); +#ifdef DEBUG + if(pEnv->IsInstanceOf(pThrowable,java_sql_SQLException_BASE::getMyClass())) + { + + java_sql_SQLException_BASE* pException = new java_sql_SQLException_BASE(pEnv,pThrowable); + ::rtl::OUString sError = pException->getMessage(); + delete pException; + } +#else + pEnv->DeleteLocalRef(pThrowable); +#endif + + } + + return bRet; +} diff --git a/connectivity/source/inc/java/tools.hxx b/connectivity/source/inc/java/tools.hxx index fcc047807006..44caf9316d91 100644 --- a/connectivity/source/inc/java/tools.hxx +++ b/connectivity/source/inc/java/tools.hxx @@ -2,9 +2,9 @@ * * $RCSfile: tools.hxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: oj $ $Date: 2002-08-01 07:16:22 $ + * last change: $Author: oj $ $Date: 2002-11-01 10:58:49 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -121,6 +121,16 @@ namespace connectivity ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > Map2XNameAccess(JNIEnv *pEnv,jobject _pMap); jobject XNameAccess2Map(JNIEnv *pEnv,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > & _rMap); + + /** return if a exception occured + @param pEnv + The native java env + @param _bClear + <TRUE/> if the execption should be cleared + @return + <TRUE/> if an exception is occured + */ + sal_Bool isExceptionOccured(JNIEnv *pEnv,sal_Bool _bClear); } #endif // _CONNECTIVITY_JAVA_TOOLS_HXX_ |