Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZODB
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
Nicolas Wavrant
ZODB
Commits
bdf25e27
Commit
bdf25e27
authored
Mar 07, 2003
by
Jeremy Hylton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add IllegalStateError calls to prevent assertions from failing.
XXX Should the manager duplicate these checks?
parent
fbc8326d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
7 deletions
+19
-7
src/transaction/txn.py
src/transaction/txn.py
+19
-7
No files found.
src/transaction/txn.py
View file @
bdf25e27
...
@@ -3,14 +3,21 @@
...
@@ -3,14 +3,21 @@
__metaclass__
=
type
__metaclass__
=
type
from
transaction.interfaces
import
ITransaction
,
TransactionError
from
transaction.interfaces
import
*
from
threading
import
Lock
from
threading
import
Lock
class
Set
(
dict
):
try
:
from
sets
import
Set
except
ImportError
:
class
Set
(
dict
):
def
add
(
self
,
k
):
def
add
(
self
,
k
):
self
[
k
]
=
1
self
[
k
]
=
1
def
remove
(
self
,
k
):
del
self
[
k
]
class
Status
:
class
Status
:
ACTIVE
=
"Active"
ACTIVE
=
"Active"
...
@@ -50,24 +57,29 @@ class Transaction:
...
@@ -50,24 +57,29 @@ class Transaction:
def
commit
(
self
):
def
commit
(
self
):
"""Commit a transaction."""
"""Commit a transaction."""
assert
self
.
_manager
is
not
None
assert
self
.
_manager
is
not
None
if
self
.
_status
!=
Status
.
ACTIVE
:
raise
IllegalStateError
(
"commit"
,
self
.
_status
)
self
.
_manager
.
commit
(
self
)
self
.
_manager
.
commit
(
self
)
def
abort
(
self
):
def
abort
(
self
):
"""Rollback to initial state."""
"""Rollback to initial state."""
assert
self
.
_manager
is
not
None
assert
self
.
_manager
is
not
None
if
self
.
_status
not
in
(
Status
.
ACTIVE
,
Status
.
PREPARED
,
Status
.
FAILED
):
raise
IllegalStateError
(
"abort"
,
self
.
_status
)
self
.
_manager
.
abort
(
self
)
self
.
_manager
.
abort
(
self
)
def
savepoint
(
self
):
def
savepoint
(
self
):
"""Save current progress and return a savepoint."""
"""Save current progress and return a savepoint."""
assert
self
.
_manager
is
not
None
assert
self
.
_manager
is
not
None
if
self
.
_status
!=
Status
.
ACTIVE
:
raise
IllegalStateError
(
"create savepoint"
,
self
.
_status
)
return
self
.
_manager
.
savepoint
(
self
)
return
self
.
_manager
.
savepoint
(
self
)
def
join
(
self
,
resource
):
def
join
(
self
,
resource
):
"""resource is participating in the transaction."""
"""resource is participating in the transaction."""
assert
self
.
_manager
is
not
None
assert
self
.
_manager
is
not
None
if
self
.
_status
!=
Status
.
ACTIVE
:
if
self
.
_status
!=
Status
.
ACTIVE
:
raise
TransactionError
(
"Can't join transaction. Status=%s"
%
raise
IllegalStateError
(
"join"
,
self
.
_status
)
self
.
_status
)
self
.
_resources
.
add
(
resource
)
self
.
_resources
.
add
(
resource
)
def
status
(
self
):
def
status
(
self
):
...
@@ -78,7 +90,7 @@ class Transaction:
...
@@ -78,7 +90,7 @@ class Transaction:
self
.
_lock
.
acquire
()
self
.
_lock
.
acquire
()
try
:
try
:
if
self
.
_status
==
Status
.
SUSPENDED
:
if
self
.
_status
==
Status
.
SUSPENDED
:
raise
TransactionError
(
"Already suspended"
)
raise
IllegalStateError
(
"suspend"
,
self
.
_status
)
self
.
_manager
.
suspend
(
self
)
self
.
_manager
.
suspend
(
self
)
self
.
_suspend
=
self
.
_status
self
.
_suspend
=
self
.
_status
self
.
_status
=
Status
.
SUSPENDED
self
.
_status
=
Status
.
SUSPENDED
...
...
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