-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrv.go
157 lines (139 loc) · 3.22 KB
/
drv.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
// Copyright 2014 Rana Ian. All rights reserved.
// Use of this source code is governed by The MIT License
// found in the accompanying LICENSE file.
package ora
/*
#include <oci.h>
#include <stdlib.h>
*/
import "C"
import (
"database/sql/driver"
"sync"
"time"
)
// DrvCfg represents configuration values for the ora package.
type DrvCfg struct {
Env *EnvCfg
Log LogDrvCfg
}
// NewDrvCfg creates a DrvCfg with default values.
func NewDrvCfg() *DrvCfg {
c := &DrvCfg{}
c.Env = NewEnvCfg()
c.Log = NewLogDrvCfg()
return c
}
// LogDrvCfg represents package-level logging configuration values.
type LogDrvCfg struct {
// Logger writes log messages.
// Logger can be replaced with any type implementing the Logger interface.
//
// The default implementation uses the standard lib's log package.
//
// For a glog-based implementation, see gopkg.in/rana/ora.v3/glg.
// LogDrvCfg.Logger = glg.Log
//
// For an gopkg.in/inconshreveable/log15.v2-based, see gopkg.in/rana/ora.v3/lg15.
// LogDrvCfg.Logger = lg15.Log
Logger Logger
// OpenEnv determines whether the ora.OpenEnv method is logged.
//
// The default is true.
OpenEnv bool
// Ins determines whether the ora.Ins method is logged.
//
// The default is true.
Ins bool
// Upd determines whether the ora.Upd method is logged.
//
// The default is true.
Upd bool
// Del determines whether the ora.Del method is logged.
//
// The default is true.
Del bool
// Sel determines whether the ora.Sel method is logged.
//
// The default is true.
Sel bool
// AddTbl determines whether the ora.AddTbl method is logged.
//
// The default is true.
AddTbl bool
Env LogEnvCfg
Srv LogSrvCfg
Ses LogSesCfg
Stmt LogStmtCfg
Tx LogTxCfg
Con LogConCfg
Rset LogRsetCfg
}
// NewLogDrvCfg creates a LogDrvCfg with default values.
func NewLogDrvCfg() LogDrvCfg {
c := LogDrvCfg{}
c.Logger = EmpLgr{}
c.OpenEnv = true
c.Ins = true
c.Upd = true
c.Del = true
c.Sel = true
c.AddTbl = true
c.Env = NewLogEnvCfg()
c.Srv = NewLogSrvCfg()
c.Ses = NewLogSesCfg()
c.Stmt = NewLogStmtCfg()
c.Tx = NewLogTxCfg()
c.Con = NewLogConCfg()
c.Rset = NewLogRsetCfg()
return c
}
// Drv represents an Oracle database driver.
//
// Drv is not meant to be called by user-code.
//
// Drv implements the driver.Driver interface.
type Drv struct {
cfg DrvCfg
mu sync.Mutex
insMu sync.Mutex
updMu sync.Mutex
delMu sync.Mutex
selMu sync.Mutex
addTblMu sync.Mutex
envId Id
srvId Id
conId Id
sesId Id
txId Id
stmtId Id
rsetId Id
listPool *pool
envPool *pool
conPool *pool
srvPool *pool
sesPool *pool
stmtPool *pool
txPool *pool
rsetPool *pool
bndPools []*pool
defPools []*pool
locations map[string]*time.Location
sqlPkgEnv *Env // An environment for use by the database/sql package.
openEnvs *envList
}
// Open opens a connection to an Oracle server with the database/sql environment.
//
// This is intended to be called by the database/sql package only.
//
// Alternatively, you may call Env.OpenCon to create an *ora.Con.
//
// Open is a member of the driver.Driver interface.
func (drv *Drv) Open(conStr string) (driver.Conn, error) {
log(true)
con, err := _drv.sqlPkgEnv.OpenCon(conStr)
if err != nil {
return nil, errE(err)
}
return con, nil
}