Exemplo n.º 1
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;
        }
Exemplo n.º 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);
		}
Exemplo n.º 3
0
        public override UpdateAttributeCommand Visit(UpdateAttributeCommand c)
        {
            _RWL.AcquireWriterLock();

            try
            {
                Entity entity = GetEntity(c.ParentType, c.ParentId);
                State tmpState = entity.State;
                entity[c.Name].Value = c.Value;
                entity.State = tmpState;
            }
            finally
            {
                _RWL.ReleaseWriterLock();
            }
            return c;
        }
Exemplo n.º 4
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");
            }
        }
Exemplo n.º 5
0
        public override UpdateAttributeCommand Visit(UpdateAttributeCommand c)
        {
            Entity e = new Entity(SyncUtils.UPDATE_ATTRIBUTE);
            PopulateDefaults(e, c);

            e.SetValue(SyncUtils.PARENTID, c.ParentId);
            e.SetValue(SyncUtils.PARENTTYPE, c.ParentType);
            e.SetValue(SyncUtils.TYPE, c.Type.Name);
            e.SetValue(SyncUtils.NAME, c.Name);
            e.SetValue(SyncUtils.VALUE, engine.Factory.Serializer.SerializeToString(c.Value));

            transaction.Serialize(e);

            return c;
        }
Exemplo n.º 6
0
        public void Process(UpdateAttributeCommand c)
        {
            EntityMapping e = _Mapping.Entities[c.ParentType, true];
            AttributeMapping a = e.Attributes[c.Name, true];

            if (a == null)
                throw new Exception(String.Format("The attribute '{0}' of the entity '{1}' is not defined in your mapping file", c.Name, c.ParentType));

            IDbCommand command;
            // teste si les attributs doivent être mis dans la même table
            if (a.Table == null | e.Table == a.Table)
            {

                command = _Driver.CreateCommand(String.Format(@"UPDATE {0} SET {1} = {2} WHERE {3}",
                    _Dialect.FormatAttribute(e.Table),
                    _Dialect.FormatAttribute(a.Field),
                    _Driver.FormatParameter("Value"),
                    GetWhereId(e.Ids)), _Connection, _Transaction);

                SerializableType serializableType = a.Type == null ? a.GetSerializableType(a.DbType, c.Type) : a.GetSerializableType(a.DbType, a.Type);

                switch (serializableType)
                {
                    case SerializableType.BinarySerialization:
                        command.Parameters.Add(a.CreateDbDataParameter("Value", Common.Utils.SerializeToArray(c.Value)));
                        break;
                    case SerializableType.StringSerialization:
                        command.Parameters.Add(a.CreateDbDataParameter("Value", Common.Utils.SerializeToString(c.Value)));
                        break;

                    case SerializableType.Standard:
                        command.Parameters.Add(a.CreateDbDataParameter("Value", c.Value));
                        break;
                    case SerializableType.String:
                        command.Parameters.Add(a.CreateDbDataParameter("Value", Common.Utils.ConvertToString(c.Value, c.Type)));
                        break;
                    case SerializableType.Int:
                        command.Parameters.Add(a.CreateDbDataParameter("Value", Convert.ToInt32(c.Value)));
                        break;
                }

                string[] parentIds = c.ParentId.Split(SqlMapperProvider.IDSEP);
                for (int i = 0; i < e.Ids.Count; i++)
                {
                    command.Parameters.Add(_Driver.CreateParameter("Id" + i.ToString(), _Dialect.GetDbTypeToPrimaryKey(e.Ids[i].Generator), parentIds[i]));
                }
            }
            else
            {
                if (a.Discriminator != null)
                {
                    string query = String.Format(@"UPDATE {0} SET {1} = {4}, TYPE = {5} WHERE {2} = {6} and {3} = {7}",
                                                 _Dialect.FormatAttribute(a.Table),
                                                 _Dialect.FormatAttribute(a.Field),
                                                 _Dialect.FormatAttribute(a.Discriminator),
                                                 _Dialect.FormatAttribute(a.ParentField),
                                                 _Driver.FormatParameter("Value"),
                                                 _Driver.FormatParameter("Type"),
                                                 _Driver.FormatParameter("Name"),
                                                 _Driver.FormatParameter("FK_Entity"));

                    command = _Driver.CreateCommand(query, _Connection, _Transaction);

                    SerializableType serializableType = a.Type == null ? a.GetSerializableType(a.DbType, c.Type) : a.GetSerializableType(a.DbType, a.Type);
                    switch (serializableType)
                    {
                        case SerializableType.BinarySerialization:
                            command.Parameters.Add(a.CreateDbDataParameter("Value", Common.Utils.SerializeToArray(c.Value)));
                            break;
                        case SerializableType.StringSerialization:
                            command.Parameters.Add(a.CreateDbDataParameter("Value", Common.Utils.SerializeToString(c.Value)));
                            break;
                        case SerializableType.Standard:
                            command.Parameters.Add(a.CreateDbDataParameter("Value", c.Value));
                            break;
                        case SerializableType.String:
                            command.Parameters.Add(a.CreateDbDataParameter("Value", Common.Utils.ConvertToString(c.Value, c.Type)));
                            break;
                        case SerializableType.Int:
                            command.Parameters.Add(a.CreateDbDataParameter("Value", (int)c.Value));
                            break;
                    }
                    command.Parameters.Add(_Driver.CreateParameter("Type", DbType.AnsiString, Utils.GetFullName(c.Type)));
                    command.Parameters.Add(_Driver.CreateParameter("Name", DbType.AnsiString, a.DiscriminatorValue == "*" ? c.Name : a.DiscriminatorValue));
                    command.Parameters.Add(_Driver.CreateParameter("FK_Entity", _Dialect.GetDbTypeToPrimaryKey(e.Ids[0].Generator), c.ParentId));
                }
                else
                {
                    string query = String.Format(@"UPDATE {0} SET {1} = {3} WHERE {2} = {4}",
                                                 _Dialect.FormatAttribute(a.Table),
                                                 _Dialect.FormatAttribute(a.Field),
                                                 _Dialect.FormatAttribute(a.ParentField),
                                                 _Driver.FormatParameter("Value"),
                                                 _Driver.FormatParameter("FK_Entity"));

                    command = _Driver.CreateCommand(query, _Connection, _Transaction);

                    SerializableType serializableType = a.Type == null ? a.GetSerializableType(a.DbType, c.Type) : a.GetSerializableType(a.DbType, a.Type);

                    switch (serializableType)
                    {
                        case SerializableType.BinarySerialization:
                            command.Parameters.Add(a.CreateDbDataParameter("Value", Common.Utils.SerializeToArray(c.Value)));
                            break;
                        case SerializableType.StringSerialization:
                            command.Parameters.Add(a.CreateDbDataParameter("Value", Common.Utils.SerializeToString(c.Value)));
                            break;
                        case SerializableType.Standard:
                            command.Parameters.Add(a.CreateDbDataParameter("Value", c.Value));
                            break;
                        case SerializableType.String:
                            command.Parameters.Add(a.CreateDbDataParameter("Value", Common.Utils.ConvertToString(c.Value, c.Type)));
                            break;
                        case SerializableType.Int:
                            command.Parameters.Add(a.CreateDbDataParameter("Value", (int)c.Value));
                            break;
                    }

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

            command.Transaction = _Transaction;

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

            command.ExecuteNonQuery();
        }
Exemplo n.º 7
0
 public abstract UpdateAttributeCommand Visit(UpdateAttributeCommand item);
Exemplo n.º 8
0
        public override UpdateAttributeCommand Visit(UpdateAttributeCommand 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[c.Name].Value = c.Value;
                entity.State = tmpState;
            }
            finally
            {
                _RWL.ReleaseWriterLock();
            }
            return c;
        }