コード例 #1
0
        /// <inheritdoc/>
        protected override void ExecuteSelf(OperationExecutionContext context)
        {
            var session = context.Session;
            var item    = session.Query.Single(context.TryRemapKey(ItemKey));

            GetEntitySet(context).Remove(item);
        }
コード例 #2
0
 /// <inheritdoc/>
 protected override void PrepareSelf(OperationExecutionContext context)
 {
     foreach (var key in Keys)
     {
         context.RegisterKey(context.TryRemapKey(key), false);
     }
 }
コード例 #3
0
 /// <inheritdoc/>
 protected override void PrepareSelf(OperationExecutionContext context)
 {
     if (prepareAction != null)
     {
         prepareAction.Invoke(context, arguments);
     }
 }
コード例 #4
0
        /// <summary>
        /// Gets the entity set involved into this operation.
        /// </summary>
        /// <param name="context">The operation context.</param>
        /// <returns>Entity set involved into this operation.</returns>
        public EntitySetBase GetEntitySet(OperationExecutionContext context)
        {
            var session = context.Session;
            var key     = context.TryRemapKey(Key);
            var target  = session.Query.Single(key);

            return((EntitySetBase)target.GetFieldValue(Field));
        }
コード例 #5
0
        private void MapCompositeKey(OperationExecutionContext context)
        {
            // TODO: AY: Review this later
            var domain    = context.Session.Domain;
            var nodeId    = context.Session.StorageNodeId;
            var keyInfo   = Key.TypeReference.Type.Key;
            var hierarchy = keyInfo.Hierarchy;

            if (hierarchy.Key.Fields.Count == 1 && !hierarchy.Key.Fields[0].IsEntity)
            {
                return;
            }
            var columnIndex = 0;
            var sourceTuple = Key.Value;
            var resultTuple = Tuple.Create(sourceTuple.Descriptor);
            var hasTemporaryComponentBeenFound = false;

            foreach (var keyField in hierarchy.Key.Fields)
            {
                if (keyField.Parent != null)
                {
                    continue;
                }
                if (keyField.IsPrimitive)
                {
                    resultTuple.SetValue(columnIndex, sourceTuple.GetValue(columnIndex));
                    columnIndex++;
                }
                else
                {
                    var association       = keyField.Associations.Last();
                    var componentKeyValue = Tuple.Create(association.TargetType.Key.TupleDescriptor);
                    sourceTuple.CopyTo(componentKeyValue, columnIndex, keyField.MappingInfo.Length);
                    var componentKey = Key.Create(domain, nodeId, association.TargetType.UnderlyingType,
                                                  TypeReferenceAccuracy.BaseType, componentKeyValue);
                    var componentKeyLength = componentKey.Value.Count;
                    Key mappedKey;
                    if (context.KeyMapping.TryGetValue(componentKey, out mappedKey))
                    {
                        mappedKey.Value.CopyTo(resultTuple, 0, columnIndex, componentKeyLength);
                        hasTemporaryComponentBeenFound = true;
                    }
                    else
                    {
                        componentKeyValue.CopyTo(resultTuple, 0, columnIndex, componentKeyLength);
                    }
                    columnIndex += componentKeyLength;
                }
            }
            if (hasTemporaryComponentBeenFound)
            {
                var result = Key.Create(domain, nodeId, Key.TypeReference.Type.UnderlyingType,
                                        TypeReferenceAccuracy.BaseType, resultTuple);
                context.AddKeyMapping(Key, result);
            }
        }
コード例 #6
0
        private void MapNewKey(OperationExecutionContext context)
        {
            var domain = context.Session.Domain;

            if (Key.IsTemporary(domain))
            {
                var mappedKey = Key.Generate(context.Session, Key.TypeInfo);
                context.AddKeyMapping(Key, mappedKey);
            }
        }
コード例 #7
0
        /// <inheritdoc/>
        protected override void ExecuteSelf(OperationExecutionContext context)
        {
            var session = context.Session;
            var domain  = session.Domain;
            var key     = context.TryRemapKey(Key);
            var type    = domain.Model.Types[TypeName];

            key = Key.Create(domain, session.StorageNodeId, type, TypeReferenceAccuracy.ExactType, key.Value);
            session.CreateOrInitializeExistingEntity(type.UnderlyingType, key);
        }
コード例 #8
0
        /// <inheritdoc/>
        protected override void ExecuteSelf(OperationExecutionContext context)
        {
            var session  = context.Session;
            var key      = context.TryRemapKey(Key);
            var valueKey = context.TryRemapKey(ValueKey);
            var entity   = session.Query.Single(key);
            var value    = ValueKey != null?session.Query.Single(valueKey) : Value;

            entity.SetFieldValue(Field, value);
        }
コード例 #9
0
        /// <inheritdoc/>
        protected override void ExecuteSelf(OperationExecutionContext context)
        {
            var session  = context.Session;
            var entities =
                from key in Keys
                let remappedKey = context.TryRemapKey(key)
                                  let entity = session.Query.Single(remappedKey)
                                               select entity;

            session.Remove(entities);
        }
コード例 #10
0
        /// <inheritdoc/>
        /// <exception cref="VersionConflictException">Version check failed.</exception>
        protected override void ExecuteSelf(OperationExecutionContext context)
        {
            var session = context.Session;
            var entity  = session.Query.Single(Key);

            if (entity.VersionInfo != Version)
            {
                if (OrmLog.IsLogged(LogLevel.Info))
                {
                    OrmLog.Info(Strings.LogSessionXVersionValidationFailedKeyYVersionZExpected3,
                                session, Key, entity.VersionInfo, Version);
                }
                throw new VersionConflictException(
                          string.Format(Strings.ExVersionOfEntityWithKeyXDiffersFromTheExpectedOne, Key));
            }
        }
コード例 #11
0
        /// <inheritdoc/>
        protected override void PrepareSelf(OperationExecutionContext context)
        {
            if (context.KeyMapping.ContainsKey(Key))
            {
                return;
            }
            var keyInfo = Key.TypeReference.Type.Key;

            if (!keyInfo.ContainsForeignKeys)
            {
                MapNewKey(context);
            }
            else
            {
                MapCompositeKey(context);
            }
        }
コード例 #12
0
 /// <inheritdoc/>
 protected override void PrepareSelf(OperationExecutionContext context)
 {
     // There should be no base method call here!
     context.RegisterKey(context.TryRemapKey(Key), true);
 }
コード例 #13
0
 /// <inheritdoc/>
 protected override void ExecuteSelf(OperationExecutionContext context)
 {
     // Does nothing.
 }
コード例 #14
0
 /// <inheritdoc/>
 protected override void ExecuteSelf(OperationExecutionContext context)
 {
 }
コード例 #15
0
 /// <inheritdoc/>
 protected override void PrepareSelf(OperationExecutionContext context)
 {
     base.PrepareSelf(context);
     // Next line works properly when ValueKey==null
     context.RegisterKey(context.TryRemapKey(ValueKey), false);
 }
コード例 #16
0
 /// <inheritdoc/>
 protected override void ExecuteSelf(OperationExecutionContext context)
 {
     GetEntitySet(context).Clear();
 }
コード例 #17
0
 /// <inheritdoc/>
 protected override void ExecuteSelf(OperationExecutionContext context)
 {
     executeAction.Invoke(context, arguments);
 }
コード例 #18
0
 /// <inheritdoc/>
 protected override void PrepareSelf(OperationExecutionContext context)
 {
     base.PrepareSelf(context);
     context.RegisterKey(context.TryRemapKey(ItemKey), false);
 }
コード例 #19
0
 /// <inheritdoc/>
 protected override void PrepareSelf(OperationExecutionContext context)
 {
     context.RegisterKey(Key, false);
 }