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 DBAUI_SUBCOMPONENTCONTROLLER_HXX
25 #define DBAUI_SUBCOMPONENTCONTROLLER_HXX
26 
27 #include "genericcontroller.hxx"
28 
29 /** === begin UNO includes === **/
30 #include <com/sun/star/document/XScriptInvocationContext.hpp>
31 #include <com/sun/star/sdbc/XConnection.hpp>
32 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
33 #include <com/sun/star/sdbc/XDataSource.hpp>
34 #include <com/sun/star/util/XNumberFormatter.hpp>
35 #include <com/sun/star/util/XModifiable.hpp>
36 /** === end UNO includes === **/
37 
38 #include <comphelper/broadcasthelper.hxx>
39 #include <comphelper/proparrhlp.hxx>
40 #include <comphelper/propertycontainer.hxx>
41 #include <connectivity/dbmetadata.hxx>
42 #include <cppuhelper/implbase2.hxx>
43 
44 #include <memory>
45 
46 //........................................................................
47 namespace dbaui
48 {
49 //........................................................................
50 
51 	//====================================================================
52 	//= DBSubComponentController
53 	//====================================================================
54 	class DBSubComponentController;
55 
56     typedef ::cppu::ImplInheritanceHelper2  <   OGenericUnoController
57                                             ,   ::com::sun::star::document::XScriptInvocationContext
58                                             ,   ::com::sun::star::util::XModifiable
59                                             >   DBSubComponentController_Base;
60 
61     struct DBSubComponentController_Impl;
62 	class DBACCESS_DLLPUBLIC DBSubComponentController : public DBSubComponentController_Base
63 	{
64 	private:
65         ::std::auto_ptr<DBSubComponentController_Impl> m_pImpl;
66 
67     private:
68 		/** forces usage of a connection which we do not own
69 			<p>To be used from within XInitialization::initialize, resp. impl_initialize, only.</p>
70 		*/
71 		void		initializeConnection( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxForeignConn );
72 
73 	protected:
74         // OGenericUnoController - initialization
75         virtual void impl_initialize();
76 
77         // OGenericUnoController
78 		virtual void			Execute(sal_uInt16 nId, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& aArgs);
79 
80         virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > getPrivateModel() const;
81 
82                 sal_Bool impl_isModified() const;
83         virtual void     impl_onModifyChanged();
84 
85 	public:
86 
87 		sal_Bool		isReadOnly()			const;
88 		sal_Bool		isEditable()			const;
89         void            setEditable(sal_Bool _bEditable);
90 
91 		// ----------------------------------------------------------------
92 		// asking for connection-related stuff
93 
94 		sal_Bool	isConnected() const;
95 
96 		::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData >
97 					getMetaData( ) const;
98 
99         // ----------------------------------------------------------------
100 		// access to the data source / document
101 		::rtl::OUString getDataSourceName() const;
102 		const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >&
103 					getDataSource() const;
104 		sal_Bool	haveDataSource() const;
105 
106         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >
107                     getDatabaseDocument() const;
108 
109         /** provides access to the SDB-level database meta data of the current connection
110         */
111         const ::dbtools::DatabaseMetaData& getSdbMetaData() const;
112 
113 		/** appends an error in the current environment.
114 		*/
115         void appendError(
116                         const ::rtl::OUString& _rErrorMessage,
117                         const ::dbtools::StandardSQLState _eSQLState = ::dbtools::SQL_GENERAL_ERROR,
118                         const sal_Int32 _nErrorCode = 1000
119                      );
120 
121 		/** clears the error state.
122 		*/
123 		void clearError();
124 
125 		/** @return
126 			    <TRUE/> when an error was set otherwise <FALSE/>
127 		*/
128 		sal_Bool hasError() const;
129 
130         /** returns the current error
131         */
132         const ::dbtools::SQLExceptionInfo& getError() const;
133 
134         /** displays the current error, or does nothing if there is no current error
135         */
136         void displayError();
137 
138 		/** shows an info box with the string conntection lost.
139 		*/
140 		void connectionLostMessage() const;
141 
142 		/** gives access to the currently used connection
143 			@return
144 				the currently used connection.
145 		*/
146 		const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >&
147 					getConnection() const;
148 
149 		/** returns the number formatter
150 		*/
151 		::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > 	getNumberFormatter() const;
152 
153 		// ::com::sun::star::frame::XController
154 		virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) throw( ::com::sun::star::uno::RuntimeException );
155 		virtual sal_Bool SAL_CALL attachModel(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > & xModel) throw( ::com::sun::star::uno::RuntimeException );
156 
157         // XScriptInvocationContext
158         virtual ::com::sun::star::uno::Reference< ::com::sun::star::document::XEmbeddedScripts > SAL_CALL getScriptContainer() throw (::com::sun::star::uno::RuntimeException);
159 
160         // XModifiable
161         virtual ::sal_Bool SAL_CALL isModified(  ) throw (::com::sun::star::uno::RuntimeException);
162         virtual void SAL_CALL setModified( ::sal_Bool bModified ) throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException);
163 
164         // XModifyBroadcaster
165         virtual void SAL_CALL addModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
166         virtual void SAL_CALL removeModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
167 
168         // XTitle
169         virtual ::rtl::OUString SAL_CALL getTitle(  ) throw (::com::sun::star::uno::RuntimeException);
170 
171 	protected:
172 		DBSubComponentController(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxORB);
173         virtual ~DBSubComponentController();
174 
175 		virtual void        disconnect();
176 		virtual void        reconnect( sal_Bool _bUI );
ensureConnected(sal_Bool _bUI)177                 sal_Bool    ensureConnected( sal_Bool _bUI )	{ if ( !isConnected() ) reconnect( _bUI ); return isConnected(); }
178 
179 		/** called when our connection is being disposed
180 			<p>The default implementation does a reconnect</p>
181 		*/
182 		virtual void losingConnection( );
183 
184 	protected:
185 		// XEventListener
186 		virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException );
187 
188 		// OComponentHelper
189 		virtual void SAL_CALL disposing();
190 
191 		// XInterface
192 		virtual ::com::sun::star::uno::Any	SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException);
193 
194 		// XTypeProvider
195 		virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  ) throw (::com::sun::star::uno::RuntimeException);
196 
197     protected:
198         sal_Int32 getCurrentStartNumber() const;
199 
200     private:
201         DBSubComponentController();    // never implemented
202 	};
203 
204 //........................................................................
205 }	// namespace dbaui
206 //........................................................................
207 
208 #endif // DBAUI_SUBCOMPONENTCONTROLLER_HXX
209 
210