Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 3a6352d9
authored
Oct 20, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
let the transaction set the initial transaction state
1 parent
84c89570
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
57 additions
and
17 deletions
lib/dialects/abstract/query-generator.js
lib/dialects/mysql/query-generator.js
lib/query-interface.js
lib/sequelize.js
lib/transaction.js
lib/dialects/abstract/query-generator.js
View file @
3a6352d
...
@@ -464,6 +464,10 @@ module.exports = (function() {
...
@@ -464,6 +464,10 @@ module.exports = (function() {
throwMethodUndefined
(
'setAutocommitQuery'
)
throwMethodUndefined
(
'setAutocommitQuery'
)
},
},
setIsolationLevelQuery
:
function
(
value
)
{
throwMethodUndefined
(
'setIsolationLevelQuery'
)
},
/**
/**
* Returns a query that starts a transaction.
* Returns a query that starts a transaction.
*
*
...
...
lib/dialects/mysql/query-generator.js
View file @
3a6352d
...
@@ -337,6 +337,10 @@ module.exports = (function() {
...
@@ -337,6 +337,10 @@ module.exports = (function() {
return
"SET autocommit = "
+
(
!!
value
?
1
:
0
)
+
";"
return
"SET autocommit = "
+
(
!!
value
?
1
:
0
)
+
";"
},
},
setIsolationLevelQuery
:
function
(
value
)
{
return
"SET SESSION TRANSACTION ISOLATION LEVEL "
+
value
+
";"
},
/**
/**
* Returns a query that starts a transaction.
* Returns a query that starts a transaction.
*
*
...
...
lib/query-interface.js
View file @
3a6352d
...
@@ -808,6 +808,15 @@ module.exports = (function() {
...
@@ -808,6 +808,15 @@ module.exports = (function() {
return
this
.
queryAndEmit
([
sql
,
null
,
{
transaction
:
transaction
}],
'setAutocommit'
)
return
this
.
queryAndEmit
([
sql
,
null
,
{
transaction
:
transaction
}],
'setAutocommit'
)
}
}
QueryInterface
.
prototype
.
setIsolationLevel
=
function
(
transaction
,
value
)
{
if
(
!
transaction
||
!
(
transaction
instanceof
Transaction
))
{
throw
new
Error
(
'Unable to set isolatipn level for a transaction without transaction object!'
)
}
var
sql
=
this
.
QueryGenerator
.
setIsolationLevelQuery
(
value
)
return
this
.
queryAndEmit
([
sql
,
null
,
{
transaction
:
transaction
}],
'setIsolationLevel'
)
}
QueryInterface
.
prototype
.
startTransaction
=
function
(
transaction
,
options
)
{
QueryInterface
.
prototype
.
startTransaction
=
function
(
transaction
,
options
)
{
if
(
!
transaction
||
!
(
transaction
instanceof
Transaction
))
{
if
(
!
transaction
||
!
(
transaction
instanceof
Transaction
))
{
throw
new
Error
(
'Unable to start a transaction without transaction object!'
)
throw
new
Error
(
'Unable to start a transaction without transaction object!'
)
...
...
lib/sequelize.js
View file @
3a6352d
...
@@ -393,28 +393,15 @@ module.exports = (function() {
...
@@ -393,28 +393,15 @@ module.exports = (function() {
,
transaction
=
new
Transaction
(
this
,
options
)
,
transaction
=
new
Transaction
(
this
,
options
)
,
self
=
this
,
self
=
this
var
startTransaction
=
function
()
{
Utils
.
tick
(
function
()
{
transaction
.
prepareEnvironment
(
function
()
{
self
self
.
getQueryInterface
()
.
getQueryInterface
()
.
startTransaction
(
transaction
,
{})
.
startTransaction
(
transaction
,
{})
.
success
(
function
()
{
.
success
(
function
()
{
callback
(
transaction
)
callback
(
transaction
)
})
})
}
})
var
setAutocommit
=
function
(
value
,
cb
)
{
self
.
getQueryInterface
()
.
setAutocommit
(
transaction
,
value
)
.
success
(
cb
)
}
Utils
.
tick
(
function
()
{
if
(
options
.
hasOwnProperty
(
'autocommit'
))
{
setAutocommit
(
!!
options
.
autocommit
,
startTransaction
)
}
else
{
startTransaction
()
}
})
})
return
transaction
return
transaction
...
...
lib/transaction.js
View file @
3a6352d
...
@@ -3,12 +3,22 @@ var Utils = require('./utils')
...
@@ -3,12 +3,22 @@ var Utils = require('./utils')
var
Transaction
=
module
.
exports
=
function
(
sequelize
,
options
)
{
var
Transaction
=
module
.
exports
=
function
(
sequelize
,
options
)
{
this
.
sequelize
=
sequelize
this
.
sequelize
=
sequelize
this
.
options
=
options
||
{}
this
.
id
=
Utils
.
generateUUID
()
this
.
id
=
Utils
.
generateUUID
()
this
.
options
=
Utils
.
_
.
extend
({
autocommit
:
true
,
isolationLevel
:
Transaction
.
ISOLATION_LEVELS
.
REPEATABLE_READ
},
options
||
{})
}
}
util
.
inherits
(
Transaction
,
Utils
.
CustomEventEmitter
)
util
.
inherits
(
Transaction
,
Utils
.
CustomEventEmitter
)
Transaction
.
ISOLATION_LEVELS
=
{
READ_UNCOMMITTED
:
"READ UNCOMMITTED"
,
READ_COMMITTED
:
"READ COMMITTED"
,
REPEATABLE_READ
:
"REPEATABLE READ"
,
SERIALIZABLE
:
"SERIALIZABLE"
}
Transaction
.
prototype
.
commit
=
function
()
{
Transaction
.
prototype
.
commit
=
function
()
{
return
this
return
this
.
sequelize
.
sequelize
...
@@ -25,3 +35,29 @@ Transaction.prototype.rollback = function() {
...
@@ -25,3 +35,29 @@ Transaction.prototype.rollback = function() {
.
rollbackTransaction
(
this
,
{})
.
rollbackTransaction
(
this
,
{})
.
proxy
(
this
)
.
proxy
(
this
)
}
}
Transaction
.
prototype
.
prepareEnvironment
=
function
(
callback
)
{
var
self
=
this
this
.
setIsolationLevel
(
function
()
{
self
.
setAutocommit
(
function
()
{
callback
()
})
})
}
Transaction
.
prototype
.
setAutocommit
=
function
(
callback
)
{
this
.
sequelize
.
getQueryInterface
()
.
setAutocommit
(
this
,
this
.
options
.
autocommit
)
.
success
(
callback
)
}
Transaction
.
prototype
.
setIsolationLevel
=
function
(
callback
)
{
this
.
sequelize
.
getQueryInterface
()
.
setIsolationLevel
(
this
,
this
.
options
.
isolationLevel
)
.
success
(
callback
)
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment