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/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> 29 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; 36 37 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" ) 41 { 42 } 43 44 java_sql_Driver::~java_sql_Driver() 45 { 46 } 47 48 OUString SAL_CALL java_sql_Driver::getImplementationName( ) 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 55 sal_Bool SAL_CALL java_sql_Driver::supportsService( const OUString& _rServiceName ) 56 { 57 return cppu::supportsService(this, _rServiceName); 58 } 59 60 61 Sequence< OUString > SAL_CALL java_sql_Driver::getSupportedServiceNames( ) 62 { 63 return { "com.sun.star.sdbc.Driver" }; 64 } 65 66 Reference< 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 { 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 ); 80 } 81 return xOut; 82 } 83 84 sal_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; 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; 102 } 103 return bEnabled && url.startsWith("jdbc:"); 104 } 105 106 Sequence< 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 } 208 ::connectivity::SharedResources aResources; 209 const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR); 210 ::dbtools::throwGenericSQLException(sMessage ,*this); 211 return Sequence< DriverPropertyInfo >(); 212 } 213 214 sal_Int32 SAL_CALL java_sql_Driver::getMajorVersion( ) 215 { 216 return 1; 217 } 218 219 sal_Int32 SAL_CALL java_sql_Driver::getMinorVersion( ) 220 { 221 return 0; 222 } 223 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&) 227 { 228 return cppu::acquire(new java_sql_Driver(context)); 229 } 230 231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 232
