Update ooo320-m1
[ooovba.git] / connectivity / source / drivers / jdbc / JDriver.cxx
blobe1066776a55aedad9474c00141a27790727dc2dc
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: JDriver.cxx,v $
10 * $Revision: 1.43.56.1 $
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"
33 #include "java/sql/Driver.hxx"
34 #include "java/lang/Object.hxx"
35 #include "java/lang/Class.hxx"
36 #include "java/sql/DriverPropertyInfo.hxx"
37 #include "java/sql/Connection.hxx"
38 #include "java/util/Property.hxx"
39 #include "java/tools.hxx"
40 #include "connectivity/dbexception.hxx"
41 #include <jvmfwk/framework.h>
42 #include "diagnose_ex.h"
43 #include "resource/jdbc_log.hrc"
44 #include "resource/common_res.hrc"
45 #include "resource/sharedresources.hxx"
46 #include <comphelper/componentcontext.hxx>
48 using namespace connectivity;
49 using namespace ::com::sun::star::uno;
50 using namespace ::com::sun::star::beans;
51 using namespace ::com::sun::star::sdbc;
52 using namespace ::com::sun::star::container;
53 using namespace ::com::sun::star::lang;
55 // -------------------------------------------------------------------------
56 java_sql_Driver::java_sql_Driver(const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory)
57 :m_aContext( _rxFactory )
58 ,m_aLogger( m_aContext.getUNOContext(), "sdbcl", "org.openoffice.sdbc.jdbcBridge" )
61 // --------------------------------------------------------------------------------
62 java_sql_Driver::~java_sql_Driver()
66 // static ServiceInfo
67 //------------------------------------------------------------------------------
68 rtl::OUString java_sql_Driver::getImplementationName_Static( ) throw(RuntimeException)
70 return ::rtl::OUString::createFromAscii("com.sun.star.comp.sdbc.JDBCDriver");
71 // this name is referenced in the configuration and in the jdbc.xml
72 // Please take care when changing it.
74 //------------------------------------------------------------------------------
75 Sequence< ::rtl::OUString > java_sql_Driver::getSupportedServiceNames_Static( ) throw (RuntimeException)
77 Sequence< ::rtl::OUString > aSNS( 1 );
78 aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver");
79 return aSNS;
81 //------------------------------------------------------------------
82 ::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 )
84 return *(new java_sql_Driver(_rxFactory));
86 // --------------------------------------------------------------------------------
87 ::rtl::OUString SAL_CALL java_sql_Driver::getImplementationName( ) throw(RuntimeException)
89 return getImplementationName_Static();
92 // --------------------------------------------------------------------------------
93 sal_Bool SAL_CALL java_sql_Driver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
95 Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
96 const ::rtl::OUString* pSupported = aSupported.getConstArray();
97 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
98 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
101 return pSupported != pEnd;
104 // --------------------------------------------------------------------------------
105 Sequence< ::rtl::OUString > SAL_CALL java_sql_Driver::getSupportedServiceNames( ) throw(RuntimeException)
107 return getSupportedServiceNames_Static();
109 // -------------------------------------------------------------------------
110 Reference< XConnection > SAL_CALL java_sql_Driver::connect( const ::rtl::OUString& url, const
111 Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
113 m_aLogger.log( LogLevel::INFO, STR_LOG_DRIVER_CONNECTING_URL, url );
115 Reference< XConnection > xOut;
116 if ( acceptsURL(url ) )
118 java_sql_Connection* pConnection = new java_sql_Connection( *this );
119 xOut = pConnection;
120 if ( !pConnection->construct(url,info) )
121 xOut.clear(); // an error occured and the java driver didn't throw an exception
122 else
123 m_aLogger.log( LogLevel::INFO, STR_LOG_DRIVER_SUCCESS );
125 return xOut;
127 // -------------------------------------------------------------------------
128 sal_Bool SAL_CALL java_sql_Driver::acceptsURL( const ::rtl::OUString& url ) throw(SQLException, RuntimeException)
130 // don't ask the real driver for the url
131 // I feel responsible for all jdbc url's
132 sal_Bool bEnabled = sal_False;
133 OSL_VERIFY_EQUALS( jfw_getEnabled( &bEnabled ), JFW_E_NONE, "error in jfw_getEnabled" );
134 static const ::rtl::OUString s_sJdbcPrefix = ::rtl::OUString::createFromAscii("jdbc:");
135 return bEnabled && 0 == url.compareTo(s_sJdbcPrefix, 5);
137 // -------------------------------------------------------------------------
138 Sequence< DriverPropertyInfo > SAL_CALL java_sql_Driver::getPropertyInfo( const ::rtl::OUString& url,
139 const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException)
141 if ( acceptsURL(url) )
143 ::std::vector< DriverPropertyInfo > aDriverInfo;
145 Sequence< ::rtl::OUString > aBooleanValues(2);
146 aBooleanValues[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) );
147 aBooleanValues[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) );
149 aDriverInfo.push_back(DriverPropertyInfo(
150 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JavaDriverClass"))
151 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("The JDBC driver class name."))
152 ,sal_True
153 ,::rtl::OUString()
154 ,Sequence< ::rtl::OUString >())
156 aDriverInfo.push_back(DriverPropertyInfo(
157 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JavaDriverClassPath"))
158 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("The class path where to look for the JDBC driver."))
159 ,sal_True
160 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "" ) )
161 ,Sequence< ::rtl::OUString >())
163 aDriverInfo.push_back(DriverPropertyInfo(
164 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SystemProperties"))
165 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Additional properties to set at java.lang.System before loading the driver."))
166 ,sal_True
167 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "" ) )
168 ,Sequence< ::rtl::OUString >())
170 aDriverInfo.push_back(DriverPropertyInfo(
171 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParameterNameSubstitution"))
172 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Change named parameters with '?'."))
173 ,sal_False
174 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
175 ,aBooleanValues)
177 aDriverInfo.push_back(DriverPropertyInfo(
178 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IgnoreDriverPrivileges"))
179 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Ignore the privileges from the database driver."))
180 ,sal_False
181 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
182 ,aBooleanValues)
184 aDriverInfo.push_back(DriverPropertyInfo(
185 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsAutoRetrievingEnabled"))
186 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Retrieve generated values."))
187 ,sal_False
188 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
189 ,aBooleanValues)
191 aDriverInfo.push_back(DriverPropertyInfo(
192 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AutoRetrievingStatement"))
193 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Auto-increment statement."))
194 ,sal_False
195 ,::rtl::OUString()
196 ,Sequence< ::rtl::OUString >())
198 aDriverInfo.push_back(DriverPropertyInfo(
199 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GenerateASBeforeCorrelationName"))
200 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Generate AS before table correlation names."))
201 ,sal_False
202 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) )
203 ,aBooleanValues)
205 aDriverInfo.push_back(DriverPropertyInfo(
206 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IgnoreCurrency"))
207 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Ignore the currency field from the ResultsetMetaData."))
208 ,sal_False
209 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
210 ,aBooleanValues)
212 aDriverInfo.push_back(DriverPropertyInfo(
213 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EscapeDateTime"))
214 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Escape date time format."))
215 ,sal_False
216 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) )
217 ,aBooleanValues)
219 aDriverInfo.push_back(DriverPropertyInfo(
220 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TypeInfoSettings"))
221 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Defines how the type info of the database metadata should be manipulated."))
222 ,sal_False
223 ,::rtl::OUString( )
224 ,Sequence< ::rtl::OUString > ())
226 aDriverInfo.push_back(DriverPropertyInfo(
227 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ImplicitCatalogRestriction"))
228 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("The catalog which should be used in getTables calls, when the caller passed NULL."))
229 ,sal_False
230 ,::rtl::OUString( )
231 ,Sequence< ::rtl::OUString > ())
233 aDriverInfo.push_back(DriverPropertyInfo(
234 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ImplicitSchemaRestriction"))
235 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("The schema which should be used in getTables calls, when the caller passed NULL."))
236 ,sal_False
237 ,::rtl::OUString( )
238 ,Sequence< ::rtl::OUString > ())
240 return Sequence< DriverPropertyInfo >(&aDriverInfo[0],aDriverInfo.size());
242 ::connectivity::SharedResources aResources;
243 const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
244 ::dbtools::throwGenericSQLException(sMessage ,*this);
245 return Sequence< DriverPropertyInfo >();
247 // -------------------------------------------------------------------------
248 sal_Int32 SAL_CALL java_sql_Driver::getMajorVersion( ) throw(RuntimeException)
250 return 1;
252 // -------------------------------------------------------------------------
253 sal_Int32 SAL_CALL java_sql_Driver::getMinorVersion( ) throw(RuntimeException)
255 return 0;
257 // -------------------------------------------------------------------------