示例#1
0
        public override CreateEntityCommand Visit(CreateEntityCommand item)
        {
            Mapping.Entity entity = engine.Provider.Mapping.Entities[item.Type];
            commands.Add(item.ParentEntity, engine.Provider.Mapping.Mapper.Create(entity));

            foreach (Mapping.Attribute attribute in entity.Attributes.Values)
            {
                if (attribute.IsId && attribute.Generator == Mapping.Generator.Guid)
                    Visit(new CreateAttributeCommand(item.ParentEntity[attribute.Name]));
            }
            //if (item.ParentEntity.Id == null)
            //{
            //    item.ParentEntity.TryCreateId();
            //    Domain.EntityEntry id = null;
            //    using (IEnumerator<Models.Attribute> enumerator = item.ParentEntity.Model.Ids.Values.GetEnumerator())
            //    {
            //        if (enumerator.MoveNext())
            //            id = item.ParentEntity[enumerator.Current];
            //    }
            //    if (id != null)
            //        new CreateAttributeCommand(item.ParentEntity, id).Accept(this);
            //    else
            //    {
            //        //If there is no Id in the business model
            //        AddParameter(command, engine.Mapping.Entities[item.ParentEntity.Type].Attributes["#Id"].Field, null);
            //    }
            //}
            return item;
        }
示例#2
0
		public void Process(CreateEntityCommand c)
		{
			XmlElement entityNode;
			_Document.DocumentElement.AppendChild(entityNode = _Document.CreateElement("Entity"));

			XmlAttribute entityType = _Document.CreateAttribute("Type");
			entityType.Value = c.Type;
			entityNode.Attributes.Append(entityType);

			XmlAttribute entityId = _Document.CreateAttribute("Id");
			entityId.Value = GetKey(c.Type, c.ParentId);
			entityNode.Attributes.Append(entityId);
		}
示例#3
0
        public override CreateEntityCommand Visit(CreateEntityCommand c)
        {
            Entity e = new Entity(SyncUtils.CREATE_ENTITY);

            PopulateDefaults(e, c);

            e.SetValue(SyncUtils.PARENTID, c.ParentId);
            e.SetValue(SyncUtils.TYPE, c.Type);

            transaction.Serialize(e);

            return c;
        }
示例#4
0
        public override CreateEntityCommand Visit(CreateEntityCommand c)
        {
            Entity entity = new Entity(c.Type);
            entity.Id = c.ParentId;
            entity.State = State.UpToDate;
            entity.MetaData = Entity.LoadMetaData.AttributesLoaded | Entity.LoadMetaData.AttributesLoaded;

            _RWL.AcquireWriterLock(Timeout.Infinite);
            try
            {
                _Entities.Add(CacheEngine.GetCacheKey(c.Type, c.ParentId), entity);
            }
            finally
            {
                _RWL.ReleaseWriterLock();
            }
            return c;
        }
示例#5
0
文件: SyncEngine.cs 项目: npenin/uss
        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");
            }
        }
示例#6
0
        public void Process(CreateEntityCommand c)
        {
            EntityMapping e = _Mapping.Entities[c.Type, true];

            IDbCommand command;

            if (e.Ids[0].Generator.Name == GeneratorMapping.GeneratorType.native)
            {
                if (e.DiscriminatorField != null)
                {
                    StringCollection column_list = new StringCollection();
                    column_list.Add(e.DiscriminatorField);

                    StringCollection value_list = new StringCollection();
                    value_list.Add(c.Type);

                    string query = String.Format(@"INSERT INTO {0}({1}) VALUES ({2})",
                                                 _Dialect.FormatAttribute(e.Table),
                                                 _Dialect.FormatAttribute(e.DiscriminatorField),
                                                 _Driver.FormatParameter("Type"));

                    command = _Driver.CreateCommand(query, _Connection, _Transaction);
                    command.Parameters.Add(_Driver.CreateParameter("Type", DbType.AnsiString, c.Type));

                }
                else
                {
                    string query = String.Format(@"INSERT INTO {0} DEFAULT VALUES", _Dialect.FormatAttribute(e.Table));

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

                command.Transaction = _Transaction;


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

                command.ExecuteNonQuery();

                command = _Driver.CreateCommand(_Dialect.GetIdentitySelect(e.Table), _Connection, _Transaction);
                using (IDataReader reader = command.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        NewId = Convert.ToString(reader[0]);
                        _NewIds.Add(c.ParentId, NewId);
                    }
                }

            }
            else
            {
                if (e.DiscriminatorField != null)
                {
                    StringCollection column_list = new StringCollection();
                    column_list.Add(e.IdFields);
                    column_list.Add(e.DiscriminatorField);

                    StringCollection value_list = new StringCollection();
                    value_list.Add(_Dialect.FormatValue(c.ParentId, _Dialect.GetDbTypeToPrimaryKey(e.Ids[0].Generator)));
                    value_list.Add(_Dialect.FormatValue(c.Type, DbType.AnsiString));

                    string query = String.Format(@"INSERT INTO {0}({1}, {2}) VALUES ({3}, {4})",
                                                 _Dialect.FormatAttribute(e.Table),
                                                 _Dialect.FormatAttribute(e.IdFields),
                                                 _Dialect.FormatAttribute(e.DiscriminatorField),
                                                 _Driver.FormatParameter("Id"),
                                                 _Driver.FormatParameter("Type"));

                    command = _Driver.CreateCommand(query, _Connection, _Transaction);
                    command.Parameters.Add(_Driver.CreateParameter("Id", c.ParentId, _Dialect.GetDbTypeToPrimaryKey(e.Ids[0].Generator), GetParameterDirectionToId(e.Ids[0].Generator.Name)));
                    command.Parameters.Add(_Driver.CreateParameter("Type", DbType.AnsiString, c.Type));

                }
                else
                {
                    StringCollection column_list = new StringCollection();
                    column_list.Add(e.IdFields);

                    StringCollection value_list = new StringCollection();
                    value_list.Add(_Dialect.FormatValue(c.ParentId, _Dialect.GetDbTypeToPrimaryKey(e.Ids[0].Generator)));

                    string query = String.Format(@"INSERT INTO {0}({1}) VALUES ({2})",
                                                 _Dialect.FormatAttribute(e.Table),
                                                 _Dialect.FormatAttribute(e.IdFields),
                                                 _Driver.FormatParameter("Id"));

                    command = _Driver.CreateCommand(query, _Connection, _Transaction);
                    command.Parameters.Add(_Driver.CreateParameter("Id", c.ParentId, _Dialect.GetDbTypeToPrimaryKey(e.Ids[0].Generator), GetParameterDirectionToId(e.Ids[0].Generator.Name)));
                }

                command.Transaction = _Transaction;

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

                command.ExecuteNonQuery();
            }

        }
示例#7
0
 public abstract CreateEntityCommand Visit(CreateEntityCommand item);