Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

Add SAVEPOINT (Fixes #56) #111

Closed
wants to merge 9 commits into from
Closed

Add SAVEPOINT (Fixes #56) #111

wants to merge 9 commits into from

Conversation

Jud
Copy link
Collaborator

@Jud Jud commented May 9, 2014

We needed this so I hacked it in and added a test case. I ran into trouble getting Mockery to correctly mock the object, so I had to change the tests up a bit.

@Jud
Copy link
Collaborator Author

Jud commented Jun 23, 2014

Ping @lox

@lox
Copy link
Owner

lox commented Jun 29, 2014

Hey, sorry for the delay @Jud. Reviewing this and other patches now.

@@ -28,12 +28,21 @@ public function execute()
$this->results = array();

try {
$this->_connection->execute('BEGIN');
$this->_connection->execute(
Copy link
Owner

Choose a reason for hiding this comment

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

It's hard to see what's going on in this method at a glance.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed -- I think I wanted the changes to be as minimal as possible, but this cuts readability. I'll refactor it a bit.

@lox
Copy link
Owner

lox commented Jun 29, 2014

What would you think of actually removing responsibility for issuing SQL entirely from the Transaction object? It already fires events, we could just have the Connection object listening for those events and converting them to SQL. That's probably a cleaner separation of responsibility. Then the API for transactions could remain the same and we could have a Strategy in the Connection to switch between plain old transactions or SAVEPOINTS.

@Jud
Copy link
Collaborator Author

Jud commented Jul 19, 2014

@lox moved the transaction sql into the Connection object. I'm not entirely sure I see the need for multiple transaction strategies. Using SAVEPOINTS with unnested Pheasant Transactions gives the same behavior as unnested 'plain old transactions'. Nesting 'plain old transactions' doesn't work, and if it is being used, would probably benefit from a working strategy.

@lox
Copy link
Owner

lox commented Jul 24, 2014

I'm pretty happy with this, @harto any thoughts before merge?

/**
* A Transaction Stack that keeps track of open savepoints
*/
class TransactionStack
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this actually a SavePointStack, or something like that? The current name implies that we push/pop Transaction objects.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, would be better as SavePointStack

@harto
Copy link
Collaborator

harto commented Jul 24, 2014

Looks good. Just a couple of questions about naming, etc.

before/afterStartTransaction to before/afterTransaction

Also changed the methodology behind the commit event, which
should only be called when the actual 'commit' query is sent
and not when the savepoint is simply released.
Allows an event to be bound and then removed.
@Jud
Copy link
Collaborator Author

Jud commented Sep 20, 2014

@harto @lox Finished up the renaming and also added an event method registerOne that adds an event listener and removes it after execution.

In this case it was useful for binding to the connection events commit message to defer callbacks.

@harto
Copy link
Collaborator

harto commented Oct 6, 2014

@lox might leave it to you to give this the final 👍

@Jud
Copy link
Collaborator Author

Jud commented Mar 24, 2015

@lox fwiw, we've been using this in production since October without issue. This was the foundation for allowing all afterSave/afterDelete events to run inside transactions.

https://github.com/judsonco/pheasant/blob/52d4a22a208f5b8b5346e0caa8102d3cb352dda8/lib/Pheasant/DomainObject.php#L89-L109

@Jud
Copy link
Collaborator Author

Jud commented Apr 23, 2015

Closing in favor of #142

@Jud Jud closed this Apr 23, 2015
@bjornpost bjornpost removed this from the 1.4.0 milestone May 7, 2016
@bjornpost bjornpost modified the milestones: 2.0.0, 1.4.0 May 7, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants