Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6A6C6200AE4 for ; Fri, 24 Jun 2016 16:01:53 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 691E1160A58; Fri, 24 Jun 2016 14:01:53 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 67498160A2E for ; Fri, 24 Jun 2016 16:01:52 +0200 (CEST) Received: (qmail 71972 invoked by uid 500); 24 Jun 2016 14:01:51 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 71963 invoked by uid 99); 24 Jun 2016 14:01:51 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Jun 2016 14:01:51 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3ACEDE049D; Fri, 24 Jun 2016 14:01:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ptupitsyn@apache.org To: commits@ignite.apache.org Message-Id: <2045ce800ea34b4596a60858e03f140b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: ignite git commit: IGNITE-3364 .NET: Fix BinaryReflectiveSerializer raw mode for DateTime members marked with QuerySqlField Date: Fri, 24 Jun 2016 14:01:51 +0000 (UTC) archived-at: Fri, 24 Jun 2016 14:01:53 -0000 Repository: ignite Updated Branches: refs/heads/master cb0deb11e -> 6cfd991ec IGNITE-3364 .NET: Fix BinaryReflectiveSerializer raw mode for DateTime members marked with QuerySqlField This closes #830 Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/6cfd991e Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6cfd991e Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6cfd991e Branch: refs/heads/master Commit: 6cfd991ecc7c27d2cd7d01a492ba41280689c285 Parents: cb0deb1 Author: Pavel Tupitsyn Authored: Fri Jun 24 17:01:39 2016 +0300 Committer: Pavel Tupitsyn Committed: Fri Jun 24 17:01:39 2016 +0300 ---------------------------------------------------------------------- .../Binary/BinarySelfTest.cs | 138 +++++++++++++------ .../Impl/Binary/BinaryReflectiveActions.cs | 10 +- 2 files changed, 106 insertions(+), 42 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/6cfd991e/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs index 9cc64c1..b32b0a2 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs @@ -31,6 +31,7 @@ namespace Apache.Ignite.Core.Tests.Binary using System.Linq; using System.Reflection; using Apache.Ignite.Core.Binary; + using Apache.Ignite.Core.Cache.Configuration; using Apache.Ignite.Core.Common; using Apache.Ignite.Core.Impl.Binary; using Apache.Ignite.Core.Impl.Binary.IO; @@ -780,7 +781,12 @@ namespace Apache.Ignite.Core.Tests.Binary } }); - PrimitiveFieldType obj = new PrimitiveFieldType(); + // Use utc date fields because reflective serializer writes [QuerySqlField] fields as timestamp + var obj = new PrimitiveFieldType + { + PDate = DateTime.UtcNow, + PnDate = DateTime.UtcNow + }; CheckPrimitiveFields(marsh, obj); } @@ -932,23 +938,6 @@ namespace Apache.Ignite.Core.Tests.Binary private void CheckPrimitiveFields(Marshaller marsh, PrimitiveFieldType obj) { - obj.PBool = true; - obj.PByte = 2; - obj.PSbyte = 3; - obj.PShort = 4; - obj.PUshort = 5; - obj.PInt = 6; - obj.PUint = 7; - obj.PLong = 8; - obj.PUlong = 9; - obj.PChar = 'a'; - obj.PFloat = 10; - obj.PDouble = 11; - obj.PString = "abc"; - obj.PGuid = Guid.NewGuid(); - obj.PnGuid = Guid.NewGuid(); - obj.IgniteGuid = new IgniteGuid(Guid.NewGuid(), 123); - CheckPrimitiveFieldsSerialization(marsh, obj); } @@ -1845,36 +1834,81 @@ namespace Apache.Ignite.Core.Tests.Binary [Serializable] public class PrimitiveFieldType { + public PrimitiveFieldType() + { + PBool = true; + PByte = 2; + PSbyte = 3; + PShort = 4; + PUshort = 5; + PInt = 6; + PUint = 7; + PLong = 8; + PUlong = 9; + PChar = 'a'; + PFloat = 10; + PDouble = 11; + PString = "abc"; + PGuid = Guid.NewGuid(); + PnGuid = Guid.NewGuid(); + PDate = DateTime.Now; + PnDate = DateTime.Now; + IgniteGuid = new IgniteGuid(Guid.NewGuid(), 123); + } + + // Mark all fields with QuerySqlField because reflective serializer takes it into account + [QuerySqlField] public bool PBool { get; set; } + [QuerySqlField] public sbyte PSbyte { get; set; } + [QuerySqlField] public byte PByte { get; set; } + [QuerySqlField] public short PShort { get; set; } + [QuerySqlField] public ushort PUshort { get; set; } + [QuerySqlField] public char PChar { get; set; } + [QuerySqlField] public int PInt { get; set; } + [QuerySqlField] public uint PUint { get; set; } + [QuerySqlField] public long PLong { get; set; } + [QuerySqlField] public ulong PUlong { get; set; } + [QuerySqlField] public float PFloat { get; set; } + [QuerySqlField] public double PDouble { get; set; } + [QuerySqlField] public string PString { get; set; } + [QuerySqlField] public Guid PGuid { get; set; } + [QuerySqlField] public Guid? PnGuid { get; set; } + [QuerySqlField] + public DateTime PDate { get; set; } + + [QuerySqlField] + public DateTime? PnDate { get; set; } + + [QuerySqlField] public IgniteGuid IgniteGuid { get; set; } /** */ @@ -1883,28 +1917,28 @@ namespace Apache.Ignite.Core.Tests.Binary if (this == obj) return true; - if (obj != null && obj is PrimitiveFieldType) - { - PrimitiveFieldType that = (PrimitiveFieldType)obj; - - return PBool == that.PBool && - PByte == that.PByte && - PSbyte == that.PSbyte && - PShort == that.PShort && - PUshort == that.PUshort && - PInt == that.PInt && - PUint == that.PUint && - PLong == that.PLong && - PUlong == that.PUlong && - PChar == that.PChar && - PFloat == that.PFloat && - PDouble == that.PDouble && - (string.Equals(PString, that.PString)) && - PGuid.Equals(that.PGuid) && - IgniteGuid.Equals(that.IgniteGuid) && - (PnGuid == null && that.PnGuid == null || PnGuid != null && PnGuid.Equals(that.PnGuid)); - } - return false; + var that = obj as PrimitiveFieldType; + if (that == null) + return false; + + return PBool == that.PBool && + PByte == that.PByte && + PSbyte == that.PSbyte && + PShort == that.PShort && + PUshort == that.PUshort && + PInt == that.PInt && + PUint == that.PUint && + PLong == that.PLong && + PUlong == that.PUlong && + PChar == that.PChar && + PFloat == that.PFloat && + PDouble == that.PDouble && + PString == that.PString && + PGuid == that.PGuid && + PnGuid == that.PnGuid && + IgniteGuid == that.IgniteGuid && + PDate == that.PDate && + PnDate == that.PnDate; } /** */ @@ -1941,6 +1975,9 @@ namespace Apache.Ignite.Core.Tests.Binary writer.WriteGuid("guid", PGuid); writer.WriteGuid("nguid", PnGuid); + writer.WriteObject("date", PDate); + writer.WriteObject("ndate", PnDate); + writer.WriteObject("iguid", IgniteGuid); } @@ -1970,6 +2007,9 @@ namespace Apache.Ignite.Core.Tests.Binary PGuid = reader.ReadObject("guid"); PnGuid = reader.ReadGuid("nguid"); + PDate = reader.ReadObject("date"); + PnDate = reader.ReadObject("ndate"); + IgniteGuid = reader.ReadObject("iguid"); } } @@ -2003,6 +2043,9 @@ namespace Apache.Ignite.Core.Tests.Binary rawWriter.WriteGuid(PGuid); rawWriter.WriteGuid(PnGuid); + rawWriter.WriteObject(PDate); + rawWriter.WriteObject(PnDate); + rawWriter.WriteObject(IgniteGuid); } @@ -2034,6 +2077,9 @@ namespace Apache.Ignite.Core.Tests.Binary PGuid = rawReader.ReadGuid().Value; PnGuid = rawReader.ReadGuid(); + PDate = rawReader.ReadObject(); + PnDate = rawReader.ReadObject(); + IgniteGuid = rawReader.ReadObject(); } } @@ -2067,6 +2113,9 @@ namespace Apache.Ignite.Core.Tests.Binary writer.WriteGuid("guid", obj0.PGuid); writer.WriteGuid("nguid", obj0.PnGuid); + writer.WriteObject("date", obj0.PDate); + writer.WriteObject("ndate", obj0.PnDate); + writer.WriteObject("iguid", obj0.IgniteGuid); } @@ -2098,6 +2147,9 @@ namespace Apache.Ignite.Core.Tests.Binary obj0.PGuid = reader.ReadObject("guid"); obj0.PnGuid = reader.ReadGuid("nguid"); + obj0.PDate = reader.ReadObject("date"); + obj0.PnDate = reader.ReadObject("ndate"); + obj0.IgniteGuid = reader.ReadObject("iguid"); } } @@ -2133,6 +2185,9 @@ namespace Apache.Ignite.Core.Tests.Binary rawWriter.WriteGuid(obj0.PGuid); rawWriter.WriteGuid(obj0.PnGuid); + rawWriter.WriteObject(obj0.PDate); + rawWriter.WriteObject(obj0.PnDate); + rawWriter.WriteObject(obj0.IgniteGuid); } @@ -2165,6 +2220,9 @@ namespace Apache.Ignite.Core.Tests.Binary obj0.PGuid = rawReader.ReadGuid().Value; obj0.PnGuid = rawReader.ReadGuid(); + obj0.PDate = rawReader.ReadObject(); + obj0.PnDate = rawReader.ReadObject(); + obj0.IgniteGuid = rawReader.ReadObject(); } } http://git-wip-us.apache.org/repos/asf/ignite/blob/6cfd991e/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReflectiveActions.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReflectiveActions.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReflectiveActions.cs index 07cf08f..795f8ac 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReflectiveActions.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReflectiveActions.cs @@ -503,12 +503,18 @@ namespace Apache.Ignite.Core.Impl.Binary ? GetRawReader(field, r => r.ReadCollection()) : GetReader(field, (f, r) => r.ReadCollection(f)); } - else if (type == typeof (DateTime) && IsQueryField(field)) + else if (type == typeof (DateTime) && IsQueryField(field) && !raw) { + // Special case for DateTime and query fields. + // If a field is marked with [QuerySqlField], write it as TimeStamp so that queries work. + // This is not needed in raw mode (queries do not work anyway). + // It may cause issues when field has attribute, but is used in a cache without queries, and user + // may expect non-UTC dates to work. However, such cases are rare, and there are workarounds. + writeAction = GetWriter(field, (f, w, o) => w.WriteTimestamp(f, o)); readAction = GetReader(field, (f, r) => r.ReadObject(f)); } - else if (nullableType == typeof (DateTime) && IsQueryField(field)) + else if (nullableType == typeof (DateTime) && IsQueryField(field) && !raw) { writeAction = GetWriter(field, (f, w, o) => w.WriteTimestamp(f, o)); readAction = GetReader(field, (f, r) => r.ReadTimestamp(f));