Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
transaction
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
transaction
Commits
fc8f8191
Commit
fc8f8191
authored
Feb 08, 2017
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented explicit mode
parent
8e45562b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
2 deletions
+45
-2
transaction/_manager.py
transaction/_manager.py
+8
-1
transaction/interfaces.py
transaction/interfaces.py
+1
-1
transaction/tests/test__manager.py
transaction/tests/test__manager.py
+36
-0
No files found.
transaction/_manager.py
View file @
fc8f8191
...
...
@@ -21,7 +21,9 @@ import threading
from
zope.interface
import
implementer
from
transaction.interfaces
import
AlreadyInTransaction
from
transaction.interfaces
import
ITransactionManager
from
transaction.interfaces
import
NoTransaction
from
transaction.interfaces
import
TransientError
from
transaction.weakset
import
WeakSet
from
transaction._compat
import
reraise
...
...
@@ -59,7 +61,8 @@ def _new_transaction(txn, synchs):
@
implementer
(
ITransactionManager
)
class
TransactionManager
(
object
):
def
__init__
(
self
):
def
__init__
(
self
,
explicit
=
False
):
self
.
explicit
=
explicit
self
.
_txn
=
None
self
.
_synchs
=
WeakSet
()
...
...
@@ -67,6 +70,8 @@ class TransactionManager(object):
""" See ITransactionManager.
"""
if
self
.
_txn
is
not
None
:
if
self
.
explicit
:
raise
AlreadyInTransaction
()
self
.
_txn
.
abort
()
txn
=
self
.
_txn
=
Transaction
(
self
.
_synchs
,
self
)
_new_transaction
(
txn
,
self
.
_synchs
)
...
...
@@ -78,6 +83,8 @@ class TransactionManager(object):
""" See ITransactionManager.
"""
if
self
.
_txn
is
None
:
if
self
.
explicit
:
raise
NoTransaction
()
self
.
_txn
=
Transaction
(
self
.
_synchs
,
self
)
return
self
.
_txn
...
...
transaction/interfaces.py
View file @
fc8f8191
...
...
@@ -32,7 +32,7 @@ class ITransactionManager(Interface):
def
begin
():
"""Explicitly begin a new transaction.
"""Explicitly begin a
nd return a
new transaction.
If an existing transaction is in progress and the transaction
manager not in explicit mode, the previous transaction will be
...
...
transaction/tests/test__manager.py
View file @
fc8f8191
...
...
@@ -711,6 +711,42 @@ class AttemptTests(unittest.TestCase):
self
.
assertFalse
(
manager
.
committed
)
self
.
assertTrue
(
manager
.
aborted
)
def
test_explicit_mode
(
self
):
from
..
import
TransactionManager
from
..interfaces
import
AlreadyInTransaction
,
NoTransaction
tm
=
TransactionManager
()
self
.
assertFalse
(
tm
.
explicit
)
tm
=
TransactionManager
(
explicit
=
True
)
self
.
assertTrue
(
tm
.
explicit
)
for
name
in
'get'
,
'commit'
,
'abort'
,
'doom'
,
'isDoomed'
,
'savepoint'
:
with
self
.
assertRaises
(
NoTransaction
):
getattr
(
tm
,
name
)()
t
=
tm
.
begin
()
with
self
.
assertRaises
(
AlreadyInTransaction
):
tm
.
begin
()
self
.
assertTrue
(
t
is
tm
.
get
())
self
.
assertFalse
(
tm
.
isDoomed
())
tm
.
doom
()
self
.
assertTrue
(
tm
.
isDoomed
())
tm
.
abort
()
for
name
in
'get'
,
'commit'
,
'abort'
,
'doom'
,
'isDoomed'
,
'savepoint'
:
with
self
.
assertRaises
(
NoTransaction
):
getattr
(
tm
,
name
)()
t
=
tm
.
begin
()
self
.
assertFalse
(
tm
.
isDoomed
())
with
self
.
assertRaises
(
AlreadyInTransaction
):
tm
.
begin
()
tm
.
savepoint
()
tm
.
commit
()
class
DummyManager
(
object
):
entered
=
False
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment