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