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 :
35 : using namespace connectivity;
36 : using namespace ::com::sun::star::uno;
37 : using namespace ::com::sun::star::beans;
38 : using namespace ::com::sun::star::sdbc;
39 : using namespace ::com::sun::star::container;
40 : using namespace ::com::sun::star::lang;
41 :
42 : // -------------------------------------------------------------------------
43 0 : java_sql_Driver::java_sql_Driver(const Reference< ::com::sun::star::uno::XComponentContext >& _rxContext)
44 : :m_aContext( _rxContext )
45 0 : ,m_aLogger( _rxContext, "sdbcl", "org.openoffice.sdbc.jdbcBridge" )
46 : {
47 0 : }
48 : // --------------------------------------------------------------------------------
49 0 : java_sql_Driver::~java_sql_Driver()
50 : {
51 0 : }
52 :
53 : // static ServiceInfo
54 : //------------------------------------------------------------------------------
55 0 : OUString java_sql_Driver::getImplementationName_Static( ) throw(RuntimeException)
56 : {
57 0 : return OUString("com.sun.star.comp.sdbc.JDBCDriver");
58 : // this name is referenced in the configuration and in the jdbc.xml
59 : // Please take care when changing it.
60 : }
61 : //------------------------------------------------------------------------------
62 0 : Sequence< OUString > java_sql_Driver::getSupportedServiceNames_Static( ) throw (RuntimeException)
63 : {
64 0 : Sequence< OUString > aSNS( 1 );
65 0 : aSNS[0] = OUString("com.sun.star.sdbc.Driver");
66 0 : return aSNS;
67 : }
68 : //------------------------------------------------------------------
69 0 : ::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 )
70 : {
71 0 : return *(new java_sql_Driver( comphelper::getComponentContext(_rxFactory)));
72 : }
73 : // --------------------------------------------------------------------------------
74 0 : OUString SAL_CALL java_sql_Driver::getImplementationName( ) throw(RuntimeException)
75 : {
76 0 : return getImplementationName_Static();
77 : }
78 :
79 : // --------------------------------------------------------------------------------
80 0 : sal_Bool SAL_CALL java_sql_Driver::supportsService( const OUString& _rServiceName ) throw(RuntimeException)
81 : {
82 0 : Sequence< OUString > aSupported(getSupportedServiceNames());
83 0 : const OUString* pSupported = aSupported.getConstArray();
84 0 : const OUString* pEnd = pSupported + aSupported.getLength();
85 0 : for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
86 : ;
87 :
88 0 : return pSupported != pEnd;
89 : }
90 :
91 : // --------------------------------------------------------------------------------
92 0 : Sequence< OUString > SAL_CALL java_sql_Driver::getSupportedServiceNames( ) throw(RuntimeException)
93 : {
94 0 : return getSupportedServiceNames_Static();
95 : }
96 : // -------------------------------------------------------------------------
97 0 : Reference< XConnection > SAL_CALL java_sql_Driver::connect( const OUString& url, const
98 : Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
99 : {
100 0 : m_aLogger.log( LogLevel::INFO, STR_LOG_DRIVER_CONNECTING_URL, url );
101 :
102 0 : Reference< XConnection > xOut;
103 0 : if ( acceptsURL(url ) )
104 : {
105 0 : java_sql_Connection* pConnection = new java_sql_Connection( *this );
106 0 : xOut = pConnection;
107 0 : if ( !pConnection->construct(url,info) )
108 0 : xOut.clear(); // an error occurred and the java driver didn't throw an exception
109 : else
110 0 : m_aLogger.log( LogLevel::INFO, STR_LOG_DRIVER_SUCCESS );
111 : }
112 0 : return xOut;
113 : }
114 : // -------------------------------------------------------------------------
115 0 : sal_Bool SAL_CALL java_sql_Driver::acceptsURL( const OUString& url ) throw(SQLException, RuntimeException)
116 : {
117 : // don't ask the real driver for the url
118 : // I feel responsible for all jdbc url's
119 0 : sal_Bool bEnabled = sal_False;
120 0 : OSL_VERIFY_EQUALS( jfw_getEnabled( &bEnabled ), JFW_E_NONE, "error in jfw_getEnabled" );
121 0 : return bEnabled && url.startsWith("jdbc:");
122 : }
123 : // -------------------------------------------------------------------------
124 0 : Sequence< DriverPropertyInfo > SAL_CALL java_sql_Driver::getPropertyInfo( const OUString& url,
125 : const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException)
126 : {
127 0 : if ( acceptsURL(url) )
128 : {
129 0 : ::std::vector< DriverPropertyInfo > aDriverInfo;
130 :
131 0 : Sequence< OUString > aBooleanValues(2);
132 0 : aBooleanValues[0] = OUString( "false" );
133 0 : aBooleanValues[1] = OUString( "true" );
134 :
135 : aDriverInfo.push_back(DriverPropertyInfo(
136 : OUString("JavaDriverClass")
137 : ,OUString("The JDBC driver class name.")
138 : ,sal_True
139 : ,OUString()
140 : ,Sequence< OUString >())
141 0 : );
142 : aDriverInfo.push_back(DriverPropertyInfo(
143 : OUString("JavaDriverClassPath")
144 : ,OUString("The class path where to look for the JDBC driver.")
145 : ,sal_True
146 : ,OUString( "" )
147 : ,Sequence< OUString >())
148 0 : );
149 : aDriverInfo.push_back(DriverPropertyInfo(
150 : OUString("SystemProperties")
151 : ,OUString("Additional properties to set at java.lang.System before loading the driver.")
152 : ,sal_True
153 : ,OUString( "" )
154 : ,Sequence< OUString >())
155 0 : );
156 : aDriverInfo.push_back(DriverPropertyInfo(
157 : OUString("ParameterNameSubstitution")
158 : ,OUString("Change named parameters with '?'.")
159 : ,sal_False
160 : ,OUString( "false" )
161 : ,aBooleanValues)
162 0 : );
163 : aDriverInfo.push_back(DriverPropertyInfo(
164 : OUString("IgnoreDriverPrivileges")
165 : ,OUString("Ignore the privileges from the database driver.")
166 : ,sal_False
167 : ,OUString( "false" )
168 : ,aBooleanValues)
169 0 : );
170 : aDriverInfo.push_back(DriverPropertyInfo(
171 : OUString("IsAutoRetrievingEnabled")
172 : ,OUString("Retrieve generated values.")
173 : ,sal_False
174 : ,OUString( "false" )
175 : ,aBooleanValues)
176 0 : );
177 : aDriverInfo.push_back(DriverPropertyInfo(
178 : OUString("AutoRetrievingStatement")
179 : ,OUString("Auto-increment statement.")
180 : ,sal_False
181 : ,OUString()
182 : ,Sequence< OUString >())
183 0 : );
184 : aDriverInfo.push_back(DriverPropertyInfo(
185 : OUString("GenerateASBeforeCorrelationName")
186 : ,OUString("Generate AS before table correlation names.")
187 : ,sal_False
188 : ,OUString( "true" )
189 : ,aBooleanValues)
190 0 : );
191 : aDriverInfo.push_back(DriverPropertyInfo(
192 : OUString("IgnoreCurrency")
193 : ,OUString("Ignore the currency field from the ResultsetMetaData.")
194 : ,sal_False
195 : ,OUString( "false" )
196 : ,aBooleanValues)
197 0 : );
198 : aDriverInfo.push_back(DriverPropertyInfo(
199 : OUString("EscapeDateTime")
200 : ,OUString("Escape date time format.")
201 : ,sal_False
202 : ,OUString( "true" )
203 : ,aBooleanValues)
204 0 : );
205 : aDriverInfo.push_back(DriverPropertyInfo(
206 : OUString("TypeInfoSettings")
207 : ,OUString("Defines how the type info of the database metadata should be manipulated.")
208 : ,sal_False
209 : ,OUString( )
210 : ,Sequence< OUString > ())
211 0 : );
212 : aDriverInfo.push_back(DriverPropertyInfo(
213 : OUString("ImplicitCatalogRestriction")
214 : ,OUString("The catalog which should be used in getTables calls, when the caller passed NULL.")
215 : ,sal_False
216 : ,OUString( )
217 : ,Sequence< OUString > ())
218 0 : );
219 : aDriverInfo.push_back(DriverPropertyInfo(
220 : OUString("ImplicitSchemaRestriction")
221 : ,OUString("The schema which should be used in getTables calls, when the caller passed NULL.")
222 : ,sal_False
223 : ,OUString( )
224 : ,Sequence< OUString > ())
225 0 : );
226 0 : return Sequence< DriverPropertyInfo >(&aDriverInfo[0],aDriverInfo.size());
227 : }
228 0 : ::connectivity::SharedResources aResources;
229 0 : const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
230 0 : ::dbtools::throwGenericSQLException(sMessage ,*this);
231 0 : return Sequence< DriverPropertyInfo >();
232 : }
233 : // -------------------------------------------------------------------------
234 0 : sal_Int32 SAL_CALL java_sql_Driver::getMajorVersion( ) throw(RuntimeException)
235 : {
236 0 : return 1;
237 : }
238 : // -------------------------------------------------------------------------
239 0 : sal_Int32 SAL_CALL java_sql_Driver::getMinorVersion( ) throw(RuntimeException)
240 : {
241 0 : return 0;
242 : }
243 : // -------------------------------------------------------------------------
244 :
245 :
246 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|