Refactoring of Delta.IDs & horizon functionality with a PrimaryKey type, needed for implementing UUID based primary keys for backends such as the appengine datastore \n Tests: at top level and if available per backend, if not then just visual

This commit is contained in:
panamafrancis 2014-12-01 23:00:06 +01:00
parent 26ceed35cc
commit abda6cbbb0
11 changed files with 135 additions and 44 deletions

View file

@ -28,6 +28,7 @@ import (
"github.com/google/cayley/graph"
"github.com/google/cayley/graph/iterator"
"github.com/google/cayley/keys"
"github.com/google/cayley/quad"
)
@ -124,8 +125,8 @@ func (qs *QuadStore) Size() int64 {
return qs.size
}
func (qs *QuadStore) Horizon() int64 {
return qs.horizon
func (qs *QuadStore) Horizon() graph.PrimaryKey {
return keys.NewSequentialKey(qs.horizon)
}
func (qs *QuadStore) createDeltaKeyFor(id int64) []byte {
@ -195,13 +196,13 @@ func (qs *QuadStore) ApplyDeltas(deltas []graph.Delta) error {
if err != nil {
return err
}
err = b.Put(qs.createDeltaKeyFor(d.ID), bytes)
err = b.Put(qs.createDeltaKeyFor(d.ID.Int()), bytes)
if err != nil {
return err
}
}
for _, d := range deltas {
err := qs.buildQuadWrite(tx, d.Quad, d.ID, d.Action == graph.Add)
err := qs.buildQuadWrite(tx, d.Quad, d.ID.Int(), d.Action == graph.Add)
if err != nil {
return err
}
@ -216,7 +217,7 @@ func (qs *QuadStore) ApplyDeltas(deltas []graph.Delta) error {
resizeMap[d.Quad.Label] += delta
}
sizeChange += delta
qs.horizon = d.ID
qs.horizon = d.ID.Int()
}
for k, v := range resizeMap {
if v != 0 {