private static Node createNode( GraphDatabaseService db, String propertyKey, Object value ) { try ( Transaction tx = db.beginTx() ) { Node node = db.createNode( label( LABEL ) ); node.setProperty( propertyKey, value ); tx.success(); return node; } }
private void createIndex() { try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() ) { graphDb.schema().indexFor( Label.label( "Node" ) ).on( "prop" ).create(); tx.success(); } try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() ) { graphDb.schema().awaitIndexesOnline( 1, TimeUnit.MINUTES ); } }
private void createNodeWith( String key ) { try ( Transaction tx = db.beginTx() ) { Node node = db.createNode(); node.setProperty( key, 1 ); tx.success(); } } }
@Test public void mustBeAbleToConsistencycheckRelationshipIndexThatIsMissingRelationshipsBecauseTheirPropertyValuesaAreNotStrings() throws Exception { GraphDatabaseService db = createDatabase(); try ( Transaction tx = db.beginTx() ) { db.execute( format( RELATIONSHIP_CREATE, "rels", array( "R1" ), array( "p1" ) ) ).close(); tx.success(); } try ( Transaction tx = db.beginTx() ) { db.schema().awaitIndexesOnline( 1, TimeUnit.MINUTES ); Node node = db.createNode(); node.createRelationshipTo( node, RelationshipType.withName( "R1" ) ).setProperty( "p1", 1 ); tx.success(); } db.shutdown(); assertIsConsistent( checkConsistency() ); }
private void createData( GraphDatabaseService database, int numberOfNodes ) { for ( int i = 0; i < numberOfNodes; i++ ) { try ( Transaction transaction = database.beginTx() ) { Node node = database.createNode( Label.label( FOOD_LABEL ), Label.label( CLOTHES_LABEL ), Label.label( WEATHER_LABEL ) ); node.setProperty( PROPERTY_NAME, "Node" + i ); Relationship relationship = node.createRelationshipTo( node, RelationshipType.withName( FOOD_LABEL ) ); relationship.setProperty( PROPERTY_NAME, "Relationship" + i ); transaction.success(); } } }
private long initWithRel( GraphDatabaseService db ) { try ( Transaction tx = db.beginTx() ) { Node node = db.createNode(); node.setProperty( "a", "prop" ); Relationship rel = node.createRelationshipTo( db.createNode(), RelationshipType.withName( "T" ) ); long id = rel.getId(); tx.success(); return id; } }
private void createConstraint( GraphDatabaseService database ) { try ( Transaction transaction = database.beginTx() ) { Schema schema = database.schema(); schema.constraintFor( constraintIndexLabel ).assertPropertyIsUnique( UNIQUE_PROPERTY_NAME ).create(); transaction.success(); } }
@Test public void testRollbackDeleteRelationship() { Node node1 = getGraphDb().createNode(); Node node2 = getGraphDb().createNode(); Relationship rel1 = node1.createRelationshipTo( node2, TEST ); newTransaction(); node1.delete(); rel1.delete(); getTransaction().failure(); getTransaction().close(); setTransaction( getGraphDb().beginTx() ); node1.delete(); node2.delete(); rel1.delete(); }
private static void generateRandomData( GraphDatabaseAPI database, Label label, String nameProperty ) { for ( int i = 0; i < 1000; i++ ) { try ( Transaction transaction = database.beginTx() ) { Node node = database.createNode( label ); node.setProperty( nameProperty, "PlanetExpress" + i ); transaction.success(); } } }
@Test public void shouldNotWarnOnSmallLabelScansWithLoadCVS() { try ( Transaction tx = db().beginTx() ) { db().createNode().addLabel( label( "A" ) ); tx.success(); } Stream.of( "CYPHER 3.1", "CYPHER 3.5" ).forEach( version -> { shouldNotNotifyInStream( version, "EXPLAIN LOAD CSV FROM 'file:///ignore/ignore.csv' AS line MATCH (a:A) RETURN *" ); shouldNotNotifyInStream( version, "EXPLAIN LOAD CSV FROM 'file:///ignore/ignore.csv' AS line MERGE (a:A) RETURN *" ); } ); }
public static void cleanupAllRelationshipsAndNodes( GraphDatabaseService db ) { try ( Transaction tx = db.beginTx() ) { for ( Relationship relationship : db.getAllRelationships() ) { relationship.delete(); } for ( Node node : db.getAllNodes() ) { node.delete(); } tx.success(); } } }
@Name( GET_CONNECTED_NODES ) @PluginTarget( Node.class ) public Iterable<Node> getAllConnectedNodes( @Source Node start ) { ArrayList<Node> nodes = new ArrayList<>(); try ( Transaction tx = start.getGraphDatabase().beginTx() ) { for ( Relationship rel : start.getRelationships() ) { nodes.add( rel.getOtherNode( start ) ); } tx.success(); } return nodes; }
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(); } }
void setProperty( String nodeName, String propertyName, Object propertyValue ) { Node i = this.getNode( nodeName ); GraphDatabaseService db = i.getGraphDatabase(); try ( Transaction tx = db.beginTx() ) { i.setProperty( propertyName, propertyValue ); tx.success(); } }
public long createRelationship( String type ) { try ( Transaction tx = database.getGraph().beginTransaction( implicit, AnonymousContext.writeToken() ) ) { Node startNode = database.getGraph().createNode(); Node endNode = database.getGraph().createNode(); Relationship relationship = startNode.createRelationshipTo( endNode, RelationshipType.withName( type ) ); tx.success(); return relationship.getId(); } }
@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(); }
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(); } }