Oracle® Fusion Middleware C++ API Reference for Oracle Coherence
12c (12.1.3.0.0)

E47891-01

coherence/util/extractor/KeyExtractor.hpp

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