forked from percona/pmgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession.go
187 lines (153 loc) · 3.78 KB
/
session.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package mgoi
import (
"time"
"github.com/globalsign/mgo"
"github.com/globalsign/mgo/bson"
)
type SessionManager interface {
BuildInfo() (info mgo.BuildInfo, err error)
Clone() SessionManager
Close()
Copy() SessionManager
DB(name string) DatabaseManager
DatabaseNames() (names []string, err error)
EnsureSafe(safe *mgo.Safe)
FindRef(ref *mgo.DBRef) QueryManager
Fsync(async bool) error
FsyncLock() error
FsyncUnlock() error
LiveServers() (addrs []string)
Login(cred *mgo.Credential) error
LogoutAll()
Mode() mgo.Mode
New() SessionManager
Ping() error
Refresh()
ResetIndexCache()
Run(cmd interface{}, result interface{}) error
Safe() (safe *mgo.Safe)
SelectServers(tags ...bson.D)
SetBatch(n int)
SetBypassValidation(bypass bool)
SetCursorTimeout(d time.Duration)
SetMode(consistency mgo.Mode, refresh bool)
SetPoolLimit(limit int)
SetPrefetch(p float64)
SetSafe(safe *mgo.Safe)
SetSocketTimeout(d time.Duration)
SetSyncTimeout(d time.Duration)
}
type Session struct {
session *mgo.Session
}
// This methos allows to use mgo's dbtest.DBServer in mgoi tests.
// Example:
// var Server dbtest.DBServer
// tempDir, _ := ioutil.TempDir("", "testing")
// Server.SetPath(tempDir)
// session := NewSessionManager(Server.Session())
func NewSessionManager(s *mgo.Session) SessionManager {
return &Session{
session: s,
}
}
func (s *Session) BuildInfo() (info mgo.BuildInfo, err error) {
return s.session.BuildInfo()
}
func (s *Session) Close() {
s.session.Close()
}
func (s *Session) Clone() SessionManager {
return &Session{
session: s.session.Clone(),
}
}
func (s *Session) Copy() SessionManager {
return &Session{
session: s.session.Copy(),
}
}
func (s *Session) DB(name string) DatabaseManager {
d := &Database{
db: s.session.DB(name),
}
return d
}
func (s *Session) DatabaseNames() (names []string, err error) {
return s.session.DatabaseNames()
}
func (s *Session) EnsureSafe(safe *mgo.Safe) {
s.session.EnsureSafe(safe)
}
func (s *Session) FindRef(ref *mgo.DBRef) QueryManager {
return &Query{s.session.FindRef(ref)}
}
func (s *Session) Fsync(async bool) error {
return s.session.Fsync(async)
}
func (s *Session) FsyncLock() error {
return s.session.FsyncLock()
}
func (s *Session) FsyncUnlock() error {
return s.session.FsyncUnlock()
}
func (s *Session) LiveServers() (addrs []string) {
return s.session.LiveServers()
}
func (s *Session) Login(cred *mgo.Credential) error {
return s.session.Login(cred)
}
func (s *Session) LogoutAll() {
s.session.LogoutAll()
}
func (s *Session) Mode() mgo.Mode {
return s.session.Mode()
}
func (s *Session) New() SessionManager {
return &Session{s.session.New()}
}
func (s *Session) Run(cmd interface{}, result interface{}) error {
return s.session.Run(cmd, result)
}
func (s *Session) Safe() (safe *mgo.Safe) {
return s.session.Safe()
}
func (s *Session) SelectServers(tags ...bson.D) {
s.session.SelectServers(tags...)
}
func (s *Session) SetBatch(n int) {
s.session.SetBatch(n)
}
func (s *Session) SetBypassValidation(bypass bool) {
s.session.SetBypassValidation(bypass)
}
func (s *Session) SetCursorTimeout(d time.Duration) {
s.session.SetCursorTimeout(d)
}
func (s *Session) Ping() error {
return s.session.Ping()
}
func (s *Session) Refresh() {
s.session.Refresh()
}
func (s *Session) ResetIndexCache() {
s.session.ResetIndexCache()
}
func (s *Session) SetMode(consistency mgo.Mode, refresh bool) {
s.session.SetMode(consistency, refresh)
}
func (s *Session) SetPoolLimit(limit int) {
s.session.SetPoolLimit(limit)
}
func (s *Session) SetPrefetch(p float64) {
s.session.SetPrefetch(p)
}
func (s *Session) SetSafe(safe *mgo.Safe) {
s.session.SetSafe(safe)
}
func (s *Session) SetSocketTimeout(d time.Duration) {
s.session.SetSocketTimeout(d)
}
func (s *Session) SetSyncTimeout(d time.Duration) {
s.session.SetSyncTimeout(d)
}