@Override public CursorFactory cursors() { return internal.cursors(); }
private ResourceIterator<Node> getNodesByLabelAndPropertyWithoutIndex( Statement statement, int labelId, IndexQuery... queries ) { KernelTransaction transaction = statementContext.getKernelTransactionBoundToThisThread( true ); NodeLabelIndexCursor nodeLabelCursor = transaction.cursors().allocateNodeLabelIndexCursor(); NodeCursor nodeCursor = transaction.cursors().allocateNodeCursor(); PropertyCursor propertyCursor = transaction.cursors().allocatePropertyCursor(); transaction.dataRead().nodeLabelScan( labelId, nodeLabelCursor ); return new NodeLabelPropertyIterator( transaction.dataRead(), nodeLabelCursor, nodeCursor, propertyCursor, statement, this::newNodeProxy, queries ); }
@Override public IndexHits<Node> query( KernelTransaction ktx, String name, Object queryOrQueryObject, GraphDatabaseService graphDatabaseService ) throws ExplicitIndexNotFoundKernelException { NodeExplicitIndexCursor cursor = ktx.cursors().allocateNodeExplicitIndexCursor(); ktx.indexRead().nodeExplicitIndexQuery( cursor, name, queryOrQueryObject ); return new CursorWrappingNodeIndexHits( cursor, graphDatabaseService, ktx, name ); }
@Override public IndexHits<Relationship> get( KernelTransaction ktx, String name, String key, Object value, GraphDatabaseService graphDatabaseService ) throws ExplicitIndexNotFoundKernelException { RelationshipExplicitIndexCursor cursor = ktx.cursors().allocateRelationshipExplicitIndexCursor(); ktx.indexRead().relationshipExplicitIndexLookup( cursor, name, key, value, -1, -1 ); return new CursorWrappingRelationshipIndexHits( cursor, graphDatabaseService, ktx, name ); }
@Override public IndexHits<Node> get( KernelTransaction ktx, String name, String key, Object value, GraphDatabaseService graphDatabaseService ) throws ExplicitIndexNotFoundKernelException { NodeExplicitIndexCursor cursor = ktx.cursors().allocateNodeExplicitIndexCursor(); ktx.indexRead().nodeExplicitIndexLookup( cursor, name, key, value ); return new CursorWrappingNodeIndexHits( cursor, graphDatabaseService, ktx, name ); }
@Override public IndexHits<Relationship> query( KernelTransaction ktx, String name, String key, Object queryOrQueryObject, GraphDatabaseService graphDatabaseService ) throws ExplicitIndexNotFoundKernelException { RelationshipExplicitIndexCursor cursor = ktx.cursors().allocateRelationshipExplicitIndexCursor(); ktx.indexRead().relationshipExplicitIndexQuery( cursor, name, key, queryOrQueryObject,-1, -1 ); return new CursorWrappingRelationshipIndexHits( cursor, graphDatabaseService, ktx, name ); }
@Override public IndexHits<Node> query( KernelTransaction ktx, String name, String key, Object queryOrQueryObject, GraphDatabaseService graphDatabaseService ) throws ExplicitIndexNotFoundKernelException { NodeExplicitIndexCursor cursor = ktx.cursors().allocateNodeExplicitIndexCursor(); ktx.indexRead().nodeExplicitIndexQuery( cursor, name, key, queryOrQueryObject ); return new CursorWrappingNodeIndexHits( cursor, graphDatabaseService, ktx, name ); }
@Override public IndexHits<Relationship> query( KernelTransaction ktx, String name, Object queryOrQueryObject, GraphDatabaseService graphDatabaseService ) throws ExplicitIndexNotFoundKernelException { RelationshipExplicitIndexCursor cursor = ktx.cursors().allocateRelationshipExplicitIndexCursor(); ktx.indexRead().relationshipExplicitIndexQuery( cursor, name, queryOrQueryObject, -1 , -1 ); return new CursorWrappingRelationshipIndexHits( cursor, graphDatabaseService, ktx, name ); }
@Override public int getDegree() { KernelTransaction transaction = safeAcquireTransaction(); try ( Statement ignore = transaction.acquireStatement() ) { NodeCursor nodes = transaction.ambientNodeCursor(); singleNode( transaction, nodes ); return Nodes.countAll( nodes, transaction.cursors() ); } }
@Deprecated @Description( "Search nodes in explicit automatic index. Replaces `START n=node:node_auto_index('key:foo*')`" ) @Procedure( name = "db.index.explicit.auto.searchNodes", mode = READ, deprecatedBy = EXPLICIT_INDEX_DEPRECATION ) public Stream<WeightedNodeResult> nodeAutoIndexSearch( @Name( "query" ) Object query ) { try ( Statement ignore = tx.acquireStatement() ) { NodeExplicitIndexCursor cursor = tx.cursors().allocateNodeExplicitIndexCursor(); tx.indexRead().nodeExplicitIndexQuery( cursor, "node_auto_index", query ); return toWeightedNodeResultStream( cursor ); } catch ( KernelException e ) { // auto index will not exist if no nodes have been added that match the auto-index rules return Stream.empty(); } }
@Deprecated @Description( "Search relationship in explicit automatic index. Replaces `START r=relationship:relationship_auto_index" + "('key:foo*')`" ) @Procedure( name = "db.index.explicit.auto.searchRelationships", mode = READ, deprecatedBy = EXPLICIT_INDEX_DEPRECATION ) public Stream<WeightedRelationshipResult> relationshipAutoIndexSearch( @Name( "query" ) Object query ) { try ( Statement ignore = tx.acquireStatement() ) { RelationshipExplicitIndexCursor cursor = tx.cursors().allocateRelationshipExplicitIndexCursor(); tx.indexRead().relationshipExplicitIndexQuery( cursor, "relationship_auto_index", query, -1, -1 ); return toWeightedRelationshipResultStream( cursor ); } catch ( KernelException e ) { // auto index will not exist if no relationships have been added that match the auto-index rules return Stream.empty(); } }
NodeValueIndexCursor indexQuery( KernelTransaction ktx, IndexDescriptor indexDescriptor, IndexQuery... indexQueries ) throws KernelException { NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(); ktx.dataRead().nodeIndexSeek( indexDescriptor, cursor, IndexOrder.NONE, false, indexQueries ); return cursor; } }
@Deprecated @Description( "Get node from explicit automatic index. Replaces `START n=node:node_auto_index(key = 'A')`" ) @Procedure( name = "db.index.explicit.auto.seekNodes", mode = READ, deprecatedBy = EXPLICIT_INDEX_DEPRECATION ) public Stream<NodeResult> nodeAutoIndexSeek( @Name( "key" ) String key, @Name( "value" ) Object value ) { try ( Statement ignore = tx.acquireStatement() ) { NodeExplicitIndexCursor cursor = tx.cursors().allocateNodeExplicitIndexCursor(); tx.indexRead().nodeExplicitIndexLookup( cursor, "node_auto_index", key, value ); return toStream( cursor, id -> new NodeResult( graphDatabaseAPI.getNodeById( id ) ) ); } catch ( KernelException e ) { // auto index will not exist if no nodes have been added that match the auto-index rules return Stream.empty(); } }
@Override public IndexHits<Relationship> get( String key, Object valueOrNull, Node startNodeOrNull, Node endNodeOrNull ) { KernelTransaction ktx = txBridge.get(); try ( Statement ignore = ktx.acquireStatement() ) { RelationshipExplicitIndexCursor cursor = ktx.cursors().allocateRelationshipExplicitIndexCursor(); long source = startNodeOrNull == null ? NO_SUCH_NODE : startNodeOrNull.getId(); long target = endNodeOrNull == null ? NO_SUCH_NODE : endNodeOrNull.getId(); ktx.indexRead().relationshipExplicitIndexLookup( cursor, name, key, valueOrNull, source, target ); return new CursorWrappingRelationshipIndexHits( cursor, getGraphDatabase(), ktx, name ); } catch ( ExplicitIndexNotFoundKernelException e ) { throw new NotFoundException( type + " index '" + name + "' doesn't exist" ); } }
@Override public IndexHits<Relationship> query( String key, Object queryOrQueryObjectOrNull, Node startNodeOrNull, Node endNodeOrNull ) { KernelTransaction ktx = txBridge.get(); try ( Statement ignore = ktx.acquireStatement() ) { RelationshipExplicitIndexCursor cursor = ktx.cursors().allocateRelationshipExplicitIndexCursor(); long source = startNodeOrNull == null ? NO_SUCH_NODE : startNodeOrNull.getId(); long target = endNodeOrNull == null ? NO_SUCH_NODE : endNodeOrNull.getId(); ktx.indexRead().relationshipExplicitIndexQuery( cursor, name, key, queryOrQueryObjectOrNull, source, target ); return new CursorWrappingRelationshipIndexHits( cursor, getGraphDatabase(), ktx, name ); } catch ( ExplicitIndexNotFoundKernelException e ) { throw new NotFoundException( type + " index '" + name + "' doesn't exist" ); } }
@Override public IndexHits<Relationship> query( Object queryOrQueryObjectOrNull, Node startNodeOrNull, Node endNodeOrNull ) { KernelTransaction ktx = txBridge.get(); try ( Statement ignore = ktx.acquireStatement() ) { RelationshipExplicitIndexCursor cursor = ktx.cursors().allocateRelationshipExplicitIndexCursor(); long source = startNodeOrNull == null ? NO_SUCH_NODE : startNodeOrNull.getId(); long target = endNodeOrNull == null ? NO_SUCH_NODE : endNodeOrNull.getId(); ktx.indexRead().relationshipExplicitIndexQuery( cursor, name, queryOrQueryObjectOrNull, source, target ); return new CursorWrappingRelationshipIndexHits( cursor, getGraphDatabase(), ktx, name ); } catch ( ExplicitIndexNotFoundKernelException e ) { throw new NotFoundException( type + " index '" + name + "' doesn't exist" ); } } }
private NodeValueIndexCursor seek( KernelTransaction transaction ) throws KernelException { NodeValueIndexCursor cursor = transaction.cursors().allocateNodeValueIndexCursor(); transaction.dataRead().nodeIndexSeek( index, cursor, IndexOrder.NONE, false, exactQuery() ); return cursor; }
@Override public int getDegree( RelationshipType type ) { KernelTransaction transaction = safeAcquireTransaction(); int typeId = transaction.tokenRead().relationshipType( type.name() ); if ( typeId == NO_TOKEN ) { // This type doesn't even exist. Return 0 return 0; } try ( Statement ignore = transaction.acquireStatement() ) { NodeCursor nodes = transaction.ambientNodeCursor(); singleNode( transaction, nodes ); return Nodes.countAll( nodes, transaction.cursors(), typeId ); } }
@Deprecated @Description( "Get node from explicit index. Replaces `START n=node:nodes(key = 'A')`" ) @Procedure( name = "db.index.explicit.seekNodes", mode = READ, deprecatedBy = EXPLICIT_INDEX_DEPRECATION ) public Stream<NodeResult> nodeManualIndexSeek( @Name( "indexName" ) String explicitIndexName, @Name( "key" ) String key, @Name( "value" ) Object value ) throws ProcedureException { try ( Statement ignore = tx.acquireStatement() ) { NodeExplicitIndexCursor cursor = tx.cursors().allocateNodeExplicitIndexCursor(); tx.indexRead().nodeExplicitIndexLookup( cursor, explicitIndexName, key, value ); return toStream( cursor, id -> new NodeResult( graphDatabaseAPI.getNodeById( id ) ) ); } catch ( KernelException e ) { throw new ProcedureException( Status.LegacyIndex.LegacyIndexNotFound, "Node index %s not found", explicitIndexName ); } }
private ResourceIterator<Node> allNodesWithLabel( final Label myLabel ) { KernelTransaction ktx = statementContext.getKernelTransactionBoundToThisThread( true ); Statement statement = ktx.acquireStatement(); int labelId = ktx.tokenRead().nodeLabel( myLabel.name() ); if ( labelId == TokenRead.NO_TOKEN ) { statement.close(); return Iterators.emptyResourceIterator(); } NodeLabelIndexCursor cursor = ktx.cursors().allocateNodeLabelIndexCursor(); ktx.dataRead().nodeLabelScan( labelId, cursor ); return new NodeCursorResourceIterator<>( cursor, statement, this::newNodeProxy ); }