xref: /AOO41X/main/connectivity/inc/connectivity/paramwrapper.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef CONNECTIVITY_PARAMWRAPPER_HXX
29*cdf0e10cSrcweir #define CONNECTIVITY_PARAMWRAPPER_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "connectivity/dbtoolsdllapi.hxx"
32*cdf0e10cSrcweir #include <connectivity/FValue.hxx>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir /** === begin UNO includes === **/
35*cdf0e10cSrcweir #include <com/sun/star/sdbc/XParameters.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/container/XEnumerationAccess.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp>
39*cdf0e10cSrcweir /** === end UNO includes === **/
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #include <comphelper/uno3.hxx>
42*cdf0e10cSrcweir #include <comphelper/broadcasthelper.hxx>
43*cdf0e10cSrcweir #include <cppuhelper/weak.hxx>
44*cdf0e10cSrcweir #include <cppuhelper/propshlp.hxx>
45*cdf0e10cSrcweir #include <cppuhelper/compbase2.hxx>
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir #include <memory>
48*cdf0e10cSrcweir #include <vector>
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir //........................................................................
51*cdf0e10cSrcweir namespace dbtools
52*cdf0e10cSrcweir {
53*cdf0e10cSrcweir namespace param
54*cdf0e10cSrcweir {
55*cdf0e10cSrcweir //........................................................................
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir     //====================================================================
58*cdf0e10cSrcweir     //= ParameterWrapper
59*cdf0e10cSrcweir     //====================================================================
60*cdf0e10cSrcweir     /** wraps a parameter column as got from an SQLQueryComposer, so that it has an additional
61*cdf0e10cSrcweir         property "Value", which is forwarded to an XParameters interface
62*cdf0e10cSrcweir     */
63*cdf0e10cSrcweir     class OOO_DLLPUBLIC_DBTOOLS ParameterWrapper  :public ::cppu::OWeakObject
64*cdf0e10cSrcweir                             ,public ::comphelper::OMutexAndBroadcastHelper
65*cdf0e10cSrcweir                             ,public ::cppu::OPropertySetHelper
66*cdf0e10cSrcweir     {
67*cdf0e10cSrcweir     private:
68*cdf0e10cSrcweir         typedef ::cppu::OWeakObject         UnoBase;
69*cdf0e10cSrcweir         typedef ::cppu::OPropertySetHelper  PropertyBase;
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir     private:
72*cdf0e10cSrcweir         /// the most recently set value of the parameter
73*cdf0e10cSrcweir         ::connectivity::ORowSetValue    m_aValue;
74*cdf0e10cSrcweir         /// the positions (in our m_xValueDestination) at which the value should be set (0-based!)
75*cdf0e10cSrcweir         ::std::vector< sal_Int32 >      m_aIndexes;
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir         /// the "delegator" column to which standard property requests are forwarded
78*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >       m_xDelegator;
79*cdf0e10cSrcweir         /// the property set info for our delegator
80*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >   m_xDelegatorPSI;
81*cdf0e10cSrcweir         /// the component taking the value
82*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XParameters >         m_xValueDestination;
83*cdf0e10cSrcweir         /// helper for implementing XPropertySetInfo
84*cdf0e10cSrcweir         ::std::auto_ptr< ::cppu::OPropertyArrayHelper >                                 m_pInfoHelper;
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir     public:
88*cdf0e10cSrcweir         const ::connectivity::ORowSetValue& Value() const { return m_aValue; }
89*cdf0e10cSrcweir               ::connectivity::ORowSetValue& Value()       { return m_aValue; }
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir     public:
92*cdf0e10cSrcweir         ParameterWrapper(
93*cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxColumn
94*cdf0e10cSrcweir         );
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir         ParameterWrapper(
97*cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxColumn,
98*cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XParameters >& _rxAllParameters,
99*cdf0e10cSrcweir             const ::std::vector< sal_Int32 >& _rIndexes
100*cdf0e10cSrcweir         );
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir         DECLARE_XINTERFACE()
103*cdf0e10cSrcweir         DECLARE_XTYPEPROVIDER()
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir         // XPropertySet
106*cdf0e10cSrcweir         virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException );
107*cdf0e10cSrcweir         virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir         // OPropertySetHelper
110*cdf0e10cSrcweir         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 );
111*cdf0e10cSrcweir         virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) throw( ::com::sun::star::uno::Exception );
112*cdf0e10cSrcweir         virtual void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const;
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir         // pseudo-XComponent
115*cdf0e10cSrcweir         virtual void SAL_CALL dispose();
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir     protected:
118*cdf0e10cSrcweir         virtual ~ParameterWrapper();
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir         // disambiguations
121*cdf0e10cSrcweir         using ::cppu::OPropertySetHelper::getFastPropertyValue;
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir     private:
124*cdf0e10cSrcweir         ::rtl::OUString impl_getPseudoAggregatePropertyName( sal_Int32 _nHandle ) const;
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir     private:
127*cdf0e10cSrcweir         ParameterWrapper(); // not implemented
128*cdf0e10cSrcweir     };
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir     //====================================================================
131*cdf0e10cSrcweir     //= ParameterWrapperContainer
132*cdf0e10cSrcweir     //====================================================================
133*cdf0e10cSrcweir     typedef ::std::vector< ::rtl::Reference< ParameterWrapper > >   Parameters;
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir     //====================================================================
136*cdf0e10cSrcweir     //= ParameterWrapperContainer
137*cdf0e10cSrcweir     //====================================================================
138*cdf0e10cSrcweir     typedef ::cppu::WeakComponentImplHelper2    <   ::com::sun::star::container::XIndexAccess
139*cdf0e10cSrcweir                                                 ,   ::com::sun::star::container::XEnumerationAccess
140*cdf0e10cSrcweir                                                 >   ParameterWrapperContainer_Base;
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir     /// class for the parameter event @see approveParameter
143*cdf0e10cSrcweir     class OOO_DLLPUBLIC_DBTOOLS ParameterWrapperContainer :
144*cdf0e10cSrcweir         public ParameterWrapperContainer_Base
145*cdf0e10cSrcweir     {
146*cdf0e10cSrcweir     private:
147*cdf0e10cSrcweir         ::osl::Mutex    m_aMutex;
148*cdf0e10cSrcweir         Parameters      m_aParameters;
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir     protected:
151*cdf0e10cSrcweir         virtual ~ParameterWrapperContainer();
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir     public:
154*cdf0e10cSrcweir         /** creates an empty container
155*cdf0e10cSrcweir         */
156*cdf0e10cSrcweir         ParameterWrapperContainer();
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir         /** creates a container from a SingleSelectQuerAnalyzer's parameter columns
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir             Note that here, the simple constructor of the ParameterWrapper will be used, which does not
161*cdf0e10cSrcweir             use a XParameters instance to forward values to, but only remembers the values itself.
162*cdf0e10cSrcweir         */
163*cdf0e10cSrcweir         ParameterWrapperContainer( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryAnalyzer >& _rxComposer );
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir         // ::com::sun::star::container::XElementAccess
166*cdf0e10cSrcweir         virtual ::com::sun::star::uno::Type SAL_CALL getElementType() throw( ::com::sun::star::uno::RuntimeException );
167*cdf0e10cSrcweir         virtual sal_Bool SAL_CALL hasElements() throw( ::com::sun::star::uno::RuntimeException );
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir         // ::com::sun::star::container::XEnumerationAccess
170*cdf0e10cSrcweir         virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration() throw( ::com::sun::star::uno::RuntimeException );
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir         // ::com::sun::star::container::XIndexAccess
173*cdf0e10cSrcweir         virtual sal_Int32 SAL_CALL getCount() throw( ::com::sun::star::uno::RuntimeException );
174*cdf0e10cSrcweir         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 );
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir     public:
177*cdf0e10cSrcweir         const Parameters& getParameters() { return m_aParameters; }
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir         const ::connectivity::ORowSetValue& operator[]( size_t _index ) const { return m_aParameters[ _index ]->Value(); }
180*cdf0e10cSrcweir               ::connectivity::ORowSetValue& operator[]( size_t _index )       { return m_aParameters[ _index ]->Value(); }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir         /** adds an ParameterWrapper to the end of the array
183*cdf0e10cSrcweir         */
184*cdf0e10cSrcweir         void    push_back( ParameterWrapper* _pParameter )
185*cdf0e10cSrcweir         {
186*cdf0e10cSrcweir             m_aParameters.push_back( _pParameter );
187*cdf0e10cSrcweir         }
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir         size_t  size() const { return m_aParameters.size(); }
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir     protected:
192*cdf0e10cSrcweir         // XComponent
193*cdf0e10cSrcweir         virtual void SAL_CALL disposing();
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir     private:
196*cdf0e10cSrcweir         void    impl_checkDisposed_throw();
197*cdf0e10cSrcweir     };
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir     //====================================================================
200*cdf0e10cSrcweir     //= ParamatersContainer
201*cdf0e10cSrcweir     //====================================================================
202*cdf0e10cSrcweir     typedef ::rtl::Reference< ParameterWrapperContainer >   ParametersContainerRef;
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir //........................................................................
205*cdf0e10cSrcweir } } // namespace dbtools::param
206*cdf0e10cSrcweir //........................................................................
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir #endif // CONNECTIVITY_PARAMWRAPPER_HXX
209