merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / drivers / jdbc / tools.cxx
blob8a3ca446dc4e64d7c50a4bd5ecc5c38e39dec2c6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tools.cxx,v $
10 * $Revision: 1.29 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
34 #include <cstdarg>
35 #include "java/tools.hxx"
36 #include "java/lang/String.hxx"
37 #include "java/lang/Class.hxx"
38 #include "java/util/Property.hxx"
39 #include <com/sun/star/sdbc/DriverPropertyInfo.hpp>
40 #include <com/sun/star/container/XNameAccess.hpp>
41 #include <connectivity/dbexception.hxx>
43 using namespace connectivity;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::beans;
46 // using namespace ::com::sun::star::sdbcx;
47 using namespace ::com::sun::star::sdbc;
48 using namespace ::com::sun::star::container;
49 using namespace ::com::sun::star::lang;
51 void java_util_Properties::setProperty(const ::rtl::OUString key, const ::rtl::OUString& value)
53 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
54 jobject out(0);
57 jvalue args[2];
58 // Parameter konvertieren
59 args[0].l = convertwchar_tToJavaString(t.pEnv,key);
60 args[1].l = convertwchar_tToJavaString(t.pEnv,value);
61 // temporaere Variable initialisieren
62 static const char * cSignature = "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;";
63 static const char * cMethodName = "setProperty";
64 // Java-Call absetzen
65 static jmethodID mID(NULL);
66 obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
67 out = t.pEnv->CallObjectMethod(object, mID, args[0].l,args[1].l);
68 ThrowSQLException(t.pEnv,NULL);
69 t.pEnv->DeleteLocalRef((jstring)args[1].l);
70 t.pEnv->DeleteLocalRef((jstring)args[0].l);
71 ThrowSQLException(t.pEnv,0);
72 if(out)
73 t.pEnv->DeleteLocalRef(out);
74 } //t.pEnv
75 // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
77 jclass java_util_Properties::theClass = 0;
79 java_util_Properties::~java_util_Properties()
82 jclass java_util_Properties::getMyClass() const
84 // die Klasse muss nur einmal geholt werden, daher statisch
85 if( !theClass )
86 theClass = findMyClass("java/util/Properties");
87 return theClass;
90 //--------------------------------------------------------------------------
91 java_util_Properties::java_util_Properties( ): java_lang_Object( NULL, (jobject)NULL )
93 SDBThreadAttach t;
94 if( !t.pEnv )
95 return;
96 // Java-Call fuer den Konstruktor absetzen
97 // temporaere Variable initialisieren
98 static const char * cSignature = "()V";
99 jobject tempObj;
100 static jmethodID mID(NULL);
101 obtainMethodId(t.pEnv, "<init>",cSignature, mID);
102 tempObj = t.pEnv->NewObject( getMyClass(), mID);
103 saveRef( t.pEnv, tempObj );
104 t.pEnv->DeleteLocalRef( tempObj );
107 // --------------------------------------------------------------------------------
108 jstring connectivity::convertwchar_tToJavaString(JNIEnv *pEnv,const ::rtl::OUString& _rTemp)
110 OSL_ENSURE(pEnv,"Environment is NULL!");
111 jstring pStr = pEnv->NewString(_rTemp.getStr(), _rTemp.getLength());
112 pEnv->ExceptionClear();
113 OSL_ENSURE(pStr,"Could not create a jsstring object!");
114 return pStr;
117 // --------------------------------------------------------------------------------
118 java_util_Properties* connectivity::createStringPropertyArray(const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
120 java_util_Properties* pProps = new java_util_Properties();
121 const PropertyValue* pBegin = info.getConstArray();
122 const PropertyValue* pEnd = pBegin + info.getLength();
124 for(;pBegin != pEnd;++pBegin)
126 // this is a special property to find the jdbc driver
127 if ( pBegin->Name.compareToAscii( "JavaDriverClass" )
128 && pBegin->Name.compareToAscii( "JavaDriverClassPath" )
129 && pBegin->Name.compareToAscii( "SystemProperties" )
130 && pBegin->Name.compareToAscii( "CharSet" )
131 && pBegin->Name.compareToAscii( "AppendTableAliasName" )
132 && pBegin->Name.compareToAscii( "AddIndexAppendix" )
133 && pBegin->Name.compareToAscii( "FormsCheckRequiredFields" )
134 && pBegin->Name.compareToAscii( "GenerateASBeforeCorrelationName" )
135 && pBegin->Name.compareToAscii( "EscapeDateTime" )
136 && pBegin->Name.compareToAscii( "ParameterNameSubstitution" )
137 && pBegin->Name.compareToAscii( "IsPasswordRequired" )
138 && pBegin->Name.compareToAscii( "IsAutoRetrievingEnabled" )
139 && pBegin->Name.compareToAscii( "AutoRetrievingStatement" )
140 && pBegin->Name.compareToAscii( "UseCatalogInSelect" )
141 && pBegin->Name.compareToAscii( "UseSchemaInSelect" )
142 && pBegin->Name.compareToAscii( "AutoIncrementCreation" )
143 && pBegin->Name.compareToAscii( "Extension" )
144 && pBegin->Name.compareToAscii( "NoNameLengthLimit" )
145 && pBegin->Name.compareToAscii( "EnableSQL92Check" )
146 && pBegin->Name.compareToAscii( "EnableOuterJoinEscape" )
147 && pBegin->Name.compareToAscii( "BooleanComparisonMode" )
148 && pBegin->Name.compareToAscii( "IgnoreCurrency" )
149 && pBegin->Name.compareToAscii( "TypeInfoSettings" )
150 && pBegin->Name.compareToAscii( "IgnoreDriverPrivileges" )
151 && pBegin->Name.compareToAscii( "ImplicitCatalogRestriction" )
152 && pBegin->Name.compareToAscii( "ImplicitSchemaRestriction" )
153 && pBegin->Name.compareToAscii( "SupportsTableCreation" )
154 && pBegin->Name.compareToAscii( "UseJava" )
155 && pBegin->Name.compareToAscii( "Authentication" )
158 ::rtl::OUString aStr;
159 OSL_VERIFY( pBegin->Value >>= aStr );
160 pProps->setProperty(pBegin->Name,aStr);
163 return pProps;
165 // --------------------------------------------------------------------------------
166 ::rtl::OUString connectivity::JavaString2String(JNIEnv *pEnv,jstring _Str)
168 ::rtl::OUString aStr;
169 if(_Str)
171 jboolean bCopy(sal_True);
172 const jchar* pChar = pEnv->GetStringChars(_Str,&bCopy);
173 jsize len = pEnv->GetStringLength(_Str);
174 aStr = ::rtl::OUString(pChar,len);
176 if(bCopy)
177 pEnv->ReleaseStringChars(_Str,pChar);
178 pEnv->DeleteLocalRef(_Str);
180 return aStr;
182 // --------------------------------------------------------------------------------
183 jobject connectivity::convertTypeMapToJavaMap(JNIEnv* /*pEnv*/,const Reference< ::com::sun::star::container::XNameAccess > & _rMap)
185 if ( _rMap.is() )
187 ::com::sun::star::uno::Sequence< ::rtl::OUString > aNames = _rMap->getElementNames();
188 if ( aNames.getLength() > 0 )
189 ::dbtools::throwFeatureNotImplementedException( "Type maps", NULL );
191 return 0;
193 // -----------------------------------------------------------------------------
194 sal_Bool connectivity::isExceptionOccured(JNIEnv *pEnv,sal_Bool _bClear)
196 if ( !pEnv )
197 return sal_False;
199 jthrowable pThrowable = pEnv->ExceptionOccurred();
200 sal_Bool bRet = pThrowable != NULL;
201 if ( pThrowable )
203 if ( _bClear )
204 pEnv->ExceptionClear();
205 #if OSL_DEBUG_LEVEL > 1
206 if(pEnv->IsInstanceOf(pThrowable,java_sql_SQLException_BASE::st_getMyClass()))
209 java_sql_SQLException_BASE* pException = new java_sql_SQLException_BASE(pEnv,pThrowable);
210 ::rtl::OUString sError = pException->getMessage();
211 delete pException;
213 #else
214 pEnv->DeleteLocalRef(pThrowable);
215 #endif
219 return bRet;