Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d5254a1
IGNITE-12824: WIP
nizhikov Dec 11, 2020
ca3cc3a
IGNITE-12824: WIP
nizhikov Dec 11, 2020
063b6f0
IGNITE-12824: Fix of writing dates to the cache from the .Net
nizhikov Dec 14, 2020
24a89ed
IGNITE-12824: Fix of writing dates to the cache from the .Net
nizhikov Dec 14, 2020
17ffb01
IGNITE-12824: Fix of writing dates to the cache from the .Net
nizhikov Dec 14, 2020
317a666
IGNITE-12824: Fix of writing dates to the cache from the .Net
nizhikov Dec 14, 2020
2086fbf
IGNITE-12824: Fix of writing dates to the cache from the .Net
nizhikov Dec 14, 2020
d0514d3
IGNITE-12824: Fix of writing dates to the cache from the .Net
nizhikov Dec 14, 2020
03469e9
IGNITE-12824: Tests fix.
nizhikov Dec 14, 2020
58254af
Merge branch 'master' into IGNITE-12824
nizhikov Dec 16, 2020
75ee2ce
IGNITE-12824: Test update
nizhikov Dec 16, 2020
5b196fe
IGNITE-13865: Support of DateTime as a key or value in .Net and Java
nizhikov Dec 16, 2020
a06e4a3
IGNITE-13865: Support of DateTime as a key or value in .Net and Java
nizhikov Dec 16, 2020
1879594
IGNITE-13865: Support of DateTime as a key or value in .Net and Java
nizhikov Dec 16, 2020
e08e09a
IGNITE-13865: Support of DateTime as a key or value in .Net and Java
nizhikov Dec 16, 2020
ef420da
IGNITE-13865: Support of DateTime as a key or value in .Net and Java
nizhikov Dec 16, 2020
7ac33e7
IGNITE-13865: Support of DateTime as a key or value in .Net and Java
nizhikov Dec 17, 2020
af92eb4
IGNITE-13865: Support of DateTime as a key or value in .Net and Java
nizhikov Dec 17, 2020
bfecbda
Update XMLDoc; minor cleanup
ptupitsyn Dec 18, 2020
6bfc1e7
IGNITE-13865: Fix style.
nizhikov Dec 18, 2020
c24815c
Merge branch 'IGNITE-13865' of https://github.com/nizhikov/ignite int…
nizhikov Dec 18, 2020
61ca343
IGNITE-13865: Fix style.
nizhikov Dec 18, 2020
cb6ed5a
IGNITE-13865: Fix test.
nizhikov Dec 18, 2020
9692e85
IGNITE-13865: Fix test.
nizhikov Dec 18, 2020
e0f85ea
IGNITE-13865: Fix test.
nizhikov Dec 18, 2020
4381e50
IGNITE-13865: Fix test.
nizhikov Dec 18, 2020
a7641c7
IGNITE-13865: Fix test.
nizhikov Dec 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteException;
import org.apache.ignite.binary.BinaryObject;
import org.apache.ignite.cluster.ClusterNode;
Expand Down Expand Up @@ -94,6 +97,9 @@ private PlatformDeployServiceJob(String serviceName) {
* Test service.
*/
public static class PlatformTestService implements Service {
@IgniteInstanceResource
private Ignite ignite;

/** */
private boolean isCancelled;

Expand Down Expand Up @@ -494,6 +500,27 @@ public Map testMap(Map map) {
return m;
}

/** */
public Timestamp testDate(Timestamp date) {
if (date == null)
return null;

assertEquals(new Timestamp(new Date(82, Calendar.APRIL, 1, 0, 0, 0).getTime()), date);

return new Timestamp(new Date(91, Calendar.OCTOBER, 1, 0, 0, 0).getTime());
}

/** */
public void testUTCDateFromCache() {
IgniteCache<Integer, Timestamp> cache = ignite.cache("net-dates");

cache.put(3, new Timestamp(new Date(82, Calendar.APRIL, 1, 0, 0, 0).getTime()));
cache.put(4, new Timestamp(new Date(91, Calendar.OCTOBER, 1, 0, 0, 0).getTime()));

assertEquals(new Timestamp(new Date(82, Calendar.APRIL, 1, 0, 0, 0).getTime()), cache.get(1));
assertEquals(new Timestamp(new Date(91, Calendar.OCTOBER, 1, 0, 0, 0).getTime()), cache.get(2));
}

/** */
public void sleep(long delayMs) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,13 @@ public interface IJavaService

/** */
IDictionary testMap(IDictionary<Key, Value> dict);


/** */
DateTime testDate(DateTime date);

/** */
void testUTCDateFromCache();

/** */
void sleep(long delayMs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,18 @@ public IDictionary testMap(IDictionary<Key, Value> dict)
return _svc.testMap(dict);
}

/** <inheritDoc /> */
public DateTime testDate(DateTime date)
{
return _svc.testDate(date);
}

/** <inheritDoc /> */
public void testUTCDateFromCache()
{
_svc.testDateFromCache();
}

/** <inheritDoc /> */
public void sleep(long delayMs)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*/

// ReSharper disable once CheckNamespace
namespace org.apache.ignite.platform
{
/// <summary>
Expand All @@ -28,7 +29,7 @@ public class Address
/** */
public string Addr { get; set; }
}

/// <summary>
/// A class is a clone of Java class Department with the same namespace.
/// </summary>
Expand All @@ -37,7 +38,7 @@ public class Department
/** */
public string Name { get; set; }
}

/// <summary>
/// A class is a clone of Java class Employee with the same namespace.
/// </summary>
Expand Down Expand Up @@ -72,6 +73,7 @@ public override bool Equals(object obj)

public override int GetHashCode()
{
// ReSharper disable once NonReadonlyMemberInGetHashCode
return Id.GetHashCode();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,21 @@ public void TestCallJavaService()
Assert.AreEqual(new[] {11, 12, 13}, binSvc.testBinaryObjectArray(binArr)
.Select(x => x.GetField<int>("Field")));

DateTime dt1 = new DateTime(1982, 4, 1, 0, 0, 0, 0, DateTimeKind.Utc);
DateTime dt2 = new DateTime(1991, 10, 1, 0, 0, 0, 0, DateTimeKind.Utc);

Assert.AreEqual(dt2, svc.testDate(dt1));

var cache = Grid1.GetOrCreateCache<int, DateTime>("net-dates");

cache.Put(1, dt1);
cache.Put(2, dt2);

svc.testUTCDateFromCache();

Assert.AreEqual(dt1, cache.Get(3));
Assert.AreEqual(dt2, cache.Get(4));

Services.Cancel(javaSvcName);
}

Expand Down Expand Up @@ -1038,6 +1053,21 @@ public void TestCallJavaServiceDynamicProxy()
Assert.AreEqual(guid, svc.testNullUUID(guid));
Assert.IsNull(svc.testNullUUID(null));
Assert.AreEqual(guid, svc.testArray(new Guid?[] { guid })[0]);

DateTime dt1 = new DateTime(1982, 4, 1, 0, 0, 0, 0, DateTimeKind.Utc);
DateTime dt2 = new DateTime(1991, 10, 1, 0, 0, 0, 0, DateTimeKind.Utc);

Assert.AreEqual(dt2, svc.testDate(dt1));

var cache = Grid1.GetOrCreateCache<int, DateTime>("net-dates");

cache.Put(1, dt1);
cache.Put(2, dt2);

svc.testUTCDateFromCache();

Assert.AreEqual(dt1, cache.Get(3));
Assert.AreEqual(dt2, cache.Get(4));
}

/// <summary>
Expand Down Expand Up @@ -1123,7 +1153,8 @@ private IgniteConfiguration GetConfiguration(string springConfigUrl)
typeof (PlatformComputeBinarizable),
typeof (BinarizableObject))
{
NameMapper = BinaryBasicNameMapper.SimpleNameInstance
NameMapper = BinaryBasicNameMapper.SimpleNameInstance,
ForceTimestamp = true
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public class BinaryConfiguration
/// </summary>
public const bool DefaultKeepDeserialized = true;

/// <summary>
/// Default <see cref="ForceTimestamp"/> setting.
/// </summary>
public const bool DefaultForceTimestamp = false;

/** Footer setting. */
private bool? _compactFooter;

Expand All @@ -49,6 +54,7 @@ public class BinaryConfiguration
public BinaryConfiguration()
{
KeepDeserialized = DefaultKeepDeserialized;
ForceTimestamp = DefaultForceTimestamp;
}

/// <summary>
Expand All @@ -72,6 +78,7 @@ internal void CopyLocalProperties(BinaryConfiguration cfg)
IdMapper = cfg.IdMapper;
NameMapper = cfg.NameMapper;
KeepDeserialized = cfg.KeepDeserialized;
ForceTimestamp = cfg.ForceTimestamp;

if (cfg.Serializer != null)
{
Expand Down Expand Up @@ -106,7 +113,7 @@ public BinaryConfiguration(params Type[] binaryTypes)
public ICollection<BinaryTypeConfiguration> TypeConfigurations { get; set; }

/// <summary>
/// Gets or sets a collection of assembly-qualified type names
/// Gets or sets a collection of assembly-qualified type names
/// (the result of <see cref="Type.AssemblyQualifiedName"/>) for binarizable types.
/// <para />
/// Shorthand for creating <see cref="BinaryTypeConfiguration"/>.
Expand Down Expand Up @@ -137,12 +144,12 @@ public BinaryConfiguration(params Type[] binaryTypes)

/// <summary>
/// Gets or sets a value indicating whether to write footers in compact form.
/// When enabled, Ignite will not write fields metadata when serializing objects,
/// When enabled, Ignite will not write fields metadata when serializing objects,
/// because internally metadata is distributed inside cluster.
/// This increases serialization performance.
/// <para/>
/// <b>WARNING!</b> This mode should be disabled when already serialized data can be taken from some external
/// sources (e.g.cache store which stores data in binary form, data center replication, etc.).
/// sources (e.g.cache store which stores data in binary form, data center replication, etc.).
/// Otherwise binary objects without any associated metadata could could not be deserialized.
/// </summary>
[DefaultValue(DefaultCompactFooter)]
Expand All @@ -152,6 +159,21 @@ public bool CompactFooter
set { _compactFooter = value; }
}

/// <summary>
/// Gets or sets a value indicating whether all DateTime keys, values and object fields
/// should be written as a Timestamp.
/// <para />
/// Timestamp format is required for values used in SQL and for interoperation with other platforms.
/// Only UTC values are supported in Timestamp format. Other values will cause an exception on write.
/// <para />
/// Normally Ignite serializer uses <see cref="IBinaryWriter.WriteObject{T}"/> for DateTime fields,
/// keys and values.
/// This attribute changes the behavior to <see cref="IBinaryWriter.WriteTimestamp"/>.
/// <para />
/// See also <see cref="TimestampAttribute"/>, <see cref="BinaryReflectiveSerializer.ForceTimestamp"/>.
/// </summary>
public bool ForceTimestamp { get; set; }

/// <summary>
/// Gets the compact footer internal nullable value.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ namespace Apache.Ignite.Core.Binary
using Apache.Ignite.Core.Impl.Binary;

/// <summary>
/// Binary serializer which reflectively writes all fields except of ones with
/// Binary serializer which reflectively writes all fields except of ones with
/// <see cref="System.NonSerializedAttribute"/>.
/// <para />
/// Note that Java platform stores dates as a difference between current time
/// and predefined absolute UTC date. Therefore, this difference is always the
/// same for all time zones. .NET, in contrast, stores dates as a difference
/// between current time and some predefined date relative to the current time
/// zone. It means that this difference will be different as you change time zones.
/// To overcome this discrepancy Ignite always converts .Net date to UTC form
/// before serializing and allows user to decide whether to deserialize them
/// in UTC or local form using <c>ReadTimestamp(..., true/false)</c> methods in
/// Note that Java platform stores dates as a difference between current time
/// and predefined absolute UTC date. Therefore, this difference is always the
/// same for all time zones. .NET, in contrast, stores dates as a difference
/// between current time and some predefined date relative to the current time
/// zone. It means that this difference will be different as you change time zones.
/// To overcome this discrepancy Ignite always converts .Net date to UTC form
/// before serializing and allows user to decide whether to deserialize them
/// in UTC or local form using <c>ReadTimestamp(..., true/false)</c> methods in
/// <see cref="IBinaryReader"/> and <see cref="IBinaryRawReader"/>.
/// This serializer always read dates in UTC form. It means that if you have
/// local date in any field/property, it will be implicitly converted to UTC
/// form after the first serialization-deserialization cycle.
/// form after the first serialization-deserialization cycle.
/// </summary>
public sealed class BinaryReflectiveSerializer : IBinarySerializer
{
Expand Down Expand Up @@ -94,7 +94,7 @@ public bool RawMode
/// Normally serializer uses <see cref="IBinaryWriter.WriteObject{T}"/> for DateTime fields.
/// This attribute changes the behavior to <see cref="IBinaryWriter.WriteTimestamp"/>.
/// <para />
/// See also <see cref="TimestampAttribute"/>.
/// See also <see cref="TimestampAttribute"/>, <see cref="BinaryConfiguration.ForceTimestamp"/>.
/// </summary>
public bool ForceTimestamp
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,25 @@ static BinarySystemHandlers()
/// Try getting write handler for type.
/// </summary>
/// <param name="type"></param>
/// <param name="forceTimestamp"></param>
/// <returns></returns>
public static IBinarySystemWriteHandler GetWriteHandler(Type type)
public static IBinarySystemWriteHandler GetWriteHandler(Type type, bool forceTimestamp)
{
return WriteHandlers.GetOrAdd(type, t =>
{
return FindWriteHandler(t);
return FindWriteHandler(t, forceTimestamp);
});
}

/// <summary>
/// Find write handler for type.
/// </summary>
/// <param name="type">Type.</param>
/// <param name="forceTimestamp">Force timestamp.</param>
/// <returns>
/// Write handler or NULL.
/// </returns>
private static IBinarySystemWriteHandler FindWriteHandler(Type type)
private static IBinarySystemWriteHandler FindWriteHandler(Type type, bool forceTimestamp)
{
// 1. Well-known types.
if (type == typeof(string))
Expand All @@ -147,6 +149,8 @@ private static IBinarySystemWriteHandler FindWriteHandler(Type type)
return new BinarySystemWriteHandler<decimal>(WriteDecimal, false);
if (type == typeof(Guid))
return new BinarySystemWriteHandler<Guid>(WriteGuid, false);
if (type == typeof(DateTime) && forceTimestamp)
return new BinarySystemWriteHandler<DateTime>(WriteTimestamp, false);
if (type == typeof (BinaryObject))
return new BinarySystemWriteHandler<BinaryObject>(WriteBinary, false);
if (type == typeof (BinaryEnum))
Expand Down Expand Up @@ -224,6 +228,8 @@ private static IBinarySystemWriteHandler FindWriteHandler(Type type)
return new BinarySystemWriteHandler<string[]>(WriteStringArray, true);
if (elemType == typeof(Guid?))
return new BinarySystemWriteHandler<Guid?[]>(WriteGuidArray, true);
if (elemType == typeof(DateTime?) && forceTimestamp)
return new BinarySystemWriteHandler<DateTime?[]>(WriteTimestampArray, true);
// Enums.
if (BinaryUtils.IsIgniteEnum(elemType) || elemType == typeof(BinaryEnum))
return new BinarySystemWriteHandler<object>(WriteEnumArray, true);
Expand Down Expand Up @@ -293,6 +299,18 @@ private static void WriteGuid(BinaryWriter ctx, Guid obj)
BinaryUtils.WriteGuid(obj, ctx.Stream);
}

/// <summary>
/// Write Date.
/// </summary>
/// <param name="ctx">Context.</param>
/// <param name="obj">Value.</param>
private static void WriteTimestamp(BinaryWriter ctx, DateTime obj)
{
ctx.Stream.WriteByte(BinaryTypeId.Timestamp);

BinaryUtils.WriteTimestamp(obj, ctx.Stream);
}

/// <summary>
/// Write boolaen array.
/// </summary>
Expand Down Expand Up @@ -425,6 +443,18 @@ private static void WriteGuidArray(BinaryWriter ctx, Guid?[] obj)
BinaryUtils.WriteGuidArray(obj, ctx.Stream);
}

/// <summary>
/// Write nullable Date array.
/// </summary>
/// <param name="ctx">Context.</param>
/// <param name="obj">Value.</param>
private static void WriteTimestampArray(BinaryWriter ctx, DateTime?[] obj)
{
ctx.Stream.WriteByte(BinaryTypeId.ArrayTimestamp);

BinaryUtils.WriteTimestampArray(obj, ctx.Stream);
}

/// <summary>
/// Writes the enum array.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ public void WriteEnum<T>(T val)
throw new BinaryObjectException("Type is not an enum: " + type);
}

var handler = BinarySystemHandlers.GetWriteHandler(type);
var handler = BinarySystemHandlers.GetWriteHandler(type, _marsh.ForceTimestamp);

if (handler != null)
{
Expand Down Expand Up @@ -1180,7 +1180,7 @@ public void Write<T>(T obj)
return;

// Are we dealing with a well-known type?
var handler = BinarySystemHandlers.GetWriteHandler(type);
var handler = BinarySystemHandlers.GetWriteHandler(type, _marsh.ForceTimestamp);

if (handler != null)
{
Expand Down
Loading