如何在 neo4j-php-client 中检测失败的事务
How to detect a failed transaction in neo4j-php-client
我在 PHP 5.6.24 上使用 graphaware/neo4j-php-client 4.5.1 和 Neo4j 3.0.4。
我不明白如何查明交易是否失败。
例如,我尝试删除一个仍然有关系的节点。如果我 运行 在这个简单的查询中删除:
$client->run
(
'MATCH (node { name: {name} }) DELETE node',
[ 'name' => 'Fred' ]
);
…我得到这个异常,这是我预期的行为:
[GraphAware\Neo4j\Client\Exception\Neo4jException]
org.neo4j.kernel.api.exceptions.ConstraintViolationTransactionFailureException:
Cannot delete node<31>, because it still has relationships.
To delete this node, you must first delete its relationships.
但是当我将相同的查询包装在事务中时:
$transaction = $client->transaction();
$transaction->push
(
'MATCH (node { name: {name} }) DELETE node',
[ 'name' => 'Fred' ]
);
$results = $transaction->commit();
foreach ($results as $result)
{
$summary = $result->summarize();
$stats = $summary->updateStatistics();
printf("Nodes deleted: %d\n", $stats->nodesDeleted());
}
printf("Transaction status: %s\n", $transaction->status());
… Neo4j 没有删除节点,但我看到了这个(表明成功)而不是异常:
Nodes deleted: 1
Transaction status: COMMITED
我是不是遗漏了什么,或者这是一个错误?提前致谢!
谢谢,
这实际上是一个错误,我在 https://github.com/graphaware/neo4j-php-client/commit/af8f01475a3cf63549498449574eb9c4bb8e7254
中修复了它
包含此修复程序的 4.5.3 版本应该会在几分钟内在 packagist 上可用。
请测试并反馈。
我在 PHP 5.6.24 上使用 graphaware/neo4j-php-client 4.5.1 和 Neo4j 3.0.4。
我不明白如何查明交易是否失败。
例如,我尝试删除一个仍然有关系的节点。如果我 运行 在这个简单的查询中删除:
$client->run
(
'MATCH (node { name: {name} }) DELETE node',
[ 'name' => 'Fred' ]
);
…我得到这个异常,这是我预期的行为:
[GraphAware\Neo4j\Client\Exception\Neo4jException]
org.neo4j.kernel.api.exceptions.ConstraintViolationTransactionFailureException:
Cannot delete node<31>, because it still has relationships.
To delete this node, you must first delete its relationships.
但是当我将相同的查询包装在事务中时:
$transaction = $client->transaction();
$transaction->push
(
'MATCH (node { name: {name} }) DELETE node',
[ 'name' => 'Fred' ]
);
$results = $transaction->commit();
foreach ($results as $result)
{
$summary = $result->summarize();
$stats = $summary->updateStatistics();
printf("Nodes deleted: %d\n", $stats->nodesDeleted());
}
printf("Transaction status: %s\n", $transaction->status());
… Neo4j 没有删除节点,但我看到了这个(表明成功)而不是异常:
Nodes deleted: 1
Transaction status: COMMITED
我是不是遗漏了什么,或者这是一个错误?提前致谢!
谢谢,
这实际上是一个错误,我在 https://github.com/graphaware/neo4j-php-client/commit/af8f01475a3cf63549498449574eb9c4bb8e7254
中修复了它包含此修复程序的 4.5.3 版本应该会在几分钟内在 packagist 上可用。
请测试并反馈。