Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / connectivity / source / drivers / jdbc / JDriver.cxx
blobf294d30b493728a928bd47c64a09cca0817efd46
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 );
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 );
81 return xOut;
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);
90 switch (e) {
91 case JFW_E_NONE:
92 break;
93 case JFW_E_DIRECT_MODE:
94 SAL_INFO(
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;
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" };
113 return
116 "JavaDriverClass"
117 ,"The JDBC driver class name."
118 ,true
119 ,OUString()
120 ,Sequence< OUString >()
123 "JavaDriverClassPath"
124 ,"The class path where to look for the JDBC driver."
125 ,true
126 , ""
127 ,Sequence< OUString >()
130 "SystemProperties"
131 ,"Additional properties to set at java.lang.System before loading the driver."
132 ,true
133 , ""
134 ,Sequence< OUString >()
137 "ParameterNameSubstitution"
138 ,"Change named parameters with '?'."
139 ,false
140 ,"false"
141 ,aBooleanValues
144 "IgnoreDriverPrivileges"
145 ,"Ignore the privileges from the database driver."
146 ,false
147 , "false"
148 ,aBooleanValues
151 "IsAutoRetrievingEnabled"
152 ,"Retrieve generated values."
153 ,false
154 ,"false"
155 ,aBooleanValues
158 "AutoRetrievingStatement"
159 ,"Auto-increment statement."
160 ,false
161 ,OUString()
162 ,Sequence< OUString >()
165 "GenerateASBeforeCorrelationName"
166 ,"Generate AS before table correlation names."
167 ,false
168 ,"false"
169 ,aBooleanValues
172 "IgnoreCurrency"
173 ,"Ignore the currency field from the ResultsetMetaData."
174 ,false
175 ,"false"
176 ,aBooleanValues
179 "EscapeDateTime"
180 ,"Escape date time format."
181 ,false
182 ,"true"
183 ,aBooleanValues
186 "TypeInfoSettings"
187 ,"Defines how the type info of the database metadata should be manipulated."
188 ,false
189 ,OUString()
190 ,Sequence< OUString > ()
193 "ImplicitCatalogRestriction"
194 ,"The catalog which should be used in getTables calls, when the caller passed NULL."
195 ,false
196 ,OUString( )
197 ,Sequence< OUString > ()
200 "ImplicitSchemaRestriction"
201 ,"The schema which should be used in getTables calls, when the caller passed NULL."
202 ,false
203 ,OUString( )
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( )
216 return 1;
219 sal_Int32 SAL_CALL java_sql_Driver::getMinorVersion( )
221 return 0;
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: */