Beispiel #1
0
 /// <summary>
 /// Indicates whether field with specified <paramref name="fieldIndex"/> is changed.
 /// </summary>
 /// <param name="fieldIndex">Index of the field to check.</param>
 /// <returns><see langword="True"/> if specified field is changed;
 /// otherwise, <see langword="false"/>.</returns>
 public bool IsChanged(int fieldIndex)
 {
     if (difference == null)
     {
         return(false);
     }
     return(difference.GetFieldState(fieldIndex).IsAvailable());
 }
Beispiel #2
0
 protected bool IsFieldAvailable(FieldInfo field)
 {
     if (field.ReflectedType.IsInterface)
     {
         field = TypeInfo.FieldMap[field];
     }
     return(Tuple.GetFieldState(field.MappingInfo.Offset).IsAvailable());
 }
        public void MainTest()
        {
            using (var session = Domain.OpenSession()) {
                using (var t = session.OpenTransaction()) {
                    Book  b     = session.Query.SingleOrDefault <Book>(key);
                    Tuple tuple = b.Tuple;

                    Assert.IsTrue(tuple.GetFieldState(2).IsAvailable());
                    Assert.IsFalse(tuple.GetFieldState(3).IsAvailable());
                    Assert.AreEqual(TITLE, b.Title);
                    Assert.IsFalse(tuple.GetFieldState(3).IsAvailable());

                    // Fetching lazy load field
                    Assert.AreEqual(TEXT, b.Text);
                    t.Complete();
                }
            }
        }
Beispiel #4
0
 public static bool IsAtLeastOneColumAvailable(this Tuple target, Segment <int> segment)
 {
     for (int i = segment.Offset; i < segment.EndOffset; i++)
     {
         var state = target.GetFieldState(i);
         if (state.IsAvailable())
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #5
0
 public static bool ContainsNonEmptyValues(this Tuple target, Segment <int> segment)
 {
     for (int i = segment.Offset; i < segment.EndOffset; i++)
     {
         var state = target.GetFieldState(i);
         if (state.HasValue())
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #6
0
 public static bool ContainsNonEmptyValues(this Tuple target)
 {
     for (int i = 0; i < target.Count; i++)
     {
         var state = target.GetFieldState(i);
         if (state.HasValue())
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #7
0
        private static void MergeTuplesPreferOriginSlow(Tuple origin, Tuple difference, int startIndex, int length)
        {
            var bound = startIndex + length;

            for (int index = startIndex; index < bound; index++)
            {
                TupleFieldState fieldState;
                if (!origin.GetFieldState(index).IsAvailable())
                {
                    CopyValue(difference, index, origin, index);
                }
            }
        }
Beispiel #8
0
        public static bool IsValidKeyTuple(Tuple tuple)
        {
            var limit = tuple.Descriptor.Count;

            for (int i = 0; i < limit; i++)
            {
                if (tuple.GetFieldState(i).IsNull())
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #9
0
        /// <summary>
        /// Gets the field state map of the specified <see cref="Tuple"/>.
        /// </summary>
        /// <param name="target">The <see cref="Tuple"/> to inspect.</param>
        /// <param name="requestedState">The state to compare with.</param>
        /// <returns>Newly created <see cref="BitArray"/> instance which holds inspection result.</returns>
        public static BitArray GetFieldStateMap(this Tuple target, TupleFieldState requestedState)
        {
            var count  = target.Descriptor.Count;
            var result = new BitArray(count);

            switch (requestedState)
            {
            case TupleFieldState.Default:
                for (int i = 0; i < count; i++)
                {
                    result[i] = target.GetFieldState(i) == 0;
                }
                break;

            default:
                for (int i = 0; i < count; i++)
                {
                    result[i] = (requestedState & target.GetFieldState(i)) != 0;
                }
                break;
            }
            return(result);
        }
Beispiel #10
0
        public static bool IsValidKeyTuple(Tuple tuple, int[] keyIndexes)
        {
            if (keyIndexes == null)
            {
                return(IsValidKeyTuple(tuple));
            }
            var limit = keyIndexes.Length;

            for (int i = 0; i < limit; i++)
            {
                if (tuple.GetFieldState(keyIndexes[i]).IsNull())
                {
                    return(false);
                }
            }
            return(true);
        }
 public static bool IsNull(Tuple tuple, int[] columns)
 {
     return(columns.Aggregate(true, (current, column) => current & tuple.GetFieldState(column).IsNull()));
 }
Beispiel #12
0
        private static void TestTuple(Xtensive.Tuples.Tuple tuple)
        {
            Assert.IsFalse(tuple.GetFieldState(0).IsAvailable());

            try {
                tuple.GetFieldState(0).IsNull();
                throw new AssertionException("Value is not available. No one knows if it is null or not.");
            } catch (InvalidOperationException) {
            }

            tuple.SetValue(0, 1);
            Assert.IsTrue(tuple.GetFieldState(0).IsAvailable());
            Assert.IsFalse(tuple.GetFieldState(0).IsNull());
            Assert.IsTrue(tuple.GetFieldState(0).HasValue());
            Assert.AreEqual(1, tuple.GetValue(0));
            Assert.AreEqual(1, tuple.GetValue <int>(0));
            Assert.AreEqual(new int?(1), tuple.GetValue <int?>(0));

            tuple.SetValue(0, null);
            Assert.IsTrue(tuple.GetFieldState(0).IsAvailable());
            Assert.IsTrue(tuple.GetFieldState(0).IsNull());
            Assert.IsFalse(tuple.GetFieldState(0).HasValue());
            Assert.AreEqual(null, tuple.GetValue(0));
            Assert.AreEqual(null, tuple.GetValue <int?>(0));

            tuple.SetValue <int?>(0, null);
            Assert.IsTrue(tuple.GetFieldState(0).IsAvailable());
            Assert.IsTrue(tuple.GetFieldState(0).IsNull());
            Assert.IsFalse(tuple.GetFieldState(0).HasValue());
            Assert.AreEqual(null, tuple.GetValue(0));
            Assert.AreEqual(null, tuple.GetValue <int?>(0));
            Assert.AreEqual(null, tuple.GetValueOrDefault(0));
            Assert.AreEqual(null, tuple.GetValueOrDefault <int?>(0));

            try {
                tuple.GetValue(1);
                throw new AssertionException("Value should not be available.");
            } catch (InvalidOperationException) {
            }

            try {
                tuple.GetValue <string>(2);
                throw new AssertionException("Value should not be available.");
            } catch (InvalidOperationException) {
            }

            try {
                tuple.GetValue <byte>(0);
                throw new AssertionException("Null reference or Invalid cast exception should be thrown.");
            }
            catch (NullReferenceException) {}
            catch (InvalidCastException) {}

            Assert.IsTrue(tuple.Equals(tuple));
        }
Beispiel #13
0
 public override bool CanMaterialize(Tuple tuple) =>
 aggregateType == AggregateType.Sum || (tuple.GetFieldState(0) & TupleFieldState.Null) == 0;
 public static bool IsNull(Tuple tuple, int[] columns) =>
 columns.All(column => tuple.GetFieldState(column).IsNull());
        public void Main()
        {
            Tuple t = Tuple.Create <int, string>(0, null);

            Assert.IsTrue(t.GetFieldState(0).IsAvailable());
            Assert.IsFalse(t.GetFieldState(0).IsNull());
            Assert.IsTrue(t.GetFieldState(1).IsAvailable());
            Assert.IsTrue(t.GetFieldState(1).IsNull());
            t.SetValue(0, null);
            t.SetValue(1, null);
            Assert.IsTrue(t.GetFieldState(0).IsAvailable());
            Assert.IsTrue(t.GetFieldState(1).IsAvailable());
            Assert.IsTrue(t.GetFieldState(0).IsNull());
            Assert.IsTrue(t.GetFieldState(1).IsNull());
            t.SetValue(0, new int?(32));
            Assert.IsTrue(t.GetFieldState(0).IsAvailable());
            Assert.IsFalse(t.GetFieldState(0).IsNull());
            t.SetValue(0, (int?)null);
            Assert.IsTrue(t.GetFieldState(0).IsAvailable());
            Assert.IsTrue(t.GetFieldState(0).IsNull());
        }
Beispiel #16
0
 /// <inheritdoc/>
 public override TupleFieldState GetFieldState(int fieldIndex)
 {
     return(InnerTuple.GetFieldState(fieldIndex));
 }
Beispiel #17
0
        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);
        }