// Constructors private Key(string nodeId, TypeInfo type, TypeReferenceAccuracy accuracy, T1 value1, T2 value2, T3 value3) : base(nodeId, type, accuracy, null) { this.value1 = value1; this.value2 = value2; this.value3 = value3; }
// Constructors /// <summary> /// Initializes a new instance of this class. /// </summary> /// <param name="nodeId">Identifier of a <see cref="StorageNode"/>.</param> /// <param name="type">The type.</param> /// <param name="accuracy">The type reference accuracy.</param> /// <param name="value">The value.</param> protected Key(string nodeId, TypeInfo type, TypeReferenceAccuracy accuracy, Tuple value) { NodeId = nodeId; TypeReference = new TypeReference(type, accuracy); this.value = value; }
public static Key Create(string nodeId, TypeInfo type, Tuple tuple, TypeReferenceAccuracy accuracy, int[] keyIndexes) { return(new Key <T1, T2, T3>(nodeId, type, accuracy, tuple.GetValueOrDefault <T1>(keyIndexes[0]), tuple.GetValueOrDefault <T2>(keyIndexes[1]), tuple.GetValueOrDefault <T3>(keyIndexes[2]))); }
public static Key Create(string nodeId, TypeInfo type, Tuple tuple, TypeReferenceAccuracy accuracy) { return(new Key <T1, T2, T3>(nodeId, type, accuracy, tuple.GetValueOrDefault <T1>(0), tuple.GetValueOrDefault <T2>(1), tuple.GetValueOrDefault <T3>(2))); }
internal static Key Create(Domain domain, string nodeId, TypeInfo type, TypeReferenceAccuracy accuracy, object[] values) { return(KeyFactory.Materialize(domain, nodeId, type, accuracy, values)); }
/// <summary> /// Creates <see cref="Key"/> instance /// for the specified <see cref="Entity"/> <paramref name="type"/>, /// with specified <paramref name="values"/>, <paramref name="accuracy"/> and <paramref name="nodeId"/>. /// </summary> /// <param name="domain">Domain to use.</param> /// <param name="nodeId">Node identifier to use.</param> /// <param name="type">Entity type.</param> /// <param name="accuracy">Key accuracy.</param> /// <param name="values">Key values.</param> /// <returns>A newly created or existing <see cref="Key"/> instance.</returns> public static Key Create([NotNull] Domain domain, [NotNull] string nodeId, [NotNull] Type type, TypeReferenceAccuracy accuracy, [NotNull] params object[] values) { ArgumentValidator.EnsureArgumentNotNull(domain, "domain"); ArgumentValidator.EnsureArgumentNotNull(nodeId, "nodeId"); ArgumentValidator.EnsureArgumentNotNull(type, "type"); ArgumentValidator.EnsureArgumentNotNull(values, "values"); return(Create(domain, nodeId, domain.Model.Types[type], accuracy, values)); }
/// <summary> /// Creates <see cref="Key"/> instance /// for the specified <see cref="Entity"/> <paramref name="type"/>, /// with specified <paramref name="values"/> and <paramref name="accuracy"/>. /// </summary> /// <param name="domain">Domain to use.</param> /// <param name="type">Entity type.</param> /// <param name="accuracy">Key accuracy.</param> /// <param name="values">Key values.</param> /// <returns>A newly created or existing <see cref="Key"/> instance.</returns> public static Key Create([NotNull] Domain domain, [NotNull] Type type, TypeReferenceAccuracy accuracy, [NotNull] params object[] values) { return(Create(domain, WellKnown.DefaultNodeId, type, accuracy, values)); }
internal static Key Create(Domain domain, string nodeId, TypeInfo type, TypeReferenceAccuracy accuracy, Tuple value) { return(KeyFactory.Materialize(domain, nodeId, type, value, accuracy, false, null)); }
public static int ExtractTypeId(TypeInfo type, TypeIdRegistry typeIdRegistry, Tuple tuple, int typeIdIndex, out TypeReferenceAccuracy accuracy) { accuracy = TypeReferenceAccuracy.Hierarchy; if (type.IsInterface) { accuracy = TypeReferenceAccuracy.BaseType; } if (typeIdIndex < 0) { if (type.IsLeaf) { accuracy = TypeReferenceAccuracy.ExactType; } return(typeIdRegistry.GetTypeId(type)); } accuracy = TypeReferenceAccuracy.ExactType; TupleFieldState state; var value = tuple.GetValue <int>(typeIdIndex, out state); if (type.IsLeaf) { return(state.HasValue() ? typeIdRegistry.GetTypeId(type) : TypeInfo.NoTypeId); } // Hack here: 0 (default) = TypeInfo.NoTypeId return(value); }
// Constructors private Key(string nodeId, TypeInfo type, TypeReferenceAccuracy accuracy, T value) : base(nodeId, type, accuracy, null) { value1 = value; }
public static Key Materialize(Domain domain, string nodeId, TypeInfo type, Tuple value, TypeReferenceAccuracy accuracy, bool canCache, int[] keyIndexes) { var hierarchy = type.Hierarchy; var keyInfo = type.Key; if (keyIndexes == null) { if (value.Descriptor != keyInfo.TupleDescriptor) { throw new ArgumentException(Strings.ExWrongKeyStructure); } if (accuracy == TypeReferenceAccuracy.ExactType) { int typeIdColumnIndex = keyInfo.TypeIdColumnIndex; if (typeIdColumnIndex >= 0 && !value.GetFieldState(typeIdColumnIndex).IsAvailable()) { // Ensures TypeId is filled in into Keys of newly created Entities value.SetValue(typeIdColumnIndex, type.TypeId); } } } if (hierarchy != null && hierarchy.Root.IsLeaf) { accuracy = TypeReferenceAccuracy.ExactType; canCache = false; // No reason to cache } Key key; var isGenericKey = keyInfo.TupleDescriptor.Count <= WellKnown.MaxGenericKeyLength; if (isGenericKey) { key = CreateGenericKey(domain, nodeId, type, accuracy, value, keyIndexes); } else { if (keyIndexes != null) { throw Exceptions.InternalError(Strings.ExKeyIndexesAreSpecifiedForNonGenericKey, OrmLog.Instance); } key = new LongKey(nodeId, type, accuracy, value); } if (!canCache) { return(key); } var keyCache = domain.KeyCache; lock (keyCache) { Key foundKey; if (keyCache.TryGetItem(key, true, out foundKey)) { key = foundKey; } else { if (accuracy == TypeReferenceAccuracy.ExactType) { keyCache.Add(key); } } } return(key); }
private static Key CreateGenericKey(Domain domain, string nodeId, TypeInfo type, TypeReferenceAccuracy accuracy, Tuple tuple, int[] keyIndexes) { var keyTypeInfo = domain.GenericKeyFactories.GetOrAdd(type, BuildGenericKeyFactory); if (keyIndexes == null) { return(keyTypeInfo.DefaultConstructor(nodeId, type, tuple, accuracy)); } return(keyTypeInfo.KeyIndexBasedConstructor(nodeId, type, tuple, accuracy, keyIndexes)); }
public static Key Materialize(Domain domain, string nodeId, TypeInfo type, TypeReferenceAccuracy accuracy, params object[] values) { var keyInfo = type.Key; ArgumentValidator.EnsureArgumentIsInRange(values.Length, 1, keyInfo.TupleDescriptor.Count, "values"); var tuple = Tuple.Create(keyInfo.TupleDescriptor); int typeIdIndex = keyInfo.TypeIdColumnIndex; if (typeIdIndex >= 0) { tuple.SetValue(typeIdIndex, type.TypeId); } int tupleIndex = 0; if (tupleIndex == typeIdIndex) { tupleIndex++; } for (int valueIndex = 0; valueIndex < values.Length; valueIndex++) { var value = values[valueIndex]; ArgumentValidator.EnsureArgumentNotNull(value, String.Format("values[{0}]", valueIndex)); var entity = value as Entity; if (entity != null) { entity.EnsureNotRemoved(); value = entity.Key; } var key = value as Key; if (key != null) { if (key.TypeReference.Type.Hierarchy == type.Hierarchy) { typeIdIndex = -1; // Key must be fully copied in this case } for (int keyIndex = 0; keyIndex < key.Value.Count; keyIndex++) { tuple.SetValue(tupleIndex++, key.Value.GetValueOrDefault(keyIndex)); if (tupleIndex == typeIdIndex) { tupleIndex++; } } continue; } tuple.SetValue(tupleIndex++, value); if (tupleIndex == typeIdIndex) { tupleIndex++; } } if (tupleIndex != tuple.Count) { throw new ArgumentException(String.Format( Strings.ExSpecifiedValuesArentEnoughToCreateKeyForTypeX, type.Name)); } return(Materialize(domain, nodeId, type, tuple, accuracy, false, null)); }
// Constructor /// <summary> /// Initializes a new instance of this class. /// </summary> /// <param name="type">The referenced type.</param> /// <param name="accuracy">The type reference accuracy.</param> public TypeReference(TypeInfo type, TypeReferenceAccuracy accuracy) : this() { Type = type; Accuracy = accuracy; }
// Constructors internal LongKey(string nodeId, TypeInfo type, TypeReferenceAccuracy accuracy, Tuple value) : base(nodeId, type, accuracy, value) { }