/// <summary> /// Updates or creates cached binary type holder. /// </summary> private void UpdateOrCreateBinaryTypeHolder(BinaryType meta) { BinaryTypeHolder holder; if (_metas.TryGetValue(meta.TypeId, out holder)) { holder.Merge(meta); return; } lock (this) { if (_metas.TryGetValue(meta.TypeId, out holder)) { holder.Merge(meta); return; } var metas0 = new Dictionary <int, BinaryTypeHolder>(_metas); holder = new BinaryTypeHolder(meta.TypeId, meta.TypeName, meta.AffinityKeyFieldName, meta.IsEnum, this); holder.Merge(meta); metas0[meta.TypeId] = holder; _metas = metas0; } }
/// <summary> /// Gets binary type handler for the given type ID. /// </summary> /// <param name="desc">Type descriptor.</param> /// <returns>Binary type handler.</returns> public IBinaryTypeHandler GetBinaryTypeHandler(IBinaryTypeDescriptor desc) { BinaryTypeHolder holder; if (!_metas.TryGetValue(desc.TypeId, out holder)) { lock (this) { if (!_metas.TryGetValue(desc.TypeId, out holder)) { IDictionary <int, BinaryTypeHolder> metas0 = new Dictionary <int, BinaryTypeHolder>(_metas); holder = new BinaryTypeHolder(desc.TypeId, desc.TypeName, desc.AffinityKeyFieldName, desc.IsEnum); metas0[desc.TypeId] = holder; _metas = metas0; } } } if (holder != null) { ICollection <int> ids = holder.GetFieldIds(); bool newType = ids.Count == 0 && !holder.Saved(); return(new BinaryTypeHashsetHandler(ids, newType)); } return(null); }
/// <summary> /// Gets the binary type holder. /// </summary> /// <param name="desc">Descriptor.</param> /// <returns>Holder</returns> private BinaryTypeHolder GetBinaryTypeHolder(IBinaryTypeDescriptor desc) { BinaryTypeHolder holder; if (_metas.TryGetValue(desc.TypeId, out holder)) { return(holder); } lock (this) { if (!_metas.TryGetValue(desc.TypeId, out holder)) { var metas0 = new Dictionary <int, BinaryTypeHolder>(_metas); holder = new BinaryTypeHolder(desc.TypeId, desc.TypeName, desc.AffinityKeyFieldName, desc.IsEnum, this); metas0[desc.TypeId] = holder; _metas = metas0; } } return(holder); }
/// <summary> /// Checks whether all field ids from provided schema are present in the given binary type. /// </summary> private static bool HasAllFields(BinaryTypeHolder binaryTypeHolder, int[] schema) { var fieldIds = binaryTypeHolder.GetFieldIds(); foreach (var fieldId in schema) { if (!fieldIds.Contains(fieldId)) { return(false); } } return(true); }