Example #1
0
        /// <summary>
        /// Update new row in data base and return the row identity
        /// </summary>
        /// <param name="id">Identity of row to be updated</param>
        /// <param name="edge">Edge to be updated</param>
        /// <returns>Success flag</returns>
        private bool Update(long id, IPersistentEdge edge)
        {
            string edgeString = edge.Serialize();

            edgeString = string.Concat(edgeString, Environment.NewLine);
            byte[] buffer = ASCIIEncoding.ASCII.GetBytes(edgeString);

            lock (lockObject)
            {
                _stream.Seek(id, SeekOrigin.Begin);
                _stream.Write(buffer, 0, edgeString.Length);
                _stream.Flush();
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// Insert a new row in data base and return the row identity
        /// </summary>
        /// <param name="edge">Edge to be inserted</param>
        /// <returns>Id of new inserted row</returns>
        private long Insert(IPersistentEdge edge)
        {
            // Append the new line character to each line
            lock (lockObject)
            {
                _stream.Seek(0, SeekOrigin.End);
                edge.Key = _stream.Position;
                string edgeString = edge.Serialize();
                edgeString = string.Concat(edgeString, Environment.NewLine);
                byte[] buffer = ASCIIEncoding.ASCII.GetBytes(edgeString);

                _stream.Write(buffer, 0, edgeString.Length);
                _stream.Flush();
            }

            return(edge.Key);
        }
Example #3
0
        /// <summary>
        /// Write the edge to database storage.
        /// 1. Serialize the given edge.
        /// 2. Write it to the database.
        /// 3. Return the Key(Id) of newly inserted row.
        /// If the edge does not have key, insert a edge in storage
        /// Else update the existing edge in storage
        /// </summary>
        /// <param name="edge">Edge to be stored</param>
        /// <returns>Index / Key / Id / Offset of new edge</returns>
        public long Write(IPersistentEdge edge)
        {
            if (edge == null)
            {
                throw new ArgumentNullException("edge");
            }

            if (edge.Key == -1)
            {
                edge.Key = Insert(edge);
            }
            else
            {
                Update(edge.Key, edge);
            }

            return(edge.Key);
        }