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