Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_CONNECTIVITY_CONNCLEANUP_HXX
21 : #define INCLUDED_CONNECTIVITY_CONNCLEANUP_HXX
22 :
23 : #include <cppuhelper/implbase2.hxx>
24 : #include <com/sun/star/beans/XPropertySet.hpp>
25 : #include <com/sun/star/sdbc/XRowSet.hpp>
26 : #include <com/sun/star/sdbc/XConnection.hpp>
27 : #include <connectivity/dbtoolsdllapi.hxx>
28 :
29 :
30 : namespace dbtools
31 : {
32 :
33 :
34 :
35 : //= OAutoConnectionDisposer
36 :
37 : typedef ::cppu::WeakImplHelper2 < ::com::sun::star::beans::XPropertyChangeListener,
38 : ::com::sun::star::sdbc::XRowSetListener
39 : > OAutoConnectionDisposer_Base;
40 :
41 0 : class OOO_DLLPUBLIC_DBTOOLS OAutoConnectionDisposer : public OAutoConnectionDisposer_Base
42 : {
43 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >
44 : m_xOriginalConnection;
45 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > m_xRowSet; // needed to add as listener
46 : bool m_bRSListening : 1; // true when we're listening on rowset
47 : bool m_bPropertyListening : 1; // true when we're listening for property changes
48 :
49 : public:
50 : /** constructs an object
51 : <p>The connection given will be set on the rowset (as ActiveConnection), and the object adds itself as property
52 : change listener for the connection. Once somebody sets a new ActiveConnection, the old one (the one given
53 : here) will be disposed.</p>
54 : */
55 : OAutoConnectionDisposer(
56 : const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet >& _rxRowSet,
57 : const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection
58 : );
59 :
60 : protected:
61 : // XPropertyChangeListener
62 : virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& _rEvent ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
63 :
64 : // XEventListener
65 : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& _rSource ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
66 :
67 : // XRowSetListener
68 : virtual void SAL_CALL cursorMoved( const ::com::sun::star::lang::EventObject& event ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
69 : virtual void SAL_CALL rowChanged( const ::com::sun::star::lang::EventObject& event ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
70 : virtual void SAL_CALL rowSetChanged( const ::com::sun::star::lang::EventObject& event ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
71 :
72 : private:
73 : void clearConnection();
74 :
75 : void startRowSetListening();
76 : void stopRowSetListening();
77 0 : bool isRowSetListening() const { return m_bRSListening; }
78 :
79 : void startPropertyListening( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxProps );
80 : void stopPropertyListening( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxEventSource );
81 0 : bool isPropertyListening() const { return m_bPropertyListening; }
82 : };
83 :
84 :
85 : } // namespace dbtools
86 :
87 :
88 : #endif // INCLUDED_CONNECTIVITY_CONNCLEANUP_HXX
89 :
90 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|