public int InsertType(CorrespondenceFactType typeMemento) { int typeId; _session.Command.CommandText = "INSERT INTO Type (TypeName, Version) VALUES (@TypeName, @Version)"; AddParameter("@TypeName", typeMemento.TypeName); AddParameter("@Version", typeMemento.Version); _session.Command.ExecuteNonQuery(); _session.Command.Parameters.Clear(); _session.Command.CommandText = "SELECT @@IDENTITY"; typeId = (int)(decimal)_session.Command.ExecuteScalar(); _session.Command.Parameters.Clear(); return(typeId); }
private IdentifiedFactMemento DeserlializeIdentifiedFactMemento(BinaryReader factReader, long factId) { short dataSize; byte[] data; short predecessorCount; CorrespondenceFactType factType = GetFactType(BinaryHelper.ReadShort(factReader)); dataSize = BinaryHelper.ReadShort(factReader); if (dataSize > MaxDataLength) { throw new CorrespondenceException("Maximum data length exceeded."); } data = dataSize > 0 ? factReader.ReadBytes(dataSize) : new byte[0]; predecessorCount = BinaryHelper.ReadShort(factReader); if (predecessorCount > MaxPredecessorCount) { throw new CorrespondenceException("Maximum predecessor count exceeded."); } FactMemento factMemento = new FactMemento(factType); factMemento.Data = data; for (short i = 0; i < predecessorCount; i++) { bool isPivot; long predecessorFactId; RoleMemento role = GetRole(BinaryHelper.ReadShort(factReader)); isPivot = BinaryHelper.ReadBoolean(factReader); predecessorFactId = BinaryHelper.ReadLong(factReader); factMemento.AddPredecessor( role, new FactID() { key = predecessorFactId }, isPivot ); } return(new IdentifiedFactMemento(new FactID { key = factId }, factMemento)); }
public int GetTypeId(CorrespondenceFactType typeMemento) { int typeId = 0; _session.Command.CommandText = "SELECT TypeID FROM Type WHERE TypeName = @TypeName AND Version = @Version"; AddParameter("@TypeName", typeMemento.TypeName); AddParameter("@Version", typeMemento.Version); using (IDataReader typeReader = _session.Command.ExecuteReader()) { _session.Command.Parameters.Clear(); if (typeReader.Read()) { typeId = typeReader.GetInt32(0); } } return(typeId); }
public short GetFactTypeId(CorrespondenceFactType factType) { return((short)_factTypes.IndexOf(factType)); }
public int InsertType(CorrespondenceFactType typeMemento) { int typeId; _session.Command.CommandText = "INSERT INTO Type (TypeName, Version) VALUES (@TypeName, @Version)"; AddParameter("@TypeName", typeMemento.TypeName); AddParameter("@Version", typeMemento.Version); _session.Command.ExecuteNonQuery(); _session.Command.Parameters.Clear(); _session.Command.CommandText = "SELECT @@IDENTITY"; typeId = (int)(decimal)_session.Command.ExecuteScalar(); _session.Command.Parameters.Clear(); return typeId; }
public int GetTypeId(CorrespondenceFactType typeMemento) { int typeId = 0; _session.Command.CommandText = "SELECT TypeID FROM Type WHERE TypeName = @TypeName AND Version = @Version"; AddParameter("@TypeName", typeMemento.TypeName); AddParameter("@Version", typeMemento.Version); using (IDataReader typeReader = _session.Command.ExecuteReader()) { _session.Command.Parameters.Clear(); if (typeReader.Read()) { typeId = typeReader.GetInt32(0); } } return typeId; }
public short GetFactTypeId(CorrespondenceFactType factType) { return (short)_factTypes.IndexOf(factType); }
public void AddFactType(CorrespondenceFactType factType) { if (!_factTypes.Contains(factType)) _factTypes.Add(factType); }
private int SaveType(Procedures procedures, CorrespondenceFactType typeMemento) { // See if the type already exists. int typeId = procedures.GetTypeId(typeMemento); // If not, create it. if (typeId == 0) { typeId = procedures.InsertType(typeMemento); } return typeId; }