Created
May 4, 2011 16:01
-
-
Save stefl/955469 to your computer and use it in GitHub Desktop.
Nested postgres transactions in datamapper?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#untested - does this work? | |
module DataMapper | |
class Transaction | |
module DataObjectsAdapter | |
def nested_transaction_primitive | |
DataObjects::SavePoint.create_for_uri(normalized_uri, current_connection) | |
end | |
end | |
# Override to use savepoints for nested transactions | |
def connect_adapter(adapter) | |
if @transaction_primitives.key?(adapter) | |
raise "Already a primitive for adapter #{adapter}" | |
end | |
primitive = if adapter.current_transaction | |
self.state = :none | |
adapter.nested_transaction_primitive | |
else | |
adapter.transaction_primitive | |
end | |
@transaction_primitives[adapter] = validate_primitive(primitive) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment