本文整理了Java中org.neo4j.graphdb.Node.createRelationshipTo()
方法的一些代码示例,展示了Node.createRelationshipTo()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.createRelationshipTo()
方法的具体详情如下:
包路径:org.neo4j.graphdb.Node
类名称:Node
方法名:createRelationshipTo
[英]Creates a relationship between this node and another node. The relationship is of type type
. It starts at this node and ends at otherNode
.
A relationship is equally well traversed in both directions so there's no need to create another relationship in the opposite direction (in regards to traversal or performance).
[中]在该节点和另一个节点之间创建关系。关系的类型为type
。它从该节点开始,在otherNode
结束。
一个关系在两个方向上都被很好地遍历,因此不需要在相反方向上创建另一个关系(关于遍历或性能)。
代码示例来源:origin: neo4j/neo4j
@Override
public Relationship create()
{
return db.createNode().createRelationshipTo( db.createNode(), type );
}
};
代码示例来源:origin: neo4j/neo4j
@Override
protected Relationship obtainEntityInTransaction( GraphDatabaseService graphDatabaseService )
{
return graphDatabaseService
.createNode()
.createRelationshipTo( graphDatabaseService.createNode(), withName( "foo" ) );
}
}
代码示例来源:origin: neo4j/neo4j
@Override
public Long apply( GraphDatabaseService graphDb )
{
try ( Transaction tx = graphDb.beginTx() )
{
Node node = graphDb.createNode();
node.createRelationshipTo( graphDb.createNode(), withName( "KNOWS" ) );
node.createRelationshipTo( graphDb.createNode(), withName( "KNOWS" ) );
long whatThisThreadSees = countsForRelationship( null, null, null );
barrier.reached();
tx.success();
return whatThisThreadSees;
}
}
}, graphDb );
代码示例来源:origin: neo4j/neo4j
@Test
public void testFromRelCypherResult()
{
Node n = gdb.createNode();
final Relationship rel = n.createRelationshipTo( n, RelationshipType.withName( "REL" ) );
final ExecutionResult result = result( "rel", rel );
final SubGraph graph = CypherResultSubGraph.from( result, gdb, true );
assertEquals( "create (_0)" + lineSeparator() +
"create (_0)-[:`REL`]->(_0)" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldOnlyReturnTypeOnce()
{
// Given
Node node;
try ( Transaction tx = db.beginTx() )
{
node = db.createNode();
node.createRelationshipTo( db.createNode(), RelationshipType.withName( "R" ) );
node.createRelationshipTo( db.createNode(), RelationshipType.withName( "R" ) );
node.createRelationshipTo( db.createNode(), RelationshipType.withName( "R" ) );
tx.success();
}
// Then
try ( Transaction tx = db.beginTx() )
{
assertThat( Iterables.asList( node.getRelationshipTypes() ),
equalTo( singletonList( RelationshipType.withName( "R" ) ) ) );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void testGetRelationshipTypesOnDenseNode()
{
Node node = getGraphDb().createNode();
Node otherNode = getGraphDb().createNode();
for ( int i = 0; i < 300; i++ )
{
node.createRelationshipTo( otherNode, RelType.INITIAL );
}
testGetRelationshipTypes( node, new HashSet<>( asList( RelType.INITIAL.name() ) ) );
}
代码示例来源:origin: neo4j/neo4j
@Override
protected Relationship create( Map<String, Object> properties )
{
assertEquals( value, properties.get( key ) );
assertEquals( 1, properties.size() );
return root.createRelationshipTo( graphDatabase().createNode(), type );
}
};
代码示例来源:origin: neo4j/neo4j
private Relationship createRelationship( Node node )
{
try ( Transaction tx = node.getGraphDatabase().beginTx() )
{
Relationship rel = node.createRelationshipTo( node, MyRelTypes.TEST );
tx.success();
return rel;
}
}
代码示例来源:origin: neo4j/neo4j
@Before
public void setup()
{
db = (GraphDatabaseFacade) new TestGraphDatabaseFactory().newImpermanentDatabase();
try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode();
node.createRelationshipTo( db.createNode(), withName( "a" ) );
node.createRelationshipTo( db.createNode(), withName( "b" ) );
relId = node.createRelationshipTo( db.createNode(), withName( "c" ) ).getId();
tx.success();
}
}
代码示例来源:origin: neo4j/neo4j
private Node createSomeData()
{
try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode();
node.createRelationshipTo( db.createNode(), MyRelTypes.TEST );
node.createRelationshipTo( db.createNode(), MyRelTypes.TEST2 );
tx.success();
return node;
}
}
}
代码示例来源:origin: neo4j/neo4j
private void createRelationshipsBetweenNodes( Node source, Node sink,
int numberOfRelationships )
{
for ( int i = 0; i < numberOfRelationships; i++ )
{
source.createRelationshipTo( sink, RelationshipType.withName( "Type" + (i % 4) ) )
.setProperty( "" + i, i );
}
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void should_remove_all_data()
{
try ( Transaction tx = db.beginTx() )
{
RelationshipType relationshipType = RelationshipType.withName( "R" );
Node n1 = db.createNode();
Node n2 = db.createNode();
Node n3 = db.createNode();
n1.createRelationshipTo(n2, relationshipType);
n2.createRelationshipTo(n1, relationshipType);
n3.createRelationshipTo(n1, relationshipType);
tx.success();
}
cleanDatabaseContent( db );
assertThat( nodeCount(), is( 0L ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldNotGetTheSameRelationshipMoreThanOnceWhenAskingForTheSameTypeMultipleTimes()
{
// given
Node node = getGraphDb().createNode();
node.createRelationshipTo( getGraphDb().createNode(), withName( "FOO" ) );
// when
long relationships = Iterables.count( node.getRelationships( withName( "FOO" ), withName( "FOO" ) ) );
// then
assertEquals( 1, relationships );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldPrintCypherEsqueRelationshipToString()
{
// GIVEN
Node start;
Node end;
RelationshipType type = RelationshipType.withName( "NICE" );
Relationship relationship;
try ( Transaction tx = db.beginTx() )
{
// GIVEN
start = db.createNode();
end = db.createNode();
relationship = start.createRelationshipTo( end, type );
tx.success();
// WHEN
String toString = relationship.toString();
// THEN
assertEquals( "(" + start.getId() + ")-[" + type + "," + relationship.getId() + "]->(" + end.getId() + ")",
toString );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void canCreateRelationshipBetweenTwoNodesWithLoopsThenDeleteOneOfTheNodesAndItsRelationships()
{
Node source = getGraphDb().createNode();
Node target = getGraphDb().createNode();
source.createRelationshipTo( source, TEST );
target.createRelationshipTo( target, TEST );
source.createRelationshipTo( target, TEST );
newTransaction();
for ( Relationship rel : target.getRelationships() )
{
rel.delete();
}
target.delete();
}
代码示例来源:origin: neo4j/neo4j
@PluginTarget( Node.class )
public Iterable<Relationship> createRelationships( @Source Node start,
@Parameter( name = "type" ) RelationshipType type, @Parameter( name = "nodes" ) Iterable<Node> nodes )
{
List<Relationship> result = new ArrayList<>();
try ( Transaction tx = start.getGraphDatabase().beginTx() )
{
for ( Node end : nodes )
{
result.add( start.createRelationshipTo( end, type ) );
}
tx.success();
}
return result;
}
代码示例来源:origin: neo4j/neo4j
private static void generateTransaction( GraphDatabaseAPI database )
{
try ( Transaction transaction = database.beginTx() )
{
Node startNode = database.createNode( Label.label( "startNode" ) );
startNode.setProperty( "key", "value" );
Node endNode = database.createNode( Label.label( "endNode" ) );
endNode.setProperty( "key", "value" );
startNode.createRelationshipTo( endNode, RelationshipType.withName( "connects" ) );
transaction.success();
}
}
代码示例来源:origin: neo4j/neo4j
private void createRelationshipsOnNode( GraphDatabaseService db, Node root, int numberOfRelationships )
{
for ( int i = 0; i < numberOfRelationships; i++ )
{
root.createRelationshipTo( db.createNode(), RelationshipType.withName( "Type" + (i % 4) ) )
.setProperty( "" + i, i );
}
}
代码示例来源:origin: neo4j/neo4j
@Override
public Relationship create( Object... properties )
{
Relationship rel = graphDb.createNode().createRelationshipTo( graphDb.createNode(), TEST_TYPE );
setProperties( rel, properties );
return rel;
}
代码示例来源:origin: neo4j/neo4j
private static Function<Node,StartRelationship> loop( String type )
{
return node ->
{
RelationshipType relType = withName( type );
return new StartRelationship(
node.createRelationshipTo( node, relType ).getId(),
Direction.BOTH,
relType );
};
}
}
内容来源于网络,如有侵权,请联系作者删除!