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