You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2016/06/28 13:07:15 UTC
[28/50] [abbrv] ignite git commit: IGNITE-3364 .NET: Fix
BinaryReflectiveSerializer raw mode for DateTime members marked with
QuerySqlField
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/ignite-1232
Commit: 6cfd991ecc7c27d2cd7d01a492ba41280689c285
Parents: cb0deb1
Author: Pavel Tupitsyn <pt...@apache.org>
Authored: Fri Jun 24 17:01:39 2016 +0300
Committer: Pavel Tupitsyn <pt...@apache.org>
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; }
/** <inheritdoc /> */
@@ -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;
}
/** <inheritdoc /> */
@@ -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>("guid");
PnGuid = reader.ReadGuid("nguid");
+ PDate = reader.ReadObject<DateTime>("date");
+ PnDate = reader.ReadObject<DateTime?>("ndate");
+
IgniteGuid = reader.ReadObject<IgniteGuid>("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<DateTime>();
+ PnDate = rawReader.ReadObject<DateTime?>();
+
IgniteGuid = rawReader.ReadObject<IgniteGuid>();
}
}
@@ -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>("guid");
obj0.PnGuid = reader.ReadGuid("nguid");
+ obj0.PDate = reader.ReadObject<DateTime>("date");
+ obj0.PnDate = reader.ReadObject<DateTime?>("ndate");
+
obj0.IgniteGuid = reader.ReadObject<IgniteGuid>("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<DateTime>();
+ obj0.PnDate = rawReader.ReadObject<DateTime?>();
+
obj0.IgniteGuid = rawReader.ReadObject<IgniteGuid>();
}
}
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<DateTime>(field, (f, w, o) => w.WriteTimestamp(f, o));
readAction = GetReader(field, (f, r) => r.ReadObject<DateTime>(f));
}
- else if (nullableType == typeof (DateTime) && IsQueryField(field))
+ else if (nullableType == typeof (DateTime) && IsQueryField(field) && !raw)
{
writeAction = GetWriter<DateTime?>(field, (f, w, o) => w.WriteTimestamp(f, o));
readAction = GetReader(field, (f, r) => r.ReadTimestamp(f));