1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
30*cdf0e10cSrcweir #include "ZConnectionWrapper.hxx"
31*cdf0e10cSrcweir #include <com/sun/star/sdbc/ColumnValue.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
34*cdf0e10cSrcweir #include <comphelper/extract.hxx>
35*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
36*cdf0e10cSrcweir #include <comphelper/sequence.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir using namespace connectivity;
39*cdf0e10cSrcweir //------------------------------------------------------------------------------
40*cdf0e10cSrcweir using namespace com::sun::star::uno;
41*cdf0e10cSrcweir using namespace com::sun::star::lang;
42*cdf0e10cSrcweir using namespace com::sun::star::beans;
43*cdf0e10cSrcweir using namespace com::sun::star::sdbc;
44*cdf0e10cSrcweir // --------------------------------------------------------------------------------
45*cdf0e10cSrcweir OConnectionWeakWrapper::OConnectionWeakWrapper(Reference< XAggregation >& _xConnection)
46*cdf0e10cSrcweir 	: OConnectionWeakWrapper_BASE(m_aMutex)
47*cdf0e10cSrcweir {
48*cdf0e10cSrcweir 	setDelegation(_xConnection,m_refCount);
49*cdf0e10cSrcweir 	OSL_ENSURE(m_xConnection.is(),"OConnectionWeakWrapper: Connection must be valid!");
50*cdf0e10cSrcweir }
51*cdf0e10cSrcweir //-----------------------------------------------------------------------------
52*cdf0e10cSrcweir OConnectionWeakWrapper::~OConnectionWeakWrapper()
53*cdf0e10cSrcweir {
54*cdf0e10cSrcweir 	if ( !OConnectionWeakWrapper_BASE::rBHelper.bDisposed )
55*cdf0e10cSrcweir 	{
56*cdf0e10cSrcweir 		osl_incrementInterlockedCount( &m_refCount );
57*cdf0e10cSrcweir 		dispose();
58*cdf0e10cSrcweir 	}
59*cdf0e10cSrcweir }
60*cdf0e10cSrcweir // XServiceInfo
61*cdf0e10cSrcweir // --------------------------------------------------------------------------------
62*cdf0e10cSrcweir IMPLEMENT_SERVICE_INFO(OConnectionWeakWrapper, "com.sun.star.sdbc.drivers.OConnectionWeakWrapper", "com.sun.star.sdbc.Connection")
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir // --------------------------------------------------------------------------------
65*cdf0e10cSrcweir Reference< XStatement > SAL_CALL OConnectionWeakWrapper::createStatement(  ) throw(SQLException, RuntimeException)
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
68*cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir 	return m_xConnection->createStatement();
72*cdf0e10cSrcweir }
73*cdf0e10cSrcweir // --------------------------------------------------------------------------------
74*cdf0e10cSrcweir Reference< XPreparedStatement > SAL_CALL OConnectionWeakWrapper::prepareStatement( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
75*cdf0e10cSrcweir {
76*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
77*cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 	return m_xConnection->prepareStatement(sql);
81*cdf0e10cSrcweir }
82*cdf0e10cSrcweir // --------------------------------------------------------------------------------
83*cdf0e10cSrcweir Reference< XPreparedStatement > SAL_CALL OConnectionWeakWrapper::prepareCall( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
86*cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 	return m_xConnection->prepareCall(sql);
90*cdf0e10cSrcweir }
91*cdf0e10cSrcweir // --------------------------------------------------------------------------------
92*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OConnectionWeakWrapper::nativeSQL( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
93*cdf0e10cSrcweir {
94*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
95*cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 	return m_xConnection->nativeSQL(sql);
99*cdf0e10cSrcweir }
100*cdf0e10cSrcweir // --------------------------------------------------------------------------------
101*cdf0e10cSrcweir void SAL_CALL OConnectionWeakWrapper::setAutoCommit( sal_Bool autoCommit ) throw(SQLException, RuntimeException)
102*cdf0e10cSrcweir {
103*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
104*cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir 	m_xConnection->setAutoCommit(autoCommit);
107*cdf0e10cSrcweir }
108*cdf0e10cSrcweir // --------------------------------------------------------------------------------
109*cdf0e10cSrcweir sal_Bool SAL_CALL OConnectionWeakWrapper::getAutoCommit(  ) throw(SQLException, RuntimeException)
110*cdf0e10cSrcweir {
111*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
112*cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 	return m_xConnection->getAutoCommit();
116*cdf0e10cSrcweir }
117*cdf0e10cSrcweir // --------------------------------------------------------------------------------
118*cdf0e10cSrcweir void SAL_CALL OConnectionWeakWrapper::commit(  ) throw(SQLException, RuntimeException)
119*cdf0e10cSrcweir {
120*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
121*cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 	m_xConnection->commit();
125*cdf0e10cSrcweir }
126*cdf0e10cSrcweir // --------------------------------------------------------------------------------
127*cdf0e10cSrcweir void SAL_CALL OConnectionWeakWrapper::rollback(  ) throw(SQLException, RuntimeException)
128*cdf0e10cSrcweir {
129*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
130*cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 	m_xConnection->rollback();
134*cdf0e10cSrcweir }
135*cdf0e10cSrcweir // --------------------------------------------------------------------------------
136*cdf0e10cSrcweir sal_Bool SAL_CALL OConnectionWeakWrapper::isClosed(  ) throw(SQLException, RuntimeException)
137*cdf0e10cSrcweir {
138*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 	return m_xConnection->isClosed();
141*cdf0e10cSrcweir }
142*cdf0e10cSrcweir // --------------------------------------------------------------------------------
143*cdf0e10cSrcweir Reference< XDatabaseMetaData > SAL_CALL OConnectionWeakWrapper::getMetaData(  ) throw(SQLException, RuntimeException)
144*cdf0e10cSrcweir {
145*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
146*cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir 	return m_xConnection->getMetaData();
150*cdf0e10cSrcweir }
151*cdf0e10cSrcweir // --------------------------------------------------------------------------------
152*cdf0e10cSrcweir void SAL_CALL OConnectionWeakWrapper::setReadOnly( sal_Bool readOnly ) throw(SQLException, RuntimeException)
153*cdf0e10cSrcweir {
154*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
155*cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 	m_xConnection->setReadOnly(readOnly);
159*cdf0e10cSrcweir }
160*cdf0e10cSrcweir // --------------------------------------------------------------------------------
161*cdf0e10cSrcweir sal_Bool SAL_CALL OConnectionWeakWrapper::isReadOnly(  ) throw(SQLException, RuntimeException)
162*cdf0e10cSrcweir {
163*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
164*cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir 	return m_xConnection->isReadOnly();
168*cdf0e10cSrcweir }
169*cdf0e10cSrcweir // --------------------------------------------------------------------------------
170*cdf0e10cSrcweir void SAL_CALL OConnectionWeakWrapper::setCatalog( const ::rtl::OUString& catalog ) throw(SQLException, RuntimeException)
171*cdf0e10cSrcweir {
172*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
173*cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir 	m_xConnection->setCatalog(catalog);
177*cdf0e10cSrcweir }
178*cdf0e10cSrcweir // --------------------------------------------------------------------------------
179*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OConnectionWeakWrapper::getCatalog(  ) throw(SQLException, RuntimeException)
180*cdf0e10cSrcweir {
181*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
182*cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 	return m_xConnection->getCatalog();
186*cdf0e10cSrcweir }
187*cdf0e10cSrcweir // --------------------------------------------------------------------------------
188*cdf0e10cSrcweir void SAL_CALL OConnectionWeakWrapper::setTransactionIsolation( sal_Int32 level ) throw(SQLException, RuntimeException)
189*cdf0e10cSrcweir {
190*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
191*cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 	m_xConnection->setTransactionIsolation(level);
195*cdf0e10cSrcweir }
196*cdf0e10cSrcweir // --------------------------------------------------------------------------------
197*cdf0e10cSrcweir sal_Int32 SAL_CALL OConnectionWeakWrapper::getTransactionIsolation(  ) throw(SQLException, RuntimeException)
198*cdf0e10cSrcweir {
199*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
200*cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 	return m_xConnection->getTransactionIsolation();
204*cdf0e10cSrcweir }
205*cdf0e10cSrcweir // --------------------------------------------------------------------------------
206*cdf0e10cSrcweir Reference< ::com::sun::star::container::XNameAccess > SAL_CALL OConnectionWeakWrapper::getTypeMap(  ) throw(SQLException, RuntimeException)
207*cdf0e10cSrcweir {
208*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
209*cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir 	return m_xConnection->getTypeMap();
213*cdf0e10cSrcweir }
214*cdf0e10cSrcweir // --------------------------------------------------------------------------------
215*cdf0e10cSrcweir void SAL_CALL OConnectionWeakWrapper::setTypeMap( const Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(SQLException, RuntimeException)
216*cdf0e10cSrcweir {
217*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
218*cdf0e10cSrcweir 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 	m_xConnection->setTypeMap(typeMap);
222*cdf0e10cSrcweir }
223*cdf0e10cSrcweir // --------------------------------------------------------------------------------
224*cdf0e10cSrcweir // XCloseable
225*cdf0e10cSrcweir void SAL_CALL OConnectionWeakWrapper::close(  ) throw(SQLException, RuntimeException)
226*cdf0e10cSrcweir {
227*cdf0e10cSrcweir 	{
228*cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
229*cdf0e10cSrcweir 		checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir 	}
232*cdf0e10cSrcweir 	dispose();
233*cdf0e10cSrcweir }
234*cdf0e10cSrcweir //------------------------------------------------------------------------------
235*cdf0e10cSrcweir void OConnectionWeakWrapper::disposing()
236*cdf0e10cSrcweir {
237*cdf0e10cSrcweir 	::osl::MutexGuard aGuard(m_aMutex);
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir 	OConnectionWeakWrapper_BASE::disposing();
240*cdf0e10cSrcweir 	OConnectionWrapper::disposing();
241*cdf0e10cSrcweir }
242*cdf0e10cSrcweir // -----------------------------------------------------------------------------
243*cdf0e10cSrcweir // com::sun::star::lang::XUnoTunnel
244*cdf0e10cSrcweir #ifdef N_DEBUG
245*cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2(OConnectionWeakWrapper,OConnectionWeakWrapper_BASE,OConnectionWrapper)
246*cdf0e10cSrcweir #else
247*cdf0e10cSrcweir IMPLEMENT_FORWARD_REFCOUNT( OConnectionWeakWrapper, OConnectionWeakWrapper_BASE ) \
248*cdf0e10cSrcweir ::com::sun::star::uno::Any SAL_CALL OConnectionWeakWrapper::queryInterface( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException) \
249*cdf0e10cSrcweir { \
250*cdf0e10cSrcweir 	::com::sun::star::uno::Any aReturn = OConnectionWeakWrapper_BASE::queryInterface( _rType ); \
251*cdf0e10cSrcweir 	if ( !aReturn.hasValue() ) \
252*cdf0e10cSrcweir 		aReturn = OConnectionWrapper::queryInterface( _rType ); \
253*cdf0e10cSrcweir 	return aReturn; \
254*cdf0e10cSrcweir }
255*cdf0e10cSrcweir #endif
256*cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2(OConnectionWeakWrapper,OConnectionWeakWrapper_BASE,OConnectionWrapper)
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir 
259