1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef CONNECTIVITY_PARAMWRAPPER_HXX 29 #define CONNECTIVITY_PARAMWRAPPER_HXX 30 31 #include "connectivity/dbtoolsdllapi.hxx" 32 #include <connectivity/FValue.hxx> 33 34 /** === begin UNO includes === **/ 35 #include <com/sun/star/sdbc/XParameters.hpp> 36 #include <com/sun/star/container/XIndexAccess.hpp> 37 #include <com/sun/star/container/XEnumerationAccess.hpp> 38 #include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp> 39 /** === end UNO includes === **/ 40 41 #include <comphelper/uno3.hxx> 42 #include <comphelper/broadcasthelper.hxx> 43 #include <cppuhelper/weak.hxx> 44 #include <cppuhelper/propshlp.hxx> 45 #include <cppuhelper/compbase2.hxx> 46 47 #include <memory> 48 #include <vector> 49 50 //........................................................................ 51 namespace dbtools 52 { 53 namespace param 54 { 55 //........................................................................ 56 57 //==================================================================== 58 //= ParameterWrapper 59 //==================================================================== 60 /** wraps a parameter column as got from an SQLQueryComposer, so that it has an additional 61 property "Value", which is forwarded to an XParameters interface 62 */ 63 class OOO_DLLPUBLIC_DBTOOLS ParameterWrapper :public ::cppu::OWeakObject 64 ,public ::comphelper::OMutexAndBroadcastHelper 65 ,public ::cppu::OPropertySetHelper 66 { 67 private: 68 typedef ::cppu::OWeakObject UnoBase; 69 typedef ::cppu::OPropertySetHelper PropertyBase; 70 71 private: 72 /// the most recently set value of the parameter 73 ::connectivity::ORowSetValue m_aValue; 74 /// the positions (in our m_xValueDestination) at which the value should be set (0-based!) 75 ::std::vector< sal_Int32 > m_aIndexes; 76 77 /// the "delegator" column to which standard property requests are forwarded 78 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xDelegator; 79 /// the property set info for our delegator 80 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > m_xDelegatorPSI; 81 /// the component taking the value 82 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XParameters > m_xValueDestination; 83 /// helper for implementing XPropertySetInfo 84 ::std::auto_ptr< ::cppu::OPropertyArrayHelper > m_pInfoHelper; 85 86 87 public: 88 const ::connectivity::ORowSetValue& Value() const { return m_aValue; } 89 ::connectivity::ORowSetValue& Value() { return m_aValue; } 90 91 public: 92 ParameterWrapper( 93 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxColumn 94 ); 95 96 ParameterWrapper( 97 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxColumn, 98 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XParameters >& _rxAllParameters, 99 const ::std::vector< sal_Int32 >& _rIndexes 100 ); 101 102 DECLARE_XINTERFACE() 103 DECLARE_XTYPEPROVIDER() 104 105 // XPropertySet 106 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException ); 107 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper(); 108 109 // OPropertySetHelper 110 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 ); 111 virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) throw( ::com::sun::star::uno::Exception ); 112 virtual void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const; 113 114 // pseudo-XComponent 115 virtual void SAL_CALL dispose(); 116 117 protected: 118 virtual ~ParameterWrapper(); 119 120 // disambiguations 121 using ::cppu::OPropertySetHelper::getFastPropertyValue; 122 123 private: 124 ::rtl::OUString impl_getPseudoAggregatePropertyName( sal_Int32 _nHandle ) const; 125 126 private: 127 ParameterWrapper(); // not implemented 128 }; 129 130 //==================================================================== 131 //= ParameterWrapperContainer 132 //==================================================================== 133 typedef ::std::vector< ::rtl::Reference< ParameterWrapper > > Parameters; 134 135 //==================================================================== 136 //= ParameterWrapperContainer 137 //==================================================================== 138 typedef ::cppu::WeakComponentImplHelper2 < ::com::sun::star::container::XIndexAccess 139 , ::com::sun::star::container::XEnumerationAccess 140 > ParameterWrapperContainer_Base; 141 142 /// class for the parameter event @see approveParameter 143 class OOO_DLLPUBLIC_DBTOOLS ParameterWrapperContainer : 144 public ParameterWrapperContainer_Base 145 { 146 private: 147 ::osl::Mutex m_aMutex; 148 Parameters m_aParameters; 149 150 protected: 151 virtual ~ParameterWrapperContainer(); 152 153 public: 154 /** creates an empty container 155 */ 156 ParameterWrapperContainer(); 157 158 /** creates a container from a SingleSelectQuerAnalyzer's parameter columns 159 160 Note that here, the simple constructor of the ParameterWrapper will be used, which does not 161 use a XParameters instance to forward values to, but only remembers the values itself. 162 */ 163 ParameterWrapperContainer( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryAnalyzer >& _rxComposer ); 164 165 // ::com::sun::star::container::XElementAccess 166 virtual ::com::sun::star::uno::Type SAL_CALL getElementType() throw( ::com::sun::star::uno::RuntimeException ); 167 virtual sal_Bool SAL_CALL hasElements() throw( ::com::sun::star::uno::RuntimeException ); 168 169 // ::com::sun::star::container::XEnumerationAccess 170 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration() throw( ::com::sun::star::uno::RuntimeException ); 171 172 // ::com::sun::star::container::XIndexAccess 173 virtual sal_Int32 SAL_CALL getCount() throw( ::com::sun::star::uno::RuntimeException ); 174 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 ); 175 176 public: 177 const Parameters& getParameters() { return m_aParameters; } 178 179 const ::connectivity::ORowSetValue& operator[]( size_t _index ) const { return m_aParameters[ _index ]->Value(); } 180 ::connectivity::ORowSetValue& operator[]( size_t _index ) { return m_aParameters[ _index ]->Value(); } 181 182 /** adds an ParameterWrapper to the end of the array 183 */ 184 void push_back( ParameterWrapper* _pParameter ) 185 { 186 m_aParameters.push_back( _pParameter ); 187 } 188 189 size_t size() const { return m_aParameters.size(); } 190 191 protected: 192 // XComponent 193 virtual void SAL_CALL disposing(); 194 195 private: 196 void impl_checkDisposed_throw(); 197 }; 198 199 //==================================================================== 200 //= ParamatersContainer 201 //==================================================================== 202 typedef ::rtl::Reference< ParameterWrapperContainer > ParametersContainerRef; 203 204 //........................................................................ 205 } } // namespace dbtools::param 206 //........................................................................ 207 208 #endif // CONNECTIVITY_PARAMWRAPPER_HXX 209