summaryrefslogtreecommitdiff
path: root/connectivity/source
diff options
context:
space:
mode:
authorOcke Janssen <oj@openoffice.org>2000-11-22 13:44:26 +0000
committerOcke Janssen <oj@openoffice.org>2000-11-22 13:44:26 +0000
commit56365a368398788a823d48423b983d93e6ff4d1c (patch)
tree5cbdab30e9bba788ed0f8268a594f17e12858b01 /connectivity/source
parent1ffd1ad2f4c3a2e154ff3de77a6054bdd03046ad (diff)
#80002# new method for driver loading
Diffstat (limited to 'connectivity/source')
-rw-r--r--connectivity/source/drivers/jdbc/Class.cxx26
-rw-r--r--connectivity/source/drivers/jdbc/DriverManager.cxx8
-rw-r--r--connectivity/source/drivers/jdbc/JDriver.cxx109
-rw-r--r--connectivity/source/drivers/jdbc/Object.cxx6
-rw-r--r--connectivity/source/drivers/jdbc/Throwable.cxx10
-rw-r--r--connectivity/source/drivers/jdbc/tools.cxx24
6 files changed, 108 insertions, 75 deletions
diff --git a/connectivity/source/drivers/jdbc/Class.cxx b/connectivity/source/drivers/jdbc/Class.cxx
index e11dbd3a3b..147b42906c 100644
--- a/connectivity/source/drivers/jdbc/Class.cxx
+++ b/connectivity/source/drivers/jdbc/Class.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: Class.cxx,v $
*
- * $Revision: 1.1.1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $
+ * last change: $Author: oj $ $Date: 2000-11-22 14:44:26 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -114,8 +114,8 @@ java_lang_Class * java_lang_Class::forName( const ::rtl::OUString& _par0 )
out = t.pEnv->CallStaticObjectMethod( getMyClass(), mID, args[0].l );
ThrowSQLException(t.pEnv,0);
// und aufraeumen
- t.pEnv->DeleteLocalRef((jstring)args[0].l);
} //mID
+ t.pEnv->DeleteLocalRef((jstring)args[0].l);
} //t.pEnv
// ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
return out==0 ? NULL : new java_lang_Class( t.pEnv, out );
@@ -162,6 +162,26 @@ java_lang_Object * java_lang_Class::newInstance()
return out==0 ? NULL : new java_lang_Object( t.pEnv, out );
}
+jobject java_lang_Class::newInstanceObject()
+{
+ jobject out(NULL);
+ SDBThreadAttach t;
+ if( t.pEnv )
+ {
+ // temporaere Variable initialisieren
+ char * cSignature = "()Ljava/lang/Object;";
+ char * cMethodName = "newInstance";
+ // Java-Call absetzen
+ jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature );
+ if( mID ){
+ out = t.pEnv->CallObjectMethod( object, mID);
+ ThrowSQLException(t.pEnv,0);
+ } //mID
+ } //t.pEnv
+ // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
+ return out;
+}
+
::rtl::OUString java_lang_Class::getName()
{
jstring out = (jstring)NULL;
diff --git a/connectivity/source/drivers/jdbc/DriverManager.cxx b/connectivity/source/drivers/jdbc/DriverManager.cxx
index bc20c0147e..4b0fdf2012 100644
--- a/connectivity/source/drivers/jdbc/DriverManager.cxx
+++ b/connectivity/source/drivers/jdbc/DriverManager.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: DriverManager.cxx,v $
*
- * $Revision: 1.1.1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $
+ * last change: $Author: oj $ $Date: 2000-11-22 14:44:26 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -115,10 +115,10 @@ jobject java_sql_DriverManager::getDriver(const ::rtl::OUString &url)
if( mID )
{
out = t.pEnv->CallStaticObjectMethod( getMyClass(), mID, args[0].l );
- ThrowSQLException(t.pEnv,0);
// und aufraeumen
- t.pEnv->DeleteLocalRef((jstring)args[0].l);
+
} //mID
+ t.pEnv->DeleteLocalRef((jstring)args[0].l);
return t.pEnv->NewGlobalRef( out );
} //t.pEnv
diff --git a/connectivity/source/drivers/jdbc/JDriver.cxx b/connectivity/source/drivers/jdbc/JDriver.cxx
index bcf7b42a2c..91b9f7a089 100644
--- a/connectivity/source/drivers/jdbc/JDriver.cxx
+++ b/connectivity/source/drivers/jdbc/JDriver.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: JDriver.cxx,v $
*
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
*
- * last change: $Author: fs $ $Date: 2000-10-30 07:58:03 $
+ * last change: $Author: oj $ $Date: 2000-11-22 14:44:26 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -65,6 +65,9 @@
#ifndef _CONNECTIVITY_JAVA_LANG_OBJECT_HXX_
#include "java/lang/Object.hxx"
#endif
+#ifndef _CONNECTIVITY_JAVA_LANG_CLASS_HXX_
+#include "java/lang/Class.hxx"
+#endif
#ifndef _CONNECTIVITY_JAVA_SQL_DRIVERMANAGER_HXX_
#include "java/sql/DriverManager.hxx"
#endif
@@ -90,6 +93,10 @@ using namespace ::com::sun::star::lang;
java_sql_Driver::java_sql_Driver(const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory)
: java_lang_Object(_rxFactory)
{
+ SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelöscht worden!");
+ // this object is not the right one
+ t.pEnv->DeleteGlobalRef( object );
+ object = 0;
}
// --------------------------------------------------------------------------------
jclass java_sql_Driver::theClass = 0;
@@ -164,13 +171,47 @@ void java_sql_Driver::saveClassRef( jclass pClass )
}
// -------------------------------------------------------------------------
Reference< XConnection > SAL_CALL java_sql_Driver::connect( const ::rtl::OUString& url, const
- Sequence< ::com::sun::star::beans::PropertyValue >& info ) throw(SQLException, RuntimeException)
+ Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
{
+ SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelöscht worden!");
Reference< XConnection > xRet;
-
- object = java_sql_DriverManager::getDriver(url);
+ // first try if the jdbc driver is alraedy registered at the driver manager
+ try
+ {
+ if(!object)
+ {
+ const PropertyValue* pBegin = info.getConstArray();
+ const PropertyValue* pEnd = pBegin + info.getLength();
+ for(jsize i=0;pBegin != pEnd;++pBegin)
+ {
+ if(!pBegin->Name.compareToAscii("JDBCDRV"))
+ {
+ // here I try to find the class for jdbc driver
+ java_sql_SQLException_BASE::getMyClass();
+ java_lang_Throwable::getMyClass();
+
+ ::rtl::OUString aStr;
+ pBegin->Value >>= aStr;
+ // the driver manager holds the class of the driver for later use
+ // if forName didn't find the class it will throw an exception
+ java_lang_Class *pDrvClass = java_lang_Class::forName(aStr);
+ if(pDrvClass)
+ {
+ saveRef(t.pEnv, pDrvClass->newInstanceObject());
+ delete pDrvClass;
+ }
+ break;
+ }
+ }
+ }
+ }
+ catch(Exception&)
+ {
+ throw SQLException(::rtl::OUString::createFromAscii("The specified driver could not be loaded!"),*this,::rtl::OUString(),1000,Any());
+ }
+
jobject out(0);
- SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelöscht worden!");
+
if( t.pEnv )
{
jvalue args[2];
@@ -199,55 +240,31 @@ Reference< XConnection > SAL_CALL java_sql_Driver::connect( const ::rtl::OUStrin
// -------------------------------------------------------------------------
sal_Bool SAL_CALL java_sql_Driver::acceptsURL( const ::rtl::OUString& url ) throw(SQLException, RuntimeException)
{
- try
+ // don't ask the real driver for the url
+ // I feel responsible for all jdbc url's
+ if(!url.compareTo(::rtl::OUString::createFromAscii("jdbc:"),5))
{
- if(object)
- {
- SDBThreadAttach t;
- if( t.pEnv )
- t.pEnv->DeleteGlobalRef( object );
- object = NULL;
- }
- object = java_sql_DriverManager::getDriver(url);
+ return sal_True;
}
- catch(SQLException&)
- {
- return sal_False;
- }
- catch(Exception&)
- {
- return sal_False;
- }
-
- jboolean out(0);
- SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelöscht worden!");
- if( t.pEnv )
- {
- if(!object)
- return sal_False;
- jvalue args;
- args.l = convertwchar_tToJavaString(t.pEnv,url);
- // temporaere Variable initialisieren
- char * cSignature = "(Ljava/lang/String;)Z";
- char * cMethodName = "acceptsURL";
- // Java-Call absetzen
- jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature );
- if( mID )
- out = t.pEnv->CallBooleanMethod( object, mID,args);
- // und aufraeumen
- t.pEnv->DeleteLocalRef((jstring)args.l);
- ThrowSQLException(t.pEnv,*this);
- } //t.pEnv
- return out;
+ return sal_False;
}
// -------------------------------------------------------------------------
-Sequence< DriverPropertyInfo > SAL_CALL java_sql_Driver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< ::com::sun::star::beans::PropertyValue >& info ) throw(SQLException, RuntimeException)
+Sequence< DriverPropertyInfo > SAL_CALL java_sql_Driver::getPropertyInfo( const ::rtl::OUString& url,
+ const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
{
+ SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelöscht worden!");
if(!object)
object = java_sql_DriverManager::getDriver(url);
+ if(!object)
+ {
+ // one of these must throw an exception
+ ThrowSQLException(t.pEnv,*this);
+ throw SQLException(); // we need a object here
+ }
+
jobjectArray out(0);
- SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelöscht worden!");
+
if( t.pEnv )
{
jvalue args[2];
diff --git a/connectivity/source/drivers/jdbc/Object.cxx b/connectivity/source/drivers/jdbc/Object.cxx
index c67966e850..3d6f68d6a1 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.1.1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $
+ * last change: $Author: oj $ $Date: 2000-11-22 14:44:26 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -387,7 +387,7 @@ void java_lang_Object::ThrowSQLException(JNIEnv * pEnv,const Reference< XInterfa
java_lang_Throwable *pThrow = new java_lang_Throwable(pEnv,jThrow);
::rtl::OUString aMsg = pThrow->getMessage();
delete pThrow;
- throw RuntimeException(aMsg,_rContext);
+ throw SQLException(aMsg,_rContext,::rtl::OUString(),-1,Any());
}
pEnv->ExceptionClear();
}
diff --git a/connectivity/source/drivers/jdbc/Throwable.cxx b/connectivity/source/drivers/jdbc/Throwable.cxx
index d939e7169b..be1534a0b1 100644
--- a/connectivity/source/drivers/jdbc/Throwable.cxx
+++ b/connectivity/source/drivers/jdbc/Throwable.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: Throwable.cxx,v $
*
- * $Revision: 1.1.1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: hr $ $Date: 2000-09-18 16:14:23 $
+ * last change: $Author: oj $ $Date: 2000-11-22 14:44:26 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -87,6 +87,7 @@ jclass java_lang_Throwable::getMyClass()
}
return theClass;
}
+// -----------------------------------------------------------------------------
void java_lang_Throwable::saveClassRef( jclass pClass )
{
@@ -95,6 +96,7 @@ void java_lang_Throwable::saveClassRef( jclass pClass )
// der uebergebe Klassen-Handle ist schon global, daher einfach speichern
theClass = pClass;
}
+// -----------------------------------------------------------------------------
::rtl::OUString java_lang_Throwable::getMessage() const
{
@@ -116,6 +118,7 @@ void java_lang_Throwable::saveClassRef( jclass pClass )
// ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
return aStr;
}
+// -----------------------------------------------------------------------------
::rtl::OUString java_lang_Throwable::getLocalizedMessage() const
{
@@ -137,6 +140,7 @@ void java_lang_Throwable::saveClassRef( jclass pClass )
// ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
return aStr;
}
+// -----------------------------------------------------------------------------
::rtl::OUString java_lang_Throwable::toString() const
{
::rtl::OUString aStr;
@@ -157,4 +161,6 @@ void java_lang_Throwable::saveClassRef( jclass pClass )
// ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
return aStr;
}
+// -----------------------------------------------------------------------------
+
diff --git a/connectivity/source/drivers/jdbc/tools.cxx b/connectivity/source/drivers/jdbc/tools.cxx
index 4b154d0075..706c130eae 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.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: hr $ $Date: 2000-10-26 15:03:02 $
+ * last change: $Author: oj $ $Date: 2000-11-22 14:44:26 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -97,28 +97,18 @@ jstring connectivity::convertwchar_tToJavaString(JNIEnv *pEnv,const ::rtl::OUStr
}
// --------------------------------------------------------------------------------
-jobjectArray connectivity::createStringPropertyArray(JNIEnv *pEnv,const Sequence< ::com::sun::star::beans::PropertyValue >& info ) throw(starsdbc::SQLException, RuntimeException)
+jobjectArray connectivity::createStringPropertyArray(JNIEnv *pEnv,const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
{
jobjectArray aArray = pEnv->NewObjectArray(info.getLength(),java_lang_String::getMyClass(),pEnv->NewStringUTF(""));
- const ::com::sun::star::beans::PropertyValue* pBegin = info.getConstArray();
- const ::com::sun::star::beans::PropertyValue* pEnd = pBegin + info.getLength();
+ const PropertyValue* pBegin = info.getConstArray();
+ const PropertyValue* pEnd = pBegin + info.getLength();
sal_Bool bFound = sal_False;
for(jsize i=0;pBegin != pEnd;++pBegin)
{
- if(!bFound || pBegin->Name.compareToAscii("JDBCDRV"))
- {
- java_sql_SQLException_BASE::getMyClass();
- java_lang_Throwable::getMyClass();
-
- ::rtl::OUString aStr;
- pBegin->Value >>= aStr;
- //Datenbanktreiber wird ueber einen Klassennamen erzeugt
- java_lang_Class *pDrvClass = java_lang_Class::forName(aStr);
- bFound = sal_True;
- }
- else
+ // this is a special property to find the jdbc driver
+ if(!pBegin->Name.compareToAscii("JDBCDRV"))
{
::rtl::OUString aStr;
pBegin->Value >>= aStr;