Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 49295180AB for ; Fri, 27 Nov 2015 09:37:01 +0000 (UTC) Received: (qmail 5301 invoked by uid 500); 27 Nov 2015 09:37:01 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 5257 invoked by uid 500); 27 Nov 2015 09:37:01 -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 5246 invoked by uid 99); 27 Nov 2015 09:37:00 -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, 27 Nov 2015 09:37:00 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C8C24DFDCF; Fri, 27 Nov 2015 09:37:00 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: vozerov@apache.org To: commits@ignite.apache.org Date: Fri, 27 Nov 2015 09:37:00 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/4] ignite git commit: IGNITE-1956: Added binary enums support. Repository: ignite Updated Branches: refs/heads/ignite-1.5 c2d4d1d2e -> e4f6224fa http://git-wip-us.apache.org/repos/asf/ignite/blob/663e78dc/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/IBinaryTypeDescriptor.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/IBinaryTypeDescriptor.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/IBinaryTypeDescriptor.cs index 99af56d..e50279c 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/IBinaryTypeDescriptor.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/IBinaryTypeDescriptor.cs @@ -30,74 +30,52 @@ namespace Apache.Ignite.Core.Impl.Binary /// /// Type. /// - Type Type - { - get; - } + Type Type { get; } /// /// Type ID. /// - int TypeId - { - get; - } + int TypeId { get; } /// /// Type name. /// - string TypeName - { - get; - } + string TypeName { get; } /// /// User type flag. /// - bool UserType - { - get; - } + bool UserType { get; } /// /// Whether to cache deserialized value in IBinaryObject /// - bool KeepDeserialized - { - get; - } + bool KeepDeserialized { get; } /// /// Name converter. /// - IBinaryNameMapper NameMapper - { - get; - } + IBinaryNameMapper NameMapper { get; } /// /// Mapper. /// - IBinaryIdMapper IdMapper - { - get; - } + IBinaryIdMapper IdMapper { get; } /// /// Serializer. /// - IBinarySerializer Serializer - { - get; - } + IBinarySerializer Serializer { get; } /// /// Affinity key field name. /// - string AffinityKeyFieldName - { - get; - } + string AffinityKeyFieldName { get; } + + /// + /// Gets a value indicating whether this descriptor represents an enum type. + /// + bool IsEnum { get; } /// /// Write type structure. http://git-wip-us.apache.org/repos/asf/ignite/blob/663e78dc/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/IgniteBinary.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/IgniteBinary.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/IgniteBinary.cs deleted file mode 100644 index ecc6807..0000000 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/IgniteBinary.cs +++ /dev/null @@ -1,192 +0,0 @@ -/* - * 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.Impl.Binary -{ - using System; - using System.Collections.Generic; - using System.IO; - using Apache.Ignite.Core.Binary; - using Apache.Ignite.Core.Common; - using Apache.Ignite.Core.Impl.Binary.IO; - using Apache.Ignite.Core.Impl.Common; - - /// - /// Binary implementation. - /// - internal class IgniteBinary : IIgniteBinary - { - /** Owning grid. */ - private readonly Marshaller _marsh; - - /// - /// Constructor. - /// - /// Marshaller. - internal IgniteBinary(Marshaller marsh) - { - _marsh = marsh; - } - - /** */ - public T ToBinary(object obj) - { - if (obj is IBinaryObject) - return (T)obj; - - IBinaryStream stream = new BinaryHeapStream(1024); - - // Serialize. - BinaryWriter writer = _marsh.StartMarshal(stream); - - try - { - writer.Write(obj); - } - finally - { - // Save metadata. - _marsh.FinishMarshal(writer); - } - - // Deserialize. - stream.Seek(0, SeekOrigin.Begin); - - return _marsh.Unmarshal(stream, BinaryMode.ForceBinary); - } - - /** */ - public IBinaryObjectBuilder GetBuilder(Type type) - { - IgniteArgumentCheck.NotNull(type, "type"); - - IBinaryTypeDescriptor desc = _marsh.GetDescriptor(type); - - if (desc == null) - throw new IgniteException("Type is not binary (add it to BinaryConfiguration): " + - type.FullName); - - return Builder0(null, BinaryFromDescriptor(desc), desc); - } - - /** */ - public IBinaryObjectBuilder GetBuilder(string typeName) - { - IgniteArgumentCheck.NotNullOrEmpty(typeName, "typeName"); - - IBinaryTypeDescriptor desc = _marsh.GetDescriptor(typeName); - - return Builder0(null, BinaryFromDescriptor(desc), desc); - } - - /** */ - public IBinaryObjectBuilder GetBuilder(IBinaryObject obj) - { - IgniteArgumentCheck.NotNull(obj, "obj"); - - BinaryObject obj0 = obj as BinaryObject; - - if (obj0 == null) - throw new ArgumentException("Unsupported object type: " + obj.GetType()); - - IBinaryTypeDescriptor desc = _marsh.GetDescriptor(true, obj0.TypeId); - - return Builder0(null, obj0, desc); - } - - /** */ - public int GetTypeId(string typeName) - { - IgniteArgumentCheck.NotNullOrEmpty(typeName, "typeName"); - - return Marshaller.GetDescriptor(typeName).TypeId; - } - - /** */ - public ICollection GetBinaryTypes() - { - return Marshaller.Ignite.ClusterGroup.GetBinaryTypes(); - } - - /** */ - public IBinaryType GetBinaryType(int typeId) - { - return Marshaller.GetBinaryType(typeId); - } - - /** */ - public IBinaryType GetBinaryType(string typeName) - { - IgniteArgumentCheck.NotNullOrEmpty(typeName, "typeName"); - - return GetBinaryType(GetTypeId(typeName)); - } - - /** */ - public IBinaryType GetBinaryType(Type type) - { - IgniteArgumentCheck.NotNull(type, "type"); - - var desc = Marshaller.GetDescriptor(type); - - return desc == null ? null : Marshaller.GetBinaryType(desc.TypeId); - } - - /// - /// Marshaller. - /// - internal Marshaller Marshaller - { - get - { - return _marsh; - } - } - - /// - /// Create empty binary object from descriptor. - /// - /// Descriptor. - /// Empty binary object. - private BinaryObject BinaryFromDescriptor(IBinaryTypeDescriptor desc) - { - var len = BinaryObjectHeader.Size; - - var hdr = new BinaryObjectHeader(desc.TypeId, 0, len, 0, len, - desc.UserType ? BinaryObjectHeader.Flag.UserType : BinaryObjectHeader.Flag.None); - - var stream = new BinaryHeapStream(len); - - BinaryObjectHeader.Write(hdr, stream, 0); - - return new BinaryObject(_marsh, stream.InternalArray, 0, hdr); - } - - /// - /// Internal builder creation routine. - /// - /// Parent builder. - /// binary object. - /// Type descriptor. - /// Builder. - private BinaryObjectBuilder Builder0(BinaryObjectBuilder parent, BinaryObject obj, - IBinaryTypeDescriptor desc) - { - return new BinaryObjectBuilder(this, parent, obj, desc); - } - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/663e78dc/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs index 251610e..457830f 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs @@ -19,7 +19,7 @@ namespace Apache.Ignite.Core.Impl.Binary { using System; using System.Collections.Generic; - using System.Globalization; + using System.Diagnostics; using System.Linq; using Apache.Ignite.Core.Binary; using Apache.Ignite.Core.Impl.Binary.IO; @@ -149,14 +149,14 @@ namespace Apache.Ignite.Core.Impl.Binary /// /// Writer. /// Dictionary with metadata. - public void FinishMarshal(IBinaryWriter writer) + public void FinishMarshal(BinaryWriter writer) { - var meta = ((BinaryWriter) writer).GetBinaryTypes(); + var metas = writer.GetBinaryTypes(); var ignite = Ignite; - if (ignite != null && meta != null && meta.Count > 0) - ignite.PutBinaryTypes(meta); + if (ignite != null && metas != null && metas.Count > 0) + ignite.PutBinaryTypes(metas); } /// @@ -266,7 +266,22 @@ namespace Apache.Ignite.Core.Impl.Binary return meta; } - return BinaryType.EmptyMeta; + return BinaryType.Empty; + } + + /// + /// Puts the binary type metadata to Ignite. + /// + /// Descriptor. + /// Fields. + public void PutBinaryType(IBinaryTypeDescriptor desc, IDictionary fields = null) + { + Debug.Assert(desc != null); + + GetBinaryTypeHandler(desc); // ensure that handler exists + + if (Ignite != null) + Ignite.PutBinaryTypes(new[] {new BinaryType(desc, fields)}); } /// @@ -287,7 +302,7 @@ namespace Apache.Ignite.Core.Impl.Binary IDictionary metas0 = new Dictionary(_metas); - holder = new BinaryTypeHolder(desc.TypeId, desc.TypeName, desc.AffinityKeyFieldName); + holder = new BinaryTypeHolder(desc.TypeId, desc.TypeName, desc.AffinityKeyFieldName, desc.IsEnum); metas0[desc.TypeId] = holder; @@ -298,7 +313,7 @@ namespace Apache.Ignite.Core.Impl.Binary if (holder != null) { - ICollection ids = holder.FieldIds(); + ICollection ids = holder.GetFieldIds(); bool newType = ids.Count == 0 && !holder.Saved(); @@ -312,23 +327,20 @@ namespace Apache.Ignite.Core.Impl.Binary /// Callback invoked when metadata has been sent to the server and acknowledged by it. /// /// Binary types. - public void OnBinaryTypesSent(IDictionary newMetas) + public void OnBinaryTypesSent(IEnumerable newMetas) { - foreach (KeyValuePair metaEntry in newMetas) + foreach (var meta in newMetas) { - BinaryType meta = (BinaryType) metaEntry.Value; - - IDictionary> mergeInfo = - new Dictionary>(meta.FieldsMap().Count); + var mergeInfo = new Dictionary>(meta.GetFieldsMap().Count); - foreach (KeyValuePair fieldMeta in meta.FieldsMap()) + foreach (KeyValuePair fieldMeta in meta.GetFieldsMap()) { - int fieldId = BinaryUtils.FieldId(metaEntry.Key, fieldMeta.Key, null, null); + int fieldId = BinaryUtils.FieldId(meta.TypeId, fieldMeta.Key, null, null); mergeInfo[fieldId] = new Tuple(fieldMeta.Key, fieldMeta.Value); } - _metas[metaEntry.Key].Merge(mergeInfo); + _metas[meta.TypeId].Merge(mergeInfo); } } @@ -396,7 +408,7 @@ namespace Apache.Ignite.Core.Impl.Binary if (type != null) { // Type is found. - var typeName = GetTypeName(type); + var typeName = BinaryUtils.GetTypeName(type); int typeId = BinaryUtils.TypeId(typeName, nameMapper, idMapper); @@ -408,8 +420,15 @@ namespace Apache.Ignite.Core.Impl.Binary if (refSerializer != null) refSerializer.Register(type, typeId, nameMapper, idMapper); + if (typeCfg.IsEnum != type.IsEnum) + throw new BinaryObjectException( + string.Format( + "Invalid IsEnum flag in binary type configuration. " + + "Configuration value: IsEnum={0}, actual type: IsEnum={1}", + typeCfg.IsEnum, type.IsEnum)); + AddType(type, typeId, typeName, true, keepDeserialized, nameMapper, idMapper, serializer, - typeCfg.AffinityKeyFieldName); + typeCfg.AffinityKeyFieldName, type.IsEnum); } else { @@ -419,7 +438,7 @@ namespace Apache.Ignite.Core.Impl.Binary int typeId = BinaryUtils.TypeId(typeName, nameMapper, idMapper); AddType(null, typeId, typeName, true, keepDeserialized, nameMapper, idMapper, null, - typeCfg.AffinityKeyFieldName); + typeCfg.AffinityKeyFieldName, typeCfg.IsEnum); } } @@ -434,7 +453,7 @@ namespace Apache.Ignite.Core.Impl.Binary ? BinarizableSerializer.Instance : null; } - + /// /// Add type. /// @@ -447,9 +466,10 @@ namespace Apache.Ignite.Core.Impl.Binary /// ID mapper. /// Serializer. /// Affinity key field name. + /// Enum flag. private void AddType(Type type, int typeId, string typeName, bool userType, bool keepDeserialized, IBinaryNameMapper nameMapper, IBinaryIdMapper idMapper, - IBinarySerializer serializer, string affKeyFieldName) + IBinarySerializer serializer, string affKeyFieldName, bool isEnum) { long typeKey = BinaryUtils.TypeKey(userType, typeId); @@ -470,9 +490,8 @@ namespace Apache.Ignite.Core.Impl.Binary if (userType && _typeNameToDesc.ContainsKey(typeName)) throw new BinaryObjectException("Conflicting type name: " + typeName); - IBinaryTypeDescriptor descriptor = - new BinaryFullTypeDescriptor(type, typeId, typeName, userType, nameMapper, idMapper, serializer, - keepDeserialized, affKeyFieldName); + var descriptor = new BinaryFullTypeDescriptor(type, typeId, typeName, userType, nameMapper, idMapper, + serializer, keepDeserialized, affKeyFieldName, isEnum); if (type != null) _typeToDesc[type] = descriptor; @@ -492,7 +511,7 @@ namespace Apache.Ignite.Core.Impl.Binary var serializer = new BinarySystemTypeSerializer(ctor); - AddType(type, typeId, GetTypeName(type), false, false, null, null, serializer, null); + AddType(type, typeId, BinaryUtils.GetTypeName(type), false, false, null, null, serializer, null, false); } /// @@ -516,22 +535,5 @@ namespace Apache.Ignite.Core.Impl.Binary AddSystemType(BinaryUtils.TypeMessageListenerHolder, w => new MessageListenerHolder(w)); AddSystemType(BinaryUtils.TypeStreamReceiverHolder, w => new StreamReceiverHolder(w)); } - - /// - /// Gets the name of the type. - /// - /// The type. - /// - /// Simple type name for non-generic types; simple type name with appended generic arguments for generic types. - /// - private static string GetTypeName(Type type) - { - if (!type.IsGenericType) - return type.Name; - - var args = type.GetGenericArguments().Select(GetTypeName).Aggregate((x, y) => x + "," + y); - - return string.Format(CultureInfo.InvariantCulture, "{0}[{1}]", type.Name, args); - } } } http://git-wip-us.apache.org/repos/asf/ignite/blob/663e78dc/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Metadata/BinaryType.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Metadata/BinaryType.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Metadata/BinaryType.cs index 3e9a28d..476e651 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Metadata/BinaryType.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Metadata/BinaryType.cs @@ -27,9 +27,8 @@ namespace Apache.Ignite.Core.Impl.Binary.Metadata internal class BinaryType : IBinaryType { /** Empty metadata. */ - [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")] - public static readonly BinaryType EmptyMeta = - new BinaryType(BinaryUtils.TypeObject, BinaryTypeNames.TypeNameObject, null, null); + public static readonly BinaryType Empty = + new BinaryType(BinaryUtils.TypeObject, BinaryTypeNames.TypeNameObject, null, null, false); /** Empty dictionary. */ private static readonly IDictionary EmptyDict = new Dictionary(); @@ -37,82 +36,74 @@ namespace Apache.Ignite.Core.Impl.Binary.Metadata /** Empty list. */ private static readonly ICollection EmptyList = new List().AsReadOnly(); + /** Type name map. */ + private static readonly string[] TypeNames = new string[byte.MaxValue]; + /** Fields. */ private readonly IDictionary _fields; + /** Enum flag. */ + private readonly bool _isEnum; + + /** Type id. */ + private readonly int _typeId; + + /** Type name. */ + private readonly string _typeName; + + /** Aff key field name. */ + private readonly string _affinityKeyFieldName; + + /// + /// Initializes the class. + /// + static BinaryType() + { + TypeNames[BinaryUtils.TypeBool] = BinaryTypeNames.TypeNameBool; + TypeNames[BinaryUtils.TypeByte] = BinaryTypeNames.TypeNameByte; + TypeNames[BinaryUtils.TypeShort] = BinaryTypeNames.TypeNameShort; + TypeNames[BinaryUtils.TypeChar] = BinaryTypeNames.TypeNameChar; + TypeNames[BinaryUtils.TypeInt] = BinaryTypeNames.TypeNameInt; + TypeNames[BinaryUtils.TypeLong] = BinaryTypeNames.TypeNameLong; + TypeNames[BinaryUtils.TypeFloat] = BinaryTypeNames.TypeNameFloat; + TypeNames[BinaryUtils.TypeDouble] = BinaryTypeNames.TypeNameDouble; + TypeNames[BinaryUtils.TypeDecimal] = BinaryTypeNames.TypeNameDecimal; + TypeNames[BinaryUtils.TypeString] = BinaryTypeNames.TypeNameString; + TypeNames[BinaryUtils.TypeGuid] = BinaryTypeNames.TypeNameGuid; + TypeNames[BinaryUtils.TypeTimestamp] = BinaryTypeNames.TypeNameTimestamp; + TypeNames[BinaryUtils.TypeEnum] = BinaryTypeNames.TypeNameEnum; + TypeNames[BinaryUtils.TypeObject] = BinaryTypeNames.TypeNameObject; + TypeNames[BinaryUtils.TypeArrayBool] = BinaryTypeNames.TypeNameArrayBool; + TypeNames[BinaryUtils.TypeArrayByte] = BinaryTypeNames.TypeNameArrayByte; + TypeNames[BinaryUtils.TypeArrayShort] = BinaryTypeNames.TypeNameArrayShort; + TypeNames[BinaryUtils.TypeArrayChar] = BinaryTypeNames.TypeNameArrayChar; + TypeNames[BinaryUtils.TypeArrayInt] = BinaryTypeNames.TypeNameArrayInt; + TypeNames[BinaryUtils.TypeArrayLong] = BinaryTypeNames.TypeNameArrayLong; + TypeNames[BinaryUtils.TypeArrayFloat] = BinaryTypeNames.TypeNameArrayFloat; + TypeNames[BinaryUtils.TypeArrayDouble] = BinaryTypeNames.TypeNameArrayDouble; + TypeNames[BinaryUtils.TypeArrayDecimal] = BinaryTypeNames.TypeNameArrayDecimal; + TypeNames[BinaryUtils.TypeArrayString] = BinaryTypeNames.TypeNameArrayString; + TypeNames[BinaryUtils.TypeArrayGuid] = BinaryTypeNames.TypeNameArrayGuid; + TypeNames[BinaryUtils.TypeArrayTimestamp] = BinaryTypeNames.TypeNameArrayTimestamp; + TypeNames[BinaryUtils.TypeArrayEnum] = BinaryTypeNames.TypeNameArrayEnum; + TypeNames[BinaryUtils.TypeArray] = BinaryTypeNames.TypeNameArrayObject; + TypeNames[BinaryUtils.TypeCollection] = BinaryTypeNames.TypeNameCollection; + TypeNames[BinaryUtils.TypeDictionary] = BinaryTypeNames.TypeNameMap; + } + /// /// Get type name by type ID. /// /// Type ID. /// Type name. - private static string ConvertTypeName(int typeId) + private static string GetTypeName(int typeId) { - switch (typeId) - { - case BinaryUtils.TypeBool: - return BinaryTypeNames.TypeNameBool; - case BinaryUtils.TypeByte: - return BinaryTypeNames.TypeNameByte; - case BinaryUtils.TypeShort: - return BinaryTypeNames.TypeNameShort; - case BinaryUtils.TypeChar: - return BinaryTypeNames.TypeNameChar; - case BinaryUtils.TypeInt: - return BinaryTypeNames.TypeNameInt; - case BinaryUtils.TypeLong: - return BinaryTypeNames.TypeNameLong; - case BinaryUtils.TypeFloat: - return BinaryTypeNames.TypeNameFloat; - case BinaryUtils.TypeDouble: - return BinaryTypeNames.TypeNameDouble; - case BinaryUtils.TypeDecimal: - return BinaryTypeNames.TypeNameDecimal; - case BinaryUtils.TypeString: - return BinaryTypeNames.TypeNameString; - case BinaryUtils.TypeGuid: - return BinaryTypeNames.TypeNameGuid; - case BinaryUtils.TypeTimestamp: - return BinaryTypeNames.TypeNameTimestamp; - case BinaryUtils.TypeEnum: - return BinaryTypeNames.TypeNameEnum; - case BinaryUtils.TypeBinary: - case BinaryUtils.TypeObject: - return BinaryTypeNames.TypeNameObject; - case BinaryUtils.TypeArrayBool: - return BinaryTypeNames.TypeNameArrayBool; - case BinaryUtils.TypeArrayByte: - return BinaryTypeNames.TypeNameArrayByte; - case BinaryUtils.TypeArrayShort: - return BinaryTypeNames.TypeNameArrayShort; - case BinaryUtils.TypeArrayChar: - return BinaryTypeNames.TypeNameArrayChar; - case BinaryUtils.TypeArrayInt: - return BinaryTypeNames.TypeNameArrayInt; - case BinaryUtils.TypeArrayLong: - return BinaryTypeNames.TypeNameArrayLong; - case BinaryUtils.TypeArrayFloat: - return BinaryTypeNames.TypeNameArrayFloat; - case BinaryUtils.TypeArrayDouble: - return BinaryTypeNames.TypeNameArrayDouble; - case BinaryUtils.TypeArrayDecimal: - return BinaryTypeNames.TypeNameArrayDecimal; - case BinaryUtils.TypeArrayString: - return BinaryTypeNames.TypeNameArrayString; - case BinaryUtils.TypeArrayGuid: - return BinaryTypeNames.TypeNameArrayGuid; - case BinaryUtils.TypeArrayTimestamp: - return BinaryTypeNames.TypeNameArrayTimestamp; - case BinaryUtils.TypeArrayEnum: - return BinaryTypeNames.TypeNameArrayEnum; - case BinaryUtils.TypeArray: - return BinaryTypeNames.TypeNameArrayObject; - case BinaryUtils.TypeCollection: - return BinaryTypeNames.TypeNameCollection; - case BinaryUtils.TypeDictionary: - return BinaryTypeNames.TypeNameMap; - default: - throw new BinaryObjectException("Invalid type ID: " + typeId); - } + var typeName = (typeId >= 0 && typeId < TypeNames.Length) ? TypeNames[typeId] : null; + + if (typeName != null) + return typeName; + + throw new BinaryObjectException("Invalid type ID: " + typeId); } /// @@ -121,10 +112,22 @@ namespace Apache.Ignite.Core.Impl.Binary.Metadata /// The reader. public BinaryType(IBinaryRawReader reader) { - TypeId = reader.ReadInt(); - TypeName = reader.ReadString(); - AffinityKeyFieldName = reader.ReadString(); + _typeId = reader.ReadInt(); + _typeName = reader.ReadString(); + _affinityKeyFieldName = reader.ReadString(); _fields = reader.ReadDictionaryAsGeneric(); + _isEnum = reader.ReadBoolean(); + } + + /// + /// Initializes a new instance of the class. + /// + /// Descriptor. + /// Fields. + public BinaryType(IBinaryTypeDescriptor desc, IDictionary fields = null) + : this (desc.TypeId, desc.TypeName, fields, desc.AffinityKeyFieldName, desc.IsEnum) + { + // No-op. } /// @@ -134,25 +137,33 @@ namespace Apache.Ignite.Core.Impl.Binary.Metadata /// Type name. /// Fields. /// Affinity key field name. + /// Enum flag. public BinaryType(int typeId, string typeName, IDictionary fields, - string affKeyFieldName) + string affKeyFieldName, bool isEnum) { - TypeId = typeId; - TypeName = typeName; - AffinityKeyFieldName = affKeyFieldName; + _typeId = typeId; + _typeName = typeName; + _affinityKeyFieldName = affKeyFieldName; _fields = fields; + _isEnum = isEnum; } /// /// Type ID. /// /// - public int TypeId { get; private set; } + public int TypeId + { + get { return _typeId; } + } /// /// Gets type name. /// - public string TypeName { get; private set; } + public string TypeName + { + get { return _typeName; } + } /// /// Gets field names for that type. @@ -177,7 +188,7 @@ namespace Apache.Ignite.Core.Impl.Binary.Metadata _fields.TryGetValue(fieldName, out typeId); - return ConvertTypeName(typeId); + return GetTypeName(typeId); } return null; @@ -186,13 +197,22 @@ namespace Apache.Ignite.Core.Impl.Binary.Metadata /// /// Gets optional affinity key field name. /// - public string AffinityKeyFieldName { get; private set; } + public string AffinityKeyFieldName + { + get { return _affinityKeyFieldName; } + } + + /** */ + public bool IsEnum + { + get { return _isEnum; } + } /// /// Gets fields map. /// /// Fields map. - public IDictionary FieldsMap() + public IDictionary GetFieldsMap() { return _fields ?? EmptyDict; } http://git-wip-us.apache.org/repos/asf/ignite/blob/663e78dc/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Metadata/BinaryTypeHolder.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Metadata/BinaryTypeHolder.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Metadata/BinaryTypeHolder.cs index 524cda9..53ad77e 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Metadata/BinaryTypeHolder.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Metadata/BinaryTypeHolder.cs @@ -19,7 +19,6 @@ namespace Apache.Ignite.Core.Impl.Binary.Metadata { using System; using System.Collections.Generic; - using Apache.Ignite.Core.Binary; /// /// Metadata for particular type. @@ -35,11 +34,11 @@ namespace Apache.Ignite.Core.Impl.Binary.Metadata /** Affinity key field name. */ private readonly string _affKeyFieldName; - /** Empty metadata when nothig is know about object fields yet. */ - private readonly IBinaryType _emptyMeta; + /** Enum flag. */ + private readonly bool _isEnum; /** Collection of know field IDs. */ - private volatile ICollection _ids; + private volatile HashSet _ids; /** Last known unmodifiable metadata which is given to the user. */ private volatile BinaryType _meta; @@ -47,19 +46,19 @@ namespace Apache.Ignite.Core.Impl.Binary.Metadata /** Saved flag (set if type metadata was saved at least once). */ private volatile bool _saved; + /// /// Constructor. /// /// Type ID. /// Type name. /// Affinity key field name. - public BinaryTypeHolder(int typeId, string typeName, string affKeyFieldName) + public BinaryTypeHolder(int typeId, string typeName, string affKeyFieldName, bool isEnum) { _typeId = typeId; _typeName = typeName; _affKeyFieldName = affKeyFieldName; - - _emptyMeta = new BinaryType(typeId, typeName, null, affKeyFieldName); + _isEnum = isEnum; } /// @@ -72,21 +71,12 @@ namespace Apache.Ignite.Core.Impl.Binary.Metadata } /// - /// Get current type metadata. - /// - /// Type metadata. - public IBinaryType BinaryType - { - get { return _meta ?? _emptyMeta; } - } - - /// /// Currently cached field IDs. /// /// Cached field IDs. - public ICollection FieldIds() + public ICollection GetFieldIds() { - ICollection ids0 = _ids; + var ids0 = _ids; if (_ids == null) { @@ -120,13 +110,13 @@ namespace Apache.Ignite.Core.Impl.Binary.Metadata lock (this) { // 1. Create copies of the old meta. - ICollection ids0 = _ids; + var ids0 = _ids; BinaryType meta0 = _meta; - ICollection newIds = ids0 != null ? new HashSet(ids0) : new HashSet(); + var newIds = ids0 != null ? new HashSet(ids0) : new HashSet(); IDictionary newFields = meta0 != null ? - new Dictionary(meta0.FieldsMap()) : new Dictionary(newMap.Count); + new Dictionary(meta0.GetFieldsMap()) : new Dictionary(newMap.Count); // 2. Add new fields. foreach (KeyValuePair> newEntry in newMap) @@ -139,7 +129,7 @@ namespace Apache.Ignite.Core.Impl.Binary.Metadata } // 3. Assign new meta. Order is important here: meta must be assigned before field IDs. - _meta = new BinaryType(_typeId, _typeName, newFields, _affKeyFieldName); + _meta = new BinaryType(_typeId, _typeName, newFields, _affKeyFieldName, _isEnum); _ids = newIds; } } http://git-wip-us.apache.org/repos/asf/ignite/blob/663e78dc/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Structure/BinaryStructureTracker.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Structure/BinaryStructureTracker.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Structure/BinaryStructureTracker.cs index 37d980e..af1b050 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Structure/BinaryStructureTracker.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Structure/BinaryStructureTracker.cs @@ -111,7 +111,7 @@ namespace Apache.Ignite.Core.Impl.Binary.Structure var meta = metaHnd.OnObjectWriteFinished(); if (meta != null) - writer.SaveMetadata(_desc.TypeId, _desc.TypeName, _desc.AffinityKeyFieldName, meta); + writer.SaveMetadata(_desc, meta); } } } http://git-wip-us.apache.org/repos/asf/ignite/blob/663e78dc/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs index ded671a..2fcada3 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs @@ -31,6 +31,7 @@ namespace Apache.Ignite.Core.Impl using Apache.Ignite.Core.DataStructures; using Apache.Ignite.Core.Events; using Apache.Ignite.Core.Impl.Binary; + using Apache.Ignite.Core.Impl.Binary.Metadata; using Apache.Ignite.Core.Impl.Cache; using Apache.Ignite.Core.Impl.Cluster; using Apache.Ignite.Core.Impl.Common; @@ -66,7 +67,7 @@ namespace Apache.Ignite.Core.Impl private readonly ClusterGroupImpl _prj; /** Binary. */ - private readonly IgniteBinary _igniteBinary; + private readonly Binary.Binary _binary; /** Cached proxy. */ private readonly IgniteProxy _proxy; @@ -117,7 +118,7 @@ namespace Apache.Ignite.Core.Impl _prj = new ClusterGroupImpl(proc, UU.ProcessorProjection(proc), marsh, this, null); - _igniteBinary = new IgniteBinary(marsh); + _binary = new Binary.Binary(marsh); _proxy = new IgniteProxy(this); @@ -394,9 +395,9 @@ namespace Apache.Ignite.Core.Impl } /** */ - public IIgniteBinary GetBinary() + public IBinary GetBinary() { - return _igniteBinary; + return _binary; } /** */ @@ -472,7 +473,7 @@ namespace Apache.Ignite.Core.Impl /// Put metadata to Grid. /// /// Metadata. - internal void PutBinaryTypes(IDictionary metas) + internal void PutBinaryTypes(ICollection metas) { _prj.PutBinaryTypes(metas); } http://git-wip-us.apache.org/repos/asf/ignite/blob/663e78dc/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs index 113f700..36aac1a 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs @@ -275,7 +275,7 @@ namespace Apache.Ignite.Core.Impl } /** */ - public IIgniteBinary GetBinary() + public IBinary GetBinary() { return _ignite.GetBinary(); } http://git-wip-us.apache.org/repos/asf/ignite/blob/663e78dc/modules/platforms/dotnet/Apache.Ignite.Core/Impl/PlatformTarget.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/PlatformTarget.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/PlatformTarget.cs index 115f30d..4a4f93b 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/PlatformTarget.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/PlatformTarget.cs @@ -23,7 +23,6 @@ namespace Apache.Ignite.Core.Impl using System.Diagnostics.CodeAnalysis; using System.IO; using System.Threading.Tasks; - using Apache.Ignite.Core.Binary; using Apache.Ignite.Core.Impl.Binary; using Apache.Ignite.Core.Impl.Binary.IO; using Apache.Ignite.Core.Impl.Binary.Metadata; @@ -581,7 +580,7 @@ namespace Apache.Ignite.Core.Impl /// Put binary types to Grid. /// /// Binary types. - internal void PutBinaryTypes(IDictionary types) + internal void PutBinaryTypes(ICollection types) { DoOutOp(OpMeta, stream => { @@ -589,15 +588,15 @@ namespace Apache.Ignite.Core.Impl metaWriter.WriteInt(types.Count); - foreach (var meta in types.Values) + foreach (var meta in types) { - BinaryType meta0 = (BinaryType)meta; + BinaryType meta0 = meta; metaWriter.WriteInt(meta0.TypeId); metaWriter.WriteString(meta0.TypeName); metaWriter.WriteString(meta0.AffinityKeyFieldName); - IDictionary fields = meta0.FieldsMap(); + IDictionary fields = meta0.GetFieldsMap(); metaWriter.WriteInt(fields.Count); @@ -606,6 +605,8 @@ namespace Apache.Ignite.Core.Impl metaWriter.WriteString(field.Key); metaWriter.WriteInt(field.Value); } + + metaWriter.WriteBoolean(meta.IsEnum); } _marsh.FinishMarshal(metaWriter); http://git-wip-us.apache.org/repos/asf/ignite/blob/663e78dc/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Transactions/TransactionsImpl.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Transactions/TransactionsImpl.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Transactions/TransactionsImpl.cs index a27bffe..0bc7172 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Transactions/TransactionsImpl.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Transactions/TransactionsImpl.cs @@ -67,8 +67,8 @@ namespace Apache.Ignite.Core.Impl.Transactions { var reader = marsh.StartUnmarshal(stream).GetRawReader(); - concurrency = reader.ReadEnum(); - isolation = reader.ReadEnum(); + concurrency = (TransactionConcurrency) reader.ReadInt(); + isolation = (TransactionIsolation) reader.ReadInt(); timeout = TimeSpan.FromMilliseconds(reader.ReadLong()); }); http://git-wip-us.apache.org/repos/asf/ignite/blob/663e78dc/modules/platforms/dotnet/examples/Config/example-cache-query.xml ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/examples/Config/example-cache-query.xml b/modules/platforms/dotnet/examples/Config/example-cache-query.xml index a3b854b..5bc9399 100644 --- a/modules/platforms/dotnet/examples/Config/example-cache-query.xml +++ b/modules/platforms/dotnet/examples/Config/example-cache-query.xml @@ -38,7 +38,14 @@ Apache.Ignite.ExamplesDll.Binary.Employee Apache.Ignite.ExamplesDll.Binary.EmployeeKey Apache.Ignite.ExamplesDll.Binary.Organization - Apache.Ignite.ExamplesDll.Binary.OrganizationType + + + + + + + + http://git-wip-us.apache.org/repos/asf/ignite/blob/663e78dc/modules/platforms/dotnet/examples/Config/example-cache.xml ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/examples/Config/example-cache.xml b/modules/platforms/dotnet/examples/Config/example-cache.xml index 21a6a76..949f3a4 100644 --- a/modules/platforms/dotnet/examples/Config/example-cache.xml +++ b/modules/platforms/dotnet/examples/Config/example-cache.xml @@ -37,7 +37,14 @@ Apache.Ignite.ExamplesDll.Binary.Employee Apache.Ignite.ExamplesDll.Binary.EmployeeKey Apache.Ignite.ExamplesDll.Binary.Organization - Apache.Ignite.ExamplesDll.Binary.OrganizationType + + + + + + + +