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