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 "TConnection.hxx" 27 #include <cppuhelper/typeprovider.hxx> 28 #include <comphelper/types.hxx> 29 #include <comphelper/officeresourcebundle.hxx> 30 #include <connectivity/dbexception.hxx> 31 32 using namespace connectivity; 33 using namespace com::sun::star::uno; 34 using namespace com::sun::star::lang; 35 using namespace com::sun::star::sdbc; 36 using namespace com::sun::star::beans; 37 using namespace ::osl; 38 39 //------------------------------------------------------------------------------ 40 OMetaConnection::OMetaConnection() 41 : OMetaConnection_BASE(m_aMutex) 42 , m_nTextEncoding(RTL_TEXTENCODING_MS_1252) 43 { 44 } 45 //------------------------------------------------------------------------------ 46 void OMetaConnection::disposing() 47 { 48 ::osl::MutexGuard aGuard(m_aMutex); 49 m_xMetaData = WeakReference< XDatabaseMetaData>(); 50 for (OWeakRefArray::iterator i = m_aStatements.begin(); m_aStatements.end() != i; ++i) 51 { 52 try 53 { 54 Reference< XInterface > xStatement( i->get() ); 55 ::comphelper::disposeComponent( xStatement ); 56 } 57 catch (DisposedException) 58 { 59 } 60 } 61 m_aStatements.clear(); 62 } 63 //XUnoTunnel 64 sal_Int64 SAL_CALL OMetaConnection::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw (::com::sun::star::uno::RuntimeException) 65 { 66 return (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) ) 67 ? reinterpret_cast< sal_Int64 >( this ) 68 : (sal_Int64)0; 69 } 70 // ----------------------------------------------------------------------------- 71 Sequence< sal_Int8 > OMetaConnection::getUnoTunnelImplementationId() 72 { 73 static ::cppu::OImplementationId * pId = 0; 74 if (! pId) 75 { 76 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 77 if (! pId) 78 { 79 static ::cppu::OImplementationId aId; 80 pId = &aId; 81 } 82 } 83 return pId->getImplementationId(); 84 } 85 // ----------------------------------------------------------------------------- 86 ::dbtools::OPropertyMap& OMetaConnection::getPropMap() 87 { 88 static ::dbtools::OPropertyMap s_aPropertyNameMap; 89 return s_aPropertyNameMap; 90 } 91 // ----------------------------------------------------------------------------- 92 void OMetaConnection::throwGenericSQLException( sal_uInt16 _nErrorResourceId,const Reference< XInterface>& _xContext ) 93 { 94 ::rtl::OUString sErrorMessage; 95 if ( _nErrorResourceId ) 96 sErrorMessage = m_aResources.getResourceString( _nErrorResourceId ); 97 Reference< XInterface> xContext = _xContext; 98 if ( !xContext.is() ) 99 xContext = *this; 100 ::dbtools::throwGenericSQLException( sErrorMessage, xContext); 101 } 102 103