Branch libreoffice-5-0-4
[LibreOffice.git] / include / connectivity / paramwrapper.hxx
blob2096260afbb2e102c1856f48ef1ab7bc1fc3143d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_CONNECTIVITY_PARAMWRAPPER_HXX
21 #define INCLUDED_CONNECTIVITY_PARAMWRAPPER_HXX
23 #include <connectivity/dbtoolsdllapi.hxx>
24 #include <connectivity/FValue.hxx>
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>
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>
37 #include <memory>
38 #include <vector>
41 namespace dbtools
43 namespace param
48 //= ParameterWrapper
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
53 class OOO_DLLPUBLIC_DBTOOLS ParameterWrapper :public ::cppu::OWeakObject
54 ,public css::lang::XTypeProvider
55 ,public ::comphelper::OMutexAndBroadcastHelper
56 ,public ::cppu::OPropertySetHelper
58 private:
59 typedef ::cppu::OWeakObject UnoBase;
60 typedef ::cppu::OPropertySetHelper PropertyBase;
62 private:
63 /// the most recently set value of the parameter
64 ::connectivity::ORowSetValue m_aValue;
65 /// the positions (in our m_xValueDestination) at which the value should be set (0-based!)
66 ::std::vector< sal_Int32 > m_aIndexes;
68 /// the "delegator" column to which standard property requests are forwarded
69 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xDelegator;
70 /// the property set info for our delegator
71 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > m_xDelegatorPSI;
72 /// the component taking the value
73 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XParameters > m_xValueDestination;
74 /// helper for implementing XPropertySetInfo
75 ::std::unique_ptr< ::cppu::OPropertyArrayHelper > m_pInfoHelper;
78 public:
79 const ::connectivity::ORowSetValue& Value() const { return m_aValue; }
80 ::connectivity::ORowSetValue& Value() { return m_aValue; }
82 public:
83 ParameterWrapper(
84 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxColumn
87 ParameterWrapper(
88 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxColumn,
89 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XParameters >& _rxAllParameters,
90 const ::std::vector< sal_Int32 >& _rIndexes
93 DECLARE_XINTERFACE()
95 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
96 virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
98 // XPropertySet
99 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
100 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() SAL_OVERRIDE;
102 // OPropertySetHelper
103 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 ) SAL_OVERRIDE;
104 virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) throw( ::com::sun::star::uno::Exception, std::exception ) SAL_OVERRIDE;
105 virtual void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const SAL_OVERRIDE;
107 // pseudo-XComponent
108 void SAL_CALL dispose();
110 protected:
111 virtual ~ParameterWrapper();
113 // disambiguations
114 using ::cppu::OPropertySetHelper::getFastPropertyValue;
116 private:
117 OUString impl_getPseudoAggregatePropertyName( sal_Int32 _nHandle ) const;
119 private:
120 ParameterWrapper(); // not implemented
124 //= ParameterWrapper
126 typedef ::std::vector< ::rtl::Reference< ParameterWrapper > > Parameters;
129 //= ParameterWrapperContainer
131 typedef ::cppu::WeakComponentImplHelper2 < ::com::sun::star::container::XIndexAccess
132 , ::com::sun::star::container::XEnumerationAccess
133 > ParameterWrapperContainer_Base;
135 /// class for the parameter event @see approveParameter
136 class OOO_DLLPUBLIC_DBTOOLS ParameterWrapperContainer :
137 public ParameterWrapperContainer_Base
139 private:
140 ::osl::Mutex m_aMutex;
141 Parameters m_aParameters;
143 protected:
144 virtual ~ParameterWrapperContainer();
146 public:
147 /** creates an empty container
149 ParameterWrapperContainer();
151 /** creates a container from a SingleSelectQuerAnalyzer's parameter columns
153 Note that here, the simple constructor of the ParameterWrapper will be used, which does not
154 use a XParameters instance to forward values to, but only remembers the values itself.
156 ParameterWrapperContainer( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryAnalyzer >& _rxComposer );
158 // ::com::sun::star::container::XElementAccess
159 virtual ::com::sun::star::uno::Type SAL_CALL getElementType() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
160 virtual sal_Bool SAL_CALL hasElements() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
162 // ::com::sun::star::container::XEnumerationAccess
163 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
165 // ::com::sun::star::container::XIndexAccess
166 virtual sal_Int32 SAL_CALL getCount() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
167 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, std::exception ) SAL_OVERRIDE;
169 public:
170 const Parameters& getParameters() { return m_aParameters; }
172 const ::connectivity::ORowSetValue& operator[]( size_t _index ) const { return m_aParameters[ _index ]->Value(); }
173 ::connectivity::ORowSetValue& operator[]( size_t _index ) { return m_aParameters[ _index ]->Value(); }
175 /** adds an ParameterWrapper to the end of the array
177 void push_back( ParameterWrapper* _pParameter )
179 m_aParameters.push_back( _pParameter );
182 size_t size() const { return m_aParameters.size(); }
184 protected:
185 // XComponent
186 virtual void SAL_CALL disposing() SAL_OVERRIDE;
188 private:
189 void impl_checkDisposed_throw();
193 //= ParametersContainer
195 typedef ::rtl::Reference< ParameterWrapperContainer > ParametersContainerRef;
198 } } // namespace dbtools::param
201 #endif // INCLUDED_CONNECTIVITY_PARAMWRAPPER_HXX
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */