public override CreateAttributeCommand Visit(CreateAttributeCommand c) { Entity e = new Entity(SyncUtils.CREATE_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; }
public CreateAttributeCommand Visit(CreateAttributeCommand c) { XmlNode entityAttribute; XmlNode parentEntity = _Document.GetElementById(GetKey(c.ParentType, c.ParentId)); if (parentEntity == null) { throw new Exception("Unknown Entity"); } parentEntity.AppendChild(entityAttribute = _Document.CreateElement("Attribute")); XmlAttribute entityName = entityAttribute.Attributes.Append(_Document.CreateAttribute("Name")); entityName.Value = c.Name; entityAttribute.InnerText = engine.Factory.Serializer.SerializeToString(c.Value); return c; }
public void Process(CreateAttributeCommand c) { XmlNode entityAttribute; XmlNode parentEntity = _Document.GetElementById( GetKey(c.ParentType, c.ParentId)); if(parentEntity == null) { throw new Exception("Unknown Entity"); } parentEntity.AppendChild(entityAttribute = _Document.CreateElement("Attribute")); XmlAttribute entityName = entityAttribute.Attributes.Append(_Document.CreateAttribute("Name")); entityName.Value = c.Name; if(Utils.IsStandardType(c.Type)) entityAttribute.InnerText = Utils.ConvertToString(c.Value, c.Type); else entityAttribute.InnerText = Utils.SerializeToString(c.Value); }
public override CreateAttributeCommand Visit(CreateAttributeCommand c) { _RWL.AcquireWriterLock(); try { Entity entity = GetEntity(c.ParentType, c.ParentId); State tmpState = entity.State; entity.Add(c.Name, c.Value, c.Type, State.UpToDate); entity.State = tmpState; } finally { _RWL.ReleaseWriterLock(); } return c; }
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"); } }
public void Process(CreateAttributeCommand c) { EntityMapping e = _Mapping.Entities[c.ParentType, true]; AttributeMapping a = e.Attributes[c.Name, true]; IDbCommand command; // teste si les attributs doivent être mis dans la même table if (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); object value = null; if (c.Value != null) { switch (serializableType) { case SerializableType.BinarySerialization: value = Utils.SerializeToArray(c.Value); break; case SerializableType.StringSerialization: value = Utils.SerializeToString(c.Value); break; case SerializableType.Standard: value = c.Value; break; case SerializableType.String: value = Utils.ConvertToString(c.Value, c.Type); break; case SerializableType.Int: value = (int)c.Value; break; } } command.Parameters.Add(a.CreateDbDataParameter("Value", value)); 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), ConvertId(e.Ids[i].Generator, parentIds[i]))); } } else { if (a.Discriminator != null) { string query = String.Format(@"INSERT INTO {0}( {1}, {2}, {3}) VALUES ( {4}, {5}, {6})", _Dialect.FormatAttribute(a.Table), _Dialect.FormatAttribute(a.Discriminator), _Dialect.FormatAttribute(a.Field), _Dialect.FormatAttribute(a.ParentField), _Driver.FormatParameter("Name"), _Driver.FormatParameter("Value"), _Driver.FormatParameter("FK_Entity")); command = _Driver.CreateCommand(query, _Connection, _Transaction); command.Parameters.Add(_Driver.CreateParameter("Name", DbType.AnsiString, a.DiscriminatorValue == "*" ? c.Name : a.DiscriminatorValue)); SerializableType serializableType = a.Type == null ? a.GetSerializableType(a.DbType, c.Type) : a.GetSerializableType(a.DbType, a.Type); object value = null; if (c.Value != null) { switch (serializableType) { case SerializableType.BinarySerialization: value = Common.Utils.SerializeToArray(c.Value); break; case SerializableType.StringSerialization: value = Common.Utils.SerializeToString(c.Value); break; case SerializableType.Standard: value = c.Value; break; case SerializableType.String: value = Common.Utils.ConvertToString(c.Value, c.Type); break; case SerializableType.Int: value = (int)c.Value; break; } } command.Parameters.Add(a.CreateDbDataParameter("Value", value)); command.Parameters.Add(_Driver.CreateParameter("FK_Entity", _Dialect.GetDbTypeToPrimaryKey(e.Ids[0].Generator), ConvertId(e.Ids[0].Generator, c.ParentId))); } else { string sValue; if (c.Type.IsValueType || c.Type == typeof(String)) // string is not a ValueType sValue = Common.Utils.ConvertToString(c.Value, c.Type); else sValue = Common.Utils.SerializeToString(c.Value); string query = String.Format(@"INSERT INTO {0}({1}, {2}) VALUES ( {3}, {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); command.Parameters.Add(_Driver.CreateParameter("Value", DbType.AnsiString, sValue)); command.Parameters.Add(_Driver.CreateParameter("FK_Entity", _Dialect.GetDbTypeToPrimaryKey(e.Ids[0].Generator), ConvertId(e.Ids[0].Generator, c.ParentId))); } } command.Transaction = _Transaction; if (_Engine.TraceSqlSwitch.Enabled) { TraceHelpler.Trace(command, _Dialect); } command.ExecuteNonQuery(); }
public abstract CreateAttributeCommand Visit(CreateAttributeCommand item);
public override CreateAttributeCommand Visit(CreateAttributeCommand 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.Add(c.Name, c.Value, c.Type, State.UpToDate); entity.State = tmpState; } finally { _RWL.ReleaseWriterLock(); } return c; }