Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #ifndef CONNECTIVITY_FILTERMANAGER_HXX
20 : #define CONNECTIVITY_FILTERMANAGER_HXX
21 :
22 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
23 : #include <com/sun/star/beans/XPropertySet.hpp>
24 : #include <com/sun/star/sdb/XSQLQueryComposer.hpp>
25 : #include <com/sun/star/sdbc/XConnection.hpp>
26 :
27 : #include <rtl/ustrbuf.hxx>
28 :
29 : #include <vector>
30 : #include "connectivity/dbtoolsdllapi.hxx"
31 :
32 : //........................................................................
33 : namespace dbtools
34 : {
35 : //........................................................................
36 :
37 : //====================================================================
38 : //= FilterManager
39 : //====================================================================
40 : /** manages the filter of a database component with filter properties
41 :
42 : The idea is that the filter which a database component actually really uses is composed of several single
43 : filter components (which all are conjunctive).
44 :
45 : First, there is a component which is visible to the clients of the database component itself - if they ask
46 : the database component for the Filter property, they will get this public filter.
47 :
48 : Second, there is an implicit filter, which is (to be) created from the MasterFields and DetailFields
49 : property of the database component, if the latter denote columns.<br/>
50 : For instance, if there is a link-pair CustomerID->cid, where |CustomerID| is a column of the master
51 : database component, and |cid| is a column of the detail database component (the database component we're responsible for), then there will
52 : be an implicit filter "cid = :param_cid_link" (or something like this), which is never visible
53 : to the clients of the database component, but nevertheless needs to be propagated to the aggregated RowSet.<br/>
54 : Actually, this implicit filter is maintained by the FormParameterManager.
55 :
56 : Potentially, there could be more filter components (for instance, you could imagine database component
57 : controls which act as live filter, which could be implemented with a third component), but
58 : at the moment there are only these two.
59 : */
60 2 : class OOO_DLLPUBLIC_DBTOOLS FilterManager
61 : {
62 : public:
63 : enum FilterComponent
64 : {
65 : fcPublicFilter = 0, // the filter which is to be published as "Filter" property of the database component
66 : fcLinkFilter, // the filter part which is implicitly created for a database component when connecting
67 : // master and detail database components via column names
68 :
69 : FC_COMPONENT_COUNT // boundary delimiter, not to be used from outside
70 : };
71 :
72 : private:
73 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
74 : m_xORB;
75 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
76 : m_xComponentAggregate;
77 : ::std::vector< ::rtl::OUString > m_aFilterComponents;
78 : sal_Bool m_bApplyPublicFilter;
79 :
80 : public:
81 : /// ctor
82 : explicit FilterManager(
83 : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB
84 : );
85 :
86 : /// late ctor
87 : void initialize(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxComponentAggregate );
88 :
89 : /// makes the object forgetting the references to the database component
90 : void dispose( );
91 :
92 : const ::rtl::OUString& getFilterComponent( FilterComponent _eWhich ) const;
93 : void setFilterComponent( FilterComponent _eWhich, const ::rtl::OUString& _rComponent );
94 :
95 1 : inline sal_Bool isApplyPublicFilter( ) const { return m_bApplyPublicFilter; }
96 : void setApplyPublicFilter( sal_Bool _bApply );
97 :
98 : private:
99 : /** retrieves a filter which is a conjunction of all single filter components
100 : */
101 : ::rtl::OUString getComposedFilter( ) const;
102 :
103 : /** appends one filter component to the statement in our composer
104 : */
105 : void appendFilterComponent( ::rtl::OUStringBuffer& io_appendTo, const ::rtl::OUString& i_component ) const;
106 :
107 : /// checks whether there is only one (or even no) non-empty filter component
108 : bool isThereAtMostOneComponent( ::rtl::OUStringBuffer& o_singleComponent ) const;
109 :
110 : /// returns the index of the first filter component which should be considered when building the composed filter
111 0 : inline sal_Int32 getFirstApplicableFilterIndex() const
112 : {
113 0 : return m_bApplyPublicFilter ? fcPublicFilter : fcPublicFilter + 1;
114 : }
115 : };
116 :
117 : //........................................................................
118 : } // namespacefrm
119 : //........................................................................
120 :
121 : #endif // CONNECTIVITY_FORMFILTERMANAGER_HXX
122 :
123 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|