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_DBACCESS_SOURCE_CORE_INC_QUERYCONTAINER_HXX
21 : #define INCLUDED_DBACCESS_SOURCE_CORE_INC_QUERYCONTAINER_HXX
22 :
23 : #include <cppuhelper/implbase5.hxx>
24 : #include <cppuhelper/interfacecontainer.hxx>
25 :
26 : #include <com/sun/star/beans/XPropertySet.hpp>
27 : #include <com/sun/star/container/XEnumerationAccess.hpp>
28 : #include <com/sun/star/container/XContainerListener.hpp>
29 : #include <com/sun/star/container/XNameContainer.hpp>
30 : #include <com/sun/star/container/XNameAccess.hpp>
31 : #include <com/sun/star/container/XIndexAccess.hpp>
32 : #include <com/sun/star/container/XContainer.hpp>
33 : #include <com/sun/star/util/XRefreshable.hpp>
34 : #include <com/sun/star/lang/XServiceInfo.hpp>
35 : #include <com/sun/star/uno/Sequence.hxx>
36 : #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
37 : #include <com/sun/star/sdbcx/XAppend.hpp>
38 : #include <com/sun/star/sdbcx/XDrop.hpp>
39 : #include <com/sun/star/sdbc/XConnection.hpp>
40 : #include <com/sun/star/beans/XPropertyChangeListener.hpp>
41 : #include <com/sun/star/container/XContainerApproveListener.hpp>
42 :
43 : #include "definitioncontainer.hxx"
44 : #include "apitools.hxx"
45 :
46 : namespace dbtools
47 : {
48 : class WarningsContainer;
49 : }
50 :
51 : namespace dbaccess
52 : {
53 :
54 : typedef ::cppu::ImplHelper5 < ::com::sun::star::container::XContainerListener
55 : , ::com::sun::star::container::XContainerApproveListener
56 : , ::com::sun::star::sdbcx::XDataDescriptorFactory
57 : , ::com::sun::star::sdbcx::XAppend
58 : , ::com::sun::star::sdbcx::XDrop
59 : > OQueryContainer_Base;
60 :
61 : // OQueryContainer
62 : class OQueryContainer : public ODefinitionContainer
63 : , public OQueryContainer_Base
64 : {
65 : private:
66 : ::dbtools::WarningsContainer* m_pWarnings;
67 : ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >
68 : m_xCommandDefinitions;
69 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >
70 : m_xConnection;
71 : // possible actions on our "aggregate"
72 : enum AGGREGATE_ACTION { NONE, INSERTING, FLUSHING };
73 : AGGREGATE_ACTION m_eDoingCurrently;
74 :
75 : /** a class which automatically resets m_eDoingCurrently in its destructor
76 : */
77 : class OAutoActionReset; // just for the following friend declaration
78 : friend class OAutoActionReset;
79 : class OAutoActionReset
80 : {
81 : OQueryContainer* m_pActor;
82 : public:
83 0 : OAutoActionReset(OQueryContainer* _pActor) : m_pActor(_pActor) { }
84 0 : ~OAutoActionReset() { m_pActor->m_eDoingCurrently = NONE; }
85 : };
86 :
87 : // ODefinitionContainer
88 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent > createObject( const OUString& _rName) SAL_OVERRIDE;
89 : virtual bool checkExistence(const OUString& _rName) SAL_OVERRIDE;
90 :
91 : // helper
92 : virtual void SAL_CALL disposing() SAL_OVERRIDE;
93 : virtual ~OQueryContainer();
94 :
95 : /** ctor of the container. The parent has to support the <type scope="com::sun::star::sdbc">XConnection</type>
96 : interface.<BR>
97 :
98 : @param _pWarnings
99 : specifies a warnings container (May be <NULL/>)
100 :
101 : Any errors which occur during the lifetime of the query container,
102 : which cannot be reported as exceptionts (for instance in methods where throwing an SQLException is
103 : not allowed) will be appended to this container.</p>
104 : <p>The caller is responsible for ensuring the lifetime of the object pointed to by this parameter.
105 : */
106 : OQueryContainer(
107 : const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& _rxCommandDefinitions,
108 : const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConn,
109 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxORB,
110 : ::dbtools::WarningsContainer* _pWarnings
111 : );
112 :
113 : void init();
114 :
115 : public:
116 : static rtl::Reference<OQueryContainer> create(
117 : const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& _rxCommandDefinitions,
118 : const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConn,
119 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxORB,
120 : ::dbtools::WarningsContainer* _pWarnings
121 : );
122 :
123 : DECLARE_XINTERFACE( )
124 : DECLARE_XTYPEPROVIDER( )
125 : DECLARE_SERVICE_INFO();
126 :
127 : // ::com::sun::star::container::XContainerListener
128 : virtual void SAL_CALL elementInserted( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
129 : virtual void SAL_CALL elementRemoved( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
130 : virtual void SAL_CALL elementReplaced( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
131 :
132 : // XContainerApproveListener
133 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XVeto > SAL_CALL approveInsertElement( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
134 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XVeto > SAL_CALL approveReplaceElement( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
135 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XVeto > SAL_CALL approveRemoveElement( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
136 :
137 : // ::com::sun::star::lang::XEventListener
138 : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
139 :
140 : // ::com::sun::star::sdbcx::XDataDescriptorFactory
141 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > SAL_CALL createDataDescriptor( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
142 :
143 : // ::com::sun::star::sdbcx::XAppend
144 : virtual void SAL_CALL appendByDescriptor( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& descriptor ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
145 :
146 : // ::com::sun::star::sdbcx::XDrop
147 : virtual void SAL_CALL dropByName( const OUString& elementName ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
148 : virtual void SAL_CALL dropByIndex( sal_Int32 index ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
149 :
150 : // ::com::sun::star::container::XElementAccess
151 : virtual sal_Bool SAL_CALL hasElements( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
152 : // ::com::sun::star::container::XIndexAccess
153 : virtual sal_Int32 SAL_CALL getCount( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
154 : // ::com::sun::star::container::XNameAccess
155 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getElementNames( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
156 :
157 : private:
158 : // OContentHelper overridables
159 : virtual OUString determineContentType() const SAL_OVERRIDE;
160 :
161 : // helper
162 : /** create a query object wrapping a CommandDefinition given by name. To retrieve the object, the CommandDescription
163 : container will be asked for the given name.<BR>
164 : The returned object is acquired once.
165 : */
166 : ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent > implCreateWrapper(const OUString& _rName);
167 : /// create a query object wrapping a CommandDefinition. The returned object is acquired once.
168 : ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent > implCreateWrapper(const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >& _rxCommandDesc);
169 :
170 : };
171 : } // namespace dbaccess
172 :
173 : #endif // INCLUDED_DBACCESS_SOURCE_CORE_INC_QUERYCONTAINER_HXX
174 :
175 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|