Add ability to check if db transaction is closed

This commit is contained in:
Tobie Morgan Hitchcock 2016-11-26 16:52:43 +00:00
parent 1bf7f5c7e4
commit f931341a95
4 changed files with 22 additions and 0 deletions

View file

@ -28,6 +28,7 @@ import (
// TX is a distributed database transaction.
type TX struct {
ds *DS
do bool
ck []byte
tx *bolt.Tx
bu *bolt.Bucket
@ -329,6 +330,10 @@ func (tx *TX) RDel(beg, end []byte, max uint64) (err error) {
}
func (tx *TX) Done() (val bool) {
return tx.do
}
func (tx *TX) Close() (err error) {
return tx.Rollback()
}
@ -338,6 +343,7 @@ func (tx *TX) Cancel() (err error) {
}
func (tx *TX) Commit() (err error) {
tx.do = true
if tx.tx.Writable() {
return tx.tx.Commit()
}
@ -345,6 +351,7 @@ func (tx *TX) Commit() (err error) {
}
func (tx *TX) Rollback() (err error) {
tx.do = true
return tx.tx.Rollback()
}

View file

@ -28,6 +28,7 @@ import (
// TX is a distributed database transaction.
type TX struct {
ds *DS
do bool
ck []byte
tx *sql.Tx
}
@ -310,6 +311,10 @@ func (tx *TX) RDel(beg, end []byte, max uint64) (err error) {
}
func (tx *TX) Done() (val bool) {
return tx.do
}
func (tx *TX) Close() (err error) {
return tx.Rollback()
}
@ -319,10 +324,12 @@ func (tx *TX) Cancel() (err error) {
}
func (tx *TX) Commit() (err error) {
tx.do = true
return tx.tx.Commit()
}
func (tx *TX) Rollback() (err error) {
tx.do = true
return tx.tx.Rollback()
}

View file

@ -28,6 +28,7 @@ import (
// TX is a distributed database transaction.
type TX struct {
ds *DS
do bool
ck []byte
tx *sql.Tx
}
@ -319,6 +320,10 @@ func (tx *TX) RDel(beg, end []byte, max uint64) (err error) {
}
func (tx *TX) Done() (val bool) {
return tx.do
}
func (tx *TX) Close() (err error) {
return tx.Rollback()
}
@ -328,10 +333,12 @@ func (tx *TX) Cancel() (err error) {
}
func (tx *TX) Commit() (err error) {
tx.do = true
return tx.tx.Commit()
}
func (tx *TX) Rollback() (err error) {
tx.do = true
return tx.tx.Rollback()
}

View file

@ -28,6 +28,7 @@ type TX interface {
MDel(...[]byte) error
PDel([]byte) error
RDel([]byte, []byte, uint64) error
Done() bool
Close() error
Cancel() error
Commit() error