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