Beispiel #1
0
		public void Process(DeleteAttributeCommand c)
		{
			XmlNode entityAttribute = FindAttribute(GetKey(c.ParentType, c.ParentId), c.Name);

			if(entityAttribute == null)
				throw new Exception("Unknown Attribute");

			entityAttribute.ParentNode.RemoveChild(entityAttribute);
		}
Beispiel #2
0
		public void Process(UpdateAttributeCommand c)
		{
			XmlNode entityAttribute = FindAttribute(GetKey(c.ParentType, c.ParentId), c.Name);

			if(entityAttribute == null)
			{
				Process(new CreateAttributeCommand(c.ParentId, c.ParentType, c.Name, c.Type, c.Value));
				return;
			}

			// Treat null values as a DeleteAttributeCommand in this engine
			if(c.Value == null)
			{
				DeleteAttributeCommand dac = new DeleteAttributeCommand(c.ParentId, c.ParentType, c.Name, c.Type, c.Value);
				Process(dac);
				return;
			}

            if (Utils.IsStandardType(c.Type)) // string is not a ValueType
                entityAttribute.InnerText = Utils.ConvertToString(c.Value, c.Type);
			else
				entityAttribute.InnerText = Utils.SerializeToString(c.Value);
		}
Beispiel #3
0
        internal Command CreateCommand(Entity e)
        {
            switch (e.Type)
            {
                case SyncUtils.CREATE_ENTITY:
                    CreateEntityCommand ce = new CreateEntityCommand(
                        e.GetString(SyncUtils.PARENTID),
                        e.GetString(SyncUtils.TYPE)
                        );
                    return ce;

                case SyncUtils.DELETE_ENTITY:
                    DeleteEntityCommand de = new DeleteEntityCommand(
                        e.GetString(SyncUtils.PARENTID),
                        e.GetString(SyncUtils.TYPE)
                        );
                    return de;

                case SyncUtils.CREATE_ATTRIBUTE:
                    CreateAttributeCommand ca = new CreateAttributeCommand(
                        e.GetString(SyncUtils.PARENTID),
                        e.GetString(SyncUtils.PARENTTYPE),
                        e.GetString(SyncUtils.NAME),
                        MetaData.TypeResolver.GetType(e.GetString(SyncUtils.TYPE)),
                        Factory.Serializer.Unserialize(e.GetString(SyncUtils.VALUE))
                        );
                    return ca;

                case SyncUtils.DELETE_ATTRIBUTE:
                    DeleteAttributeCommand da = new DeleteAttributeCommand(
                        e.GetString(SyncUtils.PARENTID),
                        e.GetString(SyncUtils.PARENTTYPE),
                        e.GetString(SyncUtils.NAME),
                        MetaData.TypeResolver.GetType(e.GetString(SyncUtils.TYPE)),
                        null
                        );
                    return da;

                case SyncUtils.UPDATE_ATTRIBUTE:
                    UpdateAttributeCommand ua = new UpdateAttributeCommand(
                        e.GetString(SyncUtils.PARENTID),
                        e.GetString(SyncUtils.PARENTTYPE),
                        e.GetString(SyncUtils.NAME),
                        MetaData.TypeResolver.GetType(e.GetString(SyncUtils.TYPE)),
                        Factory.Serializer.Unserialize(e.GetString(SyncUtils.VALUE))
                        );
                    return ua;

                case SyncUtils.CREATE_REFERENCE:
                    CreateReferenceCommand cr = new CreateReferenceCommand(
                        e.GetString(SyncUtils.ROLE),
                        e.GetString(SyncUtils.PARENTID),
                        e.GetString(SyncUtils.PARENTTYPE),
                        e.GetString(SyncUtils.CHILDID),
                        e.GetString(SyncUtils.CHILDTYPE)
                        );
                    return cr;

                case SyncUtils.DELETE_REFERENCE:
                    DeleteReferenceCommand dr = new DeleteReferenceCommand(
                        e.GetString(SyncUtils.ROLE),
                        e.GetString(SyncUtils.PARENTID),
                        e.GetString(SyncUtils.PARENTTYPE),
                        e.GetString(SyncUtils.CHILDID),
                        e.GetString(SyncUtils.CHILDTYPE)
                        );
                    return dr;

                default:
                    throw new UniversalStorageException("Unexpected command type");
            }
        }
Beispiel #4
0
        public override DeleteAttributeCommand Visit(DeleteAttributeCommand c)
        {
            _RWL.AcquireWriterLock();

            try
            {
                Entity entity = GetEntity(c.ParentType, c.ParentId);
                State tmpState = entity.State;
                entity.Remove(c.Name);
                entity.State = tmpState;
            }
            finally
            {
                _RWL.ReleaseWriterLock();
            }
            return c;
        }
Beispiel #5
0
        public override DeleteAttributeCommand Visit(DeleteAttributeCommand c)
        {
            Entity e = new Entity(SyncUtils.DELETE_ATTRIBUTE);
            PopulateDefaults(e, c);

            e.SetValue(SyncUtils.PARENTID, c.ParentId);
            e.SetValue(SyncUtils.PARENTTYPE, c.ParentType);
            e.SetValue(SyncUtils.NAME, c.Name);
            e.SetValue(SyncUtils.TYPE, c.Type.Name);

            transaction.Serialize(e);

            return c;
        }
        public void Process(DeleteAttributeCommand c)
        {
            EntityMapping e = _Mapping.Entities[c.ParentType, true];
            AttributeMapping a = e.Attributes[c.Name, true];

            IDbCommand command;

            // Specific case
            if (a.Table == null | e.Table == a.Table)
            {
                UpdateCommand upd = new UpdateCommand(a, e.Table);
                upd.ColumnValueCollection.Add(a.Field, new Constant(DBNull.Value, a.DbType));
                upd.WhereClause.SearchCondition.Add(new BinaryLogicExpression(new Column(a, e.IdFields), BinaryLogicOperator.Equals, new Parameter(null, "Id")));
                upd.Accept(_Dialect);

                command = _Driver.CreateCommand(_Dialect.RenderQueries(upd)[0], _Connection, _Transaction);

                /*command = _Driver.CreateCommand(String.Format(@"UPDATE {0} SET {1} = NULL  WHERE ({2} = {3})",
                                                               _Dialect.FormatAttribute(e.Table),
                                                               _Dialect.FormatAttribute(a.Field),
                                                               _Dialect.FormatAttribute(e.IdFields),
                                                               _Driver.FormatParameter("Id")), _Connection, _Transaction);*/

                string parentid = ConvertId(e.Ids[0].Generator, c.ParentId).ToString();
                command.Parameters.Add(_Driver.CreateParameter("Id", _Dialect.GetDbTypeToPrimaryKey(e.Ids[0].Generator), parentid));
            }
            // Generic case
            else
            {
                if (a.Discriminator != null)
                {
                    command = _Driver.CreateCommand(String.Format(@"DELETE FROM {0} WHERE ({1} = {3} and {2} = {4})",
                                                                  _Dialect.FormatAttribute(a.Table),
                                                                  _Dialect.FormatAttribute(a.Discriminator),
                                                                  _Dialect.FormatAttribute(a.ParentField),
                                                                  _Driver.FormatParameter("Name"),
                                                                  _Driver.FormatParameter("FK_Entity")), _Connection, _Transaction);

                    command.Parameters.Add(_Driver.CreateParameter("Name", DbType.AnsiString, c.Name));
                    string parentid = ConvertId(e.Ids[0].Generator, c.ParentId).ToString();
                    command.Parameters.Add(_Driver.CreateParameter("FK_Entity", _Dialect.GetDbTypeToPrimaryKey(e.Ids[0].Generator), parentid));
                }
                else
                {
                    command = _Driver.CreateCommand(String.Format(@"DELETE FROM {0} WHERE ({1} = {2})",
                                                                   _Dialect.FormatAttribute(a.Table),
                                                                   _Dialect.FormatAttribute(a.ParentField),
                                                                   _Driver.FormatParameter("FK_Entity")), _Connection, _Transaction);

                    string parentid = ConvertId(e.Ids[0].Generator, c.ParentId).ToString();
                    command.Parameters.Add(_Driver.CreateParameter("FK_Entity", _Dialect.GetDbTypeToPrimaryKey(e.Ids[0].Generator), parentid));
                }
            }

            command.Transaction = _Transaction;

            if (_Engine.TraceSqlSwitch.Enabled)
            {
                TraceHelpler.Trace(command, _Dialect);
            }

            command.ExecuteNonQuery();

        }
Beispiel #7
0
        public UpdateAttributeCommand Visit(UpdateAttributeCommand c)
        {
            XmlNode entityAttribute = FindAttribute(GetKey(c.ParentType, c.ParentId), c.Name);

            if (entityAttribute == null)
            {
                Visit(new CreateAttributeCommand(c.ParentId, c.ParentType, c.Name, c.Type, c.Value));
                return c;
            }

            // Treat null values as a DeleteAttributeCommand in this engine
            if (c.Value == null)
            {
                DeleteAttributeCommand dac = new DeleteAttributeCommand(c.ParentId, c.ParentType, c.Name, c.Type, c.Value);
                Visit(dac);
                return c;
            }

            entityAttribute.InnerText = engine.Factory.Serializer.SerializeToString(c.Value);

            return c;
        }
Beispiel #8
0
 public abstract DeleteAttributeCommand Visit(DeleteAttributeCommand item);
Beispiel #9
0
        public override DeleteAttributeCommand Visit(DeleteAttributeCommand c)
        {
            _RWL.AcquireWriterLock(Timeout.Infinite);

            try
            {
                Entity entity = _Entities[CacheEngine.GetCacheKey(c.ParentType, c.ParentId)];
                if (entity == null)
                    return c;

                State tmpState = entity.State;
                entity.Remove(c.Name);
                entity.State = tmpState;
            }
            finally
            {
                _RWL.ReleaseWriterLock();
            }
            return c;
        }