Permalink
Browse files

Remove from method names, update README

  • Loading branch information...
1 parent 146f4b4 commit 1a88380e5df166e73a8cee32ebc206bc985eab34 @brendonh committed Feb 9, 2013
View
@@ -34,16 +34,15 @@ type Person struct {
}
func main() {
- var db = loge.NewLogeDB()
-
- db.CreateType("person", &Person{})
+ var db = loge.NewLogeDB(loge.NewLevelDBStore("data/example"))
+ db.CreateType("person", 1, &Person{}, nil)
// ------------------------------------
// Create an object
db.Transact(func(trans *loge.Transaction) {
- trans.SetObj("person", "brendon", &Person{ Name: "Brendon", Age: 31 })
+ trans.Set("person", "brendon", &Person{ Name: "Brendon", Age: 31 })
}, 0)
@@ -52,15 +51,15 @@ func main() {
db.Transact(func(trans *loge.Transaction) {
if trans.Exists("person", "brendon") {
- var brendon = trans.WriteObj("person", "brendon").(*Person)
+ var brendon = trans.Write("person", "brendon").(*Person)
fmt.Printf("Existing Brendon: %v\n", brendon)
// Update
brendon.Age = 41
}
- var defaultObj = trans.ReadObj("person", "someone else").(*Person)
+ var defaultObj = trans.Read("person", "someone else").(*Person)
fmt.Printf("Default value: %v\n", defaultObj)
}, 0)
@@ -69,7 +68,7 @@ func main() {
// Check the update
db.Transact(func(trans *loge.Transaction) {
- var brendon = trans.ReadObj("person", "brendon").(*Person)
+ var brendon = trans.Read("person", "brendon").(*Person)
fmt.Printf("Updated Brendon: %v\n", brendon)
}, 0)
@@ -80,8 +79,8 @@ func main() {
var trans1 = db.CreateTransaction()
var trans2 = db.CreateTransaction()
- trans1.SetObj("person", "nai", &Person{ Name: "Nai Yu", Age: 32 })
- trans2.SetObj("person", "nai", &Person{ Name: "Not Nai Yu", Age: 16 })
+ trans1.Set("person", "nai", &Person{ Name: "Nai Yu", Age: 32 })
+ trans2.Set("person", "nai", &Person{ Name: "Not Nai Yu", Age: 16 })
fmt.Printf("Commit 1: %v\n", trans1.Commit())
fmt.Printf("Commit 2: %v\n", trans2.Commit())
@@ -91,23 +90,22 @@ func main() {
// Check which succeeded
db.Transact(func(trans *loge.Transaction) {
- var nai = trans.ReadObj("person", "nai")
+ var nai = trans.Read("person", "nai")
fmt.Printf("Nai: %v\n", nai)
}, 0)
-
-}
-```
+}```
Output:
```bash
$ go install logetest && ./bin/logetest
-Existing Brendon: &{Brendon 31}
-Default value: &{ 0}
-Updated Brendon: &{Brendon 41}
+Updating type info: person
+Existing Brendon: &{Brendon 31 []}
+Default value: <nil>
+Updated Brendon: &{Brendon 41 []}
Commit 1: true
Commit 2: false
-Nai: &{Nai Yu 32}
+Nai: &{Nai Yu 32 []}
```
Random Notes
@@ -23,7 +23,7 @@ func BenchmarkNoContention(b *testing.B) {
db.Transact(func (t *Transaction) {
for i := 0; i < procs; i++ {
var key LogeKey = LogeKey(strconv.Itoa(i))
- t.SetObj("counters", key, &TestCounter{Value: 0})
+ t.Set("counters", key, &TestCounter{Value: 0})
}
}, 0)
@@ -42,7 +42,7 @@ func BenchmarkNoContention(b *testing.B) {
db.Transact(func (t *Transaction) {
for i := 0; i < procs; i++ {
var key = LogeKey(strconv.Itoa(i))
- var counter = t.ReadObj("counters", key).(*TestCounter)
+ var counter = t.Read("counters", key).(*TestCounter)
if counter.Value != b.N {
b.Errorf("Wrong count for counter %d: %d / %d",
i, counter.Value, b.N)
@@ -65,7 +65,7 @@ func BenchmarkContention(b *testing.B) {
db.CreateType("counters", 1, &TestCounter{}, nil)
db.Transact(func (t *Transaction) {
- t.SetObj("counters", "contended", &TestCounter{Value: 0})
+ t.Set("counters", "contended", &TestCounter{Value: 0})
}, 0)
b.StartTimer()
@@ -81,7 +81,7 @@ func BenchmarkContention(b *testing.B) {
db.Transact(func (t *Transaction) {
var target = b.N * procs
- var counter = t.ReadObj("counters", "contended").(*TestCounter)
+ var counter = t.Read("counters", "contended").(*TestCounter)
if counter.Value != target {
b.Errorf("Wrong count for counter: %d / %d",
counter.Value, target)
@@ -102,6 +102,6 @@ func LoopIncrement(db *LogeDB, key LogeKey, group *sync.WaitGroup, count int) {
func Increment(trans *Transaction, key LogeKey) {
- var counter = trans.WriteObj("counters", key).(*TestCounter)
+ var counter = trans.Write("counters", key).(*TestCounter)
counter.Value += 1
}
View
@@ -12,16 +12,16 @@ func TestSimpleCreation(test *testing.T) {
db.CreateType("test", 1, &TestObj{}, nil)
db.Transact(func(t *Transaction) {
- t.SetObj("test", "one", &TestObj{Name: "One"})
+ t.Set("test", "one", &TestObj{Name: "One"})
- var one = t.ReadObj("test", "one").(*TestObj)
+ var one = t.Read("test", "one").(*TestObj)
if one.Name != "One" {
test.Error("Created object missing in transaction")
}
}, 0)
db.Transact(func(t *Transaction) {
- var one = t.ReadObj("test", "one").(*TestObj)
+ var one = t.Read("test", "one").(*TestObj)
if one.Name != "One" {
test.Error("Created object missing after transaction")
}
@@ -37,7 +37,7 @@ func TestCreationScoping(test *testing.T) {
var trans2 = db.CreateTransaction()
var trans3 = db.CreateTransaction()
- trans1.SetObj("test", "one", &TestObj{Name: "One"})
+ trans1.Set("test", "one", &TestObj{Name: "One"})
if trans2.Exists("test", "one") {
test.Error("Created object visible across transactions")
@@ -62,8 +62,8 @@ func TestOverlappingCreation(test *testing.T) {
var trans1 = db.CreateTransaction()
var trans2 = db.CreateTransaction()
- trans1.SetObj("test", "one", &TestObj{Name: "One"})
- trans2.SetObj("test", "one", &TestObj{Name: "Two"})
+ trans1.Set("test", "one", &TestObj{Name: "One"})
+ trans2.Set("test", "one", &TestObj{Name: "Two"})
trans1.Commit()
@@ -74,8 +74,8 @@ func TestOverlappingCreation(test *testing.T) {
trans1 = db.CreateTransaction()
trans2 = db.CreateTransaction()
- trans1.SetObj("test", "two", &TestObj{Name: "One"})
- trans2.SetObj("test", "two", &TestObj{Name: "Two"})
+ trans1.Set("test", "two", &TestObj{Name: "One"})
+ trans2.Set("test", "two", &TestObj{Name: "Two"})
trans2.Commit()
View
@@ -8,11 +8,11 @@ func TestSimpleDelete(test *testing.T) {
db.CreateType("test", 1, &TestObj{}, nil)
db.Transact(func (t *Transaction) {
- t.SetObj("test", "one", &TestObj{Name: "One"})
+ t.Set("test", "one", &TestObj{Name: "One"})
}, 0)
db.Transact(func (t *Transaction) {
- t.DeleteObj("test", "one")
+ t.Delete("test", "one")
if t.Exists("test", "one") {
test.Error("Deleted object exists in same transaction")
}
@@ -25,14 +25,14 @@ func TestSimpleDelete(test *testing.T) {
}, 0)
db.Transact(func (t *Transaction) {
- t.SetObj("test", "one", &TestObj{Name: "One Again"})
+ t.Set("test", "one", &TestObj{Name: "One Again"})
if !t.Exists("test", "one") {
test.Error("Re-created object doesn't exist in same transaction")
}
}, 0)
db.Transact(func (t *Transaction) {
- var one = t.ReadObj("test", "one").(*TestObj)
+ var one = t.Read("test", "one").(*TestObj)
if one.Name != "One Again" {
test.Error("Re-created object has wrong name")
}
@@ -45,16 +45,16 @@ func TestDeleteScoping(test *testing.T) {
db.CreateType("test", 1, &TestObj{}, nil)
db.Transact(func (t *Transaction) {
- t.SetObj("test", "one", &TestObj{Name: "One"})
+ t.Set("test", "one", &TestObj{Name: "One"})
}, 0)
var trans1 = db.CreateTransaction()
var trans2 = db.CreateTransaction()
- trans1.ReadObj("test", "one")
+ trans1.Read("test", "one")
- trans2.DeleteObj("test", "one")
+ trans2.Delete("test", "one")
if !trans1.Exists("test", "one") {
test.Error("Deleted object missing across transaction")
View
@@ -46,23 +46,23 @@ func (t *Transaction) Exists(typeName string, key LogeKey) bool {
}
-func (t *Transaction) ReadObj(typeName string, key LogeKey) interface{} {
+func (t *Transaction) Read(typeName string, key LogeKey) interface{} {
return t.getObj(makeObjRef(typeName, key), false, true).Object
}
-func (t *Transaction) WriteObj(typeName string, key LogeKey) interface{} {
+func (t *Transaction) Write(typeName string, key LogeKey) interface{} {
return t.getObj(makeObjRef(typeName, key), true, true).Object
}
-func (t *Transaction) SetObj(typeName string, key LogeKey, obj interface{}) {
+func (t *Transaction) Set(typeName string, key LogeKey, obj interface{}) {
var version = t.getObj(makeObjRef(typeName, key), true, false)
version.Object = obj
}
-func (t *Transaction) DeleteObj(typeName string, key LogeKey) {
+func (t *Transaction) Delete(typeName string, key LogeKey) {
var version = t.getObj(makeObjRef(typeName, key), true, true)
version.Object = version.LogeObj.Type.NilValue()
}
View
@@ -7,16 +7,16 @@ func TestSimpleUpdate(test *testing.T) {
db.CreateType("test", 1, &TestObj{}, nil)
db.Transact(func (t *Transaction) {
- t.SetObj("test", "one", &TestObj{Name: "One"})
+ t.Set("test", "one", &TestObj{Name: "One"})
}, 0)
db.Transact(func (t *Transaction) {
- var one = t.WriteObj("test", "one").(*TestObj)
+ var one = t.Write("test", "one").(*TestObj)
one.Name = "Two"
}, 0)
db.Transact(func (t *Transaction) {
- var one = t.ReadObj("test", "one").(*TestObj)
+ var one = t.Read("test", "one").(*TestObj)
if one.Name != "Two" {
test.Error("Simple update failed")
}
@@ -28,12 +28,12 @@ func TestReadWrite(test *testing.T) {
db.CreateType("test", 1, &TestObj{}, nil)
db.Transact(func (t *Transaction) {
- t.ReadObj("test", "one")
- t.SetObj("test", "one", &TestObj{Name: "One"})
+ t.Read("test", "one")
+ t.Set("test", "one", &TestObj{Name: "One"})
}, 0)
db.Transact(func (t *Transaction) {
- var one = t.ReadObj("test", "one").(*TestObj)
+ var one = t.Read("test", "one").(*TestObj)
if one.Name != "One" {
test.Error("ReadWrite failed")
}
@@ -45,34 +45,34 @@ func TestUpdateScoping(test *testing.T) {
db.CreateType("test", 1, &TestObj{}, nil)
db.Transact(func (t *Transaction) {
- t.SetObj("test", "one", &TestObj{Name: "One"})
- t.SetObj("test", "two", &TestObj{Name: "Two"})
+ t.Set("test", "one", &TestObj{Name: "One"})
+ t.Set("test", "two", &TestObj{Name: "Two"})
}, 0)
var trans1 = db.CreateTransaction()
var trans2 = db.CreateTransaction()
- trans1.ReadObj("test", "one")
- var one1 = trans1.WriteObj("test", "one").(*TestObj)
+ trans1.Read("test", "one")
+ var one1 = trans1.Write("test", "one").(*TestObj)
one1.Name = "One Update"
- var two2 = trans2.WriteObj("test", "two").(*TestObj)
+ var two2 = trans2.Write("test", "two").(*TestObj)
two2.Name = "Two Update"
- var test2 = trans1.ReadObj("test", "two").(*TestObj)
+ var test2 = trans1.Read("test", "two").(*TestObj)
if test2.Name != "Two" {
test.Errorf("Update visible across transactions before commit (%v)", test2.Name)
}
- trans2.ReadObj("test", "one")
+ trans2.Read("test", "one")
if !trans1.Commit() {
test.Error("Update 1 failed with no object conflict")
}
- if trans2.ReadObj("test", "one").(*TestObj).Name != "One" {
+ if trans2.Read("test", "one").(*TestObj).Name != "One" {
test.Error("Transaction got update for already-read object")
}
@@ -87,14 +87,14 @@ func TestUpdateConflict(test *testing.T) {
db.CreateType("test", 1, &TestObj{}, nil)
db.Transact(func (t *Transaction) {
- t.SetObj("test", "one", &TestObj{Name: "One"})
+ t.Set("test", "one", &TestObj{Name: "One"})
}, 0)
var trans1 = db.CreateTransaction()
var trans2 = db.CreateTransaction()
- trans1.SetObj("test", "one", &TestObj{Name: "One Update"})
- trans2.SetObj("test", "one", &TestObj{Name: "Two Update"})
+ trans1.Set("test", "one", &TestObj{Name: "One Update"})
+ trans2.Set("test", "one", &TestObj{Name: "Two Update"})
if !trans2.Commit() {
test.Error("Commit 2 failed")
@@ -105,7 +105,7 @@ func TestUpdateConflict(test *testing.T) {
}
db.Transact(func (t *Transaction) {
- if t.ReadObj("test", "one").(*TestObj).Name != "Two Update" {
+ if t.Read("test", "one").(*TestObj).Name != "Two Update" {
test.Error("Wrong name after update")
}
}, 0)
View
@@ -54,7 +54,7 @@ func WritePeopleBatch(db *loge.LogeDB, start int, end int, tokens chan bool) {
Name: name,
Age: uint32(i),
}
- t.SetObj("person", loge.LogeKey(name), &person)
+ t.Set("person", loge.LogeKey(name), &person)
}
}, 0)
tokens<- true
Oops, something went wrong.

0 comments on commit 1a88380

Please sign in to comment.