diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-01-26 15:29:06 -0700 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-01-26 15:29:06 -0700 |
commit | 1baa6d576a5f13a55d81c83a167efe0953c0d143 (patch) | |
tree | 83f10236ee028b8e6ef559a6ca53f1d81ad39cba /db.go | |
parent | Remove RWCursor. (diff) | |
download | dedo-1baa6d576a5f13a55d81c83a167efe0953c0d143.tar.gz dedo-1baa6d576a5f13a55d81c83a167efe0953c0d143.tar.xz |
Initialize transaction/rwtransaction.
Diffstat (limited to 'db.go')
-rw-r--r-- | db.go | 29 |
1 files changed, 12 insertions, 17 deletions
@@ -217,18 +217,8 @@ func (db *DB) Transaction() (*Transaction, error) { } // Create a transaction associated with the database. - t := &Transaction{ - db: db, - meta: db.meta(), - buckets: make(map[string]*Bucket), - cursors: make(map[uint32]*Cursor), - } - - // Save references to the sys•free and sys•buckets buckets. - t.sysfree.transaction = t - t.sysfree.bucket = &t.meta.free - t.sysbuckets.transaction = t - t.sysbuckets.bucket = &t.meta.buckets + t := &Transaction{} + t.init(db, db.meta()) return t, nil } @@ -236,16 +226,21 @@ func (db *DB) Transaction() (*Transaction, error) { // RWTransaction creates a read/write transaction. // Only one read/write transaction is allowed at a time. func (db *DB) RWTransaction() (*RWTransaction, error) { + db.Lock() + defer db.Unlock() + // TODO: db.writerMutex.Lock() // TODO: Add unlock to RWTransaction.Commit() / Abort() - t := &RWTransaction{} - - // Exit if a read-write transaction is currently in progress. - if db.transaction != nil { - return nil, TransactionInProgressError + // Exit if the database is not open yet. + if !db.opened { + return nil, DatabaseNotOpenError } + // Create a transaction associated with the database. + t := &RWTransaction{} + t.init(db, db.meta()) + return t, nil } |