Skip to content

Commit d60f718

Browse files
committed
Enh 37059890 - Port UniversalExtractor and UniversalUpdater to C++ and .NET
- UniversalExtractor #nobug80 [git-p4: depot-paths = "//dev/main.cpp/": change = 111343]
1 parent c68a800 commit d60f718

File tree

3 files changed

+298
-0
lines changed

3 files changed

+298
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
3+
*
4+
* Licensed under the Universal Permissive License v 1.0 as shown at
5+
* https://oss.oracle.com/licenses/upl.
6+
*/
7+
#ifndef COH_UNIVERSAL_EXTRACTOR_HPP
8+
#define COH_UNIVERSAL_EXTRACTOR_HPP
9+
10+
#include "coherence/lang.ns"
11+
12+
#include "coherence/io/pof/PofReader.hpp"
13+
#include "coherence/io/pof/PofWriter.hpp"
14+
15+
#include "coherence/util/extractor/AbstractExtractor.hpp"
16+
17+
COH_OPEN_NAMESPACE3(coherence,util,extractor)
18+
19+
using coherence::io::pof::PofReader;
20+
using coherence::io::pof::PofWriter;
21+
22+
/**
23+
* Universal ValueExtractor implementation.
24+
*
25+
* UniversalExtractor can only run within the Coherence cluster.
26+
*
27+
* Refer to the Coherence for Java documentation for more information.
28+
*
29+
* @author cp/gg 2002.11.01, ew 2007.02.01, jf 2017.11.20, phf 2024.09.13
30+
*
31+
* @since 14.1.2.0.0
32+
*/
33+
class COH_EXPORT UniversalExtractor
34+
: public cloneable_spec<UniversalExtractor,
35+
extends<AbstractExtractor> >
36+
{
37+
friend class factory<UniversalExtractor>;
38+
39+
// ----- constructors ---------------------------------------------------
40+
41+
protected:
42+
/**
43+
* Construct an empty UniversalExtractor
44+
* (necessary for the PortableObject interface).
45+
*/
46+
UniversalExtractor();
47+
48+
/**
49+
* Construct a UniversalExtractor based on a name, optional
50+
* parameters and the entry extraction target.
51+
*
52+
* @param vsName a method or property name
53+
* @param vaParam the array of arguments to be used in the method
54+
* invocation; may be null
55+
* @param nTarget one of the {@link #value} or {@link #key} values
56+
*/
57+
UniversalExtractor(String::View vsName, ObjectArray::View vaParam = NULL,
58+
int32_t nTarget = value);
59+
60+
/**
61+
* Copy constructor.
62+
*/
63+
UniversalExtractor(const UniversalExtractor& that);
64+
65+
// ----- PortableObject interface ---------------------------------------
66+
67+
public:
68+
/**
69+
* {@inheritDoc}
70+
*/
71+
virtual void readExternal(PofReader::Handle hIn);
72+
73+
/**
74+
* {@inheritDoc}
75+
*/
76+
virtual void writeExternal(PofWriter::Handle hOut) const;
77+
78+
// ----- Object interface -----------------------------------------------
79+
80+
public:
81+
/**
82+
* {@inheritDoc}
83+
*/
84+
virtual bool equals(Object::View v) const;
85+
86+
/**
87+
* {@inheritDoc}
88+
*/
89+
virtual size32_t hashCode() const;
90+
91+
/**
92+
* {@inheritDoc}
93+
*/
94+
virtual TypedHandle<const String> toString() const;
95+
96+
// ----- data member accessors ------------------------------------------
97+
98+
public:
99+
/**
100+
* Return the name passed into UniversalExtractor(String).
101+
*
102+
* @return the name of extraction attribute
103+
*/
104+
virtual String::View getName() const;
105+
106+
/**
107+
* Return the array of arguments used to invoke the method.
108+
*
109+
* @return the array of arguments used to invoke the method
110+
*/
111+
virtual ObjectArray::View getParameters() const;
112+
113+
// ----- data members ---------------------------------------------------
114+
115+
protected:
116+
/**
117+
* A method or property name.
118+
*/
119+
FinalView<String> f_vsName;
120+
121+
/**
122+
* The parameter array. Must be null or zero length for a property based extractor.
123+
*/
124+
FinalView<ObjectArray> f_vaParam;
125+
};
126+
127+
COH_CLOSE_NAMESPACE3
128+
129+
#endif // COH_UNIVERSAL_EXTRACTOR_HPP
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
3+
*
4+
* Licensed under the Universal Permissive License v 1.0 as shown at
5+
* https://oss.oracle.com/licenses/upl.
6+
*/
7+
#include "coherence/util/extractor/UniversalExtractor.hpp"
8+
9+
COH_OPEN_NAMESPACE3(coherence,util,extractor)
10+
11+
COH_REGISTER_PORTABLE_CLASS(192, UniversalExtractor);
12+
13+
// ----- constructors -------------------------------------------------------
14+
15+
UniversalExtractor::UniversalExtractor()
16+
: f_vsName(self()), f_vaParam(self())
17+
{
18+
m_nTarget = value;
19+
}
20+
21+
UniversalExtractor::UniversalExtractor(String::View vsName,
22+
ObjectArray::View vaParam, int32_t nTarget)
23+
: f_vsName(self(), vsName), f_vaParam(self(), vaParam)
24+
{
25+
COH_ENSURE_PARAM(vsName);
26+
m_nTarget = nTarget;
27+
}
28+
29+
UniversalExtractor::UniversalExtractor(const UniversalExtractor& that)
30+
: f_vsName(self(), that.f_vsName),
31+
f_vaParam(self(), cast<ObjectArray::View>(Object::clone(that.f_vaParam)))
32+
{
33+
// UniversalExtractor is cloneable only because MSVC tries to generate
34+
// a copy constructor for it, which blows up as MemberHandles do not
35+
// support automatic copy construction
36+
}
37+
38+
// ----- PortableObject interface -------------------------------------------
39+
40+
void UniversalExtractor::readExternal(PofReader::Handle hIn)
41+
{
42+
initialize(f_vsName, hIn->readString(0));
43+
initialize(f_vaParam, hIn->readObjectArray(1));
44+
m_nTarget = hIn->readInt32(2);
45+
}
46+
47+
void UniversalExtractor::writeExternal(PofWriter::Handle hOut) const
48+
{
49+
hOut->writeString(0, f_vsName);
50+
hOut->writeObjectArray(1, f_vaParam);
51+
hOut->writeInt32(2, m_nTarget);
52+
}
53+
54+
// ----- Object interface ---------------------------------------------------
55+
56+
bool UniversalExtractor::equals(Object::View v) const
57+
{
58+
if (this == v)
59+
{
60+
return true;
61+
}
62+
63+
UniversalExtractor::View that = cast<UniversalExtractor::View>(v, false);
64+
if (that != NULL)
65+
{
66+
return this->m_nTarget == that->m_nTarget &&
67+
Object::equals(f_vsName, that->f_vsName) &&
68+
Object::equals(f_vaParam, that->f_vaParam);
69+
}
70+
71+
return false;
72+
}
73+
74+
size32_t UniversalExtractor::hashCode() const
75+
{
76+
return f_vsName->hashCode();
77+
}
78+
79+
TypedHandle<const String> UniversalExtractor::toString() const
80+
{
81+
String::View vs = "";
82+
83+
if (m_nTarget == key)
84+
{
85+
vs = COH_TO_STRING(vs << ".getKey()");
86+
}
87+
88+
return COH_TO_STRING(vs << '.' << getName() << ' ' << getParameters());
89+
}
90+
91+
// ----- data member accessors ----------------------------------------------
92+
93+
String::View UniversalExtractor::getName() const
94+
{
95+
return f_vsName;
96+
}
97+
98+
ObjectArray::View UniversalExtractor::getParameters() const
99+
{
100+
return f_vaParam;
101+
}
102+
103+
COH_CLOSE_NAMESPACE3
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
3+
*
4+
* Licensed under the Universal Permissive License v 1.0 as shown at
5+
* https://oss.oracle.com/licenses/upl.
6+
*/
7+
#include "cxxtest/TestSuite.h"
8+
9+
#include "coherence/lang.ns"
10+
11+
#include "coherence/net/NamedCache.hpp"
12+
13+
#include "coherence/util/Iterator.hpp"
14+
#include "coherence/util/Map.hpp"
15+
#include "coherence/util/Set.hpp"
16+
17+
#include "coherence/util/extractor/IdentityExtractor.hpp"
18+
#include "coherence/util/extractor/UniversalExtractor.hpp"
19+
20+
#include "coherence/util/filter/EqualsFilter.hpp"
21+
22+
using namespace coherence::lang;
23+
24+
using coherence::net::NamedCache;
25+
using coherence::util::Iterator;
26+
using coherence::util::Map;
27+
using coherence::util::Set;
28+
using coherence::util::extractor::IdentityExtractor;
29+
using coherence::util::extractor::UniversalExtractor;
30+
using coherence::util::filter::EqualsFilter;
31+
32+
/**
33+
* Test Suite for the UniversalExtractor.
34+
*/
35+
class UniversalExtractorTest : public CxxTest::TestSuite
36+
{
37+
public:
38+
void testUniversalExtractor()
39+
{
40+
NamedCache::Handle hCache = ensureCleanCache("dist-filter");
41+
42+
Float32::View vFilterValue = Float32::valueOf(42.0F);
43+
IdentityExtractor::View vExtract = IdentityExtractor::create();
44+
EqualsFilter::Handle hFilter1 = EqualsFilter::create(vExtract,
45+
vFilterValue);
46+
EqualsFilter::Handle hFilter2 = EqualsFilter::create(vExtract,
47+
Float32::valueOf(666.0F));
48+
49+
hCache->put(String::create("EqualsFilter1"), hFilter1);
50+
hCache->put(String::create("EqualsFilter2"), hFilter2);
51+
52+
UniversalExtractor::View vUExtract =
53+
UniversalExtractor::create(String::create("getValue"));
54+
EqualsFilter::View hFilter = EqualsFilter::create(vUExtract,
55+
vFilterValue);
56+
57+
Set::View vFilterEntries = hCache->entrySet(hFilter);
58+
TS_ASSERT_EQUALS(size32_t(1), vFilterEntries->size());
59+
60+
Iterator::Handle hIter = vFilterEntries->iterator();
61+
Map::Entry::View vEntry = cast<Map::Entry::View>(hIter->next());
62+
63+
hFilter = cast<EqualsFilter::View>(vEntry->getValue());
64+
TS_ASSERT(hFilter->getValue()->equals(vFilterValue));
65+
}
66+
};

0 commit comments

Comments
 (0)