Refine search
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 ); } } }
public Relationship makeEdge( String node1, String node2, Map<String, Object> edgeProperties ) { Node n1 = getNode( node1, true ); Node n2 = getNode( node2, true ); Relationship relationship = n1 .createRelationshipTo( n2, currentRelType ); for ( Map.Entry<String, Object> property : edgeProperties.entrySet() ) { relationship.setProperty( property.getKey(), property.getValue() ); } edges.add( relationship ); return relationship; }
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 ); } }
private void createAlistairAndStefanNodes() { try ( Transaction tx = graphDb.beginTx() ) { alistair = graphDb.createNode( label ); alistair.setProperty( "name", "Alistair" ); alistair.setProperty( "country", "UK" ); stefan = graphDb.createNode( label ); stefan.setProperty( "name", "Stefan" ); stefan.setProperty( "country", "Deutschland" ); aKnowsS = alistair.createRelationshipTo( stefan, relationshipType ); aKnowsS.setProperty( "duration", "long" ); aKnowsS.setProperty( "irrelevant", "prop" ); sKnowsA = stefan.createRelationshipTo( alistair, relationshipType ); sKnowsA.setProperty( "duration", "lengthy" ); sKnowsA.setProperty( "irrelevant", "prop" ); tx.success(); } }
long createRelationshipWithProperty( long firstNodeId, long secondNodeId, String propertyKey, Object propertyValue ) { Node first = db.getNodeById( firstNodeId ); Node second = db.getNodeById( secondNodeId ); Relationship relationship = first.createRelationshipTo( second, RELTYPE ); relationship.setProperty( propertyKey, propertyValue ); return relationship.getId(); }
private Relationship createRelationshipAssumingTxWith( String key, Object value ) { Node a = db.createNode(); Node b = db.createNode(); Relationship relationship = a.createRelationshipTo( b, RelationshipType.withName( "FOO" ) ); relationship.setProperty( key, value ); return relationship; } }
private long createRelationship( Map<String,Object> properties, RelationshipType relType, long fromNode, long toNode ) { try ( org.neo4j.graphdb.Transaction tx = db.beginTx() ) { Node node1 = db.getNodeById( fromNode ); Node node2 = db.getNodeById( toNode ); Relationship relationship = node1.createRelationshipTo( node2, relType ); for ( Map.Entry<String,Object> property : properties.entrySet() ) { relationship.setProperty( property.getKey(), property.getValue() ); } tx.success(); return relationship.getId(); } }
@Test public void testEscapingOfRelationshipStringPropertyValue() { Node n = gdb.createNode(); final Relationship rel = n.createRelationshipTo( n, RelationshipType.withName( "REL" ) ); rel.setProperty( "name", "Brutus \"Brutal\" Howell" ); final ExecutionResult result = result( "rel", rel ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, true ); assertEquals( "create (_0)" + lineSeparator() + "create (_0)-[:`REL` {`name`:\"Brutus \\\"Brutal\\\" Howell\"}]->(_0)" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }
@Test public void testEscapingOfRelationshipStringArrayPropertyValue() { Node n = gdb.createNode(); final Relationship rel = n.createRelationshipTo( n, RelationshipType.withName( "REL" ) ); rel.setProperty( "name", new String[]{"Brutus \"Brutal\" Howell", "Dr."} ); final ExecutionResult result = result( "rel", rel ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, true ); assertEquals( "create (_0)" + lineSeparator() + "create (_0)-[:`REL` {`name`:[\"Brutus \\\"Brutal\\\" Howell\", \"Dr.\"]}]->(_0)" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }
@Test public void testChangeProperty() { Node node1 = getGraphDb().createNode(); Node node2 = getGraphDb().createNode(); Relationship rel = node1.createRelationshipTo( node2, TEST ); rel.setProperty( "test", "test1" ); newTransaction(); rel.setProperty( "test", "test2" ); rel.removeProperty( "test" ); rel.setProperty( "test", "test3" ); assertEquals( "test3", rel.getProperty( "test" ) ); rel.removeProperty( "test" ); rel.setProperty( "test", "test4" ); newTransaction(); assertEquals( "test4", rel.getProperty( "test" ) ); }
@Before public void prepDB() { try ( Transaction transaction = db.beginTx() ) { node1 = db.createNode( label( "hej" ), label( "ha" ), label( "he" ) ); node1.setProperty( "hej", "value" ); node1.setProperty( "ha", "value1" ); node1.setProperty( "he", "value2" ); node1.setProperty( "ho", "value3" ); node1.setProperty( "hi", "value4" ); node2 = db.createNode(); Relationship rel = node1.createRelationshipTo( node2, RelationshipType.withName( "hej" ) ); rel.setProperty( "hej", "valuuu" ); rel.setProperty( "ha", "value1" ); rel.setProperty( "he", "value2" ); rel.setProperty( "ho", "value3" ); rel.setProperty( "hi", "value4" ); transaction.success(); } }
@Test public void testAddPropertyThenDelete() { Node node1 = getGraphDb().createNode(); Node node2 = getGraphDb().createNode(); Relationship rel = node1.createRelationshipTo( node2, TEST ); rel.setProperty( "test", "test" ); newTransaction(); rel.setProperty( "test2", "test2" ); rel.delete(); node1.delete(); node2.delete(); newTransaction(); }
@Test public void shouldBeAbleToForceTypeChangeOfProperty() { // Given Relationship relationship; try ( Transaction tx = db.beginTx() ) { relationship = db.createNode().createRelationshipTo( db.createNode(), withName( "R" ) ); relationship.setProperty( "prop", 1337 ); tx.success(); } // When try ( Transaction tx = db.beginTx() ) { relationship.setProperty( "prop", 1337.0 ); tx.success(); } // Then try ( Transaction ignore = db.beginTx() ) { assertThat( relationship.getProperty( "prop" ), instanceOf( Double.class ) ); } }
@Test public void testFromSimpleGraph() { final Node n0 = gdb.createNode(); final Node n1 = gdb.createNode(); n1.setProperty( "name", "Node1" ); final Relationship relationship = n0.createRelationshipTo( n1, RelationshipType.withName( "REL" ) ); relationship.setProperty( "related", true ); final SubGraph graph = DatabaseSubGraph.from( gdb ); assertEquals( "create (_" + n0.getId() + ")" + lineSeparator() + "create (_" + n1.getId() + " {`name`:\"Node1\"})" + lineSeparator() + "create (_" + n0.getId() + ")-[:`REL` {`related`:true}]->(_" + n1.getId() + ")" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); } }
@Test public void testRelationshipAddPropertyWithNullKey() { Node node1 = getGraphDb().createNode(); Node node2 = getGraphDb().createNode(); Relationship rel1 = node1.createRelationshipTo( node2, TEST ); try { rel1.setProperty( null, "bar" ); fail( "Null key should result in exception." ); } catch ( IllegalArgumentException e ) { // OK } }
@Test public void mustBeAbleToConsistencyCheckRelationshipIndexWithMultipleRelationshipTypesAndOneProperty() throws Exception { GraphDatabaseService db = createDatabase(); RelationshipType relType1 = RelationshipType.withName( "R1" ); RelationshipType relType2 = RelationshipType.withName( "R2" ); try ( Transaction tx = db.beginTx() ) { db.execute( format( RELATIONSHIP_CREATE, "rels", array( "R1", "R2" ), array( "p1" ) ) ).close(); tx.success(); } try ( Transaction tx = db.beginTx() ) { db.schema().awaitIndexesOnline( 1, TimeUnit.MINUTES ); Node n1 = db.createNode(); Node n2 = db.createNode(); n1.createRelationshipTo( n1, relType1 ).setProperty( "p1", "value" ); n1.createRelationshipTo( n1, relType2 ).setProperty( "p1", "value" ); n2.createRelationshipTo( n2, relType1 ).setProperty( "p1", "value" ); n2.createRelationshipTo( n2, relType2 ).setProperty( "p1", "value" ); tx.success(); } db.shutdown(); assertIsConsistent( checkConsistency() ); }
@Test public void shouldBeAbleToGetPropertiesOnRelationship() throws Exception { long relationshipId; Map<String, Object> properties = new HashMap<>(); properties.put( "foo", "bar" ); properties.put( "neo", "Thomas A. Anderson" ); properties.put( "number", 15L ); try ( Transaction tx = database.getGraph().beginTx() ) { Node startNode = database.getGraph().createNode(); Node endNode = database.getGraph().createNode(); Relationship relationship = startNode.createRelationshipTo( endNode, RelationshipType.withName( "knows" ) ); for ( Map.Entry<String, Object> entry : properties.entrySet() ) { relationship.setProperty( entry.getKey(), entry.getValue() ); } relationshipId = relationship.getId(); tx.success(); } try ( Transaction transaction = graph.beginTx() ) { assertEquals( properties, serialize( actions.getAllRelationshipProperties( relationshipId ) ) ); } }
@Before public void createDataset() { GraphDatabaseAPI db = dbr.getGraphDatabaseAPI(); try ( Transaction tx = db.beginTx() ) { node = db.createNode( label ); node.setProperty( "short", 123 ); node.setProperty( "long", longString( 300 ) ); relationship = node.createRelationshipTo( db.createNode(), MyRelTypes.TEST ); relationship.setProperty( "short", 123 ); relationship.setProperty( "long", longString( 300 ) ); tx.success(); } logEntriesWrittenBeforeReadOperations = countLogEntries(); }
@Before public void setup() { for ( int i = 0; i < 100; i++ ) { try ( Transaction tx = db.beginTx() ) { Node prev = null; for ( int j = 0; j < 100; j++ ) { Node node = db.createNode( label( "L" ) ); if ( prev != null ) { Relationship rel = prev.createRelationshipTo( node, RelationshipType.withName( "T" ) ); rel.setProperty( "prop", i + j ); } prev = node; } tx.success(); } } }
@Test public void testRelMultiRemoveProperty() { Node node1 = getGraphDb().createNode(); Node node2 = getGraphDb().createNode(); Relationship rel = node1.createRelationshipTo( node2, MyRelTypes.TEST ); rel.setProperty( "key0", "0" ); rel.setProperty( "key1", "1" ); rel.setProperty( "key2", "2" ); rel.setProperty( "key3", "3" ); rel.setProperty( "key4", "4" ); newTransaction(); rel.removeProperty( "key3" ); rel.removeProperty( "key2" ); rel.removeProperty( "key3" ); newTransaction(); assertEquals( "0", rel.getProperty( "key0" ) ); assertEquals( "1", rel.getProperty( "key1" ) ); assertEquals( "4", rel.getProperty( "key4" ) ); assertTrue( !rel.hasProperty( "key2" ) ); assertTrue( !rel.hasProperty( "key3" ) ); rel.delete(); node1.delete(); node2.delete(); }