1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <java/sql/Driver.hxx>
21 #include <java/sql/Connection.hxx>
22 #include <sal/log.hxx>
23 #include <connectivity/dbexception.hxx>
24 #include <jvmfwk/framework.hxx>
25 #include <strings.hrc>
26 #include <resource/sharedresources.hxx>
27 #include <cppuhelper/supportsservice.hxx>
28 #include <strings.hxx>
30 using namespace connectivity
;
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::beans
;
33 using namespace ::com::sun::star::sdbc
;
34 using namespace ::com::sun::star::container
;
35 using namespace ::com::sun::star::lang
;
38 java_sql_Driver::java_sql_Driver(const Reference
< css::uno::XComponentContext
>& _rxContext
)
39 :m_aContext( _rxContext
)
40 ,m_aLogger( _rxContext
, "org.openoffice.sdbc.jdbcBridge" )
44 java_sql_Driver::~java_sql_Driver()
48 OUString SAL_CALL
java_sql_Driver::getImplementationName( )
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.
55 sal_Bool SAL_CALL
java_sql_Driver::supportsService( const OUString
& _rServiceName
)
57 return cppu::supportsService(this, _rServiceName
);
61 Sequence
< OUString
> SAL_CALL
java_sql_Driver::getSupportedServiceNames( )
63 return { "com.sun.star.sdbc.Driver" };
66 Reference
< XConnection
> SAL_CALL
java_sql_Driver::connect( const OUString
& url
, const
67 Sequence
< PropertyValue
>& info
)
69 m_aLogger
.log( LogLevel::INFO
, STR_LOG_DRIVER_CONNECTING_URL
, url
);
71 Reference
< XConnection
> xOut
;
72 if ( acceptsURL(url
) )
74 rtl::Reference
<java_sql_Connection
> pConnection
= new java_sql_Connection( *this );
76 if ( !pConnection
->construct(url
,info
) )
77 xOut
.clear(); // an error occurred and the java driver didn't throw an exception
79 m_aLogger
.log( LogLevel::INFO
, STR_LOG_DRIVER_SUCCESS
);
84 sal_Bool SAL_CALL
java_sql_Driver::acceptsURL( const OUString
& url
)
86 // don't ask the real driver for the url
87 // I feel responsible for all jdbc url's
88 bool bEnabled
= false;
89 javaFrameworkError e
= jfw_getEnabled(&bEnabled
);
93 case JFW_E_DIRECT_MODE
:
96 "jfw_getEnabled: JFW_E_DIRECT_MODE, assuming true");
100 SAL_WARN("connectivity.jdbc", "jfw_getEnabled: error code " << +e
);
103 return bEnabled
&& url
.startsWith("jdbc:");
106 Sequence
< DriverPropertyInfo
> SAL_CALL
java_sql_Driver::getPropertyInfo( const OUString
& url
,
107 const Sequence
< PropertyValue
>& /*info*/ )
109 if ( acceptsURL(url
) )
111 Sequence
< OUString
> aBooleanValues
{ "false", "true" };
117 ,"The JDBC driver class name."
120 ,Sequence
< OUString
>()
123 "JavaDriverClassPath"
124 ,"The class path where to look for the JDBC driver."
127 ,Sequence
< OUString
>()
131 ,"Additional properties to set at java.lang.System before loading the driver."
134 ,Sequence
< OUString
>()
137 "ParameterNameSubstitution"
138 ,"Change named parameters with '?'."
144 "IgnoreDriverPrivileges"
145 ,"Ignore the privileges from the database driver."
151 "IsAutoRetrievingEnabled"
152 ,"Retrieve generated values."
158 "AutoRetrievingStatement"
159 ,"Auto-increment statement."
162 ,Sequence
< OUString
>()
165 "GenerateASBeforeCorrelationName"
166 ,"Generate AS before table correlation names."
173 ,"Ignore the currency field from the ResultsetMetaData."
180 ,"Escape date time format."
187 ,"Defines how the type info of the database metadata should be manipulated."
190 ,Sequence
< OUString
> ()
193 "ImplicitCatalogRestriction"
194 ,"The catalog which should be used in getTables calls, when the caller passed NULL."
197 ,Sequence
< OUString
> ()
200 "ImplicitSchemaRestriction"
201 ,"The schema which should be used in getTables calls, when the caller passed NULL."
204 ,Sequence
< OUString
> ()
208 ::connectivity::SharedResources aResources
;
209 const OUString sMessage
= aResources
.getResourceString(STR_URI_SYNTAX_ERROR
);
210 ::dbtools::throwGenericSQLException(sMessage
,*this);
211 return Sequence
< DriverPropertyInfo
>();
214 sal_Int32 SAL_CALL
java_sql_Driver::getMajorVersion( )
219 sal_Int32 SAL_CALL
java_sql_Driver::getMinorVersion( )
224 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
225 connectivity_java_sql_Driver_get_implementation(
226 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const&)
228 return cppu::acquire(new java_sql_Driver(context
));
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */