Kaydet (Commit) 11fc9bd3 authored tarafından Ocke Janssen's avatar Ocke Janssen

#104636# correct exception handling

üst 0b9e50e2
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: DatabaseMetaData.cxx,v $ * $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 * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -301,8 +301,7 @@ Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getTables( ...@@ -301,8 +301,7 @@ Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getTables(
char * cMethodName = "getTables"; char * cMethodName = "getTables";
// Java-Call absetzen // Java-Call absetzen
jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature );OSL_ENSURE(mID,"Unknown method id!"); jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature );OSL_ENSURE(mID,"Unknown method id!");
t.pEnv->ExceptionClear(); sal_Bool bExcepOccured = isExceptionOccured(t.pEnv,sal_True); OSL_ENSURE(!bExcepOccured,"Exception occured!");
OSL_ENSURE(!t.pEnv->ExceptionOccurred(),"Exception occured!");
if( mID ) if( mID )
{ {
jvalue args[4]; jvalue args[4];
...@@ -310,16 +309,16 @@ Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getTables( ...@@ -310,16 +309,16 @@ Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getTables(
if(len) if(len)
{ {
jobjectArray pObjArray = t.pEnv->NewObjectArray((jsize) len, java_lang_String::getMyClass(), 0); jobjectArray pObjArray = t.pEnv->NewObjectArray((jsize) len, java_lang_String::getMyClass(), 0);
OSL_ENSURE(!t.pEnv->ExceptionOccurred(),"Exception occured!"); sal_Bool bExcepOccured = isExceptionOccured(t.pEnv,sal_True); OSL_ENSURE(!bExcepOccured,"Exception occured!");
t.pEnv->ExceptionClear();
const ::rtl::OUString* pBegin = types.getConstArray(); const ::rtl::OUString* pBegin = types.getConstArray();
for(sal_Int32 i=0;i<len;i++,++pBegin) for(sal_Int32 i=0;i<len;i++,++pBegin)
{ {
jstring aT = convertwchar_tToJavaString(t.pEnv,*pBegin); jstring aT = convertwchar_tToJavaString(t.pEnv,*pBegin);
//jstring aT = t.pEnv->NewStringUTF(_par3.GetToken(i)); //jstring aT = t.pEnv->NewStringUTF(_par3.GetToken(i));
t.pEnv->SetObjectArrayElement(pObjArray,(jsize)i,aT); t.pEnv->SetObjectArrayElement(pObjArray,(jsize)i,aT);
OSL_ENSURE(!t.pEnv->ExceptionOccurred(),"Exception occured!"); sal_Bool bExcepOccured = isExceptionOccured(t.pEnv,sal_True); OSL_ENSURE(!bExcepOccured,"Exception occured!");
t.pEnv->ExceptionClear();
} }
args[3].l = pObjArray; args[3].l = pObjArray;
}else }else
...@@ -329,27 +328,46 @@ Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getTables( ...@@ -329,27 +328,46 @@ Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getTables(
args[1].l = schemaPattern.toChar() == '%' ? NULL : convertwchar_tToJavaString(t.pEnv,schemaPattern); args[1].l = schemaPattern.toChar() == '%' ? NULL : convertwchar_tToJavaString(t.pEnv,schemaPattern);
args[2].l = convertwchar_tToJavaString(t.pEnv,tableNamePattern); 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); 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!"); jthrowable jThrow = t.pEnv->ExceptionOccurred();
t.pEnv->ExceptionClear(); 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()) if(catalog.hasValue())
{ {
t.pEnv->DeleteLocalRef((jstring)args[0].l); 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) if(args[1].l)
{ {
t.pEnv->DeleteLocalRef((jstring)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()) if(tableNamePattern.getLength())
{ {
t.pEnv->DeleteLocalRef((jstring)args[2].l); 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++) //for(INT16 i=0;i<len;i++)
t.pEnv->DeleteLocalRef((jobjectArray)args[3].l); t.pEnv->DeleteLocalRef((jobjectArray)args[3].l);
OSL_ENSURE(!t.pEnv->ExceptionOccurred(),"Exception occured!"); bExcepOccured = isExceptionOccured(t.pEnv,sal_True); OSL_ENSURE(!bExcepOccured,"Exception occured!");
ThrowSQLException(t.pEnv,*this);
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 } //mID
} //t.pEnv } //t.pEnv
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: Object.cxx,v $ * $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 * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -168,14 +168,9 @@ int SDB_JRE_InitJava(const Reference<XMultiServiceFactory >& _rxFactory) ...@@ -168,14 +168,9 @@ int SDB_JRE_InitJava(const Reference<XMultiServiceFactory >& _rxFactory)
// } // }
} }
catch (Exception e) catch (Exception& e)
{ {
if (pEnv && pEnv->ExceptionOccurred()) isExceptionOccured(pEnv,sal_True);
{
pEnv->ExceptionDescribe();
pEnv->ExceptionClear();
}
result = -1; result = -1;
} }
...@@ -194,25 +189,19 @@ int SDB_JRE_InitJava(const Reference<XMultiServiceFactory >& _rxFactory) ...@@ -194,25 +189,19 @@ int SDB_JRE_InitJava(const Reference<XMultiServiceFactory >& _rxFactory)
SDBThreadAttach::SDBThreadAttach() : bDetach(sal_False), pEnv(NULL) SDBThreadAttach::SDBThreadAttach() : bDetach(sal_False), pEnv(NULL)
{ {
attachThread(pEnv); attachThread(pEnv);
if(pEnv && pEnv->ExceptionOccurred()) isExceptionOccured(pEnv,sal_True);
pEnv->ExceptionClear();
} }
SDBThreadAttach::SDBThreadAttach(const Reference<XMultiServiceFactory >& _rxFactory) : bDetach(sal_False), pEnv(NULL) SDBThreadAttach::SDBThreadAttach(const Reference<XMultiServiceFactory >& _rxFactory) : bDetach(sal_False), pEnv(NULL)
{ {
attachThread(pEnv,_rxFactory); attachThread(pEnv,_rxFactory);
if(pEnv && pEnv->ExceptionOccurred()) isExceptionOccured(pEnv,sal_True);
pEnv->ExceptionClear();
} }
SDBThreadAttach::~SDBThreadAttach() SDBThreadAttach::~SDBThreadAttach()
{ {
if(pEnv && pEnv->ExceptionOccurred()) sal_Bool bOk = isExceptionOccured(pEnv,sal_True);
{ OSL_ENSURE(!bOk,"Exception occured in JNI!");
OSL_ENSURE(0,"Exception occured in JNI!");
pEnv->ExceptionClear();
}
detachThread(); detachThread();
} }
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: ResultSet.cxx,v $ * $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 * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -1518,8 +1518,8 @@ sal_Int32 java_sql_ResultSet::getResultSetConcurrency() const throw(::com::sun:: ...@@ -1518,8 +1518,8 @@ sal_Int32 java_sql_ResultSet::getResultSetConcurrency() const throw(::com::sun::
if( mID ){ if( mID ){
out = t.pEnv->CallIntMethod( object, 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 // 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()) isExceptionOccured(t.pEnv,sal_True);
t.pEnv->ExceptionClear();
} //mID } //mID
} //t.pEnv } //t.pEnv
return (sal_Int32)out; return (sal_Int32)out;
...@@ -1539,8 +1539,8 @@ sal_Int32 java_sql_ResultSet::getResultSetType() const throw(::com::sun::star::s ...@@ -1539,8 +1539,8 @@ sal_Int32 java_sql_ResultSet::getResultSetType() const throw(::com::sun::star::s
if( mID ){ if( mID ){
out = t.pEnv->CallIntMethod( object, 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 // 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()) isExceptionOccured(t.pEnv,sal_True);
t.pEnv->ExceptionClear();
} //mID } //mID
} //t.pEnv } //t.pEnv
return (sal_Int32)out; return (sal_Int32)out;
...@@ -1559,8 +1559,8 @@ sal_Int32 java_sql_ResultSet::getFetchDirection() const throw(::com::sun::star:: ...@@ -1559,8 +1559,8 @@ sal_Int32 java_sql_ResultSet::getFetchDirection() const throw(::com::sun::star::
if( mID ){ if( mID ){
out = t.pEnv->CallIntMethod( object, 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 // 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()) isExceptionOccured(t.pEnv,sal_True);
t.pEnv->ExceptionClear();
} //mID } //mID
} //t.pEnv } //t.pEnv
return (sal_Int32)out; return (sal_Int32)out;
...@@ -1579,8 +1579,8 @@ sal_Int32 java_sql_ResultSet::getFetchSize() const throw(::com::sun::star::sdbc: ...@@ -1579,8 +1579,8 @@ sal_Int32 java_sql_ResultSet::getFetchSize() const throw(::com::sun::star::sdbc:
if( mID ){ if( mID ){
out = t.pEnv->CallIntMethod( object, 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 // 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()) isExceptionOccured(t.pEnv,sal_True);
t.pEnv->ExceptionClear();
} //mID } //mID
} //t.pEnv } //t.pEnv
return (sal_Int32)out; return (sal_Int32)out;
...@@ -1621,8 +1621,8 @@ void java_sql_ResultSet::setFetchDirection(sal_Int32 _par0) throw(::com::sun::st ...@@ -1621,8 +1621,8 @@ void java_sql_ResultSet::setFetchDirection(sal_Int32 _par0) throw(::com::sun::st
if( mID ){ if( mID ){
t.pEnv->CallVoidMethod( object, mID,_par0); 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 // 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()) isExceptionOccured(t.pEnv,sal_True);
t.pEnv->ExceptionClear();
} //mID } //mID
} //t.pEnv } //t.pEnv
...@@ -1658,8 +1658,7 @@ void java_sql_ResultSet::setFetchSize(sal_Int32 _par0) throw(::com::sun::star::s ...@@ -1658,8 +1658,7 @@ void java_sql_ResultSet::setFetchSize(sal_Int32 _par0) throw(::com::sun::star::s
if( mID ){ if( mID ){
t.pEnv->CallVoidMethod( object, mID,_par0); 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 // 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()) isExceptionOccured(t.pEnv,sal_True);
t.pEnv->ExceptionClear();
} //mID } //mID
} //t.pEnv } //t.pEnv
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: tools.cxx,v $ * $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 * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -224,5 +224,31 @@ jobject connectivity::XNameAccess2Map(JNIEnv *pEnv,const Reference< ::com::sun:: ...@@ -224,5 +224,31 @@ jobject connectivity::XNameAccess2Map(JNIEnv *pEnv,const Reference< ::com::sun::
} }
return 0; 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;
}
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: tools.hxx,v $ * $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 * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -121,6 +121,16 @@ namespace connectivity ...@@ -121,6 +121,16 @@ namespace connectivity
::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > Map2XNameAccess(JNIEnv *pEnv,jobject _pMap); ::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); 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_ #endif // _CONNECTIVITY_JAVA_TOOLS_HXX_
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment