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 <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/compbase.hxx>
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 OOO_DLLPUBLIC_DBTOOLS ParameterWrapper
: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( ) throw (css::uno::RuntimeException
, std::exception
) override
;
95 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId( ) throw (css::uno::RuntimeException
, std::exception
) override
;
98 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo() throw( css::uno::RuntimeException
, std::exception
) 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
) throw( css::lang::IllegalArgumentException
) override
;
103 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
, const css::uno::Any
& rValue
) throw( css::uno::Exception
, std::exception
) override
;
104 virtual void SAL_CALL
getFastPropertyValue( css::uno::Any
& rValue
, sal_Int32 nHandle
) const override
;
107 void SAL_CALL
dispose();
110 virtual ~ParameterWrapper() override
;
113 using ::cppu::OPropertySetHelper::getFastPropertyValue
;
116 OUString
impl_getPseudoAggregatePropertyName( sal_Int32 _nHandle
) const;
122 typedef ::std::vector
< ::rtl::Reference
< ParameterWrapper
> > Parameters
;
125 //= ParameterWrapperContainer
127 typedef ::cppu::WeakComponentImplHelper
< css::container::XIndexAccess
128 , css::container::XEnumerationAccess
129 > ParameterWrapperContainer_Base
;
131 /// class for the parameter event @see approveParameter
132 class OOO_DLLPUBLIC_DBTOOLS ParameterWrapperContainer
:
133 public ParameterWrapperContainer_Base
136 ::osl::Mutex m_aMutex
;
137 Parameters m_aParameters
;
140 virtual ~ParameterWrapperContainer() override
;
143 /** creates an empty container
145 ParameterWrapperContainer();
147 /** creates a container from a SingleSelectQuerAnalyzer's parameter columns
149 Note that here, the simple constructor of the ParameterWrapper will be used, which does not
150 use a XParameters instance to forward values to, but only remembers the values itself.
152 ParameterWrapperContainer( const css::uno::Reference
< css::sdb::XSingleSelectQueryAnalyzer
>& _rxComposer
);
154 // css::container::XElementAccess
155 virtual css::uno::Type SAL_CALL
getElementType() throw( css::uno::RuntimeException
, std::exception
) override
;
156 virtual sal_Bool SAL_CALL
hasElements() throw( css::uno::RuntimeException
, std::exception
) override
;
158 // css::container::XEnumerationAccess
159 virtual css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
createEnumeration() throw( css::uno::RuntimeException
, std::exception
) override
;
161 // css::container::XIndexAccess
162 virtual sal_Int32 SAL_CALL
getCount() throw( css::uno::RuntimeException
, std::exception
) override
;
163 virtual css::uno::Any SAL_CALL
getByIndex(sal_Int32 _rIndex
) throw( css::lang::IndexOutOfBoundsException
, css::lang::WrappedTargetException
, css::uno::RuntimeException
, std::exception
) override
;
166 const Parameters
& getParameters() { return m_aParameters
; }
168 const ::connectivity::ORowSetValue
& operator[]( size_t _index
) const { return m_aParameters
[ _index
]->Value(); }
169 ::connectivity::ORowSetValue
& operator[]( size_t _index
) { return m_aParameters
[ _index
]->Value(); }
171 /** adds an ParameterWrapper to the end of the array
173 void push_back( ParameterWrapper
* _pParameter
)
175 m_aParameters
.push_back( _pParameter
);
178 size_t size() const { return m_aParameters
.size(); }
182 virtual void SAL_CALL
disposing() override
;
185 void impl_checkDisposed_throw();
189 //= ParametersContainer
191 typedef ::rtl::Reference
< ParameterWrapperContainer
> ParametersContainerRef
;
194 } } // namespace dbtools::param
197 #endif // INCLUDED_CONNECTIVITY_PARAMWRAPPER_HXX
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */