Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup Transaction inheritance. #16364

Merged
merged 1 commit into from
Aug 5, 2014

Conversation

arthurnn
Copy link
Member

Transaction class doesnt need to encapsulate the transaction state using
inheritance.
This removes all Transaction subclasses, and let the Transaction object
controls different actions based on its own state. Basically the only
actions would behave differently are being,commit,rollback as they
could act in a savepoint or in a real transaction.

[related to https://github.com//pull/16341#issuecomment-50791622]

review @chancancode @tenderlove @rafaelfranca @jeremy

@chancancode
Copy link
Member

Sorry, I missed the previous discussions.

Overall of this doesn't seem like an improvement to me – it seems pretty clear that a real transaction needs to behave differently than an emulated one (i.e. a savepoint), so it seems fair that we have specialized subclass that exposes a similar interface with different implementation. Collapsing down that into a single Transaction class and branch on savepoint_name instead seems like a step backwards, imo.

"Keeping track of state using inheritance is bad" is a fair criticism of the previous implementation is a fair criticism, so removing OpenTransaction seems 👍, but I think it makes sense to keep RealTransaction and SavepointTransaction separate.

@jeremy
Copy link
Member

jeremy commented Aug 1, 2014

Critique was that the txn classes inherited a mix of both interface and implementation and took on transactional recordset duties.

  • OpenTxn and NullTxn needn't share a superclass.
  • OpenTxn is used to provide a base implementation of recordset commit/rollback which RealTxn and SavepointTxn super() to. Red flag. Recordset management responsibility should be extracted entirely, and the OpenTxn superclass may turn out to be unneeded.

@arthurnn
Copy link
Member Author

arthurnn commented Aug 1, 2014

@chancancode @jeremy , I changed this a bit:

  • NullTransaction
  • Transaction
    1. RealTransaction
    2. SavepointTransaction

Thats the hierarchy now.
initialize, commit, rollback are the methods that are specialized by the subclasses.
Let me know your thoughts about it.

records.uniq.each do |record|
begin
record.rolledback!(self.is_a?(RealTransaction))
record.rolledback!(!savepoint_name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using an implementation side effect—presence of savepoint_name—to answer a different question, how far the record should roll back.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we extract that to a method then?
rollback_record() thats what you mean?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like

record.rolledback! full_rollback?

With method defined as true on txn and false on savepoint

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:done:

Transaction class doesnt need to encapsulate the transaction state using
inheritance.
This removes all Transaction subclasses, and let the Transaction object
controls different actions based on its own state. Basically the only
actions would behave differently are `being`,`commit`,`rollback` as they
could act in a savepoint or in a real transaction.
jeremy added a commit that referenced this pull request Aug 5, 2014
Clarify Transaction responsibilities by breaking unneeded inheritance hierarchy.
@jeremy jeremy merged commit b89c5a0 into rails:master Aug 5, 2014
@arthurnn arthurnn deleted the make_transaction_one_class branch August 5, 2014 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants