1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <config_options.h>
24 #include <connectivity/dbtoolsdllapi.hxx>
25 #include <connectivity/FValue.hxx>
27 #include <com/sun/star/container/XIndexAccess.hpp>
28 #include <com/sun/star/container/XEnumerationAccess.hpp>
30 #include <comphelper/uno3.hxx>
31 #include <comphelper/broadcasthelper.hxx>
32 #include <cppuhelper/weak.hxx>
33 #include <cppuhelper/propshlp.hxx>
34 #include <cppuhelper/compbase.hxx>
39 namespace com::sun::star::sdbc
{ class XParameters
; }
40 namespace com::sun::star::sdb
{ class XSingleSelectQueryAnalyzer
; }
43 namespace dbtools::param
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
52 class UNLESS_MERGELIBS(OOO_DLLPUBLIC_DBTOOLS
) ParameterWrapper final
: public ::cppu::OWeakObject
53 ,public css::lang::XTypeProvider
54 ,public ::comphelper::OMutexAndBroadcastHelper
55 ,public ::cppu::OPropertySetHelper
58 typedef ::cppu::OWeakObject UnoBase
;
59 typedef ::cppu::OPropertySetHelper PropertyBase
;
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
;
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
;
78 const ::connectivity::ORowSetValue
& Value() const { return m_aValue
; }
79 ::connectivity::ORowSetValue
& Value() { return m_aValue
; }
83 const css::uno::Reference
< css::beans::XPropertySet
>& _rxColumn
87 const css::uno::Reference
< css::beans::XPropertySet
>& _rxColumn
,
88 const css::uno::Reference
< css::sdbc::XParameters
>& _rxAllParameters
,
89 const ::std::vector
< sal_Int32
>& _rIndexes
94 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes( ) override
;
95 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId( ) override
;
98 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo() override
;
99 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper() override
;
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
;
110 virtual ~ParameterWrapper() override
;
113 using ::cppu::OPropertySetHelper::getFastPropertyValue
;
115 OUString
impl_getPseudoAggregatePropertyName( sal_Int32 _nHandle
) const;
121 typedef ::std::vector
< ::rtl::Reference
< ParameterWrapper
> > Parameters
;
124 //= ParameterWrapperContainer
126 typedef ::cppu::WeakComponentImplHelper
< css::container::XIndexAccess
127 , css::container::XEnumerationAccess
128 > ParameterWrapperContainer_Base
;
130 /// class for the parameter event @see approveParameter
131 class OOO_DLLPUBLIC_DBTOOLS ParameterWrapperContainer final
:
132 public ParameterWrapperContainer_Base
135 ::osl::Mutex m_aMutex
;
136 Parameters m_aParameters
;
138 virtual ~ParameterWrapperContainer() override
;
141 /** creates an empty container
143 ParameterWrapperContainer();
145 /** creates a container from a SingleSelectQuerAnalyzer's parameter columns
147 Note that here, the simple constructor of the ParameterWrapper will be used, which does not
148 use a XParameters instance to forward values to, but only remembers the values itself.
150 ParameterWrapperContainer( const css::uno::Reference
< css::sdb::XSingleSelectQueryAnalyzer
>& _rxComposer
);
152 // css::container::XElementAccess
153 virtual css::uno::Type SAL_CALL
getElementType() override
;
154 virtual sal_Bool SAL_CALL
hasElements() override
;
156 // css::container::XEnumerationAccess
157 virtual css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
createEnumeration() override
;
159 // css::container::XIndexAccess
160 virtual sal_Int32 SAL_CALL
getCount() override
;
161 virtual css::uno::Any SAL_CALL
getByIndex(sal_Int32 _rIndex
) override
;
164 const Parameters
& getParameters() const { return m_aParameters
; }
166 const ::connectivity::ORowSetValue
& operator[]( size_t _index
) const { return m_aParameters
[ _index
]->Value(); }
167 ::connectivity::ORowSetValue
& operator[]( size_t _index
) { return m_aParameters
[ _index
]->Value(); }
169 /** adds a ParameterWrapper to the end of the array
171 void push_back( ParameterWrapper
* _pParameter
)
173 m_aParameters
.push_back( _pParameter
);
176 size_t size() const { return m_aParameters
.size(); }
180 virtual void SAL_CALL
disposing() override
;
182 void impl_checkDisposed_throw();
186 //= ParametersContainer
188 typedef ::rtl::Reference
< ParameterWrapperContainer
> ParametersContainerRef
;
191 } // namespace dbtools::param
194 #endif // INCLUDED_CONNECTIVITY_PARAMWRAPPER_HXX
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */