1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ZConnectionWrapper.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "ZConnectionWrapper.hxx"
34 #include <com/sun/star/sdbc/ColumnValue.hpp>
35 #include <com/sun/star/sdbc/XRow.hpp>
36 #include <com/sun/star/lang/DisposedException.hpp>
37 #include <comphelper/extract.hxx>
38 #include <cppuhelper/typeprovider.hxx>
39 #include <comphelper/sequence.hxx>
41 using namespace connectivity
;
42 //------------------------------------------------------------------------------
43 using namespace com::sun::star::uno
;
44 using namespace com::sun::star::lang
;
45 using namespace com::sun::star::beans
;
46 using namespace com::sun::star::sdbc
;
47 // --------------------------------------------------------------------------------
48 OConnectionWeakWrapper::OConnectionWeakWrapper(Reference
< XAggregation
>& _xConnection
)
49 : OConnectionWeakWrapper_BASE(m_aMutex
)
51 setDelegation(_xConnection
,m_refCount
);
52 OSL_ENSURE(m_xConnection
.is(),"OConnectionWeakWrapper: Connection must be valid!");
54 //-----------------------------------------------------------------------------
55 OConnectionWeakWrapper::~OConnectionWeakWrapper()
57 if ( !OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
)
59 osl_incrementInterlockedCount( &m_refCount
);
64 // --------------------------------------------------------------------------------
65 IMPLEMENT_SERVICE_INFO(OConnectionWeakWrapper
, "com.sun.star.sdbc.drivers.OConnectionWeakWrapper", "com.sun.star.sdbc.Connection")
67 // --------------------------------------------------------------------------------
68 Reference
< XStatement
> SAL_CALL
OConnectionWeakWrapper::createStatement( ) throw(SQLException
, RuntimeException
)
70 ::osl::MutexGuard
aGuard( m_aMutex
);
71 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
74 return m_xConnection
->createStatement();
76 // --------------------------------------------------------------------------------
77 Reference
< XPreparedStatement
> SAL_CALL
OConnectionWeakWrapper::prepareStatement( const ::rtl::OUString
& sql
) throw(SQLException
, RuntimeException
)
79 ::osl::MutexGuard
aGuard( m_aMutex
);
80 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
83 return m_xConnection
->prepareStatement(sql
);
85 // --------------------------------------------------------------------------------
86 Reference
< XPreparedStatement
> SAL_CALL
OConnectionWeakWrapper::prepareCall( const ::rtl::OUString
& sql
) throw(SQLException
, RuntimeException
)
88 ::osl::MutexGuard
aGuard( m_aMutex
);
89 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
92 return m_xConnection
->prepareCall(sql
);
94 // --------------------------------------------------------------------------------
95 ::rtl::OUString SAL_CALL
OConnectionWeakWrapper::nativeSQL( const ::rtl::OUString
& sql
) throw(SQLException
, RuntimeException
)
97 ::osl::MutexGuard
aGuard( m_aMutex
);
98 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
101 return m_xConnection
->nativeSQL(sql
);
103 // --------------------------------------------------------------------------------
104 void SAL_CALL
OConnectionWeakWrapper::setAutoCommit( sal_Bool autoCommit
) throw(SQLException
, RuntimeException
)
106 ::osl::MutexGuard
aGuard( m_aMutex
);
107 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
109 m_xConnection
->setAutoCommit(autoCommit
);
111 // --------------------------------------------------------------------------------
112 sal_Bool SAL_CALL
OConnectionWeakWrapper::getAutoCommit( ) throw(SQLException
, RuntimeException
)
114 ::osl::MutexGuard
aGuard( m_aMutex
);
115 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
118 return m_xConnection
->getAutoCommit();
120 // --------------------------------------------------------------------------------
121 void SAL_CALL
OConnectionWeakWrapper::commit( ) throw(SQLException
, RuntimeException
)
123 ::osl::MutexGuard
aGuard( m_aMutex
);
124 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
127 m_xConnection
->commit();
129 // --------------------------------------------------------------------------------
130 void SAL_CALL
OConnectionWeakWrapper::rollback( ) throw(SQLException
, RuntimeException
)
132 ::osl::MutexGuard
aGuard( m_aMutex
);
133 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
136 m_xConnection
->rollback();
138 // --------------------------------------------------------------------------------
139 sal_Bool SAL_CALL
OConnectionWeakWrapper::isClosed( ) throw(SQLException
, RuntimeException
)
141 ::osl::MutexGuard
aGuard( m_aMutex
);
143 return m_xConnection
->isClosed();
145 // --------------------------------------------------------------------------------
146 Reference
< XDatabaseMetaData
> SAL_CALL
OConnectionWeakWrapper::getMetaData( ) throw(SQLException
, RuntimeException
)
148 ::osl::MutexGuard
aGuard( m_aMutex
);
149 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
152 return m_xConnection
->getMetaData();
154 // --------------------------------------------------------------------------------
155 void SAL_CALL
OConnectionWeakWrapper::setReadOnly( sal_Bool readOnly
) throw(SQLException
, RuntimeException
)
157 ::osl::MutexGuard
aGuard( m_aMutex
);
158 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
161 m_xConnection
->setReadOnly(readOnly
);
163 // --------------------------------------------------------------------------------
164 sal_Bool SAL_CALL
OConnectionWeakWrapper::isReadOnly( ) throw(SQLException
, RuntimeException
)
166 ::osl::MutexGuard
aGuard( m_aMutex
);
167 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
170 return m_xConnection
->isReadOnly();
172 // --------------------------------------------------------------------------------
173 void SAL_CALL
OConnectionWeakWrapper::setCatalog( const ::rtl::OUString
& catalog
) throw(SQLException
, RuntimeException
)
175 ::osl::MutexGuard
aGuard( m_aMutex
);
176 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
179 m_xConnection
->setCatalog(catalog
);
181 // --------------------------------------------------------------------------------
182 ::rtl::OUString SAL_CALL
OConnectionWeakWrapper::getCatalog( ) throw(SQLException
, RuntimeException
)
184 ::osl::MutexGuard
aGuard( m_aMutex
);
185 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
188 return m_xConnection
->getCatalog();
190 // --------------------------------------------------------------------------------
191 void SAL_CALL
OConnectionWeakWrapper::setTransactionIsolation( sal_Int32 level
) throw(SQLException
, RuntimeException
)
193 ::osl::MutexGuard
aGuard( m_aMutex
);
194 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
197 m_xConnection
->setTransactionIsolation(level
);
199 // --------------------------------------------------------------------------------
200 sal_Int32 SAL_CALL
OConnectionWeakWrapper::getTransactionIsolation( ) throw(SQLException
, RuntimeException
)
202 ::osl::MutexGuard
aGuard( m_aMutex
);
203 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
206 return m_xConnection
->getTransactionIsolation();
208 // --------------------------------------------------------------------------------
209 Reference
< ::com::sun::star::container::XNameAccess
> SAL_CALL
OConnectionWeakWrapper::getTypeMap( ) throw(SQLException
, RuntimeException
)
211 ::osl::MutexGuard
aGuard( m_aMutex
);
212 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
215 return m_xConnection
->getTypeMap();
217 // --------------------------------------------------------------------------------
218 void SAL_CALL
OConnectionWeakWrapper::setTypeMap( const Reference
< ::com::sun::star::container::XNameAccess
>& typeMap
) throw(SQLException
, RuntimeException
)
220 ::osl::MutexGuard
aGuard( m_aMutex
);
221 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
224 m_xConnection
->setTypeMap(typeMap
);
226 // --------------------------------------------------------------------------------
228 void SAL_CALL
OConnectionWeakWrapper::close( ) throw(SQLException
, RuntimeException
)
231 ::osl::MutexGuard
aGuard( m_aMutex
);
232 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
237 //------------------------------------------------------------------------------
238 void OConnectionWeakWrapper::disposing()
240 ::osl::MutexGuard
aGuard(m_aMutex
);
242 OConnectionWeakWrapper_BASE::disposing();
243 OConnectionWrapper::disposing();
245 // -----------------------------------------------------------------------------
246 // com::sun::star::lang::XUnoTunnel
248 IMPLEMENT_FORWARD_XINTERFACE2(OConnectionWeakWrapper
,OConnectionWeakWrapper_BASE
,OConnectionWrapper
)
250 IMPLEMENT_FORWARD_REFCOUNT( OConnectionWeakWrapper
, OConnectionWeakWrapper_BASE
) \
251 ::com::sun::star::uno::Any SAL_CALL
OConnectionWeakWrapper::queryInterface( const ::com::sun::star::uno::Type
& _rType
) throw (::com::sun::star::uno::RuntimeException
) \
253 ::com::sun::star::uno::Any aReturn
= OConnectionWeakWrapper_BASE::queryInterface( _rType
); \
254 if ( !aReturn
.hasValue() ) \
255 aReturn
= OConnectionWrapper::queryInterface( _rType
); \
259 IMPLEMENT_FORWARD_XTYPEPROVIDER2(OConnectionWeakWrapper
,OConnectionWeakWrapper_BASE
,OConnectionWrapper
)