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 #ifndef _CONNECTIVITY_CONNCLEANUP_HXX_
25 #define _CONNECTIVITY_CONNCLEANUP_HXX_
26 
27 #include <cppuhelper/implbase2.hxx>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/sdbc/XRowSet.hpp>
30 #include <com/sun/star/sdbc/XConnection.hpp>
31 #include "connectivity/dbtoolsdllapi.hxx"
32 
33 //.........................................................................
34 namespace dbtools
35 {
36 //.........................................................................
37 
38 	//=====================================================================
39 	//= OAutoConnectionDisposer
40 	//=====================================================================
41 	typedef ::cppu::WeakImplHelper2	<	::com::sun::star::beans::XPropertyChangeListener,
42 										::com::sun::star::sdbc::XRowSetListener
43 									>	OAutoConnectionDisposer_Base;
44 
45 	class OOO_DLLPUBLIC_DBTOOLS OAutoConnectionDisposer : public OAutoConnectionDisposer_Base
46 	{
47 		::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >
48 					m_xOriginalConnection;
49 		::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > m_xRowSet; // needed to add as listener
50 		sal_Bool	m_bRSListening			: 1; // true when we're listening on rowset
51 		sal_Bool	m_bPropertyListening	: 1; // true when we're listening for property changes
52 
53 	public:
54 		/** constructs an object
55 			<p>The connection given will be set on the rowset (as ActiveConnection), and the object adds itself as property
56 			change listener for the connection. Once somebody sets a new ActiveConnection, the old one (the one given
57 			here) will be disposed.</p>
58 		*/
59 		OAutoConnectionDisposer(
60 			const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet >& _rxRowSet,
61 			const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection
62 			);
63 
64 	protected:
65 		// XPropertyChangeListener
66 		virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& _rEvent ) throw (::com::sun::star::uno::RuntimeException);
67 
68 		// XEventListener
69 		virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& _rSource ) throw (::com::sun::star::uno::RuntimeException);
70 
71 		// XRowSetListener
72 		virtual void SAL_CALL cursorMoved( const ::com::sun::star::lang::EventObject& event ) throw (::com::sun::star::uno::RuntimeException);
73 		virtual void SAL_CALL rowChanged( const ::com::sun::star::lang::EventObject& event ) throw (::com::sun::star::uno::RuntimeException);
74 		virtual void SAL_CALL rowSetChanged( const ::com::sun::star::lang::EventObject& event ) throw (::com::sun::star::uno::RuntimeException);
75 
76 	private:
77 		void clearConnection();
78 
79 		void		startRowSetListening();
80 		void		stopRowSetListening();
isRowSetListening() const81 		sal_Bool	isRowSetListening() const { return m_bRSListening; }
82 
83 		void		startPropertyListening( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxProps );
84 		void		stopPropertyListening( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxEventSource );
isPropertyListening() const85 		sal_Bool	isPropertyListening() const { return m_bPropertyListening; }
86 	};
87 
88 //.........................................................................
89 }	// namespace dbtools
90 //.........................................................................
91 
92 #endif // _CONNECTIVITY_CONNCLEANUP_HXX_
93 
94