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