single writer

This commit is contained in:
Barak Michener 2014-07-27 15:39:45 -04:00
parent 7a8d4194bd
commit e13e65d09b
3 changed files with 36 additions and 3 deletions

View file

@ -16,6 +16,7 @@ package replication
import (
"sync"
"time"
"github.com/google/cayley/graph"
)
@ -42,10 +43,42 @@ func (s *Single) AcquireNextId() int64 {
return id
}
func AddTriple(*graph.Triple) error {
func (s *Single) AddTriple(t *graph.Triple) error {
trans := make([]*graph.Transaction, 1)
trans[0] = &graph.Transaction{
ID: s.AcquireNextId(),
Triple: t,
Action: graph.Add,
Timestamp: time.Now(),
}
return s.ts.ApplyTransactions(trans)
}
func (s *Single) AddTripleSet(set []*graph.Triple) error {
trans := make([]*graph.Transaction, len(set))
for i, t := range set {
trans[i] = &graph.Transaction{
ID: s.AcquireNextId(),
Triple: t,
Action: graph.Add,
Timestamp: time.Now(),
}
}
s.ts.ApplyTransactions(trans)
return nil
}
func (s *Single) RemoveTriple(t *graph.Triple) error {
trans := make([]*graph.Transaction, 1)
trans[0] = &graph.Transaction{
ID: s.AcquireNextId(),
Triple: t,
Action: graph.Delete,
Timestamp: time.Now(),
}
return s.ts.ApplyTransactions(trans)
}
func init() {
graph.RegisterWriter("single", NewSingleReplication)
}