dm-nested-transactions 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +0 -1
- data/README +1 -1
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/dm-nested-transactions.gemspec +43 -0
- data/lib/dm-nested-transactions.rb +29 -11
- metadata +11 -5
data/.gitignore
CHANGED
data/README
CHANGED
@@ -7,6 +7,6 @@ Install:
|
|
7
7
|
gem install dm-nested-transactions
|
8
8
|
|
9
9
|
Usage:
|
10
|
-
repository.adapter.extend(DataMapper::
|
10
|
+
repository.adapter.extend(DataMapper::NestedTransactions)
|
11
11
|
|
12
12
|
There's a rails/init.rb file that automatically does the above for you. If you are using rails, you probably also want xaviershay-dm-rails since dm-rails 10.2 is broken with transactions.
|
data/Rakefile
CHANGED
@@ -3,7 +3,7 @@ begin
|
|
3
3
|
Jeweler::Tasks.new do |gemspec|
|
4
4
|
gemspec.name = "dm-nested-transactions"
|
5
5
|
gemspec.summary = "Adds nested transaction support to DM"
|
6
|
-
gemspec.description = "Only tested with Postgres, and it's a bit of a hack, so use at your own risk!"
|
6
|
+
gemspec.description = "Only tested with Postgres and Oracle, and it's a bit of a hack, so use at your own risk!"
|
7
7
|
gemspec.email = "contact@rhnh.net"
|
8
8
|
gemspec.homepage = "http://github.com/xaviershay/dm-nested-transactions"
|
9
9
|
gemspec.authors = ["Xavier Shay"]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{dm-nested-transactions}
|
8
|
+
s.version = "0.0.4"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Xavier Shay"]
|
12
|
+
s.date = %q{2010-06-23}
|
13
|
+
s.description = %q{Only tested with Postgres and Oracle, and it's a bit of a hack, so use at your own risk!}
|
14
|
+
s.email = %q{contact@rhnh.net}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".gitignore",
|
20
|
+
"README",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"dm-nested-transactions.gemspec",
|
24
|
+
"lib/dm-nested-transactions.rb",
|
25
|
+
"rails/init.rb"
|
26
|
+
]
|
27
|
+
s.homepage = %q{http://github.com/xaviershay/dm-nested-transactions}
|
28
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
29
|
+
s.require_paths = ["lib"]
|
30
|
+
s.rubygems_version = %q{1.3.7}
|
31
|
+
s.summary = %q{Adds nested transaction support to DM}
|
32
|
+
|
33
|
+
if s.respond_to? :specification_version then
|
34
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
35
|
+
s.specification_version = 3
|
36
|
+
|
37
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
38
|
+
else
|
39
|
+
end
|
40
|
+
else
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
@@ -34,7 +34,7 @@ module DataMapper
|
|
34
34
|
|
35
35
|
module NestedTransactions
|
36
36
|
def nested_transaction_primitive
|
37
|
-
DataObjects::NestedTransaction.create_for_uri(normalized_uri, current_connection)
|
37
|
+
DataObjects::NestedTransaction.create_for_uri(normalized_uri, current_connection, self)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -53,35 +53,53 @@ module DataObjects
|
|
53
53
|
# A unique ID for this transaction
|
54
54
|
attr_reader :id
|
55
55
|
|
56
|
-
def self.create_for_uri(uri, connection)
|
56
|
+
def self.create_for_uri(uri, connection, adapter)
|
57
57
|
uri = uri.is_a?(String) ? URI::parse(uri) : uri
|
58
|
-
DataObjects::NestedTransaction.new(uri, connection)
|
58
|
+
DataObjects::NestedTransaction.new(uri, connection, adapter)
|
59
59
|
end
|
60
60
|
|
61
61
|
#
|
62
62
|
# Creates a NestedTransaction bound to an existing connection
|
63
63
|
#
|
64
|
-
def initialize(uri, connection)
|
64
|
+
def initialize(uri, connection, adapter)
|
65
|
+
@adapter = adapter
|
65
66
|
@connection = connection
|
66
|
-
@id = Digest::SHA256.hexdigest("#{HOST}:#{$$}:#{Time.now.to_f}:nested:#{@@counter += 1}")[0
|
67
|
+
@id = Digest::SHA256.hexdigest("#{HOST}:#{$$}:#{Time.now.to_f}:nested:#{@@counter += 1}")[0..10]
|
68
|
+
end
|
69
|
+
|
70
|
+
def begin_statement
|
71
|
+
lambda{ |id| "SAVEPOINT \"#{id}\"" }
|
72
|
+
end
|
73
|
+
|
74
|
+
def commit_statement
|
75
|
+
case @adapter.class.name
|
76
|
+
when /oracle/i
|
77
|
+
nil
|
78
|
+
else
|
79
|
+
lambda{ |id| "RELEASE SAVEPOINT \"#{id}\"" }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def rollback_statement
|
84
|
+
lambda{ |id| "ROLLBACK TO SAVEPOINT \"#{id}\"" }
|
67
85
|
end
|
68
86
|
|
69
87
|
def close
|
70
88
|
end
|
71
89
|
|
72
90
|
def begin
|
73
|
-
|
74
|
-
connection.create_command(cmd).execute_non_query
|
91
|
+
connection.create_command(begin_statement.call(@id)).execute_non_query
|
75
92
|
end
|
76
93
|
|
77
94
|
def commit
|
78
|
-
|
79
|
-
|
95
|
+
statement = commit_statement
|
96
|
+
if statement
|
97
|
+
connection.create_command(commit_statement.call(@id)).execute_non_query
|
98
|
+
end
|
80
99
|
end
|
81
100
|
|
82
101
|
def rollback
|
83
|
-
|
84
|
-
connection.create_command(cmd).execute_non_query
|
102
|
+
connection.create_command(rollback_statement.call(@id)).execute_non_query
|
85
103
|
end
|
86
104
|
end
|
87
105
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-nested-transactions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Xavier Shay
|
@@ -14,11 +15,11 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-06-23 00:00:00 +10:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
21
|
-
description: Only tested with Postgres, and it's a bit of a hack, so use at your own risk!
|
22
|
+
description: Only tested with Postgres and Oracle, and it's a bit of a hack, so use at your own risk!
|
22
23
|
email: contact@rhnh.net
|
23
24
|
executables: []
|
24
25
|
|
@@ -31,6 +32,7 @@ files:
|
|
31
32
|
- README
|
32
33
|
- Rakefile
|
33
34
|
- VERSION
|
35
|
+
- dm-nested-transactions.gemspec
|
34
36
|
- lib/dm-nested-transactions.rb
|
35
37
|
- rails/init.rb
|
36
38
|
has_rdoc: true
|
@@ -43,23 +45,27 @@ rdoc_options:
|
|
43
45
|
require_paths:
|
44
46
|
- lib
|
45
47
|
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
46
49
|
requirements:
|
47
50
|
- - ">="
|
48
51
|
- !ruby/object:Gem::Version
|
52
|
+
hash: 3
|
49
53
|
segments:
|
50
54
|
- 0
|
51
55
|
version: "0"
|
52
56
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
53
58
|
requirements:
|
54
59
|
- - ">="
|
55
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
56
62
|
segments:
|
57
63
|
- 0
|
58
64
|
version: "0"
|
59
65
|
requirements: []
|
60
66
|
|
61
67
|
rubyforge_project:
|
62
|
-
rubygems_version: 1.3.
|
68
|
+
rubygems_version: 1.3.7
|
63
69
|
signing_key:
|
64
70
|
specification_version: 3
|
65
71
|
summary: Adds nested transaction support to DM
|