1*caf5cd79SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*caf5cd79SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*caf5cd79SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*caf5cd79SAndrew Rist  * distributed with this work for additional information
6*caf5cd79SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*caf5cd79SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*caf5cd79SAndrew Rist  * "License"); you may not use this file except in compliance
9*caf5cd79SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*caf5cd79SAndrew Rist  *
11*caf5cd79SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*caf5cd79SAndrew Rist  *
13*caf5cd79SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*caf5cd79SAndrew Rist  * software distributed under the License is distributed on an
15*caf5cd79SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*caf5cd79SAndrew Rist  * KIND, either express or implied.  See the License for the
17*caf5cd79SAndrew Rist  * specific language governing permissions and limitations
18*caf5cd79SAndrew Rist  * under the License.
19*caf5cd79SAndrew Rist  *
20*caf5cd79SAndrew Rist  *************************************************************/
21*caf5cd79SAndrew Rist 
22*caf5cd79SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef CONNECTIVITY_HSQLDB_CONNECTION_HXX
25cdf0e10cSrcweir #define CONNECTIVITY_HSQLDB_CONNECTION_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "connectivity/ConnectionWrapper.hxx"
28cdf0e10cSrcweir /** === begin UNO includes === **/
29cdf0e10cSrcweir #include <com/sun/star/util/XFlushable.hpp>
30cdf0e10cSrcweir #include <com/sun/star/sdbc/XDriver.hpp>
31cdf0e10cSrcweir #ifndef __com_sun_star_sdb_application_XTableUIProvider_hpp__
32cdf0e10cSrcweir #include <com/sun/star/sdb/application/XTableUIProvider.hpp>
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
35cdf0e10cSrcweir /** === end UNO includes === **/
36cdf0e10cSrcweir #include <cppuhelper/compbase2.hxx>
37cdf0e10cSrcweir #include <comphelper/uno3.hxx>
38cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx>
39cdf0e10cSrcweir #include <memory>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir namespace connectivity
42cdf0e10cSrcweir {
43cdf0e10cSrcweir     namespace hsqldb
44cdf0e10cSrcweir     {
45cdf0e10cSrcweir         class SAL_NO_VTABLE IMethodGuardAccess
46cdf0e10cSrcweir         {
47cdf0e10cSrcweir         public:
48cdf0e10cSrcweir             virtual ::osl::Mutex&   getMutex() const = 0;
49cdf0e10cSrcweir             virtual void            checkDisposed() const = 0;
50cdf0e10cSrcweir         };
51cdf0e10cSrcweir 
52cdf0e10cSrcweir         //==========================================================================
53cdf0e10cSrcweir         //= OHsqlConnection - wraps all methods to the real connection from the driver
54cdf0e10cSrcweir         //= but when disposed it doesn't dispose the real connection
55cdf0e10cSrcweir         //==========================================================================
56cdf0e10cSrcweir         typedef ::cppu::WeakComponentImplHelper2<   ::com::sun::star::util::XFlushable
57cdf0e10cSrcweir                                                 ,   ::com::sun::star::sdb::application::XTableUIProvider
58cdf0e10cSrcweir                                                 >   OHsqlConnection_BASE;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir         class OHsqlConnection   :public ::comphelper::OBaseMutex
61cdf0e10cSrcweir                                 ,public OHsqlConnection_BASE
62cdf0e10cSrcweir                                 ,public OConnectionWrapper
63cdf0e10cSrcweir                                 ,public IMethodGuardAccess
64cdf0e10cSrcweir         {
65cdf0e10cSrcweir         private:
66cdf0e10cSrcweir             ::cppu::OInterfaceContainerHelper                                                           m_aFlushListeners;
67cdf0e10cSrcweir             ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver >                         m_xDriver;
68cdf0e10cSrcweir             ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >            m_xORB;
69cdf0e10cSrcweir             bool                                                                                        m_bIni;
70cdf0e10cSrcweir             bool                                                                                        m_bReadOnly;
71cdf0e10cSrcweir 
72cdf0e10cSrcweir         protected:
73cdf0e10cSrcweir             virtual void SAL_CALL disposing(void);
74cdf0e10cSrcweir             virtual ~OHsqlConnection();
75cdf0e10cSrcweir 
76cdf0e10cSrcweir         public:
77cdf0e10cSrcweir             OHsqlConnection(
78cdf0e10cSrcweir                 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver > _rxDriver,
79cdf0e10cSrcweir                 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _xConnection,
80cdf0e10cSrcweir                 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _xORB
81cdf0e10cSrcweir             );
82cdf0e10cSrcweir 
83cdf0e10cSrcweir             // XServiceInfo
84cdf0e10cSrcweir             DECLARE_SERVICE_INFO();
85cdf0e10cSrcweir             DECLARE_XTYPEPROVIDER()
86cdf0e10cSrcweir             DECLARE_XINTERFACE( )
87cdf0e10cSrcweir 
88cdf0e10cSrcweir             // IMethodGuardAccess
89cdf0e10cSrcweir             virtual ::osl::Mutex&   getMutex() const;
90cdf0e10cSrcweir             virtual void            checkDisposed() const;
91cdf0e10cSrcweir 
92cdf0e10cSrcweir             // XFlushable
93cdf0e10cSrcweir             virtual void SAL_CALL flush(  ) throw (::com::sun::star::uno::RuntimeException);
94cdf0e10cSrcweir             virtual void SAL_CALL addFlushListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XFlushListener >& l ) throw (::com::sun::star::uno::RuntimeException);
95cdf0e10cSrcweir             virtual void SAL_CALL removeFlushListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XFlushListener >& l ) throw (::com::sun::star::uno::RuntimeException);
96cdf0e10cSrcweir 
97cdf0e10cSrcweir             // XTableUIProvider
98cdf0e10cSrcweir             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);
99cdf0e10cSrcweir             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);
100cdf0e10cSrcweir 
101cdf0e10cSrcweir         private:
102cdf0e10cSrcweir #if 0
103cdf0e10cSrcweir         // TODO: resource
104cdf0e10cSrcweir             /** creates the dialog used for editing a linked table
105cdf0e10cSrcweir 
106cdf0e10cSrcweir                 @param _rTableName
107cdf0e10cSrcweir                     the name of the table to create the editor for.
108cdf0e10cSrcweir 
109cdf0e10cSrcweir                 @param _rxDocumentUI
110cdf0e10cSrcweir                     the UI of the database document, for which the editor is to be created.
111cdf0e10cSrcweir                     Must not be <NULL/>.
112cdf0e10cSrcweir 
113cdf0e10cSrcweir                 @return
114cdf0e10cSrcweir                     the table editor dialog instance.
115cdf0e10cSrcweir 
116cdf0e10cSrcweir                 @throws ::com::sun::star::lang::WrappedTargetException
117cdf0e10cSrcweir                     if creating the dialog instance fails
118cdf0e10cSrcweir 
119cdf0e10cSrcweir                 @throws ::com::sun::star::uno::RuntimeException
120cdf0e10cSrcweir                     if a serious error occures
121cdf0e10cSrcweir 
122cdf0e10cSrcweir                 @precond
123cdf0e10cSrcweir                     Our mutex is locked.
124cdf0e10cSrcweir             */
125cdf0e10cSrcweir             ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XExecutableDialog >
126cdf0e10cSrcweir                     impl_createLinkedTableEditor_throw(
127cdf0e10cSrcweir                         const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >& _rxDocumentUI,
128cdf0e10cSrcweir                         const ::rtl::OUString& _rTableName
129cdf0e10cSrcweir                     );
130cdf0e10cSrcweir #endif
131cdf0e10cSrcweir 
132cdf0e10cSrcweir             /** retrieves our table container
133cdf0e10cSrcweir                 @return
134cdf0e10cSrcweir                     our table container. Guaranteed to not be <NULL/>.
135cdf0e10cSrcweir                 @throws ::com::sun::star::lang::WrappedTargetException
136cdf0e10cSrcweir                     if a non-RuntimeException is caught during obtaining the container.
137cdf0e10cSrcweir                 @throws ::com::sun::star::uno::RuntimeException
138cdf0e10cSrcweir                     if a serious error occurs
139cdf0e10cSrcweir                 @precond
140cdf0e10cSrcweir                     We're not disposed.
141cdf0e10cSrcweir             */
142cdf0e10cSrcweir             ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >
143cdf0e10cSrcweir                     impl_getTableContainer_throw();
144cdf0e10cSrcweir 
145cdf0e10cSrcweir             /** checks whether the given table name denotes an existing table
146cdf0e10cSrcweir                 @param _rTableName
147cdf0e10cSrcweir                     the fully name of the table to check for existence
148cdf0e10cSrcweir                 @throws ::com::sun::star::lang::IllegalArgumentException
149cdf0e10cSrcweir                     if the name does not denote an existing table
150cdf0e10cSrcweir                 @precond
151cdf0e10cSrcweir                     We're not disposed.
152cdf0e10cSrcweir             */
153cdf0e10cSrcweir             void    impl_checkExistingTable_throw( const ::rtl::OUString& _rTableName );
154cdf0e10cSrcweir 
155cdf0e10cSrcweir             /** checks whether the given table name refers to a HSQL TEXT TABLE
156cdf0e10cSrcweir             */
157cdf0e10cSrcweir             bool    impl_isTextTable_nothrow( const ::rtl::OUString& _rTableName );
158cdf0e10cSrcweir 
159cdf0e10cSrcweir             /** retrieves the icon for HSQL TEXT TABLEs
160cdf0e10cSrcweir             */
161cdf0e10cSrcweir             ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >
162cdf0e10cSrcweir                 impl_getTextTableIcon_nothrow( ::sal_Int32 _ColorMode );
163cdf0e10cSrcweir         };
164cdf0e10cSrcweir 
165cdf0e10cSrcweir         //==========================================================================
166cdf0e10cSrcweir         //= OHsqlConnection
167cdf0e10cSrcweir         //==========================================================================
168cdf0e10cSrcweir         class MethodGuard : public ::osl::MutexGuard
169cdf0e10cSrcweir         {
170cdf0e10cSrcweir         private:
171cdf0e10cSrcweir             typedef ::osl::MutexGuard   BaseGuard;
172cdf0e10cSrcweir 
173cdf0e10cSrcweir         public:
MethodGuard(const IMethodGuardAccess & _rComponent)174cdf0e10cSrcweir             MethodGuard( const IMethodGuardAccess& _rComponent )
175cdf0e10cSrcweir                 :BaseGuard( _rComponent.getMutex() )
176cdf0e10cSrcweir             {
177cdf0e10cSrcweir                 _rComponent.checkDisposed();
178cdf0e10cSrcweir             }
179cdf0e10cSrcweir         };
180cdf0e10cSrcweir     }
181cdf0e10cSrcweir }
182cdf0e10cSrcweir #endif // CONNECTIVITY_HSQLDB_CONNECTION_HXX
183