1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef CONNECTIVITY_HSQLDB_CONNECTION_HXX
29 #define CONNECTIVITY_HSQLDB_CONNECTION_HXX
30 
31 #include "connectivity/ConnectionWrapper.hxx"
32 /** === begin UNO includes === **/
33 #include <com/sun/star/util/XFlushable.hpp>
34 #include <com/sun/star/sdbc/XDriver.hpp>
35 #ifndef __com_sun_star_sdb_application_XTableUIProvider_hpp__
36 #include <com/sun/star/sdb/application/XTableUIProvider.hpp>
37 #endif
38 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
39 /** === end UNO includes === **/
40 #include <cppuhelper/compbase2.hxx>
41 #include <comphelper/uno3.hxx>
42 #include <cppuhelper/interfacecontainer.hxx>
43 #include <memory>
44 
45 namespace connectivity
46 {
47     namespace hsqldb
48     {
49         class SAL_NO_VTABLE IMethodGuardAccess
50         {
51         public:
52             virtual ::osl::Mutex&   getMutex() const = 0;
53             virtual void            checkDisposed() const = 0;
54         };
55 
56         //==========================================================================
57         //= OHsqlConnection - wraps all methods to the real connection from the driver
58         //= but when disposed it doesn't dispose the real connection
59         //==========================================================================
60         typedef ::cppu::WeakComponentImplHelper2<   ::com::sun::star::util::XFlushable
61                                                 ,   ::com::sun::star::sdb::application::XTableUIProvider
62                                                 >   OHsqlConnection_BASE;
63 
64         class OHsqlConnection   :public ::comphelper::OBaseMutex
65                                 ,public OHsqlConnection_BASE
66                                 ,public OConnectionWrapper
67                                 ,public IMethodGuardAccess
68         {
69         private:
70             ::cppu::OInterfaceContainerHelper                                                           m_aFlushListeners;
71             ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver >                         m_xDriver;
72             ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >            m_xORB;
73             bool                                                                                        m_bIni;
74             bool                                                                                        m_bReadOnly;
75 
76         protected:
77             virtual void SAL_CALL disposing(void);
78             virtual ~OHsqlConnection();
79 
80         public:
81             OHsqlConnection(
82                 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver > _rxDriver,
83                 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _xConnection,
84                 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _xORB
85             );
86 
87             // XServiceInfo
88             DECLARE_SERVICE_INFO();
89             DECLARE_XTYPEPROVIDER()
90             DECLARE_XINTERFACE( )
91 
92             // IMethodGuardAccess
93             virtual ::osl::Mutex&   getMutex() const;
94             virtual void            checkDisposed() const;
95 
96             // XFlushable
97             virtual void SAL_CALL flush(  ) throw (::com::sun::star::uno::RuntimeException);
98             virtual void SAL_CALL addFlushListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XFlushListener >& l ) throw (::com::sun::star::uno::RuntimeException);
99             virtual void SAL_CALL removeFlushListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XFlushListener >& l ) throw (::com::sun::star::uno::RuntimeException);
100 
101             // XTableUIProvider
102             virtual ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > SAL_CALL getTableIcon( const ::rtl::OUString& TableName, ::sal_Int32 ColorMode ) throw (::com::sun::star::uno::RuntimeException);
103             virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getTableEditor( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >& DocumentUI, const ::rtl::OUString& TableName ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
104 
105         private:
106 #if 0
107         // TODO: resource
108             /** creates the dialog used for editing a linked table
109 
110                 @param _rTableName
111                     the name of the table to create the editor for.
112 
113                 @param _rxDocumentUI
114                     the UI of the database document, for which the editor is to be created.
115                     Must not be <NULL/>.
116 
117                 @return
118                     the table editor dialog instance.
119 
120                 @throws ::com::sun::star::lang::WrappedTargetException
121                     if creating the dialog instance fails
122 
123                 @throws ::com::sun::star::uno::RuntimeException
124                     if a serious error occures
125 
126                 @precond
127                     Our mutex is locked.
128             */
129             ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XExecutableDialog >
130                     impl_createLinkedTableEditor_throw(
131                         const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >& _rxDocumentUI,
132                         const ::rtl::OUString& _rTableName
133                     );
134 #endif
135 
136             /** retrieves our table container
137                 @return
138                     our table container. Guaranteed to not be <NULL/>.
139                 @throws ::com::sun::star::lang::WrappedTargetException
140                     if a non-RuntimeException is caught during obtaining the container.
141                 @throws ::com::sun::star::uno::RuntimeException
142                     if a serious error occurs
143                 @precond
144                     We're not disposed.
145             */
146             ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >
147                     impl_getTableContainer_throw();
148 
149             /** checks whether the given table name denotes an existing table
150                 @param _rTableName
151                     the fully name of the table to check for existence
152                 @throws ::com::sun::star::lang::IllegalArgumentException
153                     if the name does not denote an existing table
154                 @precond
155                     We're not disposed.
156             */
157             void    impl_checkExistingTable_throw( const ::rtl::OUString& _rTableName );
158 
159             /** checks whether the given table name refers to a HSQL TEXT TABLE
160             */
161             bool    impl_isTextTable_nothrow( const ::rtl::OUString& _rTableName );
162 
163             /** retrieves the icon for HSQL TEXT TABLEs
164             */
165             ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >
166                 impl_getTextTableIcon_nothrow( ::sal_Int32 _ColorMode );
167         };
168 
169         //==========================================================================
170         //= OHsqlConnection
171         //==========================================================================
172         class MethodGuard : public ::osl::MutexGuard
173         {
174         private:
175             typedef ::osl::MutexGuard   BaseGuard;
176 
177         public:
178             MethodGuard( const IMethodGuardAccess& _rComponent )
179                 :BaseGuard( _rComponent.getMutex() )
180             {
181                 _rComponent.checkDisposed();
182             }
183         };
184     }
185 }
186 #endif // CONNECTIVITY_HSQLDB_CONNECTION_HXX
187