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