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 "ZConnectionWrapper.hxx"
31 #include <com/sun/star/sdbc/ColumnValue.hpp>
32 #include <com/sun/star/sdbc/XRow.hpp>
33 #include <com/sun/star/lang/DisposedException.hpp>
34 #include <comphelper/extract.hxx>
35 #include <cppuhelper/typeprovider.hxx>
36 #include <comphelper/sequence.hxx>
37 
38 using namespace connectivity;
39 //------------------------------------------------------------------------------
40 using namespace com::sun::star::uno;
41 using namespace com::sun::star::lang;
42 using namespace com::sun::star::beans;
43 using namespace com::sun::star::sdbc;
44 // --------------------------------------------------------------------------------
45 OConnectionWeakWrapper::OConnectionWeakWrapper(Reference< XAggregation >& _xConnection)
46 	: OConnectionWeakWrapper_BASE(m_aMutex)
47 {
48 	setDelegation(_xConnection,m_refCount);
49 	OSL_ENSURE(m_xConnection.is(),"OConnectionWeakWrapper: Connection must be valid!");
50 }
51 //-----------------------------------------------------------------------------
52 OConnectionWeakWrapper::~OConnectionWeakWrapper()
53 {
54 	if ( !OConnectionWeakWrapper_BASE::rBHelper.bDisposed )
55 	{
56 		osl_incrementInterlockedCount( &m_refCount );
57 		dispose();
58 	}
59 }
60 // XServiceInfo
61 // --------------------------------------------------------------------------------
62 IMPLEMENT_SERVICE_INFO(OConnectionWeakWrapper, "com.sun.star.sdbc.drivers.OConnectionWeakWrapper", "com.sun.star.sdbc.Connection")
63 
64 // --------------------------------------------------------------------------------
65 Reference< XStatement > SAL_CALL OConnectionWeakWrapper::createStatement(  ) throw(SQLException, RuntimeException)
66 {
67 	::osl::MutexGuard aGuard( m_aMutex );
68 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
69 
70 
71 	return m_xConnection->createStatement();
72 }
73 // --------------------------------------------------------------------------------
74 Reference< XPreparedStatement > SAL_CALL OConnectionWeakWrapper::prepareStatement( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
75 {
76 	::osl::MutexGuard aGuard( m_aMutex );
77 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
78 
79 
80 	return m_xConnection->prepareStatement(sql);
81 }
82 // --------------------------------------------------------------------------------
83 Reference< XPreparedStatement > SAL_CALL OConnectionWeakWrapper::prepareCall( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
84 {
85 	::osl::MutexGuard aGuard( m_aMutex );
86 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
87 
88 
89 	return m_xConnection->prepareCall(sql);
90 }
91 // --------------------------------------------------------------------------------
92 ::rtl::OUString SAL_CALL OConnectionWeakWrapper::nativeSQL( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
93 {
94 	::osl::MutexGuard aGuard( m_aMutex );
95 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
96 
97 
98 	return m_xConnection->nativeSQL(sql);
99 }
100 // --------------------------------------------------------------------------------
101 void SAL_CALL OConnectionWeakWrapper::setAutoCommit( sal_Bool autoCommit ) throw(SQLException, RuntimeException)
102 {
103 	::osl::MutexGuard aGuard( m_aMutex );
104 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
105 
106 	m_xConnection->setAutoCommit(autoCommit);
107 }
108 // --------------------------------------------------------------------------------
109 sal_Bool SAL_CALL OConnectionWeakWrapper::getAutoCommit(  ) throw(SQLException, RuntimeException)
110 {
111 	::osl::MutexGuard aGuard( m_aMutex );
112 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
113 
114 
115 	return m_xConnection->getAutoCommit();
116 }
117 // --------------------------------------------------------------------------------
118 void SAL_CALL OConnectionWeakWrapper::commit(  ) throw(SQLException, RuntimeException)
119 {
120 	::osl::MutexGuard aGuard( m_aMutex );
121 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
122 
123 
124 	m_xConnection->commit();
125 }
126 // --------------------------------------------------------------------------------
127 void SAL_CALL OConnectionWeakWrapper::rollback(  ) throw(SQLException, RuntimeException)
128 {
129 	::osl::MutexGuard aGuard( m_aMutex );
130 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
131 
132 
133 	m_xConnection->rollback();
134 }
135 // --------------------------------------------------------------------------------
136 sal_Bool SAL_CALL OConnectionWeakWrapper::isClosed(  ) throw(SQLException, RuntimeException)
137 {
138 	::osl::MutexGuard aGuard( m_aMutex );
139 
140 	return m_xConnection->isClosed();
141 }
142 // --------------------------------------------------------------------------------
143 Reference< XDatabaseMetaData > SAL_CALL OConnectionWeakWrapper::getMetaData(  ) throw(SQLException, RuntimeException)
144 {
145 	::osl::MutexGuard aGuard( m_aMutex );
146 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
147 
148 
149 	return m_xConnection->getMetaData();
150 }
151 // --------------------------------------------------------------------------------
152 void SAL_CALL OConnectionWeakWrapper::setReadOnly( sal_Bool readOnly ) throw(SQLException, RuntimeException)
153 {
154 	::osl::MutexGuard aGuard( m_aMutex );
155 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
156 
157 
158 	m_xConnection->setReadOnly(readOnly);
159 }
160 // --------------------------------------------------------------------------------
161 sal_Bool SAL_CALL OConnectionWeakWrapper::isReadOnly(  ) throw(SQLException, RuntimeException)
162 {
163 	::osl::MutexGuard aGuard( m_aMutex );
164 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
165 
166 
167 	return m_xConnection->isReadOnly();
168 }
169 // --------------------------------------------------------------------------------
170 void SAL_CALL OConnectionWeakWrapper::setCatalog( const ::rtl::OUString& catalog ) throw(SQLException, RuntimeException)
171 {
172 	::osl::MutexGuard aGuard( m_aMutex );
173 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
174 
175 
176 	m_xConnection->setCatalog(catalog);
177 }
178 // --------------------------------------------------------------------------------
179 ::rtl::OUString SAL_CALL OConnectionWeakWrapper::getCatalog(  ) throw(SQLException, RuntimeException)
180 {
181 	::osl::MutexGuard aGuard( m_aMutex );
182 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
183 
184 
185 	return m_xConnection->getCatalog();
186 }
187 // --------------------------------------------------------------------------------
188 void SAL_CALL OConnectionWeakWrapper::setTransactionIsolation( sal_Int32 level ) throw(SQLException, RuntimeException)
189 {
190 	::osl::MutexGuard aGuard( m_aMutex );
191 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
192 
193 
194 	m_xConnection->setTransactionIsolation(level);
195 }
196 // --------------------------------------------------------------------------------
197 sal_Int32 SAL_CALL OConnectionWeakWrapper::getTransactionIsolation(  ) throw(SQLException, RuntimeException)
198 {
199 	::osl::MutexGuard aGuard( m_aMutex );
200 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
201 
202 
203 	return m_xConnection->getTransactionIsolation();
204 }
205 // --------------------------------------------------------------------------------
206 Reference< ::com::sun::star::container::XNameAccess > SAL_CALL OConnectionWeakWrapper::getTypeMap(  ) throw(SQLException, RuntimeException)
207 {
208 	::osl::MutexGuard aGuard( m_aMutex );
209 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
210 
211 
212 	return m_xConnection->getTypeMap();
213 }
214 // --------------------------------------------------------------------------------
215 void SAL_CALL OConnectionWeakWrapper::setTypeMap( const Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(SQLException, RuntimeException)
216 {
217 	::osl::MutexGuard aGuard( m_aMutex );
218 	checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
219 
220 
221 	m_xConnection->setTypeMap(typeMap);
222 }
223 // --------------------------------------------------------------------------------
224 // XCloseable
225 void SAL_CALL OConnectionWeakWrapper::close(  ) throw(SQLException, RuntimeException)
226 {
227 	{
228 		::osl::MutexGuard aGuard( m_aMutex );
229 		checkDisposed(OConnectionWeakWrapper_BASE::rBHelper.bDisposed);
230 
231 	}
232 	dispose();
233 }
234 //------------------------------------------------------------------------------
235 void OConnectionWeakWrapper::disposing()
236 {
237 	::osl::MutexGuard aGuard(m_aMutex);
238 
239 	OConnectionWeakWrapper_BASE::disposing();
240 	OConnectionWrapper::disposing();
241 }
242 // -----------------------------------------------------------------------------
243 // com::sun::star::lang::XUnoTunnel
244 #ifdef N_DEBUG
245 IMPLEMENT_FORWARD_XINTERFACE2(OConnectionWeakWrapper,OConnectionWeakWrapper_BASE,OConnectionWrapper)
246 #else
247 IMPLEMENT_FORWARD_REFCOUNT( OConnectionWeakWrapper, OConnectionWeakWrapper_BASE ) \
248 ::com::sun::star::uno::Any SAL_CALL OConnectionWeakWrapper::queryInterface( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException) \
249 { \
250 	::com::sun::star::uno::Any aReturn = OConnectionWeakWrapper_BASE::queryInterface( _rType ); \
251 	if ( !aReturn.hasValue() ) \
252 		aReturn = OConnectionWrapper::queryInterface( _rType ); \
253 	return aReturn; \
254 }
255 #endif
256 IMPLEMENT_FORWARD_XTYPEPROVIDER2(OConnectionWeakWrapper,OConnectionWeakWrapper_BASE,OConnectionWrapper)
257 
258 
259