@@ -15,7 +15,7 @@ type sessionManager struct {
15
15
}
16
16
17
17
type session struct {
18
- id uuid.UUID
18
+ id * uuid.UUID
19
19
e executor
20
20
}
21
21
@@ -28,16 +28,33 @@ func newSessionManager(logger logging.Logger, executor executor) *sessionManager
28
28
}
29
29
}
30
30
31
+ func (s * sessionManager ) NewNoopSession () Session {
32
+ return & session {
33
+ e : s .e ,
34
+ }
35
+ }
36
+
31
37
func (s * sessionManager ) NewSession () Session {
38
+ id := uuid .New ()
39
+ return & session {
40
+ e : s .e ,
41
+ id : & id ,
42
+ }
43
+ }
44
+
45
+ func (s * sessionManager ) GetSession (sessionId uuid.UUID ) Session {
32
46
return & session {
33
47
e : s .e ,
34
- id : uuid . New () ,
48
+ id : & sessionId ,
35
49
}
36
50
}
37
51
38
- func (s * sessionManager ) WithSession (f func (Session ) error ) error {
52
+ func (s * sessionManager ) WithNewSession (f func (Session ) error ) error {
53
+ return s .WithSession (s .NewSession (), f )
54
+ }
55
+
56
+ func (s * sessionManager ) WithSession (ss Session , f func (Session ) error ) error {
39
57
var err error
40
- ss := s .NewSession ()
41
58
defer func () {
42
59
err2 := ss .Close ()
43
60
if err == nil { // Capture close error if everything else was ok
@@ -59,19 +76,27 @@ func (s *sessionManager) WithSession(f func(Session) error) error {
59
76
}
60
77
61
78
func (s * session ) ExecuteStringQuery (stringQuery string ) (res [][]byte , err error ) {
62
- return s .e (stringQuery , nil , map [string ]string {}, map [string ]string {}, & s .id )
79
+ return s .e (stringQuery , nil , map [string ]string {}, map [string ]string {}, s .id )
63
80
}
64
81
65
82
func (s * session ) ExecuteQuery (queryObj query.Query ) (res [][]byte , err error ) {
66
83
return s .ExecuteStringQuery (queryObj .String ())
67
84
}
68
85
69
86
func (s * session ) Close () error {
70
- _ , err := s .e ("" , nil , map [string ]string {}, map [string ]string {}, & s .id )
87
+ if s .id == nil {
88
+ return nil
89
+ }
90
+
91
+ _ , err := s .e ("" , nil , map [string ]string {}, map [string ]string {}, s .id )
71
92
return err
72
93
}
73
94
74
95
func (s * session ) Commit () error {
96
+ if s .id == nil {
97
+ return nil
98
+ }
99
+
75
100
commit := traversal .NewTraversal ()
76
101
commit .AddStep ("tx" )
77
102
commit .AddStep ("commit" )
@@ -81,6 +106,10 @@ func (s *session) Commit() error {
81
106
}
82
107
83
108
func (s * session ) Rollback () error {
109
+ if s .id == nil {
110
+ return nil
111
+ }
112
+
84
113
rollback := traversal .NewTraversal ()
85
114
rollback .AddStep ("tx" )
86
115
rollback .AddStep ("rollback" )
0 commit comments