1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #ifndef CONNECTIVITY_FILTERMANAGER_HXX 24 #define CONNECTIVITY_FILTERMANAGER_HXX 25 26 /** === begin UNO includes === **/ 27 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 28 #include <com/sun/star/beans/XPropertySet.hpp> 29 #include <com/sun/star/sdb/XSQLQueryComposer.hpp> 30 #include <com/sun/star/sdbc/XConnection.hpp> 31 /** === end UNO includes === **/ 32 33 #include <rtl/ustrbuf.hxx> 34 35 #include <vector> 36 #include "connectivity/dbtoolsdllapi.hxx" 37 38 //........................................................................ 39 namespace dbtools 40 { 41 //........................................................................ 42 43 //==================================================================== 44 //= FilterManager 45 //==================================================================== 46 /** manages the filter of a database component with filter properties 47 48 The idea is that the filter which a database component actually really uses is composed of several single 49 filter components (which all are conjunctive). 50 51 First, there is a component which is visible to the clients of the database component itself - if they ask 52 the database component for the Filter property, they will get this public filter. 53 54 Second, there is an implicit filter, which is (to be) created from the MasterFields and DetailFields 55 property of the database component, if the latter denote columns.<br/> 56 For instance, if there is a link-pair CustomerID->cid, where |CustomerID| is a column of the master 57 database component, and |cid| is a column of the detail database component (the database component we're responsible for), then there will 58 be an implicit filter "cid = :param_cid_link" (or something like this), which is never visible 59 to the clients of the database component, but nevertheless needs to be propagated to the aggregated RowSet.<br/> 60 Actually, this implicit filter is maintained by the FormParameterManager. 61 62 Potentially, there could be more filter components (for instance, you could imagine database component 63 controls which act as live filter, which could be implemented with a third component), but 64 at the moment there are only these two. 65 */ 66 class OOO_DLLPUBLIC_DBTOOLS FilterManager 67 { 68 public: 69 enum FilterComponent 70 { 71 fcPublicFilter = 0, // the filter which is to be published as "Filter" property of the database component 72 fcLinkFilter, // the filter part which is implicitly created for a database component when connecting 73 // master and detail database components via column names 74 75 FC_COMPONENT_COUNT // boundary delimiter, not to be used from outside 76 }; 77 78 private: 79 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > 80 m_xORB; 81 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > 82 m_xComponentAggregate; 83 ::std::vector< ::rtl::OUString > m_aFilterComponents; 84 sal_Bool m_bApplyPublicFilter; 85 86 public: 87 /// ctor 88 explicit FilterManager( 89 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB 90 ); 91 92 /// late ctor 93 void initialize(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxComponentAggregate ); 94 95 /// makes the object forgetting the references to the database component 96 void dispose( ); 97 98 const ::rtl::OUString& getFilterComponent( FilterComponent _eWhich ) const; 99 void setFilterComponent( FilterComponent _eWhich, const ::rtl::OUString& _rComponent ); 100 isApplyPublicFilter() const101 inline sal_Bool isApplyPublicFilter( ) const { return m_bApplyPublicFilter; } 102 void setApplyPublicFilter( sal_Bool _bApply ); 103 104 private: 105 /** retrieves a filter which is a conjunction of all single filter components 106 */ 107 ::rtl::OUString getComposedFilter( ) const; 108 109 /** appends one filter component to the statement in our composer 110 */ 111 void appendFilterComponent( ::rtl::OUStringBuffer& io_appendTo, const ::rtl::OUString& i_component ) const; 112 113 /// checks whether there is only one (or even no) non-empty filter component 114 bool isThereAtMostOneComponent( ::rtl::OUStringBuffer& o_singleComponent ) const; 115 116 /// returns the index of the first filter component which should be considered when building the composed filter getFirstApplicableFilterIndex() const117 inline sal_Int32 getFirstApplicableFilterIndex() const 118 { 119 return m_bApplyPublicFilter ? fcPublicFilter : fcPublicFilter + 1; 120 } 121 }; 122 123 //........................................................................ 124 } // namespacefrm 125 //........................................................................ 126 127 #endif // CONNECTIVITY_FORMFILTERMANAGER_HXX 128 129