public override Tuple GenerateKey(KeyInfo keyInfo, Session session) { return(Tuple.Create(seed++, seed++)); }
/// <summary> /// Converts the <paramref name="source"/> <see cref="Tuple"/> to /// its string representation. /// </summary> /// <param name="source">The tuple to convert.</param> /// <param name="format">Indicates whether to use <see cref="Format"/>, /// or <see cref="Tuple.ToString"/> method.</param> /// <returns>String representation of <paramref name="source"/> <see cref="Tuple"/>.</returns> public static string ToString(this Tuple source, bool format) { return(format ? source.Format() : source.ToString()); }
public abstract void Execute(Tuple source, string[] targets, int fieldIndex);
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); }
public abstract void Execute(string[] source, Tuple target, int fieldIndex);
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)); }
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)); }
/// <summary> /// Extracts the key part from <paramref name="tuple"/> using <see cref="OrderKeyExtractorTransform"/>. /// </summary> /// <param name="tuple">The tuple to extract the key from.</param> /// <returns>A tuple containing extracted order key.</returns> public Tuple OrderKeyExtractor(Tuple tuple) { return(OrderKeyExtractorTransform.Apply(TupleTransformType.Auto, tuple)); }
/// <summary> /// Initializes a new instance of this class. /// </summary> /// <param name="source">The <see cref="UnaryProvider.Source"/> property value.</param> /// <param name="key">Wrapped to <see cref="Key"/> property value.</param> public SeekProvider(CompilableProvider source, Tuple key) : base(ProviderType.Seek, source) { Key = () => key; Initialize(); }
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); }
/// <summary> /// Creates <see cref="Key"/> instance /// for the specified <see cref="Entity"/> <paramref name="type"/>, /// with specified <paramref name="value"/>, <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="value">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] Tuple value) { ArgumentValidator.EnsureArgumentNotNull(domain, "domain"); ArgumentValidator.EnsureArgumentNotNull(type, "type"); ArgumentValidator.EnsureArgumentNotNull(value, "value"); return(Create(domain, nodeId, domain.Model.Types[type], accuracy, value)); }
/// <summary> /// Creates <see cref="Key"/> instance /// for the specified <see cref="Entity"/> <paramref name="type"/>, /// with specified <paramref name="value"/> 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="value">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] Tuple value) { return(Create(domain, WellKnown.DefaultNodeId, type, accuracy, value)); }
/// <summary> /// Creates <see cref="Key"/> instance /// for the specified <see cref="Entity"/> type <typeparamref name="T"/> /// and with specified <paramref name="value"/>. /// </summary> /// <typeparam name="T">Type of <see cref="Entity"/> descendant to get <see cref="Key"/> for.</typeparam> /// <param name="domain">Domain to use.</param> /// <param name="value">Key value.</param> /// <returns> /// A newly created or existing <see cref="Key"/> instance. /// </returns> public static Key Create <T>([NotNull] Domain domain, [NotNull] Tuple value) where T : IEntity { return(Create(domain, WellKnown.DefaultNodeId, typeof(T), TypeReferenceAccuracy.BaseType, value)); }
internal Tuple CreateTuple() { var descriptor = TypeReference.Type.Key.TupleDescriptor; return(Tuple.Create(descriptor)); }
public void FieldAccessTest() { const int iterationCount = 10000000; TupleDescriptor descriptor = TupleDescriptor.Create(shortFieldTypes); Tuple tuple = Tuple.Create(descriptor); for (int i = 0; i < iterationCount; i++) { tuple.SetValue(0, (object)i); } for (int i = 0; i < iterationCount; i++) { TupleFieldState state; tuple.GetValue(0, out state); } for (int i = 0; i < iterationCount; i++) { tuple.SetValue(0, i); } for (int i = 0; i < iterationCount; i++) { tuple.GetValue <int>(0); } for (int i = 0; i < iterationCount; i++) { TupleFieldState state; tuple.GetValue <int>(0, out state); } for (int i = 0; i < iterationCount; i++) { TupleFieldState state; tuple.GetValue <int?>(0, out state); } using (new Measurement("Tuple.SetValue?", iterationCount)) for (int i = 0; i < iterationCount; i++) { tuple.SetValue(0, null); } using (new Measurement("Tuple.SetValue", iterationCount)) for (int i = 0; i < iterationCount; i++) { tuple.SetValue(0, (object)i); } using (new Measurement("Tuple.GetValue", iterationCount)) for (int i = 0; i < iterationCount; i++) { tuple.GetValue(0); } using (new Measurement("Tuple.GetValue(_,_)", iterationCount)) for (int i = 0; i < iterationCount; i++) { TupleFieldState state; tuple.GetValue(0, out state); } using (new Measurement("Tuple.GetValueOrDefault", iterationCount)) for (int i = 0; i < iterationCount; i++) { tuple.GetValueOrDefault(0); } using (new Measurement("Tuple.SetValue<T>", iterationCount)) for (int i = 0; i < iterationCount; i++) { tuple.SetValue(0, i); } using (new Measurement("Tuple.GetValue<T>", iterationCount)) for (int i = 0; i < iterationCount; i++) { tuple.GetValue <int>(0); } using (new Measurement("Tuple.GetValue<T>(_,_)", iterationCount)) for (int i = 0; i < iterationCount; i++) { TupleFieldState state; tuple.GetValue <int>(0, out state); } using (new Measurement("Tuple.GetValueOrDefault<T>", iterationCount)) for (int i = 0; i < iterationCount; i++) { tuple.GetValueOrDefault <int>(0); } using (new Measurement("Tuple.SetValue<T?>", iterationCount)) for (int i = 0; i < iterationCount; i++) { tuple.SetValue(0, new int?(i)); } using (new Measurement("Tuple.GetValue<T?>", iterationCount)) for (int i = 0; i < iterationCount; i++) { tuple.GetValue <int?>(0); } using (new Measurement("Tuple.GetValue<T?>(_,_)", iterationCount)) for (int i = 0; i < iterationCount; i++) { TupleFieldState state; tuple.GetValue <int?>(0, out state); } using (new Measurement("Tuple.GetValueOrDefault<T?>", iterationCount)) for (int i = 0; i < iterationCount; i++) { tuple.GetValueOrDefault <int?>(0); } }