summaryrefslogtreecommitdiff
path: root/connectivity
diff options
context:
space:
mode:
authorOcke Janssen <oj@openoffice.org>2001-05-09 11:59:06 +0000
committerOcke Janssen <oj@openoffice.org>2001-05-09 11:59:06 +0000
commit0223e3fb8ac21a9d72ba5781ba367bbcbf9450e5 (patch)
tree617ba4e5b0df5abb081838d3a93690d019424ea9 /connectivity
parent904761fc639e4bab5e1826406d051784043e7f03 (diff)
correct the java Properties
Diffstat (limited to 'connectivity')
-rw-r--r--connectivity/source/drivers/jdbc/JDriver.cxx45
-rw-r--r--connectivity/source/drivers/jdbc/Object.cxx18
-rw-r--r--connectivity/source/drivers/jdbc/tools.cxx98
-rw-r--r--connectivity/source/inc/java/tools.hxx13
-rw-r--r--connectivity/source/inc/java/util/Property.hxx39
5 files changed, 155 insertions, 58 deletions
diff --git a/connectivity/source/drivers/jdbc/JDriver.cxx b/connectivity/source/drivers/jdbc/JDriver.cxx
index f44482f27d..6286aaca46 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.10 $
+ * $Revision: 1.11 $
*
- * last change: $Author: oj $ $Date: 2001-05-04 09:58:43 $
+ * last change: $Author: oj $ $Date: 2001-05-09 12:58:20 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -77,6 +77,7 @@
#ifndef _CONNECTIVITY_JAVA_SQL_CONNECTION_HXX_
#include "java/sql/Connection.hxx"
#endif
+#include "java/util/Property.hxx"
#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_
#include "java/tools.hxx"
#endif
@@ -215,23 +216,27 @@ Reference< XConnection > SAL_CALL java_sql_Driver::connect( const ::rtl::OUStrin
if( t.pEnv )
{
- jvalue args[2];
- // Parameter konvertieren
- args[0].l = convertwchar_tToJavaString(t.pEnv,url);
- args[1].l = createStringPropertyArray(t.pEnv,info);
// temporaere Variable initialisieren
- char * cSignature = "(Ljava/lang/String;Ljava/util/Properties)Ljava/sql/Connection;";
+ char * cSignature = "(Ljava/lang/String;Ljava/util/Properties;)Ljava/sql/Connection;";
char * cMethodName = "connect";
// Java-Call absetzen
jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature );
+ ThrowSQLException(t.pEnv,*this);
if( mID )
{
- out = t.pEnv->CallObjectMethodA( getMyClass(), mID, args );
+ jvalue args[2];
+ // Parameter konvertieren
+ args[0].l = convertwchar_tToJavaString(t.pEnv,url);
+ java_util_Properties* pProps = createStringPropertyArray(t.pEnv,info);
+ args[1].l = pProps->getJavaObject();
+
+ out = t.pEnv->CallObjectMethod( object, mID, args[0].l,args[1].l );
+ ThrowSQLException(t.pEnv,*this);
+ // und aufraeumen
+ t.pEnv->DeleteLocalRef((jstring)args[0].l);
+ ThrowSQLException(t.pEnv,*this);
+ delete pProps;
} //mID
- // und aufraeumen
- t.pEnv->DeleteLocalRef((jstring)args[0].l);
- t.pEnv->DeleteLocalRef((jstring)args[1].l);
- ThrowSQLException(t.pEnv,*this);
} //t.pEnv
// ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
Reference< XConnection > xOut;
@@ -264,22 +269,24 @@ Sequence< DriverPropertyInfo > SAL_CALL java_sql_Driver::getPropertyInfo( const
if( t.pEnv )
{
- jvalue args[2];
- // Parameter konvertieren
- args[0].l = convertwchar_tToJavaString(t.pEnv,url);
- args[1].l = createStringPropertyArray(t.pEnv,info);
// temporaere Variable initialisieren
- char * cSignature = "(Ljava/lang/String;Ljava/util/Properties)[Ljava/sql/DriverPropertyInfo;";
+ char * cSignature = "(Ljava/lang/String;Ljava/util/Properties;)[Ljava/sql/DriverPropertyInfo;";
char * cMethodName = "getPropertyInfo";
// Java-Call absetzen
jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature );
if( mID )
{
- out = (jobjectArray)t.pEnv->CallObjectMethodA( getMyClass(), mID, args );
+ jvalue args[2];
+ // Parameter konvertieren
+ args[0].l = convertwchar_tToJavaString(t.pEnv,url);
+ java_util_Properties* pProps = createStringPropertyArray(t.pEnv,info);
+ args[1].l = pProps->getJavaObject();
+
+ out = (jobjectArray)t.pEnv->CallObjectMethodA( object, mID, args );
ThrowSQLException(t.pEnv,*this);
// und aufraeumen
t.pEnv->DeleteLocalRef((jstring)args[0].l);
- t.pEnv->DeleteLocalRef((jstring)args[1].l);
+ delete pProps;
} //mID
} //t.pEnv
// ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
diff --git a/connectivity/source/drivers/jdbc/Object.cxx b/connectivity/source/drivers/jdbc/Object.cxx
index 8ba9fec83b..da26014fce 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.5 $
+ * $Revision: 1.6 $
*
- * last change: $Author: jl $ $Date: 2001-03-20 17:03:17 $
+ * last change: $Author: oj $ $Date: 2001-05-09 12:58:20 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -384,12 +384,24 @@ void java_lang_Object::ThrowSQLException(JNIEnv * pEnv,const Reference< XInterfa
{
if(pEnv->IsInstanceOf(jThrow,java_sql_SQLException_BASE::getMyClass()))
{
- throw java_sql_SQLException(java_sql_SQLException_BASE(pEnv,jThrow),_rContext);
+ java_sql_SQLException_BASE* pException = new java_sql_SQLException_BASE(pEnv,jThrow);
+ SQLException e( pException->getMessage(),
+ _rContext,
+ pException->getSQLState(),
+ pException->getErrorCode(),
+ makeAny(pException->getNextException())
+ );
+ 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());
}
diff --git a/connectivity/source/drivers/jdbc/tools.cxx b/connectivity/source/drivers/jdbc/tools.cxx
index 6e1ae808fe..01777776cc 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.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: fs $ $Date: 2001-02-07 08:19:46 $
+ * last change: $Author: oj $ $Date: 2001-05-09 12:58:20 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -69,6 +69,9 @@
#ifndef _CONNECTIVITY_JAVA_LANG_CLASS_HXX_
#include "java/lang/Class.hxx"
#endif
+#ifndef CONNECTIVITY_java_util_Properties
+#include "java/util/Property.hxx"
+#endif
#ifndef _COM_SUN_STAR_SDBC_DRIVERPROPERTYINFO_HPP_
#include <com/sun/star/sdbc/DriverPropertyInfo.hpp>
@@ -85,38 +88,99 @@ using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::lang;
-// --------------------------------------------------------------------------------
-jstring connectivity::convertwchar_tToJavaString(JNIEnv *pEnv,const ::rtl::OUString& Temp)
+void java_util_Properties::setProperty(const ::rtl::OUString key, const ::rtl::OUString& value)
{
- if (pEnv)
+ SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment gelöscht worden!");
+ jobject out(0);
+ if( t.pEnv )
{
- ::rtl::OString aT = ::rtl::OUStringToOString(Temp,RTL_TEXTENCODING_UTF8);
- return pEnv->NewString((const unsigned short *)aT.getStr(), aT.getLength());
+ jvalue args[2];
+ // Parameter konvertieren
+ args[0].l = convertwchar_tToJavaString(t.pEnv,key);
+ args[1].l = convertwchar_tToJavaString(t.pEnv,value);
+ // temporaere Variable initialisieren
+ char * cSignature = "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;";
+ char * cMethodName = "setProperty";
+ // Java-Call absetzen
+ jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature );
+ if( mID )
+ out = t.pEnv->CallObjectMethod(object, mID, args[0].l,args[1].l);
+ t.pEnv->DeleteLocalRef((jstring)args[1].l);
+ t.pEnv->DeleteLocalRef((jstring)args[0].l);
+ ThrowSQLException(t.pEnv,0);
+ if(out)
+ t.pEnv->DeleteLocalRef(out);
+ } //t.pEnv
+ // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
+}
+jclass java_util_Properties::theClass = 0;
+
+java_util_Properties::~java_util_Properties()
+{}
+
+jclass java_util_Properties::getMyClass()
+{
+ // die Klasse muss nur einmal geholt werden, daher statisch
+ if( !theClass ){
+ SDBThreadAttach t;
+ if( !t.pEnv ) return (jclass)NULL;
+ jclass tempClass = t.pEnv->FindClass( "java/util/Properties" );
+ jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass );
+ t.pEnv->DeleteLocalRef( tempClass );
+ saveClassRef( globClass );
}
- return NULL;
+ return theClass;
+}
+
+void java_util_Properties::saveClassRef( jclass pClass )
+{
+ if( SDBThreadAttach::IsJavaErrorOccured() || pClass==NULL )
+ return;
+ // der uebergebe Klassen-Handle ist schon global, daher einfach speichern
+ theClass = pClass;
+}
+//--------------------------------------------------------------------------
+java_util_Properties::java_util_Properties( ): java_lang_Object( NULL, (jobject)NULL )
+{
+ SDBThreadAttach t;
+ if( !t.pEnv )
+ return;
+ // Java-Call fuer den Konstruktor absetzen
+ // temporaere Variable initialisieren
+ char * cSignature = "()V";
+ jobject tempObj;
+ jmethodID mID = t.pEnv->GetMethodID( getMyClass(), "<init>", cSignature );
+ tempObj = t.pEnv->NewObject( getMyClass(), mID);
+ saveRef( t.pEnv, tempObj );
+ t.pEnv->DeleteLocalRef( tempObj );
}
// --------------------------------------------------------------------------------
-jobjectArray connectivity::createStringPropertyArray(JNIEnv *pEnv,const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
+jstring connectivity::convertwchar_tToJavaString(JNIEnv *pEnv,const ::rtl::OUString& _rTemp)
{
- jobjectArray aArray = pEnv->NewObjectArray(info.getLength(),java_lang_String::getMyClass(),pEnv->NewStringUTF(""));
+ if (pEnv)
+ return pEnv->NewString(_rTemp.getStr(), _rTemp.getLength());
+ return NULL;
+}
+// --------------------------------------------------------------------------------
+java_util_Properties* connectivity::createStringPropertyArray(JNIEnv *pEnv,const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
+{
+ java_util_Properties* pProps = new java_util_Properties();
const PropertyValue* pBegin = info.getConstArray();
const PropertyValue* pEnd = pBegin + info.getLength();
- sal_Bool bFound = sal_False;
- for(jsize i=0;pBegin != pEnd;++pBegin)
+ for(;pBegin != pEnd;++pBegin)
{
// this is a special property to find the jdbc driver
- if(!pBegin->Name.compareToAscii("JavaDriverClass"))
+ if(pBegin->Name.compareToAscii("JavaDriverClass"))
{
::rtl::OUString aStr;
pBegin->Value >>= aStr;
- jstring a = convertwchar_tToJavaString(pEnv,aStr.getStr());
- pEnv->SetObjectArrayElement(aArray,i++,a);
+ pProps->setProperty(pBegin->Name,aStr);
}
}
- return aArray;
+ return pProps;
}
// --------------------------------------------------------------------------------
::rtl::OUString connectivity::JavaString2String(JNIEnv *pEnv,jstring _Str)
@@ -127,7 +191,7 @@ jobjectArray connectivity::createStringPropertyArray(JNIEnv *pEnv,const Sequence
jboolean bCopy(sal_True);
const jchar* pChar = pEnv->GetStringChars(_Str,&bCopy);
jsize len = pEnv->GetStringLength(_Str);
- aStr = ::rtl::OUString(pChar,RTL_TEXTENCODING_UTF8);
+ aStr = ::rtl::OUString(pChar,len);
if(bCopy)
pEnv->ReleaseStringChars(_Str,pChar);
diff --git a/connectivity/source/inc/java/tools.hxx b/connectivity/source/inc/java/tools.hxx
index 7466e0d60a..dd2d7e3d35 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.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: fs $ $Date: 2000-10-11 10:42:28 $
+ * last change: $Author: oj $ $Date: 2001-05-09 12:59:06 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -97,10 +97,11 @@ namespace connectivity
jstring convertwchar_tToJavaString(JNIEnv *pEnv,const ::rtl::OUString& _Temp);
::rtl::OUString JavaString2String(JNIEnv *pEnv,jstring _Str);
+ class java_util_Properties;
- jobjectArray createStringPropertyArray(JNIEnv *pEnv,const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
+ java_util_Properties* createStringPropertyArray(JNIEnv *pEnv,const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
- template<class T,class JT> ::com::sun::star::uno::Sequence< T > copyArrayAndDelete(JNIEnv *pEnv,jobjectArray _Array,const T& _rD1,const JT& _rD2)
+ template<class T,class JT> ::com::sun::star::uno::Sequence< T > copyArrayAndDelete(JNIEnv *pEnv,jobjectArray _Array,const T& _rD1,const JT& _rD2)
{
::com::sun::star::uno::Sequence< T > xOut;
if(_Array)
@@ -117,8 +118,8 @@ namespace connectivity
return xOut;
}
- ::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);
+ ::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);
}
#endif // _CONNECTIVITY_JAVA_TOOLS_HXX_
diff --git a/connectivity/source/inc/java/util/Property.hxx b/connectivity/source/inc/java/util/Property.hxx
index 63f78d2644..6acd95de3d 100644
--- a/connectivity/source/inc/java/util/Property.hxx
+++ b/connectivity/source/inc/java/util/Property.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: Property.hxx,v $
*
- * $Revision: 1.1.1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: hr $ $Date: 2000-09-18 16:14:27 $
+ * last change: $Author: oj $ $Date: 2001-05-09 12:59:06 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -58,17 +58,30 @@
*
*
************************************************************************/
+#ifndef CONNECTIVITY_java_util_Properties
+#define CONNECTIVITY_java_util_Properties
+#ifndef _CONNECTIVITY_JAVA_LANG_OBJECT_HXX_
+#include "java/lang/Object.hxx"
+#endif
-class java_util_Property : public java_lang_Object
+namespace connectivity
{
-protected:
-// statische Daten fuer die Klasse
- static jclass theClass;
- // der Destruktor um den Object-Counter zu aktualisieren
- static void saveClassRef( jclass pClass );
-public:
- static jclass getMyClass();
- virtual ~java_util_Property();
- // ein Konstruktor, der fuer das Returnen des Objektes benoetigt wird:
-}; java_util_Property( JNIEnv * pEnv, jobject myObj ) : java_lang_Object( pEnv, myObj ){}
+ class java_util_Properties : public java_lang_Object
+ {
+ protected:
+ // statische Daten fuer die Klasse
+ static jclass theClass;
+ // der Destruktor um den Object-Counter zu aktualisieren
+ static void saveClassRef( jclass pClass );
+ public:
+ static jclass getMyClass();
+ virtual ~java_util_Properties();
+ // ein Konstruktor, der fuer das Returnen des Objektes benoetigt wird:
+ java_util_Properties( JNIEnv * pEnv, jobject myObj ) : java_lang_Object( pEnv, myObj ){}
+ java_util_Properties( );
+ void setProperty(const ::rtl::OUString key, const ::rtl::OUString& value);
+ };
+}
+
+#endif // CONNECTIVITY_java_util_Properties \ No newline at end of file