本文整理了Java中org.neo4j.internal.kernel.api.Write.relationshipDelete()
方法的一些代码示例,展示了Write.relationshipDelete()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Write.relationshipDelete()
方法的具体详情如下:
包路径:org.neo4j.internal.kernel.api.Write
类名称:Write
方法名:relationshipDelete
[英]Delete a relationship
[中]删除关系
代码示例来源:origin: neo4j/neo4j
@Override
public void delete()
{
KernelTransaction transaction = spi.kernelTransaction();
try
{
boolean deleted = transaction.dataWrite().relationshipDelete( id );
if ( !deleted )
{
throw new NotFoundException( "Unable to delete relationship[" +
getId() + "] since it is already deleted." );
}
}
catch ( InvalidTransactionTypeKernelException e )
{
throw new ConstraintViolationException( e.getMessage(), e );
}
catch ( AutoIndexingKernelException e )
{
throw new IllegalStateException( "Auto indexing encountered a failure while deleting the relationship: "
+ e.getMessage(), e );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldNotDeleteRelationshipThatDoesNotExist() throws Exception
{
long relationship = 0;
try ( Transaction tx = beginTransaction() )
{
assertFalse( tx.dataWrite().relationshipDelete( relationship ) );
tx.failure();
}
try ( Transaction tx = beginTransaction() )
{
assertFalse( tx.dataWrite().relationshipDelete( relationship ) );
tx.success();
}
// should not crash
}
代码示例来源:origin: neo4j/neo4j
throw new IllegalStateException( "Oh ye be cursed, foul checkstyle!" );
tx.dataWrite().relationshipDelete( head.id );
expectedCounts.put( kv.getKey(), rs.size() + 1 );
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldNotAllowModifyingPropertiesOnDeletedRelationship() throws Exception
{
// given
Transaction transaction = newTransaction( AnonymousContext.writeToken() );
int prop1 = transaction.tokenWrite().propertyKeyGetOrCreateForName( "prop1" );
int type = transaction.tokenWrite().relationshipTypeGetOrCreateForName( "RELATED" );
long startNodeId = transaction.dataWrite().nodeCreate();
long endNodeId = transaction.dataWrite().nodeCreate();
long rel = transaction.dataWrite().relationshipCreate( startNodeId, type, endNodeId );
transaction.dataWrite().relationshipSetProperty( rel, prop1, Values.stringValue( "As" ) );
transaction.dataWrite().relationshipDelete( rel );
// When
try
{
transaction.dataWrite().relationshipRemoveProperty( rel, prop1 );
fail( "Should have failed." );
}
catch ( EntityNotFoundException e )
{
assertThat( e.getMessage(), equalTo( "Unable to load RELATIONSHIP with id " + rel + "." ) );
}
commit();
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldNotCountRemovedRelationships() throws Exception
{
int relationshipId;
long relationship;
try ( Transaction tx = beginTransaction() )
{
Write write = tx.dataWrite();
relationshipId = tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" );
relationship = write.relationshipCreate( write.nodeCreate(), relationshipId, write.nodeCreate() );
tx.success();
}
try ( Transaction tx = beginTransaction() )
{
Write write = tx.dataWrite();
write.relationshipDelete( relationship );
long countsTxState = tx.dataRead().countsForRelationship( -1, relationshipId, -1 );
long countsNoTxState = tx.dataRead().countsForRelationshipWithoutTxState( -1, relationshipId, -1 );
assertEquals( 0, countsTxState );
assertEquals( 1, countsNoTxState );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldDetectRelationshipDeletedInTransaction() throws Exception
{
// GIVEN
long node;
int relType;
long deletedInTx, unaffected, addedInTx, addedAndRemovedInTx;
try ( Transaction tx = beginTransaction() )
{
node = tx.dataWrite().nodeCreate();
relType = tx.tokenWrite().relationshipTypeCreateForName( "REL_TYPE" );
deletedInTx = tx.dataWrite().relationshipCreate(node, relType, node);
unaffected = tx.dataWrite().relationshipCreate(node, relType, node);
tx.success();
}
try ( Transaction tx = beginTransaction() )
{
// WHEN
addedInTx = tx.dataWrite().relationshipCreate(node, relType, node);
addedAndRemovedInTx = tx.dataWrite().relationshipCreate(node, relType, node);
tx.dataWrite().relationshipDelete( deletedInTx );
tx.dataWrite().relationshipDelete( addedAndRemovedInTx );
// THEN
assertFalse( tx.dataRead().relationshipDeletedInTransaction( addedInTx ) );
assertFalse( tx.dataRead().relationshipDeletedInTransaction( unaffected ) );
assertTrue( tx.dataRead().relationshipDeletedInTransaction( addedAndRemovedInTx ) );
assertTrue( tx.dataRead().relationshipDeletedInTransaction( deletedInTx ) );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldDeleteRelationship() throws Exception
{
long n1, r;
try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() )
{
Node node1 = graphDb.createNode();
Node node2 = graphDb.createNode();
n1 = node1.getId();
r = node1.createRelationshipTo( node2, RelationshipType.withName( "R" ) ).getId();
tx.success();
}
try ( Transaction tx = beginTransaction() )
{
assertTrue( "should delete relationship", tx.dataWrite().relationshipDelete( r ) );
tx.success();
}
try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() )
{
assertEquals( 0, graphDb.getNodeById( n1 ).getDegree() );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldDeleteRelationshipAddedInTransaction() throws Exception
{
long n1, n2;
try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() )
{
n1 = graphDb.createNode().getId();
n2 = graphDb.createNode().getId();
tx.success();
}
try ( Transaction tx = beginTransaction() )
{
int label = tx.token().relationshipTypeGetOrCreateForName( "R" );
long r = tx.dataWrite().relationshipCreate( n1, label, n2 );
assertTrue( tx.dataWrite().relationshipDelete( r ) );
tx.success();
}
try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() )
{
assertEquals( 0, graphDb.getNodeById( n1 ).getDegree() );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldNotScanRelationshipWhichWasDeletedInTransaction() throws Exception
{
final int nRelationshipsInStore = 5 + 1 + 5;
int type;
long n1, n2, r;
try ( Transaction tx = beginTransaction() )
{
n1 = tx.dataWrite().nodeCreate();
n2 = tx.dataWrite().nodeCreate();
type = tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" );
relateNTimes( 5, type, n1, n2, tx );
r = tx.dataWrite().relationshipCreate( n1, type, n2 );
relateNTimes( 5, type, n1, n2, tx );
tx.success();
}
try ( Transaction tx = beginTransaction() )
{
assertTrue( "should delete relationship", tx.dataWrite().relationshipDelete( r ) );
try ( RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor() )
{
tx.dataRead().allRelationshipsScan( relationship );
assertCountRelationships( relationship, nRelationshipsInStore - 1, n1, type, n2 );
}
tx.success();
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldNotSeeRelationshipDeletedInTransaction() throws Exception
{
long n1, n2, r;
try ( Transaction tx = beginTransaction() )
{
n1 = tx.dataWrite().nodeCreate();
n2 = tx.dataWrite().nodeCreate();
int label = tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" );
r = tx.dataWrite().relationshipCreate( n1, label, n2 );
tx.success();
}
try ( Transaction tx = beginTransaction() )
{
tx.dataWrite().relationshipDelete( r );
try ( NodeCursor node = tx.cursors().allocateNodeCursor();
RelationshipTraversalCursor relationship = tx.cursors().allocateRelationshipTraversalCursor() )
{
tx.dataRead().singleNode( n1, node );
assertTrue( "should access node", node.next() );
node.allRelationships( relationship );
assertFalse( "should not find relationship", relationship.next() );
}
tx.success();
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldNotSeeSingleRelationshipWhichWasDeletedInTransaction() throws Exception
{
int label;
long n1, n2, r;
try ( Transaction tx = beginTransaction() )
{
n1 = tx.dataWrite().nodeCreate();
n2 = tx.dataWrite().nodeCreate();
label = tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" );
long decoyNode = tx.dataWrite().nodeCreate();
tx.dataWrite().relationshipCreate( n2, label, decoyNode ); // to have >1 relationship in the db
r = tx.dataWrite().relationshipCreate( n1, label, n2 );
tx.success();
}
try ( Transaction tx = beginTransaction() )
{
assertTrue( "should delete relationship", tx.dataWrite().relationshipDelete( r ) );
try ( RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor() )
{
tx.dataRead().singleRelationship( r, relationship );
assertFalse( "should not find relationship", relationship.next() );
}
tx.success();
}
}
代码示例来源:origin: neo4j/neo4j
transaction.dataWrite().relationshipDelete( fromRefToOther1 );
long endNode = transaction.dataWrite().nodeCreate();
long localTxRel = transaction.dataWrite().relationshipCreate( refNode, relType1, endNode );
代码示例来源:origin: org.neo4j/neo4j-kernel
@Override
public void delete()
{
KernelTransaction transaction = spi.kernelTransaction();
try
{
boolean deleted = transaction.dataWrite().relationshipDelete( id );
if ( !deleted )
{
throw new NotFoundException( "Unable to delete relationship[" +
getId() + "] since it is already deleted." );
}
}
catch ( InvalidTransactionTypeKernelException e )
{
throw new ConstraintViolationException( e.getMessage(), e );
}
catch ( AutoIndexingKernelException e )
{
throw new IllegalStateException( "Auto indexing encountered a failure while deleting the relationship: "
+ e.getMessage(), e );
}
}
内容来源于网络,如有侵权,请联系作者删除!