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 "NConnection.hxx" 27 #include "NDatabaseMetaData.hxx" 28 #include "NCatalog.hxx" 29 #include <com/sun/star/lang/DisposedException.hpp> 30 #include <com/sun/star/sdbc/TransactionIsolation.hpp> 31 #include <tools/urlobj.hxx> 32 #include "NPreparedStatement.hxx" 33 #include "NStatement.hxx" 34 #include <comphelper/extract.hxx> 35 #include <connectivity/dbexception.hxx> 36 #include <comphelper/processfactory.hxx> 37 #include <vos/process.hxx> 38 #include <tools/debug.hxx> 39 #include "NDebug.hxx" 40 #include <comphelper/sequence.hxx> 41 42 using namespace connectivity::evoab; 43 using namespace vos; 44 using namespace dbtools; 45 46 //------------------------------------------------------------------------------ 47 using namespace ::com::sun::star::uno; 48 using namespace ::com::sun::star::beans; 49 using namespace ::com::sun::star::sdbcx; 50 using namespace ::com::sun::star::sdbc; 51 using namespace ::com::sun::star::lang; 52 53 ::rtl::OUString implGetExceptionMsg( Exception& e, const ::rtl::OUString& aExceptionType_ ) 54 { 55 ::rtl::OUString aExceptionType = aExceptionType_; 56 if( aExceptionType.getLength() == 0 ) 57 aExceptionType = ::rtl::OUString::createFromAscii("Unknown" ) ; 58 59 ::rtl::OUString aTypeLine( RTL_CONSTASCII_USTRINGPARAM("\nType: " ) ); 60 aTypeLine += aExceptionType; 61 62 ::rtl::OUString aMessageLine( RTL_CONSTASCII_USTRINGPARAM("\nMessage: " ) ); 63 aMessageLine += ::rtl::OUString( e.Message ); 64 65 ::rtl::OUString aMsg(aTypeLine); 66 aMsg += aMessageLine; 67 return aMsg; 68 } 69 70 // Exception type unknown 71 ::rtl::OUString implGetExceptionMsg( Exception& e ) 72 { 73 ::rtl::OUString aMsg = implGetExceptionMsg( e, ::rtl::OUString() ); 74 return aMsg; 75 } 76 77 // -------------------------------------------------------------------------------- 78 OEvoabConnection::OEvoabConnection( OEvoabDriver& _rDriver ) 79 :OSubComponent<OEvoabConnection, OConnection_BASE>( (::cppu::OWeakObject*)(&_rDriver), this ) 80 ,m_rDriver(_rDriver) 81 ,m_xCatalog(NULL) 82 { 83 } 84 //----------------------------------------------------------------------------- 85 OEvoabConnection::~OEvoabConnection() 86 { 87 ::osl::MutexGuard aGuard( m_aMutex ); 88 89 if(!isClosed()) { 90 acquire(); 91 close(); 92 } 93 } 94 95 //----------------------------------------------------------------------------- 96 void SAL_CALL OEvoabConnection::release() throw() 97 { 98 relase_ChildImpl(); 99 } 100 101 // XServiceInfo 102 // -------------------------------------------------------------------------------- 103 IMPLEMENT_SERVICE_INFO(OEvoabConnection, "com.sun.star.sdbc.drivers.evoab.Connection", "com.sun.star.sdbc.Connection") 104 105 //----------------------------------------------------------------------------- 106 void OEvoabConnection::construct(const ::rtl::OUString& url, const Sequence< PropertyValue >& info) throw(SQLException) 107 { 108 osl_incrementInterlockedCount( &m_refCount ); 109 EVO_TRACE_STRING("OEvoabConnection::construct()::url = %s\n", url ); 110 111 ::rtl::OUString sPassword; 112 const char* pPwd = "password"; 113 114 const PropertyValue *pIter = info.getConstArray(); 115 const PropertyValue *pEnd = pIter + info.getLength(); 116 for(;pIter != pEnd;++pIter) 117 { 118 if(!pIter->Name.compareToAscii(pPwd)) 119 { 120 pIter->Value >>= sPassword; 121 break; 122 } 123 } 124 125 if (url.equalsAscii("sdbc:address:evolution:groupwise")) 126 setSDBCAddressType(SDBCAddress::EVO_GWISE); 127 else if (url.equalsAscii("sdbc:address:evolution:ldap")) 128 setSDBCAddressType(SDBCAddress::EVO_LDAP); 129 else 130 setSDBCAddressType(SDBCAddress::EVO_LOCAL); 131 setURL(url); 132 setPassword(::rtl::OUStringToOString(sPassword,RTL_TEXTENCODING_UTF8)); 133 osl_decrementInterlockedCount( &m_refCount ); 134 } 135 136 // -------------------------------------------------------------------------------- 137 ::rtl::OUString SAL_CALL OEvoabConnection::nativeSQL( const ::rtl::OUString& _sSql ) throw(SQLException, RuntimeException) 138 { 139 // when you need to transform SQL92 to you driver specific you can do it here 140 return _sSql; 141 } 142 // -------------------------------------------------------------------------------- 143 Reference< XDatabaseMetaData > SAL_CALL OEvoabConnection::getMetaData( ) throw(SQLException, RuntimeException) 144 { 145 ::osl::MutexGuard aGuard( m_aMutex ); 146 checkDisposed(OConnection_BASE::rBHelper.bDisposed); 147 148 Reference< XDatabaseMetaData > xMetaData = m_xMetaData; 149 if(!xMetaData.is()) 150 { 151 xMetaData = new OEvoabDatabaseMetaData(this); 152 m_xMetaData = xMetaData; 153 } 154 155 return xMetaData; 156 } 157 //------------------------------------------------------------------------------ 158 ::com::sun::star::uno::Reference< XTablesSupplier > OEvoabConnection::createCatalog() 159 { 160 ::osl::MutexGuard aGuard( m_aMutex ); 161 Reference< XTablesSupplier > xTab = m_xCatalog; 162 if(!xTab.is()) 163 { 164 OEvoabCatalog *pCat = new OEvoabCatalog(this); 165 xTab = pCat; 166 m_xCatalog = xTab; 167 } 168 return xTab; 169 } 170 // -------------------------------------------------------------------------------- 171 Reference< XStatement > SAL_CALL OEvoabConnection::createStatement( ) throw(SQLException, RuntimeException) 172 { 173 ::osl::MutexGuard aGuard( m_aMutex ); 174 checkDisposed(OConnection_BASE::rBHelper.bDisposed); 175 176 OStatement* pStmt = new OStatement(this); 177 178 Reference< XStatement > xStmt = pStmt; 179 m_aStatements.push_back(WeakReferenceHelper(*pStmt)); 180 return xStmt; 181 } 182 // -------------------------------------------------------------------------------- 183 Reference< XPreparedStatement > SAL_CALL OEvoabConnection::prepareStatement( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) 184 { 185 ::osl::MutexGuard aGuard( m_aMutex ); 186 checkDisposed(OConnection_BASE::rBHelper.bDisposed); 187 188 OEvoabPreparedStatement* pStmt = new OEvoabPreparedStatement( this ); 189 Reference< XPreparedStatement > xStmt = pStmt; 190 pStmt->construct( sql ); 191 192 m_aStatements.push_back(WeakReferenceHelper(*pStmt)); 193 return xStmt; 194 } 195 196 Reference< XPreparedStatement > SAL_CALL OEvoabConnection::prepareCall( const ::rtl::OUString& /*sql*/ ) throw( SQLException, RuntimeException) 197 { 198 ::dbtools::throwFeatureNotImplementedException( "XConnection::prepareCall", *this ); 199 return NULL; 200 } 201 sal_Bool SAL_CALL OEvoabConnection::isClosed( ) throw(SQLException, RuntimeException) 202 { 203 ::osl::MutexGuard aGuard( m_aMutex ); 204 return OConnection_BASE::rBHelper.bDisposed; 205 } 206 207 // -------------------------------------------------------------------------------- 208 // XCloseable 209 void SAL_CALL OEvoabConnection::close( ) throw(SQLException, RuntimeException) 210 { 211 { // we just dispose us 212 ::osl::MutexGuard aGuard( m_aMutex ); 213 checkDisposed(OConnection_BASE::rBHelper.bDisposed); 214 } 215 dispose(); 216 } 217 218 // -------------------------------------------------------------------------------- 219 // XWarningsSupplier 220 Any SAL_CALL OEvoabConnection::getWarnings( ) throw(SQLException, RuntimeException) 221 { 222 return m_aWarnings.getWarnings(); 223 } 224 void SAL_CALL OEvoabConnection::clearWarnings( ) throw(SQLException, RuntimeException) 225 { 226 m_aWarnings.clearWarnings(); 227 } 228 //------------------------------------------------------------------------------ 229 230 void OEvoabConnection::disposing() 231 { 232 // we noticed that we should be destroyed in near future so we have to dispose our statements 233 ::osl::MutexGuard aGuard(m_aMutex); 234 OConnection_BASE::disposing(); 235 dispose_ChildImpl(); 236 } 237 238 // -------------------------------- stubbed methods ------------------------------------------------ 239 void SAL_CALL OEvoabConnection::setAutoCommit( sal_Bool /*autoCommit*/ ) throw(SQLException, RuntimeException) 240 { 241 ::dbtools::throwFeatureNotImplementedException( "XConnection::setAutoCommit", *this ); 242 } 243 sal_Bool SAL_CALL OEvoabConnection::getAutoCommit( ) throw(SQLException, RuntimeException) 244 { 245 return sal_True; 246 } 247 void SAL_CALL OEvoabConnection::commit( ) throw(SQLException, RuntimeException) 248 { 249 } 250 void SAL_CALL OEvoabConnection::rollback( ) throw(SQLException, RuntimeException) 251 { 252 } 253 void SAL_CALL OEvoabConnection::setReadOnly( sal_Bool /*readOnly*/ ) throw(SQLException, RuntimeException) 254 { 255 ::dbtools::throwFeatureNotImplementedException( "XConnection::setReadOnly", *this ); 256 } 257 sal_Bool SAL_CALL OEvoabConnection::isReadOnly( ) throw(SQLException, RuntimeException) 258 { 259 return sal_False; 260 } 261 void SAL_CALL OEvoabConnection::setCatalog( const ::rtl::OUString& /*catalog*/ ) throw(SQLException, RuntimeException) 262 { 263 ::dbtools::throwFeatureNotImplementedException( "XConnection::setCatalog", *this ); 264 } 265 266 ::rtl::OUString SAL_CALL OEvoabConnection::getCatalog( ) throw(SQLException, RuntimeException) 267 { 268 return ::rtl::OUString(); 269 } 270 void SAL_CALL OEvoabConnection::setTransactionIsolation( sal_Int32 /*level*/ ) throw(SQLException, RuntimeException) 271 { 272 ::dbtools::throwFeatureNotImplementedException( "XConnection::setTransactionIsolation", *this ); 273 } 274 275 sal_Int32 SAL_CALL OEvoabConnection::getTransactionIsolation( ) throw(SQLException, RuntimeException) 276 { 277 return TransactionIsolation::NONE; 278 } 279 280 Reference< ::com::sun::star::container::XNameAccess > SAL_CALL OEvoabConnection::getTypeMap( ) throw(SQLException, RuntimeException) 281 { 282 ::dbtools::throwFeatureNotImplementedException( "XConnection::getTypeMap", *this ); 283 return NULL; 284 } 285 void SAL_CALL OEvoabConnection::setTypeMap( const Reference< ::com::sun::star::container::XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException) 286 { 287 ::dbtools::throwFeatureNotImplementedException( "XConnection::setTypeMap", *this ); 288 } 289