Skip to content

Commit

Permalink
Add AutoCommitCommand marker interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Miertsch committed May 9, 2015
1 parent 92469e0 commit 2115e91
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
25 changes: 25 additions & 0 deletions src/EventStore/AutoCommitCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/*
* This file is part of prooph/proophessor.
* (c) 2014-2015 prooph software GmbH <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Date: 5/9/15 - 6:23 PM
*/

namespace Prooph\Proophessor\EventStore;

/**
* Interface AutoCommitCommand
*
* This is a marker interface for commands which should not be handled by the transaction manager.
* The transaction manager will neither begin a new transaction nor commit it.
*
* @package Prooph\Proophessor\EventStore
* @author Alexander Miertsch <[email protected]>
*/
interface AutoCommitCommand
{
}
6 changes: 3 additions & 3 deletions src/EventStore/TransactionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private function handleRecordedEvents(array &$recordedEvents)
public function onInitialize(CommandDispatch $commandDispatch)
{
$command = $commandDispatch->getCommand();
if ($command instanceof Command) {
if ($command instanceof Command && !$command instanceof AutoCommitCommand) {
if (! $this->inTransaction) {
$this->eventStore->beginTransaction();
$this->inTransaction = true;
Expand All @@ -133,7 +133,7 @@ public function onInitialize(CommandDispatch $commandDispatch)

public function onError(CommandDispatch $commandDispatch)
{
if (! $commandDispatch->getCommand() instanceof Command) return;
if (! $commandDispatch->getCommand() instanceof Command || $commandDispatch->getCommand() instanceof AutoCommitCommand) return;
if (! $this->inTransaction) return;

$this->eventStore->rollback();
Expand All @@ -143,7 +143,7 @@ public function onError(CommandDispatch $commandDispatch)

public function onFinalize(CommandDispatch $commandDispatch)
{
if (! $commandDispatch->getCommand() instanceof Command) return;
if (! $commandDispatch->getCommand() instanceof Command || $commandDispatch->getCommand() instanceof AutoCommitCommand) return;
if (! $this->inTransaction) return;

$this->eventStore->commit();
Expand Down

0 comments on commit 2115e91

Please sign in to comment.