Skip to content
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
40 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
e99e251
Merge branch 'master' into IGNITE-12824
nizhikov Dec 18, 2020
3fb26e1
IGNITE-12824: Test update
nizhikov Dec 18, 2020
d84249a
IGNITE-12824: Update of the date conversion(works on Mac)
nizhikov Dec 19, 2020
0b0af6f
IGNITE-12824: Allows local dates only for `ForceTimestamp` mode.
nizhikov Dec 20, 2020
e3ecbaa
IGNITE-12824: Allows local dates only for `ForceTimestamp` mode.
nizhikov Dec 20, 2020
332eb06
IGNITE-12824: Allows local dates only for `ForceTimestamp` mode.
nizhikov Dec 20, 2020
1d1dc86
IGNITE-12824: Allows local dates only for `ForceTimestamp` mode.
nizhikov Dec 20, 2020
c846297
IGNITE-12824: Allows usages of Local dates but only for .NetCore appl…
nizhikov Dec 20, 2020
2e5edb3
IGNITE-12824: Allows usages of Local dates but only for .NetCore appl…
nizhikov Dec 20, 2020
078b658
IGNITE-12824: IDateTimeConverter implemented
nizhikov Dec 21, 2020
969e5c5
IGNITE-12824: IDateTimeConverter implemented
nizhikov Dec 21, 2020
14b4456
IGNITE-12824: IDateTimeConverter implemented
nizhikov Dec 21, 2020
a93dc9f
IGNITE-12824: License fix.
nizhikov Dec 22, 2020
8a481da
IGNITE-12824: Code review fixes.
nizhikov Dec 22, 2020
e635495
IGNITE-12824: Code review fixes.
nizhikov Dec 22, 2020
f7fe8cd
Merge branch 'master' into IGNITE-12824
nizhikov Dec 23, 2020
c66a2f1
IGNITE-12824: Code review fixes.
nizhikov Dec 23, 2020
be9a7df
IGNITE-12824: Code review fixes.
nizhikov Dec 23, 2020
05a244b
IGNITE-12824: Code review fixes.
nizhikov Dec 24, 2020
9500998
IGNITE-12824: Code review fixes.
nizhikov Dec 24, 2020
fc2b7b1
Add TestAddYearTimestampConverter
ptupitsyn Dec 24, 2020
ae70be9
Add TestAddYearTimestampConverter
ptupitsyn Dec 24, 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 @@ -18,6 +18,8 @@
package org.apache.ignite.platform;

import java.sql.Timestamp;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
Expand Down Expand Up @@ -530,6 +532,24 @@ public void testUTCDateFromCache() {
assertEquals(new Timestamp(new Date(91, Calendar.OCTOBER, 1, 0, 0, 0).getTime()), cache.get(2));
}

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

ZoneId msk = ZoneId.of("Europe/Moscow");

//This Date in Europe/Moscow have offset +4.
Timestamp ts1 = new Timestamp(ZonedDateTime.of(1982, 4, 1, 1, 0, 0, 0, msk).toInstant().toEpochMilli());
//This Date in Europe/Moscow have offset +3.
Timestamp ts2 = new Timestamp(ZonedDateTime.of(1982, 3, 31, 22, 0, 0, 0, msk).toInstant().toEpochMilli());

assertEquals(ts1, cache.get(5));
assertEquals(ts2, cache.get(6));

cache.put(7, ts1);
cache.put(8, ts2);
}

/** */
public void sleep(long delayMs) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ public interface IJavaService
/** */
void testUTCDateFromCache();

/** */
void testLocalDateFromCache();

/** */
void sleep(long delayMs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,12 @@ public void testUTCDateFromCache()
_svc.testDateFromCache();
}

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

/** <inheritDoc /> */
public void sleep(long delayMs)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace Apache.Ignite.Core.Tests.Services
using Apache.Ignite.Core.Cluster;
using Apache.Ignite.Core.Common;
using Apache.Ignite.Core.Impl;
using Apache.Ignite.Core.Impl.Binary;
using Apache.Ignite.Core.Resource;
using Apache.Ignite.Core.Services;
using NUnit.Framework;
Expand Down Expand Up @@ -973,6 +974,28 @@ public void TestCallJavaService()
Assert.AreEqual(dt1, cache.Get(3));
Assert.AreEqual(dt2, cache.Get(4));

#if NETCOREAPP
//This Date in Europe/Moscow have offset +4.
DateTime dt3 = new DateTime(1982, 4, 1, 1, 0, 0, 0, DateTimeKind.Local);
//This Date in Europe/Moscow have offset +3.
DateTime dt4 = new DateTime(1982, 3, 31, 22, 0, 0, 0, DateTimeKind.Local);

cache.Put(5, dt3);
cache.Put(6, dt4);

Assert.AreEqual(dt3.ToUniversalTime(), cache.Get(5).ToUniversalTime());
Assert.AreEqual(dt4.ToUniversalTime(), cache.Get(6).ToUniversalTime());

svc.testLocalDateFromCache();

Assert.AreEqual(dt3, cache.Get(7).ToLocalTime());
Assert.AreEqual(dt4, cache.Get(8).ToLocalTime());

var now = DateTime.Now;
cache.Put(9, now);
Assert.AreEqual(now.ToUniversalTime(), cache.Get(9).ToUniversalTime());
#endif

Services.Cancel(javaSvcName);
}

Expand Down Expand Up @@ -1157,6 +1180,9 @@ private IgniteConfiguration GetConfiguration(string springConfigUrl)
{
NameMapper = BinaryBasicNameMapper.SimpleNameInstance,
ForceTimestamp = true
#if NETCOREAPP
, DateTimeConverter = new DateTimeConverter()
#endif
}
};
}
Expand Down Expand Up @@ -1539,5 +1565,23 @@ public class PlatformComputeBinarizable2
/** */
public int Field { get; set; }
}

#if NETCOREAPP
class DateTimeConverter : IDateTimeConverter
{
public void ToJavaTicks(DateTime date, out long high, out int low)
{
if (date.Kind == DateTimeKind.Local)
date = date.ToUniversalTime();

BinaryUtils.ToJavaDate(date, out high, out low);
}

public DateTime FromJavaTicks(long high, int low)
{
return new DateTime(BinaryUtils.JavaDateTicks + high * TimeSpan.TicksPerMillisecond + low / 100, DateTimeKind.Utc);
}
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ internal void CopyLocalProperties(BinaryConfiguration cfg)
NameMapper = cfg.NameMapper;
KeepDeserialized = cfg.KeepDeserialized;
ForceTimestamp = cfg.ForceTimestamp;
DateTimeConverter = cfg.DateTimeConverter;

if (cfg.Serializer != null)
{
Expand Down Expand Up @@ -136,6 +137,11 @@ public BinaryConfiguration(params Type[] binaryTypes)
/// </summary>
public IBinarySerializer Serializer { get; set; }

/// <summary>
/// Default date time converter.
/// </summary>
public IDateTimeConverter DateTimeConverter { get; set; }

/// <summary>
/// Default keep deserialized flag.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Apache.Ignite.Core.Binary
{
using System;

/// <summary>
/// Converter for DateTime objects.
/// </summary>
public interface IDateTimeConverter
{
/// <summary>Convert date to Java ticks.</summary>
/// <param name="date">Date</param>
/// <param name="high">High part (milliseconds).</param>
/// <param name="low">Low part (nanoseconds)</param>
void ToJavaTicks(DateTime date, out long high, out int low);

/// <summary>Convert date from Java ticks.</summary>
/// <param name="high">High part (milliseconds).</param>
/// <param name="low">Low part (nanoseconds)</param>
DateTime FromJavaTicks(long high, int low);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,13 @@ public double[] ReadDoubleArray()
/** <inheritdoc /> */
public DateTime? ReadTimestamp(string fieldName)
{
return ReadField(fieldName, BinaryUtils.ReadTimestamp, BinaryTypeId.Timestamp);
return ReadField(fieldName, stream => BinaryUtils.ReadTimestamp(stream, _marsh.DateTimeConverter), BinaryTypeId.Timestamp);
}

/** <inheritdoc /> */
public DateTime? ReadTimestamp()
{
return Read(BinaryUtils.ReadTimestamp, BinaryTypeId.Timestamp);
return Read(stream => BinaryUtils.ReadTimestamp(stream, _marsh.DateTimeConverter), BinaryTypeId.Timestamp);
}

/** <inheritdoc /> */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ static BinarySystemHandlers()
ReadHandlers[BinaryTypeId.Double] = new BinarySystemReader<double>(s => s.ReadDouble());
ReadHandlers[BinaryTypeId.Decimal] = new BinarySystemReader<decimal?>(BinaryUtils.ReadDecimal);

// 2. Date.
ReadHandlers[BinaryTypeId.Timestamp] = new BinarySystemReader<DateTime?>(BinaryUtils.ReadTimestamp);

// 3. String.
ReadHandlers[BinaryTypeId.String] = new BinarySystemReader<string>(BinaryUtils.ReadString);

Expand Down Expand Up @@ -258,8 +255,16 @@ public static bool TryReadSystemType<T>(byte typeId, BinaryReader ctx, out T res

if (handler == null)
{
res = default(T);
return false;
if (typeId == BinaryTypeId.Timestamp)
{
// Date.
handler = new BinarySystemReader<DateTime?>(stream => BinaryUtils.ReadTimestamp(stream, ctx.Marshaller.DateTimeConverter));
}
else
{
res = default(T);
return false;
}
}

res = handler.Read<T>(ctx);
Expand Down Expand Up @@ -311,7 +316,7 @@ private static void WriteTimestamp(BinaryWriter ctx, DateTime obj)
{
ctx.Stream.WriteByte(BinaryTypeId.Timestamp);

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

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ internal static class BinaryUtils
public const int ObjTypeId = -1;

/** Ticks for Java epoch. */
private static readonly long JavaDateTicks = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).Ticks;
public static readonly long JavaDateTicks = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).Ticks;

/** Binding flags for static search. */
private const BindingFlags BindFlagsStatic = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
Expand Down Expand Up @@ -388,13 +388,17 @@ public static double[] ReadDoubleArray(IBinaryStream stream)
* <summary>Write date.</summary>
* <param name="val">Date.</param>
* <param name="stream">Stream.</param>
* <param name="converter">DateTime Converter.</param>
*/
public static void WriteTimestamp(DateTime val, IBinaryStream stream)
public static void WriteTimestamp(DateTime val, IBinaryStream stream, IDateTimeConverter converter)
{
long high;
int low;

ToJavaDate(val, out high, out low);
if (converter != null)
converter.ToJavaTicks(val, out high, out low);
else
ToJavaDate(val, out high, out low);

stream.WriteLong(high);
stream.WriteInt(low);
Expand All @@ -403,14 +407,18 @@ public static void WriteTimestamp(DateTime val, IBinaryStream stream)
/**
* <summary>Read date.</summary>
* <param name="stream">Stream.</param>
* <param name="converter">DateTime Converter.</param>
* <returns>Date</returns>
*/
public static DateTime? ReadTimestamp(IBinaryStream stream)
public static DateTime? ReadTimestamp(IBinaryStream stream, IDateTimeConverter converter)
{
long high = stream.ReadLong();
int low = stream.ReadInt();

return new DateTime(JavaDateTicks + high * TimeSpan.TicksPerMillisecond + low / 100, DateTimeKind.Utc);
if (converter != null)
return converter.FromJavaTicks(high, low);
else
return new DateTime(JavaDateTicks + high * TimeSpan.TicksPerMillisecond + low / 100, DateTimeKind.Utc);
}

/// <summary>
Expand Down Expand Up @@ -448,7 +456,7 @@ public static void WriteTimestampArray(DateTime?[] vals, IBinaryStream stream)
{
stream.WriteByte(BinaryTypeId.Timestamp);

WriteTimestamp(val.Value, stream);
WriteTimestamp(val.Value, stream, Marsh.DateTimeConverter);
}
else
stream.WriteByte(HdrNull);
Expand Down Expand Up @@ -1173,7 +1181,7 @@ public static T[] ReadArray<T>(BinaryReader ctx, bool typed)
DateTime?[] vals = new DateTime?[len];

for (int i = 0; i < len; i++)
vals[i] = stream.ReadByte() == HdrNull ? null : ReadTimestamp(stream);
vals[i] = stream.ReadByte() == HdrNull ? null : ReadTimestamp(stream, Marshaller.DateTimeConverter);

return vals;
}
Expand Down Expand Up @@ -1612,7 +1620,7 @@ public static void ValidateProtocolVersion(byte version)
* <param name="high">High part (milliseconds).</param>
* <param name="low">Low part (nanoseconds)</param>
*/
private static void ToJavaDate(DateTime date, out long high, out int low)
public static void ToJavaDate(DateTime date, out long high, out int low)
{
if (date.Kind != DateTimeKind.Utc)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ public void WriteTimestamp(string fieldName, DateTime? val)
else
{
_stream.WriteByte(BinaryTypeId.Timestamp);
BinaryUtils.WriteTimestamp(val.Value, _stream);
BinaryUtils.WriteTimestamp(val.Value, _stream, _marsh.DateTimeConverter);
}
}

Expand All @@ -672,7 +672,7 @@ public void WriteTimestamp(DateTime? val)
else
{
_stream.WriteByte(BinaryTypeId.Timestamp);
BinaryUtils.WriteTimestamp(val.Value, _stream);
BinaryUtils.WriteTimestamp(val.Value, _stream, _marsh.DateTimeConverter);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ public bool ForceTimestamp
get { return _cfg.ForceTimestamp; }
}

/// <summary>
/// Gets date time converter.
/// </summary>
public IDateTimeConverter DateTimeConverter
{
get { return _cfg.DateTimeConverter; }
}

/// <summary>
/// Marshal object.
/// </summary>
Expand Down