private long createNodeWithProperty( String propertyKey, Object value ) { Node node; try ( org.neo4j.graphdb.Transaction ctx = graphDb.beginTx() ) { node = graphDb.createNode(); node.setProperty( propertyKey, value ); ctx.success(); } return node.getId(); }
@Test public void testRandomPropertyName() { Node node1 = getGraphDb().createNode(); String key = "random_" + new Random( System.currentTimeMillis() ).nextLong(); node1.setProperty( key, "value" ); assertEquals( "value", node1.getProperty( key ) ); node1.delete(); }
private static void bareStartAndEnd( GraphDatabaseService graphDb ) { try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() ) { bare = graphDb.createNode().getId(); Node x = graphDb.createNode(), y = graphDb.createNode(); start = x.getId(); end = y.getId(); x.createRelationshipTo( y, withName( "GEN" ) ); tx.success(); } }
private static void delete( Node node ) { for ( Relationship rel : node.getRelationships() ) { rel.delete(); } node.delete(); }
private long createTheThirdNode() { long secondNodeId; try ( Transaction transaction = db.beginTx() ) { Node hej = db.createNode( label( "hej" ) ); secondNodeId = hej.getId(); hej.setProperty( "hej", "villa" ); hej.setProperty( "ho", "value3" ); transaction.success(); } return secondNodeId; }
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 long addRelationshipToExplicitIndex() { long relId; try ( org.neo4j.graphdb.Transaction ctx = graphDb.beginTx() ) { Relationship rel = graphDb.createNode().createRelationshipTo( graphDb.createNode(), RelationshipType.withName( "R" ) ); relId = rel .getId(); graphDb.index().forRelationships( INDEX_NAME ).add( rel, KEY, VALUE ); ctx.success(); } return relId; } }
@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(); }
@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 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 ); } }
private void deleteNode( long nodeId ) { try ( Transaction tx = db.beginTx() ) { db.getNodeById( nodeId ).delete(); tx.success(); } }
private long ensurePropertyIsCachedLazyProperty( GraphDatabaseAPI slave, String key ) { long nId; try ( Transaction tx = slave.beginTx() ) { Node n = slave.createNode(); nId = n.getId(); n.setProperty( key, new long[]{-1, 2, 2, 3, 4, 5, 5} ); tx.success(); } try ( Transaction tx = slave.beginTx() ) { slave.getNodeById( nId ).hasProperty( key ); tx.success(); } return nId; }
@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 long createNode( Label label, int number ) { try ( Transaction tx = db.beginTx() ) { Node node = db.createNode( label ); node.setProperty( NUM_BANANAS_KEY, number ); tx.success(); return node.getId(); } }
private static Function<Node,StartRelationship> outgoing( String type ) { return node -> { GraphDatabaseService db = node.getGraphDatabase(); RelationshipType relType = withName( type ); return new StartRelationship( node.createRelationshipTo( db.createNode(), relType ).getId(), Direction.OUTGOING, relType ); }; }
@Test public void testPointTypeWithOneOtherProperty() { Point point = Values.pointValue( CoordinateReferenceSystem.Cartesian, 1, 1 ); String key = "location"; node1.setProperty( "prop1", 1 ); node1.setProperty( key, point ); newTransaction(); Object property = node1.getProperty( key ); assertEquals( point, property ); }
@Test public void testBooleanType() { String key = "testbool"; node1.setProperty( key, Boolean.TRUE ); newTransaction(); Boolean propertyValue = (Boolean) node1.getProperty( key ); assertEquals( Boolean.TRUE, propertyValue ); node1.setProperty( key, Boolean.FALSE ); newTransaction(); propertyValue = (Boolean) node1.getProperty( key ); assertEquals( Boolean.FALSE, propertyValue ); node1.removeProperty( key ); newTransaction(); assertTrue( !node1.hasProperty( key ) ); }
private void assertCanCreateAndFind( GraphDatabaseService db, Label label, String propertyKey, Object value ) { Node created = createNode( db, map( propertyKey, value ), label ); try ( Transaction tx = db.beginTx() ) { Node found = db.findNode( label, propertyKey, value ); assertThat( found, equalTo( created ) ); found.delete(); tx.success(); } }