Esempio n. 1
0
        // Constructors

        /// <summary>
        /// Initializes a new instance of this class.
        /// </summary>
        /// <param name="owner">Persistent this entity set belongs to.</param>
        /// <param name="field">Field corresponds to this entity set.</param>
        protected EntitySetBase(Entity owner, FieldInfo field)
            : base(owner.Session)
        {
            this.owner = owner;
            Field      = field;
            State      = new EntitySetState(this);
            var association = Field.Associations.Last();

            if (association.AuxiliaryType != null && association.IsMaster)
            {
                Domain domain   = Session.Domain;
                var    itemType = domain.Model.Types[Field.ItemType];
                auxilaryTypeKeyTransform = new CombineTransform(
                    false,
                    owner.TypeInfo.Key.TupleDescriptor,
                    itemType.Key.TupleDescriptor);
            }

            if (association.Multiplicity != Multiplicity.ManyToOne && association.Multiplicity != Multiplicity.OneToMany)
            {
                skipOwnerVersionChange = false;
            }
            else
            {
                skipOwnerVersionChange = Session.Domain.Configuration.VersioningConvention.DenyEntitySetOwnerVersionChange;
            }

            Initialize(WellKnownOrmTypes.EntitySetBase);
        }
        public void BaseTest()
        {
            Xtensive.Tuples.Tuple t1 = Xtensive.Tuples.Tuple.Create(1, "2");
            Xtensive.Tuples.Tuple t2 = Xtensive.Tuples.Tuple.Create(3, 4.0, "5");
            TestLog.Info("Originals: {0}, {1}", t1, t2);

            CombineTransform mt   = new CombineTransform(false, t1.Descriptor, t2.Descriptor);
            CombineTransform mtro = new CombineTransform(true, t1.Descriptor, t2.Descriptor);

            Xtensive.Tuples.Tuple wt1 = mt.Apply(TupleTransformType.TransformedTuple, t1, t2);
            TestLog.Info("Wrapper:   {0}", wt1);
            Xtensive.Tuples.Tuple ct1 = mt.Apply(TupleTransformType.Tuple, t1, t2);
            TestLog.Info("Copy:      {0}", ct1);
            Xtensive.Tuples.Tuple wt2 = mt.Apply(TupleTransformType.TransformedTuple, t1, t2);
            Xtensive.Tuples.Tuple ct2 = mt.Apply(TupleTransformType.Tuple, t1, t2);

            Assert.AreEqual(wt1, wt2);
            Assert.AreEqual(wt2, ct1);
            Assert.AreEqual(ct1, ct2);

            wt1.SetValue(2, 0);
            Assert.AreEqual(t2.GetValue(0), wt1.GetValue(2));
            Assert.AreEqual(wt1, wt2);
            Assert.AreNotEqual(wt2, ct1);
            Assert.AreEqual(ct1, ct2);

            ct1.SetValue(2, 0);
            Assert.AreEqual(t2.GetValue(0), ct1.GetValue(2));
            Assert.AreEqual(wt1, wt2);
            Assert.AreEqual(wt2, ct1);
            Assert.AreNotEqual(ct1, ct2);

            Xtensive.Tuples.Tuple wtro = mtro.Apply(TupleTransformType.TransformedTuple, t1, t2);
            AssertEx.Throws <NotSupportedException>(delegate {
                wtro.SetValue(2, 0);
            });

            CombineTransform mt3 = new CombineTransform(false, t1.Descriptor, t1.Descriptor, t1.Descriptor);

            Xtensive.Tuples.Tuple wt3 = mt3.Apply(TupleTransformType.TransformedTuple, t1, t1, t1);
            TestLog.Info("Wrapper:   {0}", wt3);
            Xtensive.Tuples.Tuple ct3 = mt3.Apply(TupleTransformType.Tuple, t1, t1, t1);
            TestLog.Info("Copy:      {0}", ct3);
            t1.SetValue(0, 0);
            Assert.AreEqual(wt3.GetValue(4), t1.GetValue(0));
            t1.SetValue(0, 1);

            CombineTransform mt4 = new CombineTransform(false, t1.Descriptor, t1.Descriptor, t1.Descriptor, t1.Descriptor);

            Xtensive.Tuples.Tuple wt4 = mt4.Apply(TupleTransformType.TransformedTuple, t1, t1, t1, t1);
            TestLog.Info("Wrapper:   {0}", wt4);
            Xtensive.Tuples.Tuple ct4 = mt4.Apply(TupleTransformType.Tuple, t1, t1, t1, t1);
            TestLog.Info("Copy:      {0}", ct4);
            t1.SetValue(0, 0);
            Assert.AreEqual(wt4.GetValue(6), t1.GetValue(0));
            t1.SetValue(0, 1);
        }
        /// <inheritdoc/>
        protected override RecordSetHeader BuildHeader()
        {
            var newHeader = Source.Header.Add(new SystemColumn(ResultColumnName, 0, typeof(bool)));
            var types     = FilteredColumns.Select(m => newHeader.Columns[m].Type);

            FilteredColumnsExtractionTransform = new MapTransform(true, TupleDescriptor.Create(types), FilteredColumns);
            ResultTransform = new CombineTransform(true, Source.Header.TupleDescriptor, TupleDescriptor.Create(new [] { typeof(bool) }));
            return(newHeader);
        }
Esempio n. 4
0
        /// <inheritdoc/>
        protected override RecordSetHeader BuildHeader()
        {
            var newHeader  = Source.Header.Add(new SystemColumn(ResultColumnName, 0, BoolType));
            var fieldTypes = new Type[FilteredColumns.Count];

            for (var index = 0; index < fieldTypes.Length; index++)
            {
                fieldTypes[index] = newHeader.Columns[FilteredColumns[index]].Type;
            }
            var tupleDescriptor = TupleDescriptor.Create(fieldTypes);

            FilteredColumnsExtractionTransform = new MapTransform(true, tupleDescriptor, FilteredColumns);
            ResultTransform = new CombineTransform(true, Source.Header.TupleDescriptor, BoolTupleDescriptor);
            return(newHeader);
        }
Esempio n. 5
0
        private void RemapEntitySetReference(RemapContext context, ReferenceFieldChangeInfo info)
        {
            var fieldAssociation = info.Field.GetAssociation(info.FieldValue.TypeInfo);

            if (!fieldAssociation.IsMaster && fieldAssociation.IsPaired)
            {
                return;
            }

            var oldCombinedKey = info.AuxiliaryEntity;

            var fieldOwnerKey = context.TryRemapKey(info.FieldOwner);
            var fieldValueKey = context.TryRemapKey(info.FieldValue);

            var transformer   = new CombineTransform(false, fieldOwnerKey.Value.Descriptor, fieldValueKey.Value.Descriptor);
            var combinedTuple = transformer.Apply(TupleTransformType.Tuple, fieldOwnerKey.Value, fieldValueKey.Value);

            var newCombinedKey = Key.Create(Session.Domain, Session.StorageNodeId, fieldAssociation.AuxiliaryType, TypeReferenceAccuracy.ExactType, combinedTuple);

            context.RegisterKeyMap(oldCombinedKey, newCombinedKey);
        }
        public void PerformanceTest2()
        {
            AdvancedComparerStruct <Xtensive.Tuples.Tuple> comparer = AdvancedComparerStruct <Xtensive.Tuples.Tuple> .Default;

            Xtensive.Tuples.Tuple t  = Xtensive.Tuples.Tuple.Create(1);
            CombineTransform      mt = new CombineTransform(false, t.Descriptor, t.Descriptor, t.Descriptor, t.Descriptor);
            SegmentTransform      st = new SegmentTransform(false, mt.Descriptor, new Segment <int>(1, 2));

            Xtensive.Tuples.Tuple wt1 = st.Apply(TupleTransformType.TransformedTuple, mt.Apply(TupleTransformType.TransformedTuple, t, t, t, t));
            Xtensive.Tuples.Tuple wt2 = st.Apply(TupleTransformType.TransformedTuple, mt.Apply(TupleTransformType.TransformedTuple, t, t, t, t));
            Xtensive.Tuples.Tuple ct1 = st.Apply(TupleTransformType.Tuple, mt.Apply(TupleTransformType.Tuple, t, t, t, t));
            Xtensive.Tuples.Tuple ct2 = st.Apply(TupleTransformType.Tuple, mt.Apply(TupleTransformType.Tuple, t, t, t, t));
            int count = IterationCount;

            comparer.Equals(ct1, ct2);
            comparer.Equals(ct1, wt1);
            comparer.Equals(wt1, wt2);

            TestHelper.CollectGarbage();
            using (new Measurement("O&O", MeasurementOptions.Log, count))
                for (int i = 0; i < count; i++)
                {
                    comparer.Equals(ct1, ct2);
                }

            TestHelper.CollectGarbage();
            using (new Measurement("O&W", MeasurementOptions.Log, count))
                for (int i = 0; i < count; i++)
                {
                    comparer.Equals(ct1, wt1);
                }

            TestHelper.CollectGarbage();
            using (new Measurement("W&W", MeasurementOptions.Log, count))
                for (int i = 0; i < count; i++)
                {
                    comparer.Equals(wt1, wt2);
                }
        }
Esempio n. 7
0
        /// <summary>
        /// Combines the <paramref name="left"/> with <paramref name="right"/>.
        /// </summary>
        /// <param name="left">The first <see cref="Tuple"/> to combine.</param>
        /// <param name="right">The second <see cref="Tuple"/> to combine.</param>
        /// <returns></returns>
        public static Tuple Combine(this Tuple left, Tuple right)
        {
            var transform = new CombineTransform(false, new[] { left.Descriptor, right.Descriptor });

            return(transform.Apply(TupleTransformType.TransformedTuple, left, right));
        }