1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "ZConnectionWrapper.hxx"
21 #include <com/sun/star/sdbc/ColumnValue.hpp>
22 #include <com/sun/star/sdbc/XRow.hpp>
23 #include <com/sun/star/lang/DisposedException.hpp>
24 #include <comphelper/extract.hxx>
25 #include <cppuhelper/typeprovider.hxx>
26 #include <comphelper/sequence.hxx>
28 using namespace connectivity
;
30 using namespace com::sun::star::uno
;
31 using namespace com::sun::star::lang
;
32 using namespace com::sun::star::beans
;
33 using namespace com::sun::star::sdbc
;
35 OConnectionWeakWrapper::OConnectionWeakWrapper(Reference
< XAggregation
>& _xConnection
)
36 : OConnectionWeakWrapper_BASE(m_aMutex
)
38 setDelegation(_xConnection
,m_refCount
);
39 OSL_ENSURE(m_xConnection
.is(),"OConnectionWeakWrapper: Connection must be valid!");
42 OConnectionWeakWrapper::~OConnectionWeakWrapper()
44 if ( !OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
)
46 osl_atomic_increment( &m_refCount
);
52 IMPLEMENT_SERVICE_INFO(OConnectionWeakWrapper
, "com.sun.star.sdbc.drivers.OConnectionWeakWrapper", "com.sun.star.sdbc.Connection")
55 Reference
< XStatement
> SAL_CALL
OConnectionWeakWrapper::createStatement( ) throw(SQLException
, RuntimeException
, std::exception
)
57 ::osl::MutexGuard
aGuard( m_aMutex
);
58 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
61 return m_xConnection
->createStatement();
64 Reference
< XPreparedStatement
> SAL_CALL
OConnectionWeakWrapper::prepareStatement( const OUString
& sql
) throw(SQLException
, RuntimeException
, std::exception
)
66 ::osl::MutexGuard
aGuard( m_aMutex
);
67 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
70 return m_xConnection
->prepareStatement(sql
);
73 Reference
< XPreparedStatement
> SAL_CALL
OConnectionWeakWrapper::prepareCall( const OUString
& sql
) throw(SQLException
, RuntimeException
, std::exception
)
75 ::osl::MutexGuard
aGuard( m_aMutex
);
76 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
79 return m_xConnection
->prepareCall(sql
);
82 OUString SAL_CALL
OConnectionWeakWrapper::nativeSQL( const OUString
& sql
) throw(SQLException
, RuntimeException
, std::exception
)
84 ::osl::MutexGuard
aGuard( m_aMutex
);
85 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
88 return m_xConnection
->nativeSQL(sql
);
91 void SAL_CALL
OConnectionWeakWrapper::setAutoCommit( sal_Bool autoCommit
) throw(SQLException
, RuntimeException
, std::exception
)
93 ::osl::MutexGuard
aGuard( m_aMutex
);
94 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
96 m_xConnection
->setAutoCommit(autoCommit
);
99 sal_Bool SAL_CALL
OConnectionWeakWrapper::getAutoCommit( ) throw(SQLException
, RuntimeException
, std::exception
)
101 ::osl::MutexGuard
aGuard( m_aMutex
);
102 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
105 return m_xConnection
->getAutoCommit();
108 void SAL_CALL
OConnectionWeakWrapper::commit( ) throw(SQLException
, RuntimeException
, std::exception
)
110 ::osl::MutexGuard
aGuard( m_aMutex
);
111 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
114 m_xConnection
->commit();
117 void SAL_CALL
OConnectionWeakWrapper::rollback( ) throw(SQLException
, RuntimeException
, std::exception
)
119 ::osl::MutexGuard
aGuard( m_aMutex
);
120 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
123 m_xConnection
->rollback();
126 sal_Bool SAL_CALL
OConnectionWeakWrapper::isClosed( ) throw(SQLException
, RuntimeException
, std::exception
)
128 ::osl::MutexGuard
aGuard( m_aMutex
);
130 return m_xConnection
->isClosed();
133 Reference
< XDatabaseMetaData
> SAL_CALL
OConnectionWeakWrapper::getMetaData( ) throw(SQLException
, RuntimeException
, std::exception
)
135 ::osl::MutexGuard
aGuard( m_aMutex
);
136 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
139 return m_xConnection
->getMetaData();
142 void SAL_CALL
OConnectionWeakWrapper::setReadOnly( sal_Bool readOnly
) throw(SQLException
, RuntimeException
, std::exception
)
144 ::osl::MutexGuard
aGuard( m_aMutex
);
145 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
148 m_xConnection
->setReadOnly(readOnly
);
151 sal_Bool SAL_CALL
OConnectionWeakWrapper::isReadOnly( ) throw(SQLException
, RuntimeException
, std::exception
)
153 ::osl::MutexGuard
aGuard( m_aMutex
);
154 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
157 return m_xConnection
->isReadOnly();
160 void SAL_CALL
OConnectionWeakWrapper::setCatalog( const OUString
& catalog
) throw(SQLException
, RuntimeException
, std::exception
)
162 ::osl::MutexGuard
aGuard( m_aMutex
);
163 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
166 m_xConnection
->setCatalog(catalog
);
169 OUString SAL_CALL
OConnectionWeakWrapper::getCatalog( ) throw(SQLException
, RuntimeException
, std::exception
)
171 ::osl::MutexGuard
aGuard( m_aMutex
);
172 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
175 return m_xConnection
->getCatalog();
178 void SAL_CALL
OConnectionWeakWrapper::setTransactionIsolation( sal_Int32 level
) throw(SQLException
, RuntimeException
, std::exception
)
180 ::osl::MutexGuard
aGuard( m_aMutex
);
181 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
184 m_xConnection
->setTransactionIsolation(level
);
187 sal_Int32 SAL_CALL
OConnectionWeakWrapper::getTransactionIsolation( ) throw(SQLException
, RuntimeException
, std::exception
)
189 ::osl::MutexGuard
aGuard( m_aMutex
);
190 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
193 return m_xConnection
->getTransactionIsolation();
196 Reference
< ::com::sun::star::container::XNameAccess
> SAL_CALL
OConnectionWeakWrapper::getTypeMap( ) throw(SQLException
, RuntimeException
, std::exception
)
198 ::osl::MutexGuard
aGuard( m_aMutex
);
199 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
202 return m_xConnection
->getTypeMap();
205 void SAL_CALL
OConnectionWeakWrapper::setTypeMap( const Reference
< ::com::sun::star::container::XNameAccess
>& typeMap
) throw(SQLException
, RuntimeException
, std::exception
)
207 ::osl::MutexGuard
aGuard( m_aMutex
);
208 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
211 m_xConnection
->setTypeMap(typeMap
);
215 void SAL_CALL
OConnectionWeakWrapper::close( ) throw(SQLException
, RuntimeException
, std::exception
)
218 ::osl::MutexGuard
aGuard( m_aMutex
);
219 checkDisposed(OConnectionWeakWrapper_BASE::rBHelper
.bDisposed
);
225 void OConnectionWeakWrapper::disposing()
227 ::osl::MutexGuard
aGuard(m_aMutex
);
229 OConnectionWeakWrapper_BASE::disposing();
230 OConnectionWrapper::disposing();
233 // com::sun::star::lang::XUnoTunnel
234 IMPLEMENT_FORWARD_REFCOUNT( OConnectionWeakWrapper
, OConnectionWeakWrapper_BASE
) \
235 ::com::sun::star::uno::Any SAL_CALL
OConnectionWeakWrapper::queryInterface( const ::com::sun::star::uno::Type
& _rType
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) \
237 ::com::sun::star::uno::Any aReturn
= OConnectionWeakWrapper_BASE::queryInterface( _rType
); \
238 if ( !aReturn
.hasValue() ) \
239 aReturn
= OConnectionWrapper::queryInterface( _rType
); \
242 IMPLEMENT_FORWARD_XTYPEPROVIDER2(OConnectionWeakWrapper
,OConnectionWeakWrapper_BASE
,OConnectionWrapper
)
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */