00001 /* 00002 * ViewBuilder.hpp 00003 * 00004 * Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. 00005 * 00006 * Oracle is a registered trademarks of Oracle Corporation and/or its 00007 * affiliates. 00008 * 00009 * This software is the confidential and proprietary information of Oracle 00010 * Corporation. You shall not disclose such confidential and proprietary 00011 * information and shall use it only in accordance with the terms of the 00012 * license agreement you entered into with Oracle. 00013 * 00014 * This notice may not be removed or altered. 00015 */ 00016 #ifndef COH_VIEW_BUILDER_HPP 00017 #define COH_VIEW_BUILDER_HPP 00018 00019 #include "coherence/lang.ns" 00020 00021 #include "coherence/util/Filter.hpp" 00022 #include "coherence/util/MapListener.hpp" 00023 #include "coherence/util/Supplier.hpp" 00024 #include "coherence/util/ValueExtractor.hpp" 00025 00026 COH_OPEN_NAMESPACE2(coherence,net) 00027 00028 using coherence::util::Filter; 00029 using coherence::util::MapListener; 00030 using coherence::util::Supplier; 00031 using coherence::util::ValueExtractor; 00032 00033 // forward reference to avoid circular header inclusion 00034 class NamedCache; 00035 00036 /** 00037 * The ViewBuilder provides a means to build() a view (ContinuousQueryCache) 00038 * using a fluent pattern / style. 00039 * 00040 * @see ContinuousQueryCache 00041 * 00042 * @author rl 6.2.19 00043 * @since 12.2.1.4 00044 */ 00045 class COH_EXPORT ViewBuilder 00046 : public class_spec<ViewBuilder, 00047 extends<Object> > 00048 { 00049 friend class factory<ViewBuilder>; 00050 00051 // ----- handle definitions --------------------------------------------- 00052 00053 public: 00054 /** 00055 * NamedCache Handle definition. 00056 */ 00057 typedef TypedHandle<NamedCache> NamedCacheHandle; 00058 00059 // ----- constructors --------------------------------------------------- 00060 00061 protected: 00062 /** 00063 * Construct a new ViewBuilder for the provided NamedCache. 00064 * 00065 * @param hCache the NamedCache from which the view will be created 00066 */ 00067 ViewBuilder(NamedCacheHandle hCache); 00068 00069 /** 00070 * Construct a new ViewBuilder for the provided NamedCache. 00071 * The Supplier should return a new NamedCache instance upon 00072 * each invocation. 00073 * 00074 * @param hSupplierCache the Supplier returning a NamedCache 00075 * from which the view will be created 00076 */ 00077 ViewBuilder(Supplier::Handle hSupplierCache); 00078 00079 private: 00080 /** 00081 * Blocked copy constructor. 00082 */ 00083 ViewBuilder(const ViewBuilder&); 00084 00085 // ----- builder interface ---------------------------------------------- 00086 00087 public: 00088 /** 00089 * The Filter that will be used to define the entries maintained in this view. 00090 * If no Filter is specified, AlwaysFilter#INSTANCE will be used. 00091 * 00092 * @param vFilter the Filter that will be used to query the 00093 * underlying NamedCache 00094 * 00095 * @return this ViewBuilder 00096 */ 00097 ViewBuilder::Handle filter(Filter::View vFilter); 00098 00099 /** 00100 * The MapListener that will receive all events, including those that 00101 * result from the initial population of the view. 00102 * 00103 * @param hListener the MapListener that will receive all the events from 00104 * the view, including those corresponding to its initial 00105 * population. 00106 * 00107 * @return this ViewBuilder 00108 */ 00109 ViewBuilder::Handle listener(MapListener::Handle hListener); 00110 00111 /** 00112 * The ValueExtractor that this view will use to transform the results from 00113 * the underlying cache prior to storing them locally. 00114 * 00115 * @param vMapper the ValueExtractor that will be used to 00116 * transform values retrieved from the underlying cache 00117 * before storing them locally; if specified, this 00118 * view will become read-only 00119 * 00120 * @return this ViewBuilder 00121 */ 00122 ViewBuilder::Handle map(ValueExtractor::View VMapper); 00123 00124 /** 00125 * The resulting view will only cache keys. 00126 * 00127 * NOTE: this is mutually exclusive with values(). 00128 * 00129 * @return this ViewBuilder 00130 */ 00131 ViewBuilder::Handle keys(); 00132 00133 /** 00134 * The resulting view with cache both keys and values. 00135 * 00136 * NOTE: this is mutually exclusive with keys(). 00137 * 00138 * @return this ViewBuilder 00139 */ 00140 ViewBuilder::Handle values(); 00141 00142 /** 00143 * Construct a view of the NamedCache provided to this builder. 00144 * 00145 * @return the view of the NamedCache provided to this builder 00146 */ 00147 NamedCacheHandle build(); 00148 00149 // ----- data members --------------------------------------------------- 00150 00151 protected: 00152 /** 00153 * The Supplier returning a NamedCache from which the 00154 * view will be created. 00155 */ 00156 FinalHolder<Supplier> f_hSupplierCache; 00157 00158 /** 00159 * The Filter that will be used to define the entries maintained 00160 * in this view. 00161 */ 00162 MemberView<Filter> m_vFilter; 00163 00164 /** 00165 * The MapListener that will receive all the events from 00166 * the view, including those corresponding to its initial 00167 * population. 00168 */ 00169 MemberHandle<MapListener> m_hListener; 00170 00171 /** 00172 * The ValueExtractor that will be used to transform values 00173 * retrieved from the underlying cache before storing them locally; if 00174 * specified, this view will become read-only. 00175 */ 00176 MemberView<ValueExtractor> m_vMapper; 00177 00178 /** 00179 * Flag controlling if the view will cache both keys and values 00180 * or only keys. 00181 */ 00182 bool m_fCacheValues; 00183 }; 00184 00185 COH_CLOSE_NAMESPACE2 00186 00187 #endif // COH_VIEW_BUILDER_HPP