1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_connectivity.hxx" 30 #include "java/sql/Driver.hxx" 31 #include "java/lang/Object.hxx" 32 #include "java/lang/Class.hxx" 33 #include "java/sql/DriverPropertyInfo.hxx" 34 #include "java/sql/Connection.hxx" 35 #include "java/util/Property.hxx" 36 #include "java/tools.hxx" 37 #include "connectivity/dbexception.hxx" 38 #include <jvmfwk/framework.h> 39 #include "diagnose_ex.h" 40 #include "resource/jdbc_log.hrc" 41 #include "resource/common_res.hrc" 42 #include "resource/sharedresources.hxx" 43 #include <comphelper/componentcontext.hxx> 44 45 using namespace connectivity; 46 using namespace ::com::sun::star::uno; 47 using namespace ::com::sun::star::beans; 48 using namespace ::com::sun::star::sdbc; 49 using namespace ::com::sun::star::container; 50 using namespace ::com::sun::star::lang; 51 52 // ------------------------------------------------------------------------- 53 java_sql_Driver::java_sql_Driver(const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) 54 :m_aContext( _rxFactory ) 55 ,m_aLogger( m_aContext.getUNOContext(), "sdbcl", "org.openoffice.sdbc.jdbcBridge" ) 56 { 57 } 58 // -------------------------------------------------------------------------------- 59 java_sql_Driver::~java_sql_Driver() 60 { 61 } 62 63 // static ServiceInfo 64 //------------------------------------------------------------------------------ 65 rtl::OUString java_sql_Driver::getImplementationName_Static( ) throw(RuntimeException) 66 { 67 return ::rtl::OUString::createFromAscii("com.sun.star.comp.sdbc.JDBCDriver"); 68 // this name is referenced in the configuration and in the jdbc.xml 69 // Please take care when changing it. 70 } 71 //------------------------------------------------------------------------------ 72 Sequence< ::rtl::OUString > java_sql_Driver::getSupportedServiceNames_Static( ) throw (RuntimeException) 73 { 74 Sequence< ::rtl::OUString > aSNS( 1 ); 75 aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver"); 76 return aSNS; 77 } 78 //------------------------------------------------------------------ 79 ::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 ) 80 { 81 return *(new java_sql_Driver(_rxFactory)); 82 } 83 // -------------------------------------------------------------------------------- 84 ::rtl::OUString SAL_CALL java_sql_Driver::getImplementationName( ) throw(RuntimeException) 85 { 86 return getImplementationName_Static(); 87 } 88 89 // -------------------------------------------------------------------------------- 90 sal_Bool SAL_CALL java_sql_Driver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException) 91 { 92 Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); 93 const ::rtl::OUString* pSupported = aSupported.getConstArray(); 94 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength(); 95 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported) 96 ; 97 98 return pSupported != pEnd; 99 } 100 101 // -------------------------------------------------------------------------------- 102 Sequence< ::rtl::OUString > SAL_CALL java_sql_Driver::getSupportedServiceNames( ) throw(RuntimeException) 103 { 104 return getSupportedServiceNames_Static(); 105 } 106 // ------------------------------------------------------------------------- 107 Reference< XConnection > SAL_CALL java_sql_Driver::connect( const ::rtl::OUString& url, const 108 Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException) 109 { 110 m_aLogger.log( LogLevel::INFO, STR_LOG_DRIVER_CONNECTING_URL, url ); 111 112 Reference< XConnection > xOut; 113 if ( acceptsURL(url ) ) 114 { 115 java_sql_Connection* pConnection = new java_sql_Connection( *this ); 116 xOut = pConnection; 117 if ( !pConnection->construct(url,info) ) 118 xOut.clear(); // an error occured and the java driver didn't throw an exception 119 else 120 m_aLogger.log( LogLevel::INFO, STR_LOG_DRIVER_SUCCESS ); 121 } 122 return xOut; 123 } 124 // ------------------------------------------------------------------------- 125 sal_Bool SAL_CALL java_sql_Driver::acceptsURL( const ::rtl::OUString& url ) throw(SQLException, RuntimeException) 126 { 127 // don't ask the real driver for the url 128 // I feel responsible for all jdbc url's 129 sal_Bool bEnabled = sal_False; 130 OSL_VERIFY_EQUALS( jfw_getEnabled( &bEnabled ), JFW_E_NONE, "error in jfw_getEnabled" ); 131 static const ::rtl::OUString s_sJdbcPrefix = ::rtl::OUString::createFromAscii("jdbc:"); 132 return bEnabled && 0 == url.compareTo(s_sJdbcPrefix, 5); 133 } 134 // ------------------------------------------------------------------------- 135 Sequence< DriverPropertyInfo > SAL_CALL java_sql_Driver::getPropertyInfo( const ::rtl::OUString& url, 136 const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException) 137 { 138 if ( acceptsURL(url) ) 139 { 140 ::std::vector< DriverPropertyInfo > aDriverInfo; 141 142 Sequence< ::rtl::OUString > aBooleanValues(2); 143 aBooleanValues[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) ); 144 aBooleanValues[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) ); 145 146 aDriverInfo.push_back(DriverPropertyInfo( 147 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JavaDriverClass")) 148 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("The JDBC driver class name.")) 149 ,sal_True 150 ,::rtl::OUString() 151 ,Sequence< ::rtl::OUString >()) 152 ); 153 aDriverInfo.push_back(DriverPropertyInfo( 154 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JavaDriverClassPath")) 155 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("The class path where to look for the JDBC driver.")) 156 ,sal_True 157 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "" ) ) 158 ,Sequence< ::rtl::OUString >()) 159 ); 160 aDriverInfo.push_back(DriverPropertyInfo( 161 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SystemProperties")) 162 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Additional properties to set at java.lang.System before loading the driver.")) 163 ,sal_True 164 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "" ) ) 165 ,Sequence< ::rtl::OUString >()) 166 ); 167 aDriverInfo.push_back(DriverPropertyInfo( 168 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParameterNameSubstitution")) 169 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Change named parameters with '?'.")) 170 ,sal_False 171 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) ) 172 ,aBooleanValues) 173 ); 174 aDriverInfo.push_back(DriverPropertyInfo( 175 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IgnoreDriverPrivileges")) 176 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Ignore the privileges from the database driver.")) 177 ,sal_False 178 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) ) 179 ,aBooleanValues) 180 ); 181 aDriverInfo.push_back(DriverPropertyInfo( 182 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsAutoRetrievingEnabled")) 183 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Retrieve generated values.")) 184 ,sal_False 185 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) ) 186 ,aBooleanValues) 187 ); 188 aDriverInfo.push_back(DriverPropertyInfo( 189 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AutoRetrievingStatement")) 190 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Auto-increment statement.")) 191 ,sal_False 192 ,::rtl::OUString() 193 ,Sequence< ::rtl::OUString >()) 194 ); 195 aDriverInfo.push_back(DriverPropertyInfo( 196 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GenerateASBeforeCorrelationName")) 197 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Generate AS before table correlation names.")) 198 ,sal_False 199 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) ) 200 ,aBooleanValues) 201 ); 202 aDriverInfo.push_back(DriverPropertyInfo( 203 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IgnoreCurrency")) 204 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Ignore the currency field from the ResultsetMetaData.")) 205 ,sal_False 206 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) ) 207 ,aBooleanValues) 208 ); 209 aDriverInfo.push_back(DriverPropertyInfo( 210 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EscapeDateTime")) 211 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Escape date time format.")) 212 ,sal_False 213 ,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) ) 214 ,aBooleanValues) 215 ); 216 aDriverInfo.push_back(DriverPropertyInfo( 217 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TypeInfoSettings")) 218 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Defines how the type info of the database metadata should be manipulated.")) 219 ,sal_False 220 ,::rtl::OUString( ) 221 ,Sequence< ::rtl::OUString > ()) 222 ); 223 aDriverInfo.push_back(DriverPropertyInfo( 224 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ImplicitCatalogRestriction")) 225 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("The catalog which should be used in getTables calls, when the caller passed NULL.")) 226 ,sal_False 227 ,::rtl::OUString( ) 228 ,Sequence< ::rtl::OUString > ()) 229 ); 230 aDriverInfo.push_back(DriverPropertyInfo( 231 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ImplicitSchemaRestriction")) 232 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("The schema which should be used in getTables calls, when the caller passed NULL.")) 233 ,sal_False 234 ,::rtl::OUString( ) 235 ,Sequence< ::rtl::OUString > ()) 236 ); 237 return Sequence< DriverPropertyInfo >(&aDriverInfo[0],aDriverInfo.size()); 238 } 239 ::connectivity::SharedResources aResources; 240 const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR); 241 ::dbtools::throwGenericSQLException(sMessage ,*this); 242 return Sequence< DriverPropertyInfo >(); 243 } 244 // ------------------------------------------------------------------------- 245 sal_Int32 SAL_CALL java_sql_Driver::getMajorVersion( ) throw(RuntimeException) 246 { 247 return 1; 248 } 249 // ------------------------------------------------------------------------- 250 sal_Int32 SAL_CALL java_sql_Driver::getMinorVersion( ) throw(RuntimeException) 251 { 252 return 0; 253 } 254 // ------------------------------------------------------------------------- 255 256 257