public MapChange(long transactionId, Guid mapParameter, Metadata metadata, TransactionType operation) { TransactionId = transactionId; MapParameter = mapParameter; Metadata = metadata; Operation = operation; }
public MetadataContext(Metadata metadata) { MetadataId = metadata.MetadataId; NodeUid = metadata.NodeUid; RelationshipUid = metadata.RelationshipUid; DescriptorTypeUid = metadata.DescriptorTypeUid; }
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(); }
public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response) { IMapTransaction transaction = (IMapTransaction)transactionWrapper; SqlCommand command = SelectDeleteMetadataCommand(connectionAbstraction.Connection, transactionWrapper.MetadataParameter.Value); connectionAbstraction.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { Metadata deletedMetadata = new Metadata(); deletedMetadata.LoadElement(reader); response.Changes.Add(new MapChange(transaction.TransactionId, transactionWrapper.ResponseParameter.Id, deletedMetadata, TransactionType.DeleteMetadata)); transactionWrapper.ResponseParameter.Value = deletedMetadata.MetadataId; } connectionAbstraction.Close(); }
public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response) { IMapTransaction transaction = (IMapTransaction)transactionWrapper; DateTime currentTime = DateTime.Now; Metadata updatedMetadata = new Metadata(); updatedMetadata.MetadataId = transactionWrapper.MetadataParameter.Value; updatedMetadata.MetadataName = transaction.MetadataName; updatedMetadata.MetadataValue = transaction.MetadataValue; updatedMetadata.Modified = currentTime; updatedMetadata.ModifiedBy = transaction.User; SqlCommand command = UpdateMetadataCommand(connectionAbstraction.Connection, updatedMetadata); connectionAbstraction.Open(); command.ExecuteNonQuery(); connectionAbstraction.Close(); response.Changes.Add(new MapChange(transaction.TransactionId, transactionWrapper.ResponseParameter.Id, updatedMetadata, TransactionType.UpdateMetadata)); transactionWrapper.ResponseParameter.Value = updatedMetadata.MetadataId; }
public void AddMetadata(Metadata metadata) { Metadata.Add(metadata.MetadataId, metadata); }
public MapChange(long transactionId, Metadata metadata, TransactionType operation) { TransactionId = transactionId; Metadata = metadata; Operation = operation; }
protected SqlCommand CreateMetadataCommand(SqlConnection connection, out Guid newMetadataId, Metadata newMetadataParameters) { SqlCommand createMetadataCommand = new SqlCommand(); createMetadataCommand.CommandText = "INSERT INTO [Metadata] ([MetadataId], [MetadataTypeUid], [NodeUid], [RelationshipUid], [DescriptorTypeUid], [MetadataName], [MetadataValue], [DomainUid], [RootMapUid], [Created], [Modified], [CreatedBy], [ModifiedBy]) VALUES (@MetadataId, @MetadataTypeUid, @NodeUid, @RelationshipUid, @DescriptorTypeUid, @MetadataName, @MetadataValue, @DomainUid, @RootMapUid, @Created, @Modified, @CreatedBy, @ModifiedBy)"; createMetadataCommand.Connection = connection; newMetadataId = Guid.NewGuid(); createMetadataCommand.Parameters.AddWithValue("@MetadataId", newMetadataId); createMetadataCommand.Parameters.AddWithValue("@MetadataTypeUid", newMetadataParameters.MetadataTypeUid); if (newMetadataParameters.NodeUid == null) { createMetadataCommand.Parameters.AddWithValue("@NodeUid", DBNull.Value); } else { createMetadataCommand.Parameters.AddWithValue("@NodeUid", newMetadataParameters.NodeUid); } if (newMetadataParameters.RelationshipUid == null) { createMetadataCommand.Parameters.AddWithValue("@RelationshipUid", DBNull.Value); } else { createMetadataCommand.Parameters.AddWithValue("@RelationshipUid", newMetadataParameters.RelationshipUid); } if (newMetadataParameters.DescriptorTypeUid == null) { createMetadataCommand.Parameters.AddWithValue("@DescriptorTypeUid", DBNull.Value); } else { createMetadataCommand.Parameters.AddWithValue("@DescriptorTypeUid", newMetadataParameters.DescriptorTypeUid); } createMetadataCommand.Parameters.AddWithValue("@MetadataName", newMetadataParameters.MetadataName); createMetadataCommand.Parameters.AddWithValue("@MetadataValue", newMetadataParameters.MetadataValue); createMetadataCommand.Parameters.AddWithValue("@DomainUid", newMetadataParameters.DomainUid); if (newMetadataParameters.RootMapUid == null) { createMetadataCommand.Parameters.AddWithValue("@RootMapUid", DBNull.Value); } else { createMetadataCommand.Parameters.AddWithValue("@RootMapUid", newMetadataParameters.RootMapUid); } if (newMetadataParameters.Created == null) { createMetadataCommand.Parameters.AddWithValue("@Created", DBNull.Value); } else { createMetadataCommand.Parameters.AddWithValue("@Created", newMetadataParameters.Created); } if (newMetadataParameters.Modified == null) { createMetadataCommand.Parameters.AddWithValue("@Modified", DBNull.Value); } else { createMetadataCommand.Parameters.AddWithValue("@Modified", newMetadataParameters.Modified); } if (newMetadataParameters.CreatedBy == null) { createMetadataCommand.Parameters.AddWithValue("@CreatedBy", DBNull.Value); } else { createMetadataCommand.Parameters.AddWithValue("@CreatedBy", newMetadataParameters.CreatedBy); } if (newMetadataParameters.ModifiedBy == null) { createMetadataCommand.Parameters.AddWithValue("@ModifiedBy", DBNull.Value); } else { createMetadataCommand.Parameters.AddWithValue("@ModifiedBy", newMetadataParameters.ModifiedBy); } return createMetadataCommand; }
public void ExecuteTransaction(IDbConnectionAbstraction connectionAbstraction, MapTransactionWrapper transactionWrapper, ref MapResponse response) { IMapTransaction transaction = (IMapTransaction)transactionWrapper; DateTime currentTime = DateTime.Now; Metadata newMetadata = new Metadata(); newMetadata.MetadataTypeUid = transaction.MetadataTypeUid.Value; newMetadata.DomainUid = transactionWrapper.DomainParameter.Value; if (transactionWrapper.RootMapParameter != null) { newMetadata.RootMapUid = transactionWrapper.RootMapParameter.Value; } else { newMetadata.RootMapUid = null; } newMetadata.Created = currentTime; newMetadata.Modified = currentTime; newMetadata.CreatedBy = transaction.User; newMetadata.ModifiedBy = transaction.User; if (transactionWrapper.NodeParameter == null) { newMetadata.NodeUid = null; } else { newMetadata.NodeUid = transactionWrapper.NodeParameter.Value; } if (transactionWrapper.RelationshipParameter == null) { newMetadata.RelationshipUid = null; } else { newMetadata.RelationshipUid = transactionWrapper.RelationshipParameter.Value; } if (transaction.DescriptorTypeUid == null) { newMetadata.DescriptorTypeUid = null; } else { newMetadata.DescriptorTypeUid = transaction.DescriptorTypeUid.Value; } newMetadata.MetadataName = transaction.MetadataName; newMetadata.MetadataValue = transaction.MetadataValue; Guid newMetadataId; SqlCommand command = CreateMetadataCommand(connectionAbstraction.Connection, out newMetadataId, newMetadata); connectionAbstraction.Open(); command.ExecuteNonQuery(); connectionAbstraction.Close(); newMetadata.MetadataId = newMetadataId; response.Changes.Add(new MapChange(transaction.TransactionId, transactionWrapper.ResponseParameter.Id, newMetadata, TransactionType.CreateMetadata)); transactionWrapper.ResponseParameter.Value = newMetadataId; }
protected SqlCommand UpdateMetadataCommand(SqlConnection connection, Metadata metadata) { bool hasName = false; bool hasValue = false; string commandText = "UPDATE [Metadata] SET {0}{1}{2}, [Modified] = @Modified, [ModifiedBy] = @ModifiedBy WHERE [MetadataId] = @MetadataId"; string metadataNameText = string.Empty; string metadataValueText = string.Empty; string separatorText = string.Empty; if (!string.IsNullOrEmpty(metadata.MetadataName)) { metadataNameText = "[MetadataName] = @MetadataName"; hasName = true; } if (metadata.MetadataValue != null) { metadataValueText = "[MetadataValue] = @MetadataValue"; hasValue = true; } if (hasName && hasValue) { separatorText = ", "; } SqlCommand updateMetadataCommand = new SqlCommand(); updateMetadataCommand.CommandText = string.Format(commandText, metadataNameText, separatorText, metadataValueText); updateMetadataCommand.Connection = connection; updateMetadataCommand.Parameters.AddWithValue("@MetadataId", metadata.MetadataId); if (hasName) { updateMetadataCommand.Parameters.AddWithValue("@MetadataName", metadata.MetadataName); } if (hasValue) { updateMetadataCommand.Parameters.AddWithValue("@MetadataValue", metadata.MetadataValue); } if (metadata.Modified == null) { updateMetadataCommand.Parameters.AddWithValue("@Modified", DBNull.Value); } else { updateMetadataCommand.Parameters.AddWithValue("@Modified", metadata.Modified); } if (metadata.ModifiedBy == null) { updateMetadataCommand.Parameters.AddWithValue("@ModifiedBy", DBNull.Value); } else { updateMetadataCommand.Parameters.AddWithValue("@ModifiedBy", metadata.ModifiedBy); } return updateMetadataCommand; }