Skip to content

Commit d4ea212

Browse files
committed
Enh 37059890 - Port UniversalExtractor and UniversalUpdater to C++ and .NET
- UniversalUpdater [git-p4: depot-paths = "//dev/main.net/": change = 111548]
1 parent 8fc8593 commit d4ea212

File tree

3 files changed

+171
-3
lines changed

3 files changed

+171
-3
lines changed

src/Coherence/Config/coherence-pof-config.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,11 @@
533533
<class-name>Tangosol.Util.Extractor.UniversalExtractor, Coherence</class-name>
534534
</user-type>
535535

536+
<user-type>
537+
<type-id>193</type-id>
538+
<class-name>Tangosol.Util.Extractor.UniversalUpdater, Coherence</class-name>
539+
</user-type>
540+
536541
<!-- Tangosol.Util.Aggregator namespace (continued) (250-259) -->
537542

538543
<user-type>
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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+
using System;
8+
using System.Diagnostics;
9+
using System.IO;
10+
11+
using Tangosol.IO.Pof;
12+
13+
namespace Tangosol.Util.Extractor
14+
{
15+
/// <summary>
16+
/// Universal <see cref="IValueUpdater"/> implementation.
17+
/// </summary>
18+
/// <remarks>
19+
/// UniversalUpdater can only run within the Coherence cluster.
20+
/// Refer to the Coherence for Java documentation for more information.
21+
/// </remarks>
22+
/// <author>Gene Gleyzer 2005.10.27</author>
23+
/// <author>Joe Fialli 2017.11.28</author>
24+
/// <author>Patrick Fry 2024.09.23</author>
25+
/// <since>14.1.2.0.0</since>
26+
public class UniversalUpdater : IValueUpdater, IPortableObject
27+
{
28+
#region Properties
29+
30+
/// <summary>
31+
/// Get the method or property name.
32+
/// </summary>
33+
/// <value>
34+
/// the method or property name.
35+
/// </value>
36+
public virtual string Name
37+
{
38+
get { return m_name; }
39+
}
40+
41+
#endregion
42+
43+
#region Constructors
44+
45+
/// <summary>
46+
/// Default constructor (necessary for the IPortableObject interface).
47+
/// </summary>
48+
public UniversalUpdater()
49+
{
50+
}
51+
52+
/// <summary>
53+
/// Construct a UniversalUpdater for the provided name.
54+
/// </summary>
55+
/// <param name="name">
56+
/// A method or property name.
57+
/// </param>
58+
public UniversalUpdater(string name)
59+
{
60+
Debug.Assert(name != null);
61+
62+
m_name = name;
63+
}
64+
65+
#endregion
66+
67+
#region IValueUpdater implementation
68+
69+
/// <summary>
70+
/// Update the passed target object using the specified value.
71+
/// </summary>
72+
/// <remarks>
73+
/// This method will always throw a <see cref="NotSupportedException"/>
74+
/// if called directly by the .NET client application, as its execution
75+
/// is only meaningful within the cluster.
76+
/// </remarks>
77+
/// <param name="target">
78+
/// The object to update.
79+
/// </param>
80+
/// <param name="value">
81+
/// The new value to update the target's property with.
82+
/// </param>
83+
/// <exception cref="NotSupportedException">
84+
/// Always, as it is expected that this extractor will only be
85+
/// executed within the cluster.
86+
/// </exception>
87+
public void Update(object target, object value)
88+
{
89+
throw new NotSupportedException();
90+
}
91+
92+
#endregion
93+
94+
#region IPortableObject implementation
95+
96+
/// <summary>
97+
/// Restore the contents of a user type instance by reading its state
98+
/// using the specified <see cref="IPofReader"/> object.
99+
/// </summary>
100+
/// <param name="reader">
101+
/// The <b>IPofReader</b> from which to read the object's state.
102+
/// </param>
103+
/// <exception cref="IOException">
104+
/// If an I/O error occurs.
105+
/// </exception>
106+
public void ReadExternal(IPofReader reader)
107+
{
108+
m_name = reader.ReadString(0);
109+
}
110+
111+
/// <summary>
112+
/// Save the contents of a POF user type instance by writing its
113+
/// state using the specified <see cref="IPofWriter"/> object.
114+
/// </summary>
115+
/// <param name="writer">
116+
/// The <b>IPofWriter</b> to which to write the object's state.
117+
/// </param>
118+
/// <exception cref="IOException">
119+
/// If an I/O error occurs.
120+
/// </exception>
121+
public void WriteExternal(IPofWriter writer)
122+
{
123+
writer.WriteString(0, Name);
124+
}
125+
126+
#endregion
127+
128+
#region Data members
129+
130+
/// <summary>
131+
/// A method name, or a property name.
132+
/// </summary>
133+
protected string m_name;
134+
135+
#endregion
136+
}
137+
}

tests/Coherence.Tests/Util/Extractor/UpdaterTests.cs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
/*
2-
* Copyright (c) 2000, 2020, Oracle and/or its affiliates.
2+
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
33
*
44
* Licensed under the Universal Permissive License v 1.0 as shown at
5-
* http://oss.oracle.com/licenses/upl.
5+
* https://oss.oracle.com/licenses/upl.
66
*/
77
using System;
88
using System.Collections.Specialized;
99
using System.IO;
10+
1011
using NUnit.Framework;
12+
1113
using Tangosol.IO;
1214
using Tangosol.IO.Pof;
1315
using Tangosol.IO.Pof.Reflection;
1416
using Tangosol.Net;
17+
using Tangosol.Net.Cache;
1518
using Tangosol.Util.Processor;
1619

1720
namespace Tangosol.Util.Extractor
@@ -160,5 +163,28 @@ public void TestPofUpdater()
160163

161164
CacheFactory.Shutdown();
162165
}
166+
167+
[Test]
168+
public void TestUniversalUpdater()
169+
{
170+
INamedCache cache = CacheFactory.GetCache(CacheName);
171+
cache.Clear();
172+
173+
string key = "p1";
174+
string lastName = "Van Halen";
175+
SimplePerson person = new SimplePerson("123-45-6789", "Eddie", lastName, 1955,
176+
"987-65-4321", new String[] { "456-78-9123" });
177+
UniversalUpdater updater = new UniversalUpdater("LastName");
178+
179+
cache[key] = person;
180+
Assert.AreEqual(lastName, ((SimplePerson) cache[key]).LastName);
181+
182+
// update the last name
183+
lastName = "Van Helen";
184+
cache.Invoke(key, new UpdaterProcessor(updater, lastName));
185+
Assert.AreEqual(lastName, ((SimplePerson) cache[key]).LastName);
186+
187+
CacheFactory.Shutdown();
188+
}
163189
}
164-
}
190+
}

0 commit comments

Comments
 (0)