summaryrefslogtreecommitdiff
path: root/connectivity/source/drivers
diff options
context:
space:
mode:
authorOcke Janssen <oj@openoffice.org>2002-11-01 09:58:49 +0000
committerOcke Janssen <oj@openoffice.org>2002-11-01 09:58:49 +0000
commit0b01fd887a2d22f2e310c078e55ea0e24bbae847 (patch)
treea86a388cfab4b43c814864a19f084eeca2262bb0 /connectivity/source/drivers
parent43488b09cf16ef1f3a338f0af2a545a1c1853689 (diff)
#104636# correct exception handling
Diffstat (limited to 'connectivity/source/drivers')
-rw-r--r--connectivity/source/drivers/jdbc/DatabaseMetaData.cxx48
-rw-r--r--connectivity/source/drivers/jdbc/Object.cxx27
-rw-r--r--connectivity/source/drivers/jdbc/ResultSet.cxx27
-rw-r--r--connectivity/source/drivers/jdbc/tools.cxx30
4 files changed, 82 insertions, 50 deletions
diff --git a/connectivity/source/drivers/jdbc/DatabaseMetaData.cxx b/connectivity/source/drivers/jdbc/DatabaseMetaData.cxx
index d340f9f846..ae36bf1c9e 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 39763c1e75..23edb7efd7 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 3803900aa3..4d0f674429 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 d7b79ffc3c..c7e79c9344 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;
+}