C++ Client API Reference for Oracle Coherence
14c (14.1.2.0.0)

F79659-03

coherence/util/extractor/KeyExtractor.hpp

00001 /*
00002  * Copyright (c) 2000, 2020, Oracle and/or its affiliates.
00003  *
00004  * Licensed under the Universal Permissive License v 1.0 as shown at
00005  * http://oss.oracle.com/licenses/upl.
00006  */
00007 #ifndef COH_KEY_EXTRACTOR_HPP
00008 #define COH_KEY_EXTRACTOR_HPP
00009 
00010 #include "coherence/lang.ns"
00011 
00012 #include "coherence/io/pof/PofReader.hpp"
00013 #include "coherence/io/pof/PofWriter.hpp"
00014 #include "coherence/util/ValueExtractor.hpp"
00015 #include "coherence/util/extractor/AbstractExtractor.hpp"
00016 
00017 COH_OPEN_NAMESPACE3(coherence,util,extractor)
00018 
00019 using coherence::io::pof::PofReader;
00020 using coherence::io::pof::PofWriter;
00021 
00022 
00023 /**
00024 * The KeyExtractor is a special purpose ValueExtractor implementation that
00025 * serves as an indicator that a query should be run against the key objects
00026 * rather than the values. The major difference between the KeyExtractor and a
00027 * standard ReflectionExtractor is that when used in various EntryFilter
00028 * implementations it forces the evaluation of entry keys rather than entry
00029 * values.
00030 *
00031 * For example, consider a key object that consists of two properties:
00032 * "FirstName" and "LastName". To retrieve all keys that have a value of the
00033 * "LastName" property equal to "Smith", the following query could be used:
00034 * <pre>
00035 * ValueExtractor::View extractor = KeyExtractor::create("getLastName");
00036 * Set::View setKeys = cache->keySet(EqualsFilter::create(extractor, "Smith"));
00037 *
00038 * </pre>
00039 * As of Coherence 3.5, the same effect can be achieved for subclasses of the
00040 * AbstractExtractor, for example:
00041 * <pre>
00042 * ValueExtractor::View vExtractor = ReflectionExtractor::create("getLastName",
00043 *       NULL, AbstractExtractor::KEY);
00044 * Set::View setKeys = cache->keySet(EqualsFilter::create(vExtractor, "Smith"));
00045 * </pre>
00046 *
00047 * @author djl 2008.03.24
00048 */
00049 class COH_EXPORT KeyExtractor
00050     : public class_spec<KeyExtractor,
00051         extends<AbstractExtractor> >
00052     {
00053     friend class factory<KeyExtractor>;
00054 
00055     // ----- constructors ---------------------------------------------------
00056 
00057     protected:
00058         /**
00059         * Create and return a Handle to a new Object instance.
00060         */
00061         KeyExtractor();
00062 
00063         /**
00064         * Construct a KeyExtractor based on a specified ValueExtractor.
00065         *
00066         * @param vExtractor  the underlying ValueExtractor
00067         */
00068         KeyExtractor(ValueExtractor::View vExtractor);
00069 
00070 
00071     // ----- ValueExtractor interface ---------------------------------------
00072 
00073     public:
00074         /**
00075         * {@inheritDoc}
00076         */
00077         virtual Object::Holder extract(Object::Holder ohTarget) const;
00078 
00079 
00080     // ----- PortableObject interface ---------------------------------------
00081 
00082     public:
00083         /**
00084         * {@inheritDoc}
00085         */
00086         virtual void readExternal(PofReader::Handle hIn);
00087 
00088         /**
00089         * {@inheritDoc}
00090         */
00091         virtual void writeExternal(PofWriter::Handle hOut) const;
00092 
00093 
00094     // ----- Object interface -----------------------------------------------
00095 
00096     public:
00097         /**
00098         * {@inheritDoc}
00099         */
00100         virtual bool equals(Object::View v) const;
00101 
00102         /**
00103         * {@inheritDoc}
00104         */
00105         virtual size32_t hashCode() const;
00106 
00107         /**
00108         * {@inheritDoc}
00109         */
00110         virtual TypedHandle<const String> toString() const;
00111 
00112 
00113     // ----- data member accessors ------------------------------------------
00114 
00115     public:
00116         /**
00117         * Obtain the underlying ValueExtractor.
00118         *
00119         * @return the ValueExtractor
00120         */
00121         virtual ValueExtractor::View getExtractor() const;
00122 
00123 
00124     // ----- data members ---------------------------------------------------
00125 
00126     protected:
00127         /**
00128         * The underlying ValueExtractor.
00129         */
00130         MemberView<ValueExtractor> m_vExtractor;
00131     };
00132 
00133 COH_CLOSE_NAMESPACE3
00134 
00135 #endif // COH_IDENTITY_EXTRACTOR_HPP
Copyright © 2000, 2025, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.