-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransaction.go
52 lines (47 loc) · 994 Bytes
/
transaction.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package neo4j
import (
"github.com/aliworkshop/error"
"github.com/neo4j/neo4j-go-driver/neo4j"
)
func (n *neo) getTx(query Query) neo4j.Transaction {
if query == nil {
return nil
}
iTx := query.GetTransaction()
if iTx != nil {
tx := iTx.(neo4j.Transaction)
return tx
}
return nil
}
func (n *neo) StartTransaction(query Query) (err error.ErrorModel) {
session, e := n.db.Session(neo4j.AccessModeWrite)
if e != nil {
return error.Internal(e)
}
tx := n.getTx(query)
if tx == nil {
tx, e = session.BeginTransaction()
if e != nil {
return error.Internal(e)
}
}
query.SetTransaction(tx)
return nil
}
func (n *neo) CommitTransaction(query Query) (err error.ErrorModel) {
tx := n.getTx(query)
if tx == nil {
return
}
defer tx.Close()
return error.HandleError(tx.Commit())
}
func (n *neo) RollbackTransaction(query Query) (err error.ErrorModel) {
tx := n.getTx(query)
if tx == nil {
return
}
defer tx.Close()
return error.HandleError(tx.Rollback())
}