1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*9b5730f6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*9b5730f6SAndrew Rist * distributed with this work for additional information
6*9b5730f6SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*9b5730f6SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*9b5730f6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*9b5730f6SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist * KIND, either express or implied. See the License for the
17*9b5730f6SAndrew Rist * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*9b5730f6SAndrew Rist *************************************************************/
21*9b5730f6SAndrew Rist
22*9b5730f6SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir #include "java/sql/Driver.hxx"
27cdf0e10cSrcweir #include "java/lang/Object.hxx"
28cdf0e10cSrcweir #include "java/lang/Class.hxx"
29cdf0e10cSrcweir #include "java/sql/DriverPropertyInfo.hxx"
30cdf0e10cSrcweir #include "java/sql/Connection.hxx"
31cdf0e10cSrcweir #include "java/util/Property.hxx"
32cdf0e10cSrcweir #include "java/tools.hxx"
33cdf0e10cSrcweir #include "connectivity/dbexception.hxx"
34cdf0e10cSrcweir #include <jvmfwk/framework.h>
35cdf0e10cSrcweir #include "diagnose_ex.h"
36cdf0e10cSrcweir #include "resource/jdbc_log.hrc"
37cdf0e10cSrcweir #include "resource/common_res.hrc"
38cdf0e10cSrcweir #include "resource/sharedresources.hxx"
39cdf0e10cSrcweir #include <comphelper/componentcontext.hxx>
40cdf0e10cSrcweir
41cdf0e10cSrcweir using namespace connectivity;
42cdf0e10cSrcweir using namespace ::com::sun::star::uno;
43cdf0e10cSrcweir using namespace ::com::sun::star::beans;
44cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
45cdf0e10cSrcweir using namespace ::com::sun::star::container;
46cdf0e10cSrcweir using namespace ::com::sun::star::lang;
47cdf0e10cSrcweir
48cdf0e10cSrcweir // -------------------------------------------------------------------------
java_sql_Driver(const Reference<::com::sun::star::lang::XMultiServiceFactory> & _rxFactory)49cdf0e10cSrcweir java_sql_Driver::java_sql_Driver(const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory)
50cdf0e10cSrcweir :m_aContext( _rxFactory )
51cdf0e10cSrcweir ,m_aLogger( m_aContext.getUNOContext(), "sdbcl", "org.openoffice.sdbc.jdbcBridge" )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir }
54cdf0e10cSrcweir // --------------------------------------------------------------------------------
~java_sql_Driver()55cdf0e10cSrcweir java_sql_Driver::~java_sql_Driver()
56cdf0e10cSrcweir {
57cdf0e10cSrcweir }
58cdf0e10cSrcweir
59cdf0e10cSrcweir // static ServiceInfo
60cdf0e10cSrcweir //------------------------------------------------------------------------------
getImplementationName_Static()61cdf0e10cSrcweir rtl::OUString java_sql_Driver::getImplementationName_Static( ) throw(RuntimeException)
62cdf0e10cSrcweir {
63cdf0e10cSrcweir return ::rtl::OUString::createFromAscii("com.sun.star.comp.sdbc.JDBCDriver");
64cdf0e10cSrcweir // this name is referenced in the configuration and in the jdbc.xml
65cdf0e10cSrcweir // Please take care when changing it.
66cdf0e10cSrcweir }
67cdf0e10cSrcweir //------------------------------------------------------------------------------
getSupportedServiceNames_Static()68cdf0e10cSrcweir Sequence< ::rtl::OUString > java_sql_Driver::getSupportedServiceNames_Static( ) throw (RuntimeException)
69cdf0e10cSrcweir {
70cdf0e10cSrcweir Sequence< ::rtl::OUString > aSNS( 1 );
71cdf0e10cSrcweir aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver");
72cdf0e10cSrcweir return aSNS;
73cdf0e10cSrcweir }
74cdf0e10cSrcweir //------------------------------------------------------------------
java_sql_Driver_CreateInstance(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _rxFactory)75cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL connectivity::java_sql_Driver_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception )
76cdf0e10cSrcweir {
77cdf0e10cSrcweir return *(new java_sql_Driver(_rxFactory));
78cdf0e10cSrcweir }
79cdf0e10cSrcweir // --------------------------------------------------------------------------------
getImplementationName()80cdf0e10cSrcweir ::rtl::OUString SAL_CALL java_sql_Driver::getImplementationName( ) throw(RuntimeException)
81cdf0e10cSrcweir {
82cdf0e10cSrcweir return getImplementationName_Static();
83cdf0e10cSrcweir }
84cdf0e10cSrcweir
85cdf0e10cSrcweir // --------------------------------------------------------------------------------
supportsService(const::rtl::OUString & _rServiceName)86cdf0e10cSrcweir sal_Bool SAL_CALL java_sql_Driver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
87cdf0e10cSrcweir {
88cdf0e10cSrcweir Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
89cdf0e10cSrcweir const ::rtl::OUString* pSupported = aSupported.getConstArray();
90cdf0e10cSrcweir const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
91cdf0e10cSrcweir for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
92cdf0e10cSrcweir ;
93cdf0e10cSrcweir
94cdf0e10cSrcweir return pSupported != pEnd;
95cdf0e10cSrcweir }
96cdf0e10cSrcweir
97cdf0e10cSrcweir // --------------------------------------------------------------------------------
getSupportedServiceNames()98cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL java_sql_Driver::getSupportedServiceNames( ) throw(RuntimeException)
99cdf0e10cSrcweir {
100cdf0e10cSrcweir return getSupportedServiceNames_Static();
101cdf0e10cSrcweir }
102cdf0e10cSrcweir // -------------------------------------------------------------------------
connect(const::rtl::OUString & url,const Sequence<PropertyValue> & info)103cdf0e10cSrcweir Reference< XConnection > SAL_CALL java_sql_Driver::connect( const ::rtl::OUString& url, const
104cdf0e10cSrcweir Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
105cdf0e10cSrcweir {
106cdf0e10cSrcweir m_aLogger.log( LogLevel::INFO, STR_LOG_DRIVER_CONNECTING_URL, url );
107cdf0e10cSrcweir
108cdf0e10cSrcweir Reference< XConnection > xOut;
109cdf0e10cSrcweir if ( acceptsURL(url ) )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir java_sql_Connection* pConnection = new java_sql_Connection( *this );
112cdf0e10cSrcweir xOut = pConnection;
113cdf0e10cSrcweir if ( !pConnection->construct(url,info) )
114cdf0e10cSrcweir xOut.clear(); // an error occured and the java driver didn't throw an exception
115cdf0e10cSrcweir else
116cdf0e10cSrcweir m_aLogger.log( LogLevel::INFO, STR_LOG_DRIVER_SUCCESS );
117cdf0e10cSrcweir }
118cdf0e10cSrcweir return xOut;
119cdf0e10cSrcweir }
120cdf0e10cSrcweir // -------------------------------------------------------------------------
acceptsURL(const::rtl::OUString & url)121cdf0e10cSrcweir sal_Bool SAL_CALL java_sql_Driver::acceptsURL( const ::rtl::OUString& url ) throw(SQLException, RuntimeException)
122cdf0e10cSrcweir {
123cdf0e10cSrcweir // don't ask the real driver for the url
124cdf0e10cSrcweir // I feel responsible for all jdbc url's
125cdf0e10cSrcweir sal_Bool bEnabled = sal_False;
126cdf0e10cSrcweir OSL_VERIFY_EQUALS( jfw_getEnabled( &bEnabled ), JFW_E_NONE, "error in jfw_getEnabled" );
127cdf0e10cSrcweir static const ::rtl::OUString s_sJdbcPrefix = ::rtl::OUString::createFromAscii("jdbc:");
128cdf0e10cSrcweir return bEnabled && 0 == url.compareTo(s_sJdbcPrefix, 5);
129cdf0e10cSrcweir }
130cdf0e10cSrcweir // -------------------------------------------------------------------------
getPropertyInfo(const::rtl::OUString & url,const Sequence<PropertyValue> &)131cdf0e10cSrcweir Sequence< DriverPropertyInfo > SAL_CALL java_sql_Driver::getPropertyInfo( const ::rtl::OUString& url,
132cdf0e10cSrcweir const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException)
133cdf0e10cSrcweir {
134cdf0e10cSrcweir if ( acceptsURL(url) )
135cdf0e10cSrcweir {
136cdf0e10cSrcweir ::std::vector< DriverPropertyInfo > aDriverInfo;
137cdf0e10cSrcweir
138cdf0e10cSrcweir Sequence< ::rtl::OUString > aBooleanValues(2);
139cdf0e10cSrcweir aBooleanValues[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) );
140cdf0e10cSrcweir aBooleanValues[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) );
141cdf0e10cSrcweir
142cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo(
143cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JavaDriverClass"))
144cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("The JDBC driver class name."))
145cdf0e10cSrcweir ,sal_True
146cdf0e10cSrcweir ,::rtl::OUString()
147cdf0e10cSrcweir ,Sequence< ::rtl::OUString >())
148cdf0e10cSrcweir );
149cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo(
150cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JavaDriverClassPath"))
151cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("The class path where to look for the JDBC driver."))
152cdf0e10cSrcweir ,sal_True
153cdf0e10cSrcweir ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "" ) )
154cdf0e10cSrcweir ,Sequence< ::rtl::OUString >())
155cdf0e10cSrcweir );
156cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo(
157cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SystemProperties"))
158cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Additional properties to set at java.lang.System before loading the driver."))
159cdf0e10cSrcweir ,sal_True
160cdf0e10cSrcweir ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "" ) )
161cdf0e10cSrcweir ,Sequence< ::rtl::OUString >())
162cdf0e10cSrcweir );
163cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo(
164cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParameterNameSubstitution"))
165cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Change named parameters with '?'."))
166cdf0e10cSrcweir ,sal_False
167cdf0e10cSrcweir ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
168cdf0e10cSrcweir ,aBooleanValues)
169cdf0e10cSrcweir );
170cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo(
171cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IgnoreDriverPrivileges"))
172cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Ignore the privileges from the database driver."))
173cdf0e10cSrcweir ,sal_False
174cdf0e10cSrcweir ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
175cdf0e10cSrcweir ,aBooleanValues)
176cdf0e10cSrcweir );
177cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo(
178cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsAutoRetrievingEnabled"))
179cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Retrieve generated values."))
180cdf0e10cSrcweir ,sal_False
181cdf0e10cSrcweir ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
182cdf0e10cSrcweir ,aBooleanValues)
183cdf0e10cSrcweir );
184cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo(
185cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AutoRetrievingStatement"))
186cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Auto-increment statement."))
187cdf0e10cSrcweir ,sal_False
188cdf0e10cSrcweir ,::rtl::OUString()
189cdf0e10cSrcweir ,Sequence< ::rtl::OUString >())
190cdf0e10cSrcweir );
191cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo(
192cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GenerateASBeforeCorrelationName"))
193cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Generate AS before table correlation names."))
194cdf0e10cSrcweir ,sal_False
195cdf0e10cSrcweir ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) )
196cdf0e10cSrcweir ,aBooleanValues)
197cdf0e10cSrcweir );
198cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo(
199cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IgnoreCurrency"))
200cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Ignore the currency field from the ResultsetMetaData."))
201cdf0e10cSrcweir ,sal_False
202cdf0e10cSrcweir ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
203cdf0e10cSrcweir ,aBooleanValues)
204cdf0e10cSrcweir );
205cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo(
206cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EscapeDateTime"))
207cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Escape date time format."))
208cdf0e10cSrcweir ,sal_False
209cdf0e10cSrcweir ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) )
210cdf0e10cSrcweir ,aBooleanValues)
211cdf0e10cSrcweir );
212cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo(
213cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TypeInfoSettings"))
214cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Defines how the type info of the database metadata should be manipulated."))
215cdf0e10cSrcweir ,sal_False
216cdf0e10cSrcweir ,::rtl::OUString( )
217cdf0e10cSrcweir ,Sequence< ::rtl::OUString > ())
218cdf0e10cSrcweir );
219cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo(
220cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ImplicitCatalogRestriction"))
221cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("The catalog which should be used in getTables calls, when the caller passed NULL."))
222cdf0e10cSrcweir ,sal_False
223cdf0e10cSrcweir ,::rtl::OUString( )
224cdf0e10cSrcweir ,Sequence< ::rtl::OUString > ())
225cdf0e10cSrcweir );
226cdf0e10cSrcweir aDriverInfo.push_back(DriverPropertyInfo(
227cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ImplicitSchemaRestriction"))
228cdf0e10cSrcweir ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("The schema which should be used in getTables calls, when the caller passed NULL."))
229cdf0e10cSrcweir ,sal_False
230cdf0e10cSrcweir ,::rtl::OUString( )
231cdf0e10cSrcweir ,Sequence< ::rtl::OUString > ())
232cdf0e10cSrcweir );
233cdf0e10cSrcweir return Sequence< DriverPropertyInfo >(&aDriverInfo[0],aDriverInfo.size());
234cdf0e10cSrcweir }
235cdf0e10cSrcweir ::connectivity::SharedResources aResources;
236cdf0e10cSrcweir const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
237cdf0e10cSrcweir ::dbtools::throwGenericSQLException(sMessage ,*this);
238cdf0e10cSrcweir return Sequence< DriverPropertyInfo >();
239cdf0e10cSrcweir }
240cdf0e10cSrcweir // -------------------------------------------------------------------------
getMajorVersion()241cdf0e10cSrcweir sal_Int32 SAL_CALL java_sql_Driver::getMajorVersion( ) throw(RuntimeException)
242cdf0e10cSrcweir {
243cdf0e10cSrcweir return 1;
244cdf0e10cSrcweir }
245cdf0e10cSrcweir // -------------------------------------------------------------------------
getMinorVersion()246cdf0e10cSrcweir sal_Int32 SAL_CALL java_sql_Driver::getMinorVersion( ) throw(RuntimeException)
247cdf0e10cSrcweir {
248cdf0e10cSrcweir return 0;
249cdf0e10cSrcweir }
250cdf0e10cSrcweir // -------------------------------------------------------------------------
251cdf0e10cSrcweir
252cdf0e10cSrcweir
253