Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions src/Bolt/BoltConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,20 +258,6 @@ public function run(
return $response->content;
}

/**
* Commits a transaction.
*
* Any of the preconditioned states are: 'TX_READY', 'INTERRUPTED'.
*/
public function commit(): void
{
$this->consumeResults();

$message = $this->messageFactory->createCommitMessage();
$response = $message->send()->getResponse();
$this->assertNoFailure($response);
}

/**
* Rolls back a transaction.
*
Expand Down
5 changes: 3 additions & 2 deletions src/Bolt/BoltMessageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Laudis\Neo4j\Bolt\Messages\BoltRollbackMessage;
use Laudis\Neo4j\Bolt\Messages\BoltRunMessage;
use Laudis\Neo4j\Common\Neo4jLogger;
use Laudis\Neo4j\Databags\BookmarkHolder;

/**
* Factory class for creating Bolt protocol messages.
Expand Down Expand Up @@ -63,9 +64,9 @@ public function createRunMessage(string $text, array $parameters, array $extra):
return new BoltRunMessage($this->protocol, $text, $parameters, $extra, $this->logger);
}

public function createCommitMessage(): BoltCommitMessage
public function createCommitMessage(BookmarkHolder $bookmarkHolder): BoltCommitMessage
{
return new BoltCommitMessage($this->protocol, $this->logger);
return new BoltCommitMessage($this->protocol, $this->logger, $bookmarkHolder);
}

public function createRollbackMessage(): BoltRollbackMessage
Expand Down
5 changes: 3 additions & 2 deletions src/Bolt/BoltUnmanagedTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function __construct(
private readonly SessionConfiguration $config,
private readonly TransactionConfiguration $tsxConfig,
private readonly BookmarkHolder $bookmarkHolder,
private readonly BoltMessageFactory $messageFactory,
) {
}

Expand Down Expand Up @@ -83,7 +84,7 @@ public function commit(iterable $statements = []): CypherList
$list->preload();
});

$this->connection->commit();
$this->messageFactory->createCommitMessage($this->bookmarkHolder)->send();
$this->state = TransactionState::COMMITTED;

return $tbr;
Expand All @@ -105,7 +106,7 @@ public function rollback(): void
}
}

$this->connection->rollback();
$this->messageFactory->createRollbackMessage()->send();
$this->state = TransactionState::ROLLED_BACK;
}

Expand Down
16 changes: 15 additions & 1 deletion src/Bolt/Messages/BoltCommitMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Laudis\Neo4j\Bolt\Messages;

use Bolt\enum\ServerState;
use Bolt\protocol\V4_4;
use Bolt\protocol\V5;
use Bolt\protocol\V5_1;
Expand All @@ -21,21 +22,34 @@
use Bolt\protocol\V5_4;
use Laudis\Neo4j\Common\Neo4jLogger;
use Laudis\Neo4j\Contracts\BoltMessage;
use Laudis\Neo4j\Databags\Bookmark;
use Laudis\Neo4j\Databags\BookmarkHolder;
use Psr\Log\LogLevel;

final class BoltCommitMessage extends BoltMessage
{
public function __construct(
private readonly V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol,
private readonly ?Neo4jLogger $logger,
private readonly BookmarkHolder $bookmarks,
) {
parent::__construct($protocol);
}

public function send(): BoltCommitMessage
{
$this->logger?->log(LogLevel::DEBUG, 'COMMIT');
$this->protocol->commit();
$response = $this->protocol->commit()->getResponse();

/** @var array{bookmark?: string} $content */
$content = $response->content;
$bookmark = $content['bookmark'] ?? '';

if (trim($bookmark) !== '') {
$this->bookmarks->setBookmark(new Bookmark([$bookmark]));
}

$this->protocol->serverState = ServerState::READY;

return $this;
}
Expand Down
20 changes: 18 additions & 2 deletions src/Bolt/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,15 @@ private function beginInstantTransaction(
$this->getLogger()?->log(LogLevel::INFO, 'Starting instant transaction', ['config' => $tsxConfig]);
$connection = $this->acquireConnection($tsxConfig, $config);

return new BoltUnmanagedTransaction($this->config->getDatabase(), $this->formatter, $connection, $this->config, $tsxConfig, $this->bookmarkHolder);
return new BoltUnmanagedTransaction(
$this->config->getDatabase(),
$this->formatter,
$connection,
$this->config,
$tsxConfig,
$this->bookmarkHolder,
new BoltMessageFactory($connection->protocol(), $this->getLogger()),
);
}

/**
Expand Down Expand Up @@ -184,7 +192,15 @@ private function startTransaction(TransactionConfiguration $config, SessionConfi
throw $e;
}

return new BoltUnmanagedTransaction($this->config->getDatabase(), $this->formatter, $connection, $this->config, $config, $this->bookmarkHolder);
return new BoltUnmanagedTransaction(
$this->config->getDatabase(),
$this->formatter,
$connection,
$this->config,
$config,
$this->bookmarkHolder,
new BoltMessageFactory($connection->protocol(), $this->getLogger()),
);
}

private function mergeTsxConfig(?TransactionConfiguration $config): TransactionConfiguration
Expand Down
1 change: 1 addition & 0 deletions tests/Integration/TransactionIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public function testCommitValidEmpty(): void
self::assertTrue($tsx->isFinished());
self::assertFalse($tsx->isRolledBack());
self::assertTrue($tsx->isCommitted());
self::assertFalse($this->getSession()->getLastBookmark()->isEmpty());
}

public function testCommitValidFilled(): void
Expand Down