LibreOffice Module connectivity (master) 1
JDriver.cxx
Go to the documentation of this file.
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>
22#include <sal/log.hxx>
24#include <jvmfwk/framework.hxx>
25#include <strings.hrc>
28#include <strings.hxx>
29
30using namespace connectivity;
31using namespace ::com::sun::star::uno;
32using namespace ::com::sun::star::beans;
33using namespace ::com::sun::star::sdbc;
34using namespace ::com::sun::star::container;
35using namespace ::com::sun::star::lang;
36
37
38java_sql_Driver::java_sql_Driver(const Reference< css::uno::XComponentContext >& _rxContext)
39 :m_aContext( _rxContext )
40 ,m_aLogger( _rxContext, "org.openoffice.sdbc.jdbcBridge" )
41{
42}
43
45{
46}
47
49{
50 return "com.sun.star.comp.sdbc.JDBCDriver";
51 // this name is referenced in the configuration and in the jdbc.xml
52 // Please take care when changing it.
53}
54
55sal_Bool SAL_CALL java_sql_Driver::supportsService( const OUString& _rServiceName )
56{
57 return cppu::supportsService(this, _rServiceName);
58}
59
60
61Sequence< OUString > SAL_CALL java_sql_Driver::getSupportedServiceNames( )
62{
63 return { "com.sun.star.sdbc.Driver" };
64}
65
66Reference< XConnection > SAL_CALL java_sql_Driver::connect( const OUString& url, const
67 Sequence< PropertyValue >& info )
68{
69 m_aLogger.log( LogLevel::INFO, STR_LOG_DRIVER_CONNECTING_URL, url );
70
71 Reference< XConnection > xOut;
72 if ( acceptsURL(url ) )
73 {
75 xOut = pConnection;
76 if ( !pConnection->construct(url,info) )
77 xOut.clear(); // an error occurred and the java driver didn't throw an exception
78 else
79 m_aLogger.log( LogLevel::INFO, STR_LOG_DRIVER_SUCCESS );
80 }
81 return xOut;
82}
83
84sal_Bool SAL_CALL java_sql_Driver::acceptsURL( const OUString& url )
85{
86 // don't ask the real driver for the url
87 // I feel responsible for all jdbc url's
88 bool bEnabled = false;
90 switch (e) {
91 case JFW_E_NONE:
92 break;
95 "connectivity.jdbc",
96 "jfw_getEnabled: JFW_E_DIRECT_MODE, assuming true");
97 bEnabled = true;
98 break;
99 default:
100 SAL_WARN("connectivity.jdbc", "jfw_getEnabled: error code " << +e);
101 break;
102 }
103 return bEnabled && url.startsWith("jdbc:");
104}
105
106Sequence< DriverPropertyInfo > SAL_CALL java_sql_Driver::getPropertyInfo( const OUString& url,
107 const Sequence< PropertyValue >& /*info*/ )
108{
109 if ( acceptsURL(url) )
110 {
111 Sequence< OUString > aBooleanValues{ "false", "true" };
112
113 return
114 {
115 {
116 "JavaDriverClass"
117 ,"The JDBC driver class name."
118 ,true
119 ,OUString()
120 ,Sequence< OUString >()
121 },
122 {
123 "JavaDriverClassPath"
124 ,"The class path where to look for the JDBC driver."
125 ,true
126 , ""
127 ,Sequence< OUString >()
128 },
129 {
130 "SystemProperties"
131 ,"Additional properties to set at java.lang.System before loading the driver."
132 ,true
133 , ""
134 ,Sequence< OUString >()
135 },
136 {
137 "ParameterNameSubstitution"
138 ,"Change named parameters with '?'."
139 ,false
140 ,"false"
141 ,aBooleanValues
142 },
143 {
144 "IgnoreDriverPrivileges"
145 ,"Ignore the privileges from the database driver."
146 ,false
147 , "false"
148 ,aBooleanValues
149 },
150 {
151 "IsAutoRetrievingEnabled"
152 ,"Retrieve generated values."
153 ,false
154 ,"false"
155 ,aBooleanValues
156 },
157 {
158 "AutoRetrievingStatement"
159 ,"Auto-increment statement."
160 ,false
161 ,OUString()
162 ,Sequence< OUString >()
163 },
164 {
165 "GenerateASBeforeCorrelationName"
166 ,"Generate AS before table correlation names."
167 ,false
168 ,"false"
169 ,aBooleanValues
170 },
171 {
172 "IgnoreCurrency"
173 ,"Ignore the currency field from the ResultsetMetaData."
174 ,false
175 ,"false"
176 ,aBooleanValues
177 },
178 {
179 "EscapeDateTime"
180 ,"Escape date time format."
181 ,false
182 ,"true"
183 ,aBooleanValues
184 },
185 {
186 "TypeInfoSettings"
187 ,"Defines how the type info of the database metadata should be manipulated."
188 ,false
189 ,OUString()
190 ,Sequence< OUString > ()
191 },
192 {
193 "ImplicitCatalogRestriction"
194 ,"The catalog which should be used in getTables calls, when the caller passed NULL."
195 ,false
196 ,OUString( )
197 ,Sequence< OUString > ()
198 },
199 {
200 "ImplicitSchemaRestriction"
201 ,"The schema which should be used in getTables calls, when the caller passed NULL."
202 ,false
203 ,OUString( )
204 ,Sequence< OUString > ()
205 }
206 };
207 }
209 const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
211 return Sequence< DriverPropertyInfo >();
212}
213
215{
216 return 1;
217}
218
220{
221 return 0;
222}
223
224extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
226 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
227{
228 return cppu::acquire(new java_sql_Driver(context));
229}
230
231/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * connectivity_java_sql_Driver_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: JDriver.cxx:225
void log(const sal_Int32 _nLogLevel, const OUString &rMessage) const
helper class for accessing resources shared by different libraries in the connectivity module
OUString getResourceString(TranslateId pResId) const
loads a string from the shared resource file
virtual sal_Int32 SAL_CALL getMajorVersion() override
Definition: JDriver.cxx:214
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: JDriver.cxx:55
::comphelper::EventLogger m_aLogger
virtual css::uno::Sequence< css::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo(const OUString &url, const css::uno::Sequence< css::beans::PropertyValue > &info) override
Definition: JDriver.cxx:106
virtual sal_Int32 SAL_CALL getMinorVersion() override
Definition: JDriver.cxx:219
virtual sal_Bool SAL_CALL acceptsURL(const OUString &url) override
Definition: JDriver.cxx:84
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: JDriver.cxx:61
virtual OUString SAL_CALL getImplementationName() override
Definition: JDriver.cxx:48
virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL connect(const OUString &url, const css::uno::Sequence< css::beans::PropertyValue > &info) override
Definition: JDriver.cxx:66
virtual ~java_sql_Driver() override
Definition: JDriver.cxx:44
Reference< XComponentContext > m_aContext
javaFrameworkError jfw_getEnabled(bool *pbEnabled)
javaFrameworkError
JFW_E_DIRECT_MODE
JFW_E_NONE
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
void throwGenericSQLException(const OUString &_rMsg, const css::uno::Reference< css::uno::XInterface > &_rxSource)
throw a generic SQLException, i.e.
OUString sMessage
constexpr OUStringLiteral STR_LOG_DRIVER_SUCCESS
Definition: strings.hxx:17
#define STR_LOG_DRIVER_CONNECTING_URL
Definition: strings.hxx:16
unsigned char sal_Bool