1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9b5730f6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9b5730f6SAndrew Rist  * distributed with this work for additional information
6*9b5730f6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9b5730f6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist  * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9b5730f6SAndrew Rist  *
11*9b5730f6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9b5730f6SAndrew Rist  *
13*9b5730f6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist  * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9b5730f6SAndrew Rist  * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist  * under the License.
19*9b5730f6SAndrew Rist  *
20*9b5730f6SAndrew Rist  *************************************************************/
21*9b5730f6SAndrew Rist 
22*9b5730f6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir #include "ZConnectionWrapper.hxx"
27cdf0e10cSrcweir #include <com/sun/star/sdbc/ColumnValue.hpp>
28cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
29cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
30cdf0e10cSrcweir #include <comphelper/extract.hxx>
31cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
32cdf0e10cSrcweir #include <comphelper/sequence.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir using namespace connectivity;
35cdf0e10cSrcweir //------------------------------------------------------------------------------
36cdf0e10cSrcweir using namespace com::sun::star::uno;
37cdf0e10cSrcweir using namespace com::sun::star::lang;
38cdf0e10cSrcweir using namespace com::sun::star::beans;
39cdf0e10cSrcweir using namespace com::sun::star::sdbc;
40cdf0e10cSrcweir // --------------------------------------------------------------------------------
OConnectionWeakWrapper(Reference<XAggregation> & _xConnection)41cdf0e10cSrcweir OConnectionWeakWrapper::OConnectionWeakWrapper(Reference< XAggregation >& _xConnection)
42cdf0e10cSrcweir 	: OConnectionWeakWrapper_BASE(m_aMutex)
43cdf0e10cSrcweir {
44cdf0e10cSrcweir 	setDelegation(_xConnection,m_refCount);
45cdf0e10cSrcweir 	OSL_ENSURE(m_xConnection.is(),"OConnectionWeakWrapper: Connection must be valid!");
46cdf0e10cSrcweir }
47cdf0e10cSrcweir //-----------------------------------------------------------------------------
~OConnectionWeakWrapper()48cdf0e10cSrcweir OConnectionWeakWrapper::~OConnectionWeakWrapper()
49cdf0e10cSrcweir {
50cdf0e10cSrcweir 	if ( !OConnectionWeakWrapper_BASE::rBHelper.bDisposed )
51cdf0e10cSrcweir 	{
52cdf0e10cSrcweir 		osl_incrementInterlockedCount( &m_refCount );
53cdf0e10cSrcweir 		dispose();
54cdf0e10cSrcweir 	}
55cdf0e10cSrcweir }
56cdf0e10cSrcweir // XServiceInfo
57cdf0e10cSrcweir // --------------------------------------------------------------------------------
58cdf0e10cSrcweir IMPLEMENT_SERVICE_INFO(OConnectionWeakWrapper, "com.sun.star.sdbc.drivers.OConnectionWeakWrapper", "com.sun.star.sdbc.Connection")
59cdf0e10cSrcweir 
60cdf0e10cSrcweir // --------------------------------------------------------------------------------
createStatement()61cdf0e10cSrcweir Reference< XStatement > SAL_CALL OConnectionWeakWrapper::createStatement(  ) throw(SQLException, RuntimeException)
62cdf0e10cSrcweir {
63cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
64cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 	return m_xConnection->createStatement();
68cdf0e10cSrcweir }
69cdf0e10cSrcweir // --------------------------------------------------------------------------------
prepareStatement(const::rtl::OUString & sql)70cdf0e10cSrcweir Reference< XPreparedStatement > SAL_CALL OConnectionWeakWrapper::prepareStatement( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
71cdf0e10cSrcweir {
72cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
73cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 	return m_xConnection->prepareStatement(sql);
77cdf0e10cSrcweir }
78cdf0e10cSrcweir // --------------------------------------------------------------------------------
prepareCall(const::rtl::OUString & sql)79cdf0e10cSrcweir Reference< XPreparedStatement > SAL_CALL OConnectionWeakWrapper::prepareCall( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
80cdf0e10cSrcweir {
81cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
82cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 	return m_xConnection->prepareCall(sql);
86cdf0e10cSrcweir }
87cdf0e10cSrcweir // --------------------------------------------------------------------------------
nativeSQL(const::rtl::OUString & sql)88cdf0e10cSrcweir ::rtl::OUString SAL_CALL OConnectionWeakWrapper::nativeSQL( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
89cdf0e10cSrcweir {
90cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
91cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	return m_xConnection->nativeSQL(sql);
95cdf0e10cSrcweir }
96cdf0e10cSrcweir // --------------------------------------------------------------------------------
setAutoCommit(sal_Bool autoCommit)97cdf0e10cSrcweir void SAL_CALL OConnectionWeakWrapper::setAutoCommit( sal_Bool autoCommit ) throw(SQLException, RuntimeException)
98cdf0e10cSrcweir {
99cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
100cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 	m_xConnection->setAutoCommit(autoCommit);
103cdf0e10cSrcweir }
104cdf0e10cSrcweir // --------------------------------------------------------------------------------
getAutoCommit()105cdf0e10cSrcweir sal_Bool SAL_CALL OConnectionWeakWrapper::getAutoCommit(  ) throw(SQLException, RuntimeException)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
108cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 	return m_xConnection->getAutoCommit();
112cdf0e10cSrcweir }
113cdf0e10cSrcweir // --------------------------------------------------------------------------------
commit()114cdf0e10cSrcweir void SAL_CALL OConnectionWeakWrapper::commit(  ) throw(SQLException, RuntimeException)
115cdf0e10cSrcweir {
116cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
117cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	m_xConnection->commit();
121cdf0e10cSrcweir }
122cdf0e10cSrcweir // --------------------------------------------------------------------------------
rollback()123cdf0e10cSrcweir void SAL_CALL OConnectionWeakWrapper::rollback(  ) throw(SQLException, RuntimeException)
124cdf0e10cSrcweir {
125cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
126cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	m_xConnection->rollback();
130cdf0e10cSrcweir }
131cdf0e10cSrcweir // --------------------------------------------------------------------------------
isClosed()132cdf0e10cSrcweir sal_Bool SAL_CALL OConnectionWeakWrapper::isClosed(  ) throw(SQLException, RuntimeException)
133cdf0e10cSrcweir {
134cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 	return m_xConnection->isClosed();
137cdf0e10cSrcweir }
138cdf0e10cSrcweir // --------------------------------------------------------------------------------
getMetaData()139cdf0e10cSrcweir Reference< XDatabaseMetaData > SAL_CALL OConnectionWeakWrapper::getMetaData(  ) throw(SQLException, RuntimeException)
140cdf0e10cSrcweir {
141cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
142cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 	return m_xConnection->getMetaData();
146cdf0e10cSrcweir }
147cdf0e10cSrcweir // --------------------------------------------------------------------------------
setReadOnly(sal_Bool readOnly)148cdf0e10cSrcweir void SAL_CALL OConnectionWeakWrapper::setReadOnly( sal_Bool readOnly ) throw(SQLException, RuntimeException)
149cdf0e10cSrcweir {
150cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
151cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 	m_xConnection->setReadOnly(readOnly);
155cdf0e10cSrcweir }
156cdf0e10cSrcweir // --------------------------------------------------------------------------------
isReadOnly()157cdf0e10cSrcweir sal_Bool SAL_CALL OConnectionWeakWrapper::isReadOnly(  ) throw(SQLException, RuntimeException)
158cdf0e10cSrcweir {
159cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
160cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 	return m_xConnection->isReadOnly();
164cdf0e10cSrcweir }
165cdf0e10cSrcweir // --------------------------------------------------------------------------------
setCatalog(const::rtl::OUString & catalog)166cdf0e10cSrcweir void SAL_CALL OConnectionWeakWrapper::setCatalog( const ::rtl::OUString& catalog ) throw(SQLException, RuntimeException)
167cdf0e10cSrcweir {
168cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
169cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 	m_xConnection->setCatalog(catalog);
173cdf0e10cSrcweir }
174cdf0e10cSrcweir // --------------------------------------------------------------------------------
getCatalog()175cdf0e10cSrcweir ::rtl::OUString SAL_CALL OConnectionWeakWrapper::getCatalog(  ) throw(SQLException, RuntimeException)
176cdf0e10cSrcweir {
177cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
178cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 
181cdf0e10cSrcweir 	return m_xConnection->getCatalog();
182cdf0e10cSrcweir }
183cdf0e10cSrcweir // --------------------------------------------------------------------------------
setTransactionIsolation(sal_Int32 level)184cdf0e10cSrcweir void SAL_CALL OConnectionWeakWrapper::setTransactionIsolation( sal_Int32 level ) throw(SQLException, RuntimeException)
185cdf0e10cSrcweir {
186cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
187cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 	m_xConnection->setTransactionIsolation(level);
191cdf0e10cSrcweir }
192cdf0e10cSrcweir // --------------------------------------------------------------------------------
getTransactionIsolation()193cdf0e10cSrcweir sal_Int32 SAL_CALL OConnectionWeakWrapper::getTransactionIsolation(  ) throw(SQLException, RuntimeException)
194cdf0e10cSrcweir {
195cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
196cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 
199cdf0e10cSrcweir 	return m_xConnection->getTransactionIsolation();
200cdf0e10cSrcweir }
201cdf0e10cSrcweir // --------------------------------------------------------------------------------
getTypeMap()202cdf0e10cSrcweir Reference< ::com::sun::star::container::XNameAccess > SAL_CALL OConnectionWeakWrapper::getTypeMap(  ) throw(SQLException, RuntimeException)
203cdf0e10cSrcweir {
204cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
205cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 	return m_xConnection->getTypeMap();
209cdf0e10cSrcweir }
210cdf0e10cSrcweir // --------------------------------------------------------------------------------
setTypeMap(const Reference<::com::sun::star::container::XNameAccess> & typeMap)211cdf0e10cSrcweir void SAL_CALL OConnectionWeakWrapper::setTypeMap( const Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(SQLException, RuntimeException)
212cdf0e10cSrcweir {
213cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
214cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 
217cdf0e10cSrcweir 	m_xConnection->setTypeMap(typeMap);
218cdf0e10cSrcweir }
219cdf0e10cSrcweir // --------------------------------------------------------------------------------
220cdf0e10cSrcweir // XCloseable
close()221cdf0e10cSrcweir void SAL_CALL OConnectionWeakWrapper::close(  ) throw(SQLException, RuntimeException)
222cdf0e10cSrcweir {
223cdf0e10cSrcweir 	{
224cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
225cdf0e10cSrcweir 		checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
226cdf0e10cSrcweir 
227cdf0e10cSrcweir 	}
228cdf0e10cSrcweir 	dispose();
229cdf0e10cSrcweir }
230cdf0e10cSrcweir //------------------------------------------------------------------------------
disposing()231cdf0e10cSrcweir void OConnectionWeakWrapper::disposing()
232cdf0e10cSrcweir {
233cdf0e10cSrcweir 	::osl::MutexGuard aGuard(m_aMutex);
234cdf0e10cSrcweir 
235cdf0e10cSrcweir 	OConnectionWeakWrapper_BASE::disposing();
236cdf0e10cSrcweir 	OConnectionWrapper::disposing();
237cdf0e10cSrcweir }
238cdf0e10cSrcweir // -----------------------------------------------------------------------------
239cdf0e10cSrcweir // com::sun::star::lang::XUnoTunnel
240cdf0e10cSrcweir #ifdef N_DEBUG
241cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2(OConnectionWeakWrapper,OConnectionWeakWrapper_BASE,OConnectionWrapper)
242cdf0e10cSrcweir #else
243cdf0e10cSrcweir IMPLEMENT_FORWARD_REFCOUNT( OConnectionWeakWrapper, OConnectionWeakWrapper_BASE ) \
244cdf0e10cSrcweir ::com::sun::star::uno::Any SAL_CALL OConnectionWeakWrapper::queryInterface( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException) \
245cdf0e10cSrcweir { \
246cdf0e10cSrcweir 	::com::sun::star::uno::Any aReturn = OConnectionWeakWrapper_BASE::queryInterface( _rType ); \
247cdf0e10cSrcweir 	if ( !aReturn.hasValue() ) \
248cdf0e10cSrcweir 		aReturn = OConnectionWrapper::queryInterface( _rType ); \
249cdf0e10cSrcweir 	return aReturn; \
250cdf0e10cSrcweir }
251cdf0e10cSrcweir #endif
252cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2(OConnectionWeakWrapper,OConnectionWeakWrapper_BASE,OConnectionWrapper)
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 
255