/src/libreoffice/include/connectivity/paramwrapper.hxx
Line | Count | Source |
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_CONNECTIVITY_PARAMWRAPPER_HXX |
21 | | #define INCLUDED_CONNECTIVITY_PARAMWRAPPER_HXX |
22 | | |
23 | | #include <config_options.h> |
24 | | #include <connectivity/dbtoolsdllapi.hxx> |
25 | | #include <connectivity/FValue.hxx> |
26 | | |
27 | | #include <com/sun/star/container/XIndexAccess.hpp> |
28 | | #include <com/sun/star/container/XEnumerationAccess.hpp> |
29 | | |
30 | | #include <comphelper/uno3.hxx> |
31 | | #include <comphelper/broadcasthelper.hxx> |
32 | | #include <cppuhelper/weak.hxx> |
33 | | #include <cppuhelper/propshlp.hxx> |
34 | | #include <comphelper/compbase.hxx> |
35 | | |
36 | | #include <memory> |
37 | | #include <vector> |
38 | | |
39 | | namespace com::sun::star::sdbc { class XParameters; } |
40 | | namespace com::sun::star::sdb { class XSingleSelectQueryAnalyzer; } |
41 | | |
42 | | |
43 | | namespace dbtools::param |
44 | | { |
45 | | |
46 | | |
47 | | //= ParameterWrapper |
48 | | |
49 | | /** wraps a parameter column as got from an SQLQueryComposer, so that it has an additional |
50 | | property "Value", which is forwarded to an XParameters interface |
51 | | */ |
52 | | class OOO_DLLPUBLIC_DBTOOLS ParameterWrapper final : public ::cppu::OWeakObject |
53 | | ,public css::lang::XTypeProvider |
54 | | ,public ::comphelper::OMutexAndBroadcastHelper |
55 | | ,public ::cppu::OPropertySetHelper |
56 | | { |
57 | | private: |
58 | | typedef ::cppu::OWeakObject UnoBase; |
59 | | typedef ::cppu::OPropertySetHelper PropertyBase; |
60 | | |
61 | | private: |
62 | | /// the most recently set value of the parameter |
63 | | ::connectivity::ORowSetValue m_aValue; |
64 | | /// the positions (in our m_xValueDestination) at which the value should be set (0-based!) |
65 | | ::std::vector< sal_Int32 > m_aIndexes; |
66 | | |
67 | | /// the "delegator" column to which standard property requests are forwarded |
68 | | css::uno::Reference< css::beans::XPropertySet > m_xDelegator; |
69 | | /// the property set info for our delegator |
70 | | css::uno::Reference< css::beans::XPropertySetInfo > m_xDelegatorPSI; |
71 | | /// the component taking the value |
72 | | css::uno::Reference< css::sdbc::XParameters > m_xValueDestination; |
73 | | /// helper for implementing XPropertySetInfo |
74 | | ::std::unique_ptr< ::cppu::OPropertyArrayHelper > m_pInfoHelper; |
75 | | |
76 | | |
77 | | public: |
78 | 0 | const ::connectivity::ORowSetValue& Value() const { return m_aValue; } |
79 | 0 | ::connectivity::ORowSetValue& Value() { return m_aValue; } |
80 | | |
81 | | public: |
82 | | ParameterWrapper( |
83 | | const css::uno::Reference< css::beans::XPropertySet >& _rxColumn |
84 | | ); |
85 | | |
86 | | ParameterWrapper( |
87 | | const css::uno::Reference< css::beans::XPropertySet >& _rxColumn, |
88 | | const css::uno::Reference< css::sdbc::XParameters >& _rxAllParameters, |
89 | | std::vector< sal_Int32 >&& _rIndexes |
90 | | ); |
91 | | |
92 | | DECLARE_XINTERFACE() |
93 | | |
94 | | virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; |
95 | | virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) override; |
96 | | |
97 | | // XPropertySet |
98 | | virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override; |
99 | | virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; |
100 | | |
101 | | // OPropertySetHelper |
102 | | virtual sal_Bool SAL_CALL convertFastPropertyValue( css::uno::Any& rConvertedValue, css::uno::Any& rOldValue, sal_Int32 nHandle, const css::uno::Any& rValue) override; |
103 | | virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const css::uno::Any& rValue ) override; |
104 | | virtual void SAL_CALL getFastPropertyValue( css::uno::Any& rValue, sal_Int32 nHandle ) const override; |
105 | | |
106 | | // pseudo-XComponent |
107 | | void dispose(); |
108 | | |
109 | | private: |
110 | | virtual ~ParameterWrapper() override; |
111 | | |
112 | | // disambiguations |
113 | | using ::cppu::OPropertySetHelper::getFastPropertyValue; |
114 | | |
115 | | OUString impl_getPseudoAggregatePropertyName( sal_Int32 _nHandle ) const; |
116 | | }; |
117 | | |
118 | | |
119 | | //= ParameterWrapper |
120 | | |
121 | | typedef ::std::vector< ::rtl::Reference< ParameterWrapper > > Parameters; |
122 | | |
123 | | |
124 | | //= ParameterWrapperContainer |
125 | | |
126 | | typedef ::comphelper::WeakComponentImplHelper < css::container::XIndexAccess |
127 | | , css::container::XEnumerationAccess |
128 | | > ParameterWrapperContainer_Base; |
129 | | |
130 | | /// class for the parameter event @see approveParameter |
131 | | class UNLESS_MERGELIBS_MORE(OOO_DLLPUBLIC_DBTOOLS) ParameterWrapperContainer final : |
132 | | public ParameterWrapperContainer_Base |
133 | | { |
134 | | private: |
135 | | Parameters m_aParameters; |
136 | | |
137 | | virtual ~ParameterWrapperContainer() override; |
138 | | |
139 | | public: |
140 | | /** creates an empty container |
141 | | */ |
142 | | ParameterWrapperContainer(); |
143 | | |
144 | | /** creates a container from a SingleSelectQuerAnalyzer's parameter columns |
145 | | |
146 | | Note that here, the simple constructor of the ParameterWrapper will be used, which does not |
147 | | use a XParameters instance to forward values to, but only remembers the values itself. |
148 | | */ |
149 | | ParameterWrapperContainer( const css::uno::Reference< css::sdb::XSingleSelectQueryAnalyzer >& _rxComposer ); |
150 | | |
151 | | // css::container::XElementAccess |
152 | | virtual css::uno::Type SAL_CALL getElementType() override; |
153 | | virtual sal_Bool SAL_CALL hasElements() override; |
154 | | |
155 | | // css::container::XEnumerationAccess |
156 | | virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override; |
157 | | |
158 | | // css::container::XIndexAccess |
159 | | virtual sal_Int32 SAL_CALL getCount() override; |
160 | | virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 _rIndex) override; |
161 | | |
162 | | public: |
163 | 0 | const Parameters& getParameters() const { return m_aParameters; } |
164 | | |
165 | 0 | const ::connectivity::ORowSetValue& operator[]( size_t _index ) const { return m_aParameters[ _index ]->Value(); } |
166 | 0 | ::connectivity::ORowSetValue& operator[]( size_t _index ) { return m_aParameters[ _index ]->Value(); } |
167 | | |
168 | | /** adds a ParameterWrapper to the end of the array |
169 | | */ |
170 | | void push_back( ParameterWrapper* _pParameter ) |
171 | 0 | { |
172 | 0 | m_aParameters.push_back( _pParameter ); |
173 | 0 | } |
174 | | |
175 | 26.8k | size_t size() const { return m_aParameters.size(); } |
176 | | |
177 | | private: |
178 | | // XComponent |
179 | | virtual void disposing(std::unique_lock<std::mutex>& rGuard) override; |
180 | | |
181 | | void impl_checkDisposed_throw(); |
182 | | }; |
183 | | |
184 | | |
185 | | //= ParametersContainer |
186 | | |
187 | | typedef ::rtl::Reference< ParameterWrapperContainer > ParametersContainerRef; |
188 | | |
189 | | |
190 | | } // namespace dbtools::param |
191 | | |
192 | | |
193 | | #endif // INCLUDED_CONNECTIVITY_PARAMWRAPPER_HXX |
194 | | |
195 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |