@Override public Node getNodeById( long id ) { return getGraphDatabaseAPI().getNodeById( id ); }
private Node node( long id ) throws NodeNotFoundException { try { return graphDb.getNodeById( id ); } catch ( NotFoundException e ) { throw new NodeNotFoundException( String.format( "Cannot find node with id [%d] in database.", id ), e ); } }
public FindParams invoke() { startNode = graphDb.getNodeById( startId ); endNode = graphDb.getNodeById( endId ); Integer maxDepthObj = (Integer) map.get( "max_depth" ); int maxDepth = (maxDepthObj != null) ? maxDepthObj : 1; PathExpander expander = RelationshipExpanderBuilder.describeRelationships( map ); String algorithm = (String) map.get( "algorithm" ); algorithm = (algorithm != null) ? algorithm : "shortestPath"; finder = getAlgorithm( algorithm, expander, maxDepth ); return this; }
protected Node getNode( GraphDatabaseAPI graphDb, URI uri ) throws BadInputException, NodeNotFoundException { try { return graphDb.getNodeById( extractId( uri ) ); } catch ( NotFoundException e ) { throw new NodeNotFoundException( e ); } }
private Node node( long id ) throws NodeNotFoundException { try ( Transaction tx = graphDb.beginTx() ) { Node node = graphDb.getNodeById( id ); tx.success(); return node; } catch ( NotFoundException e ) { throw new NodeNotFoundException( e ); } }
public void removeFromNodeIndexNoKeyValue( String indexName, long id ) { graphDb.index().forNodes( indexName ).remove( graphDb.getNodeById( id ) ); }
public void removeFromNodeIndexNoValue( String indexName, String key, long id ) { graphDb.index().forNodes( indexName ).remove( graphDb.getNodeById( id ), key ); }
public void removeFromNodeIndex( String indexName, String key, String value, long id ) { graphDb.index().forNodes( indexName ).remove( graphDb.getNodeById( id ), key, value ); }
public IndexedEntityRepresentation getIndexedNode( String indexName, String key, String value, long id ) { if ( !nodeIsIndexed( indexName, key, value, id ) ) { throw new NotFoundException(); } Node node = graphDb.getNodeById( id ); return new IndexedEntityRepresentation( node, key, value, new NodeIndexRepresentation( indexName, Collections.emptyMap() ) ); }
public boolean nodeIsIndexed( String indexName, String key, Object value, long nodeId ) { Index<Node> index = graphDb.index().forNodes( indexName ); Node expectedNode = graphDb.getNodeById( nodeId ); try ( IndexHits<Node> hits = index.get( key, value ) ) { return iterableContains( hits, expectedNode ); } }
public IndexedEntityRepresentation addToNodeIndex( String indexName, String key, String value, long nodeId ) { Node node = graphDb.getNodeById( nodeId ); Index<Node> index = graphDb.index().forNodes( indexName ); index.add( node, key, value ); return new IndexedEntityRepresentation( node, key, value, new NodeIndexRepresentation( indexName, Collections.emptyMap() ) ); }
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(); } }
@Override protected WeightedNodeResult fetchNextOrNull() { if ( cursor.next() ) { return new WeightedNodeResult( graphDatabaseAPI.getNodeById( cursor.nodeReference() ), cursor.score() ); } else { close(); return null; } } };
private void updateNode( long nodeId, int value ) { try ( Transaction tx = db.beginTx() ) { Node node = db.getNodeById( nodeId ); node.setProperty( NUM_BANANAS_KEY, value ); tx.success(); } }
private void deleteNode( long node ) { try ( Transaction tx = db.beginTx() ) { db.getNodeById( node ).delete(); tx.success(); } }
private Runnable getById() { return () -> { dbr.getGraphDatabaseAPI().getNodeById( node.getId() ); dbr.getGraphDatabaseAPI().getRelationshipById( relationship.getId() ); }; }
@Test public void testPropertyStoreReferencesOnWrite() throws Throwable { // Given GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); // and Given the cache contains a LazyProperty long nId = ensurePropertyIsCachedLazyProperty( db, "some" ); // When restartNeoDataSource( db ); // Then it should still be possible to manipulate properties on this node try ( Transaction tx = db.beginTx() ) { db.getNodeById( nId ).setProperty( "some", new long[]{-1, 2, 2, 3, 4, 5, 5} ); tx.success(); } }
@Test public void testPropertyStoreReferencesOnRead() throws Throwable { // Given GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); // and Given the cache contains a LazyProperty long nId = ensurePropertyIsCachedLazyProperty( db, "some" ); // When restartNeoDataSource( db ); // Then reading the property is still possible try ( Transaction tx = db.beginTx() ) { db.getNodeById( nId ).getProperty( "some" ); 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; }
@Test public void shouldTellIfNodeExists() { // Given long created = createLabeledNode( db, map() ).getId(); long createdAndRemoved = createLabeledNode( db, map() ).getId(); long neverExisted = createdAndRemoved + 99; try ( Transaction tx = db.beginTx() ) { db.getNodeById( createdAndRemoved ).delete(); tx.success(); } // When & then assertTrue( nodeExists( created )); assertFalse( nodeExists( createdAndRemoved ) ); assertFalse( nodeExists( neverExisted ) ); }