1*caf5cd79SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*caf5cd79SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*caf5cd79SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*caf5cd79SAndrew Rist * distributed with this work for additional information 6*caf5cd79SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*caf5cd79SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*caf5cd79SAndrew Rist * "License"); you may not use this file except in compliance 9*caf5cd79SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*caf5cd79SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*caf5cd79SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*caf5cd79SAndrew Rist * software distributed under the License is distributed on an 15*caf5cd79SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*caf5cd79SAndrew Rist * KIND, either express or implied. See the License for the 17*caf5cd79SAndrew Rist * specific language governing permissions and limitations 18*caf5cd79SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*caf5cd79SAndrew Rist *************************************************************/ 21*caf5cd79SAndrew Rist 22*caf5cd79SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef CONNECTIVITY_PARAMWRAPPER_HXX 25cdf0e10cSrcweir #define CONNECTIVITY_PARAMWRAPPER_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "connectivity/dbtoolsdllapi.hxx" 28cdf0e10cSrcweir #include <connectivity/FValue.hxx> 29cdf0e10cSrcweir 30cdf0e10cSrcweir /** === begin UNO includes === **/ 31cdf0e10cSrcweir #include <com/sun/star/sdbc/XParameters.hpp> 32cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp> 33cdf0e10cSrcweir #include <com/sun/star/container/XEnumerationAccess.hpp> 34cdf0e10cSrcweir #include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp> 35cdf0e10cSrcweir /** === end UNO includes === **/ 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include <comphelper/uno3.hxx> 38cdf0e10cSrcweir #include <comphelper/broadcasthelper.hxx> 39cdf0e10cSrcweir #include <cppuhelper/weak.hxx> 40cdf0e10cSrcweir #include <cppuhelper/propshlp.hxx> 41cdf0e10cSrcweir #include <cppuhelper/compbase2.hxx> 42cdf0e10cSrcweir 43cdf0e10cSrcweir #include <memory> 44cdf0e10cSrcweir #include <vector> 45cdf0e10cSrcweir 46cdf0e10cSrcweir //........................................................................ 47cdf0e10cSrcweir namespace dbtools 48cdf0e10cSrcweir { 49cdf0e10cSrcweir namespace param 50cdf0e10cSrcweir { 51cdf0e10cSrcweir //........................................................................ 52cdf0e10cSrcweir 53cdf0e10cSrcweir //==================================================================== 54cdf0e10cSrcweir //= ParameterWrapper 55cdf0e10cSrcweir //==================================================================== 56cdf0e10cSrcweir /** wraps a parameter column as got from an SQLQueryComposer, so that it has an additional 57cdf0e10cSrcweir property "Value", which is forwarded to an XParameters interface 58cdf0e10cSrcweir */ 59cdf0e10cSrcweir class OOO_DLLPUBLIC_DBTOOLS ParameterWrapper :public ::cppu::OWeakObject 60cdf0e10cSrcweir ,public ::comphelper::OMutexAndBroadcastHelper 61cdf0e10cSrcweir ,public ::cppu::OPropertySetHelper 62cdf0e10cSrcweir { 63cdf0e10cSrcweir private: 64cdf0e10cSrcweir typedef ::cppu::OWeakObject UnoBase; 65cdf0e10cSrcweir typedef ::cppu::OPropertySetHelper PropertyBase; 66cdf0e10cSrcweir 67cdf0e10cSrcweir private: 68cdf0e10cSrcweir /// the most recently set value of the parameter 69cdf0e10cSrcweir ::connectivity::ORowSetValue m_aValue; 70cdf0e10cSrcweir /// the positions (in our m_xValueDestination) at which the value should be set (0-based!) 71cdf0e10cSrcweir ::std::vector< sal_Int32 > m_aIndexes; 72cdf0e10cSrcweir 73cdf0e10cSrcweir /// the "delegator" column to which standard property requests are forwarded 74cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xDelegator; 75cdf0e10cSrcweir /// the property set info for our delegator 76cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > m_xDelegatorPSI; 77cdf0e10cSrcweir /// the component taking the value 78cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XParameters > m_xValueDestination; 79cdf0e10cSrcweir /// helper for implementing XPropertySetInfo 80cdf0e10cSrcweir ::std::auto_ptr< ::cppu::OPropertyArrayHelper > m_pInfoHelper; 81cdf0e10cSrcweir 82cdf0e10cSrcweir 83cdf0e10cSrcweir public: Value() const84cdf0e10cSrcweir const ::connectivity::ORowSetValue& Value() const { return m_aValue; } Value()85cdf0e10cSrcweir ::connectivity::ORowSetValue& Value() { return m_aValue; } 86cdf0e10cSrcweir 87cdf0e10cSrcweir public: 88cdf0e10cSrcweir ParameterWrapper( 89cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxColumn 90cdf0e10cSrcweir ); 91cdf0e10cSrcweir 92cdf0e10cSrcweir ParameterWrapper( 93cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxColumn, 94cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XParameters >& _rxAllParameters, 95cdf0e10cSrcweir const ::std::vector< sal_Int32 >& _rIndexes 96cdf0e10cSrcweir ); 97cdf0e10cSrcweir 98cdf0e10cSrcweir DECLARE_XINTERFACE() 99cdf0e10cSrcweir DECLARE_XTYPEPROVIDER() 100cdf0e10cSrcweir 101cdf0e10cSrcweir // XPropertySet 102cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException ); 103cdf0e10cSrcweir virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper(); 104cdf0e10cSrcweir 105cdf0e10cSrcweir // OPropertySetHelper 106cdf0e10cSrcweir 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 ); 107cdf0e10cSrcweir virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) throw( ::com::sun::star::uno::Exception ); 108cdf0e10cSrcweir virtual void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const; 109cdf0e10cSrcweir 110cdf0e10cSrcweir // pseudo-XComponent 111cdf0e10cSrcweir virtual void SAL_CALL dispose(); 112cdf0e10cSrcweir 113cdf0e10cSrcweir protected: 114cdf0e10cSrcweir virtual ~ParameterWrapper(); 115cdf0e10cSrcweir 116cdf0e10cSrcweir // disambiguations 117cdf0e10cSrcweir using ::cppu::OPropertySetHelper::getFastPropertyValue; 118cdf0e10cSrcweir 119cdf0e10cSrcweir private: 120cdf0e10cSrcweir ::rtl::OUString impl_getPseudoAggregatePropertyName( sal_Int32 _nHandle ) const; 121cdf0e10cSrcweir 122cdf0e10cSrcweir private: 123cdf0e10cSrcweir ParameterWrapper(); // not implemented 124cdf0e10cSrcweir }; 125cdf0e10cSrcweir 126cdf0e10cSrcweir //==================================================================== 127cdf0e10cSrcweir //= ParameterWrapperContainer 128cdf0e10cSrcweir //==================================================================== 129cdf0e10cSrcweir typedef ::std::vector< ::rtl::Reference< ParameterWrapper > > Parameters; 130cdf0e10cSrcweir 131cdf0e10cSrcweir //==================================================================== 132cdf0e10cSrcweir //= ParameterWrapperContainer 133cdf0e10cSrcweir //==================================================================== 134cdf0e10cSrcweir typedef ::cppu::WeakComponentImplHelper2 < ::com::sun::star::container::XIndexAccess 135cdf0e10cSrcweir , ::com::sun::star::container::XEnumerationAccess 136cdf0e10cSrcweir > ParameterWrapperContainer_Base; 137cdf0e10cSrcweir 138cdf0e10cSrcweir /// class for the parameter event @see approveParameter 139cdf0e10cSrcweir class OOO_DLLPUBLIC_DBTOOLS ParameterWrapperContainer : 140cdf0e10cSrcweir public ParameterWrapperContainer_Base 141cdf0e10cSrcweir { 142cdf0e10cSrcweir private: 143cdf0e10cSrcweir ::osl::Mutex m_aMutex; 144cdf0e10cSrcweir Parameters m_aParameters; 145cdf0e10cSrcweir 146cdf0e10cSrcweir protected: 147cdf0e10cSrcweir virtual ~ParameterWrapperContainer(); 148cdf0e10cSrcweir 149cdf0e10cSrcweir public: 150cdf0e10cSrcweir /** creates an empty container 151cdf0e10cSrcweir */ 152cdf0e10cSrcweir ParameterWrapperContainer(); 153cdf0e10cSrcweir 154cdf0e10cSrcweir /** creates a container from a SingleSelectQuerAnalyzer's parameter columns 155cdf0e10cSrcweir 156cdf0e10cSrcweir Note that here, the simple constructor of the ParameterWrapper will be used, which does not 157cdf0e10cSrcweir use a XParameters instance to forward values to, but only remembers the values itself. 158cdf0e10cSrcweir */ 159cdf0e10cSrcweir ParameterWrapperContainer( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryAnalyzer >& _rxComposer ); 160cdf0e10cSrcweir 161cdf0e10cSrcweir // ::com::sun::star::container::XElementAccess 162cdf0e10cSrcweir virtual ::com::sun::star::uno::Type SAL_CALL getElementType() throw( ::com::sun::star::uno::RuntimeException ); 163cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasElements() throw( ::com::sun::star::uno::RuntimeException ); 164cdf0e10cSrcweir 165cdf0e10cSrcweir // ::com::sun::star::container::XEnumerationAccess 166cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration() throw( ::com::sun::star::uno::RuntimeException ); 167cdf0e10cSrcweir 168cdf0e10cSrcweir // ::com::sun::star::container::XIndexAccess 169cdf0e10cSrcweir virtual sal_Int32 SAL_CALL getCount() throw( ::com::sun::star::uno::RuntimeException ); 170cdf0e10cSrcweir 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 ); 171cdf0e10cSrcweir 172cdf0e10cSrcweir public: getParameters()173cdf0e10cSrcweir const Parameters& getParameters() { return m_aParameters; } 174cdf0e10cSrcweir operator [](size_t _index) const175cdf0e10cSrcweir const ::connectivity::ORowSetValue& operator[]( size_t _index ) const { return m_aParameters[ _index ]->Value(); } operator [](size_t _index)176cdf0e10cSrcweir ::connectivity::ORowSetValue& operator[]( size_t _index ) { return m_aParameters[ _index ]->Value(); } 177cdf0e10cSrcweir 178cdf0e10cSrcweir /** adds an ParameterWrapper to the end of the array 179cdf0e10cSrcweir */ push_back(ParameterWrapper * _pParameter)180cdf0e10cSrcweir void push_back( ParameterWrapper* _pParameter ) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir m_aParameters.push_back( _pParameter ); 183cdf0e10cSrcweir } 184cdf0e10cSrcweir size() const185cdf0e10cSrcweir size_t size() const { return m_aParameters.size(); } 186cdf0e10cSrcweir 187cdf0e10cSrcweir protected: 188cdf0e10cSrcweir // XComponent 189cdf0e10cSrcweir virtual void SAL_CALL disposing(); 190cdf0e10cSrcweir 191cdf0e10cSrcweir private: 192cdf0e10cSrcweir void impl_checkDisposed_throw(); 193cdf0e10cSrcweir }; 194cdf0e10cSrcweir 195cdf0e10cSrcweir //==================================================================== 196cdf0e10cSrcweir //= ParamatersContainer 197cdf0e10cSrcweir //==================================================================== 198cdf0e10cSrcweir typedef ::rtl::Reference< ParameterWrapperContainer > ParametersContainerRef; 199cdf0e10cSrcweir 200cdf0e10cSrcweir //........................................................................ 201cdf0e10cSrcweir } } // namespace dbtools::param 202cdf0e10cSrcweir //........................................................................ 203cdf0e10cSrcweir 204cdf0e10cSrcweir #endif // CONNECTIVITY_PARAMWRAPPER_HXX 205