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