rename to quads
This commit is contained in:
parent
cedaac35d0
commit
81b3bf9881
4 changed files with 91 additions and 88 deletions
|
|
@ -24,6 +24,8 @@ package graph
|
|||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/google/cayley/quad"
|
||||
)
|
||||
|
||||
type Procedure byte
|
||||
|
|
@ -34,37 +36,37 @@ const (
|
|||
Delete
|
||||
)
|
||||
|
||||
type Transaction struct {
|
||||
type Delta struct {
|
||||
ID int64
|
||||
Triple *Triple
|
||||
Quad *quad.Quad
|
||||
Action Procedure
|
||||
Timestamp time.Time
|
||||
}
|
||||
|
||||
type TripleWriter interface {
|
||||
type QuadWriter interface {
|
||||
// Add a triple to the store.
|
||||
AddTriple(*Triple) error
|
||||
AddQuad(*quad.Quad) error
|
||||
|
||||
// Add a set of triples to the store, atomically if possible.
|
||||
AddTripleSet([]*Triple) error
|
||||
AddQuadSet([]*quad.Quad) error
|
||||
|
||||
// Removes a triple matching the given one from the database,
|
||||
// if it exists. Does nothing otherwise.
|
||||
RemoveTriple(*Triple) error
|
||||
RemoveQuad(*quad.Quad) error
|
||||
}
|
||||
|
||||
type NewTripleWriterFunc func(TripleStore, Options) (TripleWriter, error)
|
||||
type NewQuadWriterFunc func(TripleStore, Options) (QuadWriter, error)
|
||||
|
||||
var writerRegistry = make(map[string]NewTripleWriterFunc)
|
||||
var writerRegistry = make(map[string]NewQuadWriterFunc)
|
||||
|
||||
func RegisterWriter(name string, newFunc NewTripleWriterFunc) {
|
||||
func RegisterWriter(name string, newFunc NewQuadWriterFunc) {
|
||||
if _, found := writerRegistry[name]; found {
|
||||
panic("already registered TripleWriter " + name)
|
||||
}
|
||||
writerRegistry[name] = newFunc
|
||||
}
|
||||
|
||||
func NewTripleWriter(name string, ts TripleStore, opts Options) (TripleWriter, error) {
|
||||
func NewQuadWriter(name string, ts TripleStore, opts Options) (QuadWriter, error) {
|
||||
newFunc, hasNew := writerRegistry[name]
|
||||
if !hasNew {
|
||||
return nil, errors.New("replication: name '" + name + "' is not registered")
|
||||
|
|
@ -41,7 +41,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) error
|
||||
ApplyDeltas([]*Delta) error
|
||||
|
||||
// Given an opaque token, returns the triple for that token from the store.
|
||||
Quad(Value) *quad.Quad
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/google/cayley/graph"
|
||||
"github.com/google/cayley/quad"
|
||||
)
|
||||
|
||||
type Single struct {
|
||||
|
|
@ -27,7 +28,7 @@ type Single struct {
|
|||
mut sync.Mutex
|
||||
}
|
||||
|
||||
func NewSingleReplication(ts graph.TripleStore, opts graph.Options) (graph.TripleWriter, error) {
|
||||
func NewSingleReplication(ts graph.TripleStore, opts graph.Options) (graph.QuadWriter, error) {
|
||||
rep := &Single{nextID: ts.Horizon(), ts: ts}
|
||||
if rep.nextID == -1 {
|
||||
rep.nextID = 1
|
||||
|
|
@ -43,23 +44,23 @@ func (s *Single) AcquireNextId() int64 {
|
|||
return id
|
||||
}
|
||||
|
||||
func (s *Single) AddTriple(t *graph.Triple) error {
|
||||
func (s *Single) AddQuad(t *quad.Quad) error {
|
||||
trans := make([]*graph.Transaction, 1)
|
||||
trans[0] = &graph.Transaction{
|
||||
ID: s.AcquireNextId(),
|
||||
Triple: t,
|
||||
Quad: t,
|
||||
Action: graph.Add,
|
||||
Timestamp: time.Now(),
|
||||
}
|
||||
return s.ts.ApplyTransactions(trans)
|
||||
}
|
||||
|
||||
func (s *Single) AddTripleSet(set []*graph.Triple) error {
|
||||
func (s *Single) AddQuadSet(set []*quad.Quad) error {
|
||||
trans := make([]*graph.Transaction, len(set))
|
||||
for i, t := range set {
|
||||
trans[i] = &graph.Transaction{
|
||||
ID: s.AcquireNextId(),
|
||||
Triple: t,
|
||||
Quad: t,
|
||||
Action: graph.Add,
|
||||
Timestamp: time.Now(),
|
||||
}
|
||||
|
|
@ -68,7 +69,7 @@ func (s *Single) AddTripleSet(set []*graph.Triple) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *Single) RemoveTriple(t *graph.Triple) error {
|
||||
func (s *Single) RemoveQuad(t *graph.Quad) error {
|
||||
trans := make([]*graph.Transaction, 1)
|
||||
trans[0] = &graph.Transaction{
|
||||
ID: s.AcquireNextId(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue