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

@ -38,7 +38,7 @@ type Transaction struct {
ID int64
Triple *Triple
Action Procedure
Timestamp *time.Time
Timestamp time.Time
}
type TripleWriter interface {

View file

@ -39,7 +39,7 @@ type Value interface{}
type TripleStore interface {
// The only way in is through building a transaction, which
// is done by a replication strategy.
ApplyTransactions([]*Transaction)
ApplyTransactions([]*Transaction) error
// Given an opaque token, returns the triple for that token from the store.
Triple(Value) *Triple

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)
}