本文整理了Java中org.neo4j.graphdb.Transaction.close()
方法的一些代码示例,展示了Transaction.close()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Transaction.close()
方法的具体详情如下:
包路径:org.neo4j.graphdb.Transaction
类名称:Transaction
方法名:close
[英]Commits or marks this transaction for rollback, depending on whether #success() or #failure() has been previously invoked. All ResourceIterable that where returned from operations executed inside this transaction will be automatically closed by this method. This method comes from AutoCloseable so that a Transaction can participate in try-with-resource statements. It will not throw any declared exception. Invoking this method (which is unnecessary when in try-with-resource statement).
[中]提交或标记此事务以进行回滚,具体取决于之前是否调用了#success()或#failure()。在此事务中执行的操作返回的所有ResourceIterable都将通过此方法自动关闭。此方法来自AutoCloseable,因此事务可以参与try with resource语句。它不会抛出任何已声明的异常。调用此方法(在try with resource语句中不需要此方法)。
代码示例来源:origin: neo4j/neo4j
public void success()
{
try
{
if ( tx != null )
{
tx.success();
tx.close();
}
}
finally
{
tx = null;
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldNotRollbackParentIfSuccessCalled()
{
// When
placeboTx.success();
placeboTx.close();
// Then
verify( kernelTransaction, never() ).failure();
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldRollbackParentByDefault()
{
// When
placeboTx.close();
// Then
verify( kernelTransaction ).failure();
}
代码示例来源:origin: neo4j/neo4j
@Test
public void successCannotOverrideFailure()
{
// When
placeboTx.failure();
placeboTx.success();
placeboTx.close();
// Then
verify( kernelTransaction ).failure();
verify( kernelTransaction, never() ).success();
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldRollbackParentIfFailureCalled()
{
// When
placeboTx.failure();
placeboTx.close();
// Then
verify( kernelTransaction, times(2) ).failure(); // We accept two calls to failure, since KernelTX#failure is idempotent
}
代码示例来源:origin: neo4j/neo4j
@Override
public Void doWork( CommandState state )
{
state.tx.success();
state.tx.close();
return null;
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void getAllRelationshipsIteratorShouldPickUpHigherIdsThanHighIdWhenStarted() throws Exception
{
// GIVEN
Transaction tx = db.beginTx();
createRelationshipAssumingTxWith( "key", 1 );
createRelationshipAssumingTxWith( "key", 2 );
tx.success();
tx.close();
// WHEN
tx = db.beginTx();
Iterator<Relationship> allRelationships = db.getAllRelationships().iterator();
Thread thread = new Thread( () ->
{
Transaction newTx = db.beginTx();
assertThat( newTx, not( instanceOf( PlaceboTransaction.class ) ) );
createRelationshipAssumingTxWith( "key", 3 );
newTx.success();
newTx.close();
} );
thread.start();
thread.join();
// THEN
assertThat( addToCollection( allRelationships, new ArrayList<>() ).size(), is(3) );
tx.success();
tx.close();
}
代码示例来源:origin: neo4j/neo4j
@Test
public void terminateNestedTransactionThrowsExceptionOnNextNestedOperationMultiThreadedVersionWithNestedTx()
throws Exception
transaction.close();
代码示例来源:origin: neo4j/neo4j
@Override
public Void doWork( WorkerState state )
{
state.tx.success();
state.tx.close();
return null;
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void getAllNodesIteratorShouldPickUpHigherIdsThanHighIdWhenStarted() throws Exception
{
// GIVEN
{
Transaction tx = db.beginTx();
db.createNode();
db.createNode();
tx.success();
tx.close();
}
// WHEN iterator is started
Transaction transaction = db.beginTx();
Iterator<Node> allNodes = db.getAllNodes().iterator();
allNodes.next();
// and WHEN another node is then added
Thread thread = new Thread( () ->
{
Transaction newTx = db.beginTx();
assertThat( newTx, not( instanceOf( PlaceboTransaction.class ) ) );
db.createNode();
newTx.success();
newTx.close();
} );
thread.start();
thread.join();
// THEN the new node is picked up by the iterator
assertThat( addToCollection( allNodes, new ArrayList<>() ).size(), is( 2 ) );
transaction.close();
}
代码示例来源:origin: neo4j/neo4j
@Test
public void deletedNodeShouldShowUpWithinTransaction()
{
// GIVEN
GraphDatabaseService beansAPI = dbRule.getGraphDatabaseAPI();
Neo4jMatchers.createIndex( beansAPI, LABEL1, "name" );
Node firstNode = createNode( beansAPI, map( "name", "Mattias" ), LABEL1 );
// WHEN
Transaction tx = beansAPI.beginTx();
long sizeBeforeDelete = count( beansAPI.findNodes( LABEL1, "name", "Mattias" ) );
firstNode.delete();
long sizeAfterDelete = count( beansAPI.findNodes( LABEL1, "name", "Mattias" ) );
tx.close();
// THEN
assertThat( sizeBeforeDelete, equalTo(1L) );
assertThat( sizeAfterDelete, equalTo(0L) );
}
代码示例来源:origin: neo4j/neo4j
private void closeTx()
{
tx.success();
tx.close();
}
代码示例来源:origin: neo4j/neo4j
@Test
public void getNonExistentGraphPropertyWithDefaultValue()
{
GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase();
PropertyContainer graphProperties = properties( db );
Transaction tx = db.beginTx();
assertEquals( "default", graphProperties.getProperty( "test", "default" ) );
tx.success();
tx.close();
db.shutdown();
}
代码示例来源:origin: neo4j/neo4j
@Test
public void createdNodeShouldShowUpWithinTransaction()
{
// GIVEN
GraphDatabaseService beansAPI = dbRule.getGraphDatabaseAPI();
Neo4jMatchers.createIndex( beansAPI, LABEL1, "name" );
// WHEN
Transaction tx = beansAPI.beginTx();
Node firstNode = createNode( beansAPI, map( "name", "Mattias" ), LABEL1 );
long sizeBeforeDelete = count( beansAPI.findNodes( LABEL1, "name", "Mattias" ) );
firstNode.delete();
long sizeAfterDelete = count( beansAPI.findNodes( LABEL1, "name", "Mattias" ) );
tx.close();
// THEN
assertThat( sizeBeforeDelete, equalTo(1L) );
assertThat( sizeAfterDelete, equalTo(0L) );
}
代码示例来源:origin: neo4j/neo4j
@Override
public void accept( Transaction transaction )
{
transaction.success();
// We also call close() here, because some validations and checks don't run until commit
transaction.close();
}
};
代码示例来源:origin: neo4j/neo4j
@Test
public void testMultipleDeleteNode()
{
Node node1 = getGraphDb().createNode();
node1.delete();
try
{
node1.delete();
Transaction tx = getTransaction();
tx.success();
tx.close();
fail( "Should not validate" );
}
catch ( Exception e )
{
// ok
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void createdNodeShouldShowUpInIndexQuery()
{
// GIVEN
GraphDatabaseService beansAPI = dbRule.getGraphDatabaseAPI();
Neo4jMatchers.createIndex( beansAPI, LABEL1, "name" );
createNode( beansAPI, map( "name", "Mattias" ), LABEL1 );
// WHEN
Transaction tx = beansAPI.beginTx();
long sizeBeforeDelete = count( beansAPI.findNodes( LABEL1, "name", "Mattias" ) );
createNode( beansAPI, map( "name", "Mattias" ), LABEL1 );
long sizeAfterDelete = count( beansAPI.findNodes( LABEL1, "name", "Mattias" ) );
tx.close();
// THEN
assertThat( sizeBeforeDelete, equalTo(1L) );
assertThat( sizeAfterDelete, equalTo(2L) );
}
代码示例来源:origin: neo4j/neo4j
public void finishTx( boolean success )
{
if ( tx != null )
{
if ( success )
{
tx.success();
}
tx.close();
tx = null;
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void testRemovePropertyDeletedNode()
{
Node node = getGraphDb().createNode();
node.setProperty( key, 1 );
node.delete();
try
{
node.removeProperty( key );
Transaction tx = getTransaction();
tx.success();
tx.close();
fail( "Change property on deleted node should not validate" );
}
catch ( Exception e )
{
// ok
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void onlineConstraintShouldRejectChangingEntryToAlreadyIndexedValueThatOtherTransactionsAreRemoving()
{
// Given
givenOnlineConstraint();
transaction(
setProperty( b, "b" ),
success );
Transaction otherTx = db.beginTx();
a.removeLabel( label );
suspend( otherTx );
// When
try
{
transaction(
setProperty( b, "a" ),
success,
fail( "Changing a property to an already indexed value should have thrown" ) );
}
catch ( ConstraintViolationException ignore )
{
// we're happy
}
finally
{
resume( otherTx );
otherTx.failure();
otherTx.close();
}
}
内容来源于网络,如有侵权,请联系作者删除!