Skip to content

Commit c0e8db0

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

File tree

3 files changed

+212
-0
lines changed

3 files changed

+212
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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_UPDATER_HPP
8+
#define COH_UNIVERSAL_UPDATER_HPP
9+
10+
#include "coherence/lang.ns"
11+
12+
#include "coherence/io/pof/PofReader.hpp"
13+
#include "coherence/io/pof/PofWriter.hpp"
14+
#include "coherence/io/pof/PortableObject.hpp"
15+
16+
#include "coherence/util/extractor/AbstractUpdater.hpp"
17+
18+
COH_OPEN_NAMESPACE3(coherence,util,extractor)
19+
20+
using coherence::io::pof::PofReader;
21+
using coherence::io::pof::PofWriter;
22+
using coherence::io::pof::PortableObject;
23+
24+
/**
25+
* Universal ValueUpdater implementation.
26+
*
27+
* UniversalUpdater can only run within the Coherence cluster.
28+
*
29+
* Refer to the Coherence for Java documentation for more information.
30+
*
31+
* @author gg 2005.10.27, jf 2017.11.28, phf 2024.09.23
32+
*
33+
* @see CompositeUpdater
34+
*
35+
* @since 14.1.2.0.0
36+
*/
37+
class COH_EXPORT UniversalUpdater
38+
: public cloneable_spec<UniversalUpdater,
39+
extends<AbstractUpdater>,
40+
implements<PortableObject> >
41+
{
42+
friend class factory<UniversalUpdater>;
43+
44+
// ----- constructors ---------------------------------------------------
45+
46+
protected:
47+
/**
48+
* Construct an empty UniversalUpdater
49+
* (necessary for the PortableObject interface).
50+
*/
51+
UniversalUpdater();
52+
53+
/**
54+
* Construct a UniversalUpdater for the provided name.
55+
*
56+
* @param vsName a method or property name
57+
*/
58+
UniversalUpdater(String::View vsName);
59+
60+
/**
61+
* Copy constructor.
62+
*/
63+
UniversalUpdater(const UniversalUpdater& 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 TypedHandle<const String> toString() const;
85+
86+
// ----- data members ---------------------------------------------------
87+
88+
protected:
89+
/**
90+
* A method name, or a property name.
91+
*/
92+
FinalView<String> f_vsName;
93+
};
94+
95+
COH_CLOSE_NAMESPACE3
96+
97+
#endif // COH_UNIVERSAL_UPDATER_HPP
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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/UniversalUpdater.hpp"
8+
9+
COH_OPEN_NAMESPACE3(coherence,util,extractor)
10+
11+
COH_REGISTER_PORTABLE_CLASS(193, UniversalUpdater);
12+
13+
// ----- constructors -------------------------------------------------------
14+
15+
UniversalUpdater::UniversalUpdater()
16+
: f_vsName(self())
17+
{
18+
}
19+
20+
UniversalUpdater::UniversalUpdater(String::View vsName)
21+
: f_vsName(self(), vsName)
22+
{
23+
COH_ENSURE_PARAM(vsName);
24+
}
25+
26+
UniversalUpdater::UniversalUpdater(const UniversalUpdater& that)
27+
: f_vsName(self(), that.f_vsName)
28+
{
29+
// UniversalUpdater is cloneable only because MSVC tries to generate
30+
// a copy constructor for it, which blows up as MemberHandles do not
31+
// support automatic copy construction
32+
}
33+
34+
// ----- PortableObject interface -------------------------------------------
35+
36+
void UniversalUpdater::readExternal(PofReader::Handle hIn)
37+
{
38+
initialize(f_vsName, hIn->readString(0));
39+
}
40+
41+
void UniversalUpdater:: writeExternal(PofWriter::Handle hOut) const
42+
{
43+
hOut->writeString(0, f_vsName);
44+
}
45+
46+
// ----- Object interface ---------------------------------------------------
47+
48+
TypedHandle<const String> UniversalUpdater::toString() const
49+
{
50+
return f_vsName;
51+
}
52+
53+
COH_CLOSE_NAMESPACE3
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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/tests/SimplePerson.hpp"
14+
15+
#include "coherence/util/extractor/UniversalUpdater.hpp"
16+
17+
#include "coherence/util/processor/UpdaterProcessor.hpp"
18+
19+
#include "common/TestClasses.hpp"
20+
21+
using namespace coherence::lang;
22+
23+
using coherence::net::NamedCache;
24+
25+
using coherence::util::extractor::UniversalUpdater;
26+
using coherence::util::processor::UpdaterProcessor;
27+
using coherence::tests::SimplePerson;
28+
29+
/**
30+
* Test Suite for the UniversalUpdater.
31+
*/
32+
class UniversalUpdaterTests : public CxxTest::TestSuite
33+
{
34+
public:
35+
/**
36+
* Update SimplePerson LastName.
37+
*/
38+
void testUniversalUpdater()
39+
{
40+
NamedCache::Handle hCache = ensureCleanCache("dist-filter");
41+
42+
ArrayList::Handle hasChildrenIds = ArrayList::create(1);
43+
hasChildrenIds->add(String::create("456-78-9123"));
44+
45+
String::View vsKey = "p1";
46+
String::View vsLastName = "Van Halen";
47+
SimplePerson::View vPerson = SimplePerson::create(String::create("123-45-6789"),
48+
String::create("Eddie"), vsLastName, 1955,
49+
String::create("987-65-4321"), hasChildrenIds);
50+
UniversalUpdater::View vUpdater = UniversalUpdater::create(String::create("LastName"));
51+
52+
hCache->put(vsKey, vPerson);
53+
vPerson = cast<SimplePerson::View>(hCache->get(vsKey));
54+
TS_ASSERT(vPerson->getLastName()->equals(vsLastName));
55+
56+
// update the last name
57+
vsLastName = "Van Helen";
58+
hCache->invoke(vsKey, UpdaterProcessor::create(vUpdater, vsLastName));
59+
vPerson = cast<SimplePerson::View>(hCache->get(vsKey));
60+
TS_ASSERT(vPerson->getLastName()->equals(vsLastName));
61+
}
62+
};

0 commit comments

Comments
 (0)