@Override public Relationship create() { return db.createNode().createRelationshipTo( db.createNode(), type ); } };
@Override protected Relationship obtainEntityInTransaction( GraphDatabaseService graphDatabaseService ) { return graphDatabaseService .createNode() .createRelationshipTo( graphDatabaseService.createNode(), withName( "foo" ) ); } }
@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 );
@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 ) ); }
@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" ) ) ) ); } }
@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() ) ) ); }
@Override protected Relationship create( Map<String, Object> properties ) { assertEquals( value, properties.get( key ) ); assertEquals( 1, properties.size() ); return root.createRelationshipTo( graphDatabase().createNode(), type ); } };
private Relationship createRelationship( Node node ) { try ( Transaction tx = node.getGraphDatabase().beginTx() ) { Relationship rel = node.createRelationshipTo( node, MyRelTypes.TEST ); tx.success(); return rel; } }
@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(); } }
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; } } }
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 ); } } }
@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 ) ); }
@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 ); }
@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 ); } }
@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(); }
@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; }
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(); } }
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 ); } }
@Override public Relationship create( Object... properties ) { Relationship rel = graphDb.createNode().createRelationshipTo( graphDb.createNode(), TEST_TYPE ); setProperties( rel, properties ); return rel; }
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 ); }; } }