Наследование: IMapElement, IMapElementLoader
Пример #1
0
        protected SqlCommand UpdateRelationshipCommand(SqlConnection connection, Relationship relationship)
        {
            SqlCommand updateRelationshipCommand = new SqlCommand();
            updateRelationshipCommand.CommandText = "UPDATE [Relationships] SET [RelationshipTypeUid] = @RelationshipTypeUid, [Modified] = @Modified, [ModifiedBy] = @ModifiedBy WHERE [DomainUid] = @DomainUid AND [RelationshipUid] = @RelationshipUid";
            updateRelationshipCommand.Connection = connection;

            updateRelationshipCommand.Parameters.AddWithValue("@RelationshipTypeUid", relationship.RelationshipTypeUid);
            updateRelationshipCommand.Parameters.AddWithValue("@DomainUid", relationship.DomainUid);
            updateRelationshipCommand.Parameters.AddWithValue("@RelationshipUid", relationship.RelationshipUid);

            if (relationship.Modified == null)
            {
                updateRelationshipCommand.Parameters.AddWithValue("@Modified", DBNull.Value);
            }
            else
            {
                updateRelationshipCommand.Parameters.AddWithValue("@Modified", relationship.Modified);
            }

            if (relationship.ModifiedBy == null)
            {
                updateRelationshipCommand.Parameters.AddWithValue("@ModifiedBy", DBNull.Value);
            }
            else
            {
                updateRelationshipCommand.Parameters.AddWithValue("@ModifiedBy", relationship.ModifiedBy);
            }

            return updateRelationshipCommand;
        }
Пример #2
0
 public MapChange(long transactionId, Guid mapParameter, Relationship relationship, TransactionType operation)
 {
     TransactionId = transactionId;
     MapParameter = mapParameter;
     Relationship = relationship;
     Operation = operation;
 }
Пример #3
0
        public Relationship RelationshipCreate(Domain newDomain, Guid relationshipTypeId, IDictionary<Guid, Guid> nodes)
        {
            Guid newRelationshipId;
            Relationship newRelationship = new Relationship();

            SqlCommand createRelationshipCommand = CreateRelationshipCommand(out newRelationshipId, newDomain.DomainUid, relationshipTypeId, nodes);

            createRelationshipCommand.ExecuteNonQuery();

            newRelationship.RelationshipUid = Guid.Empty;
            newRelationship.RelationshipOriginalId = string.Empty;
            newRelationship.RelationshipTypeUid = relationshipTypeId;
            newRelationship.DomainUid = newDomain.DomainUid;

            return newRelationship;
        }
Пример #4
0
        public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response)
        {
            IMapTransaction transaction = (IMapTransaction)transactionWrapper;

            SqlCommand command = SelectDeleteNodeRelationshipsDescriptorsMetadataCommand(connectionAbstraction.Connection, transactionWrapper.NodeParameter.Value);

            connectionAbstraction.Open();

            SqlDataReader reader = command.ExecuteReader();

            if (reader.Read())
            {
                Node deletedNode = new Node();
                deletedNode.LoadElement(reader);

                response.Changes.Add(new MapChange(transaction.TransactionId, transactionWrapper.ResponseParameter.Id, deletedNode, TransactionType.DeleteNode));

                if (reader.NextResult())
                {
                    while (reader.Read())
                    {
                        Metadata deletedMetadata = new Metadata();
                        deletedMetadata.LoadElement(reader);

                        response.Changes.Add(new MapChange(transaction.TransactionId, transactionWrapper.ResponseParameter.Id, deletedMetadata, TransactionType.DeleteMetadata));
                    }
                }

                if (reader.NextResult())
                {
                    while (reader.Read())
                    {
                        Relationship deletedRelationship = new Relationship();
                        deletedRelationship.LoadElement(reader);

                        response.Changes.Add(new MapChange(transaction.TransactionId, transactionWrapper.ResponseParameter.Id, deletedRelationship, TransactionType.DeleteRelationship));
                    }
                }

                transactionWrapper.ResponseParameter.Value = deletedNode.NodeUid;
            }
            connectionAbstraction.Close();
        }
Пример #5
0
        public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response)
        {
            IMapTransaction transaction = (IMapTransaction)transactionWrapper;

            DateTime currentTime = DateTime.Now;

            Relationship newRelationship = new Relationship();
            newRelationship.RelationshipTypeUid = transaction.RelationshipTypeUid.Value;
            newRelationship.DomainUid = transactionWrapper.DomainParameter.Value;

            if (transactionWrapper.RootMapParameter != null)
            {
                newRelationship.RootMapUid = transactionWrapper.RootMapParameter.Value;
            }
            else
            {
                newRelationship.RootMapUid = null;
            }

            newRelationship.Created = currentTime;
            newRelationship.Modified = currentTime;
            newRelationship.CreatedBy = transaction.User;
            newRelationship.ModifiedBy = transaction.User;

            Guid newRelationshipId;

            SqlCommand command = CreateRelationshipCommand(connectionAbstraction.Connection, out newRelationshipId, newRelationship);

            connectionAbstraction.Open();

            command.ExecuteNonQuery();
            connectionAbstraction.Close();
            
            newRelationship.RelationshipUid = newRelationshipId;
            response.Changes.Add(new MapChange(transaction.TransactionId, transactionWrapper.ResponseParameter.Id, newRelationship, TransactionType.CreateRelationship));

            transactionWrapper.ResponseParameter.Value = newRelationshipId;
        }
Пример #6
0
        public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response)
        {
            IMapTransaction transaction = (IMapTransaction)transactionWrapper;

            DateTime currentTime = DateTime.Now;

            Relationship updatedRelationship = new Relationship();
            updatedRelationship.DomainUid = transactionWrapper.DomainParameter.Value;
            updatedRelationship.RelationshipUid = transactionWrapper.RelationshipParameter.Value;
            updatedRelationship.RelationshipTypeUid = transaction.RelationshipTypeUid.Value;
            updatedRelationship.Modified = currentTime;
            updatedRelationship.ModifiedBy = transaction.User;

            SqlCommand updateRelationshipCommand = UpdateRelationshipCommand(connectionAbstraction.Connection, updatedRelationship);

            connectionAbstraction.Open();
            updateRelationshipCommand.ExecuteNonQuery();
            connectionAbstraction.Close();

            response.Changes.Add(new MapChange(transaction.TransactionId, transactionWrapper.ResponseParameter.Id, updatedRelationship, TransactionType.UpdateRelationship));

            transactionWrapper.ResponseParameter.Value = updatedRelationship.RelationshipUid;
        }
Пример #7
0
 public void AddRelationship(Relationship relationship)
 {
     Relationships.Add(relationship.RelationshipUid, relationship);
 }
Пример #8
0
 public MapChange(long transactionId, Relationship relationship, TransactionType operation)
 {
     TransactionId = transactionId;
     Relationship = relationship;
     Operation = operation;
 }
Пример #9
0
        protected SqlCommand CreateRelationshipCommand(SqlConnection connection, out Guid newRelationshipUid, Relationship newRelationshipParameters)
        {
            SqlCommand createRelationshipCommand = new SqlCommand();
            //createRelationshipCommand.CommandText = "INSERT INTO [Relationships] (RelationshipUid, RelationshipOriginalId, RelationshipTypeUid, DomainUid) VALUES (@RelationshipUid, @RelationshipOriginalId, @RelationshipTypeUid, @DomainUid)";
            createRelationshipCommand.CommandText = "INSERT INTO [Relationships] ([RelationshipUid], [RelationshipTypeUid], [DomainUid], [RootMapUid], [Created], [Modified], [CreatedBy], [ModifiedBy]) VALUES (@RelationshipUid, @RelationshipTypeUid, @DomainUid, @RootMapUid, @Created, @Modified, @CreatedBy, @ModifiedBy)";
            createRelationshipCommand.Connection = connection;

            newRelationshipUid = Guid.NewGuid();

            createRelationshipCommand.Parameters.AddWithValue("@RelationshipUid", newRelationshipUid);
            /// TODO: Need to persist the RelationshipOriginalId value.
            //createRelationshipCommand.Parameters.AddWithValue("@RelationshipOriginalId", OriginalId);
            createRelationshipCommand.Parameters.AddWithValue("@RelationshipTypeUid", newRelationshipParameters.RelationshipTypeUid);
            createRelationshipCommand.Parameters.AddWithValue("@DomainUid", newRelationshipParameters.DomainUid);

            if (newRelationshipParameters.RootMapUid == null)
            {
                createRelationshipCommand.Parameters.AddWithValue("@RootMapUid", DBNull.Value);
            }
            else
            {
                createRelationshipCommand.Parameters.AddWithValue("@RootMapUid", newRelationshipParameters.RootMapUid);
            }

            if (newRelationshipParameters.Created == null)
            {
                createRelationshipCommand.Parameters.AddWithValue("@Created", DBNull.Value);
            }
            else
            {
                createRelationshipCommand.Parameters.AddWithValue("@Created", newRelationshipParameters.Created);
            }

            if (newRelationshipParameters.Modified == null)
            {
                createRelationshipCommand.Parameters.AddWithValue("@Modified", DBNull.Value);
            }
            else
            {
                createRelationshipCommand.Parameters.AddWithValue("@Modified", newRelationshipParameters.Modified);
            }

            if (newRelationshipParameters.CreatedBy == null)
            {
                createRelationshipCommand.Parameters.AddWithValue("@CreatedBy", DBNull.Value);
            }
            else
            {
                createRelationshipCommand.Parameters.AddWithValue("@CreatedBy", newRelationshipParameters.CreatedBy);
            }

            if (newRelationshipParameters.ModifiedBy == null)
            {
                createRelationshipCommand.Parameters.AddWithValue("@ModifiedBy", DBNull.Value);
            }
            else
            {
                createRelationshipCommand.Parameters.AddWithValue("@ModifiedBy", newRelationshipParameters.ModifiedBy);
            }

            return createRelationshipCommand;
        }