org.neo4j.kernel.impl.api.parallel.ExecutionContextNode Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of neo4j-kernel Show documentation
Show all versions of neo4j-kernel Show documentation
Neo4j kernel is a lightweight, embedded Java database designed to
store data structured as graphs rather than tables. For more
information, see http://neo4j.org.
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [https://neo4j.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package org.neo4j.kernel.impl.api.parallel;
import static java.lang.String.format;
import static org.neo4j.internal.kernel.api.helpers.RelationshipSelections.allIterator;
import static org.neo4j.internal.kernel.api.helpers.RelationshipSelections.incomingIterator;
import static org.neo4j.internal.kernel.api.helpers.RelationshipSelections.outgoingIterator;
import java.util.Map;
import org.neo4j.common.EntityType;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.NotFoundException;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.ResourceIterable;
import org.neo4j.graphdb.ResourceIterator;
import org.neo4j.internal.helpers.collection.AbstractResourceIterable;
import org.neo4j.internal.kernel.api.NodeCursor;
import org.neo4j.internal.kernel.api.PropertyCursor;
import org.neo4j.internal.kernel.api.RelationshipTraversalCursor;
import org.neo4j.internal.kernel.api.TokenRead;
import org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException;
import org.neo4j.internal.kernel.api.helpers.RelationshipFactory;
import org.neo4j.kernel.api.ExecutionContext;
import org.neo4j.kernel.impl.core.AbstractNodeEntity;
public class ExecutionContextNode extends AbstractNodeEntity {
private final long nodeId;
private final ExecutionContext executionContext;
public ExecutionContextNode(long nodeId, ExecutionContext executionContext) {
this.nodeId = nodeId;
this.executionContext = executionContext;
}
@Override
public long getId() {
return nodeId;
}
@Override
public String getElementId() {
return executionContext.elementIdMapper().nodeElementId(nodeId);
}
@Override
public boolean hasProperty(String key) {
var cursors = executionContext.cursors();
try (NodeCursor nodes =
cursors.allocateNodeCursor(executionContext.cursorContext(), executionContext.memoryTracker());
PropertyCursor properties = cursors.allocatePropertyCursor(
executionContext.cursorContext(), executionContext.memoryTracker())) {
singleNode(nodes);
return hasProperty(key, nodes, properties);
}
}
@Override
public Object getProperty(String key) {
var cursors = executionContext.cursors();
try (NodeCursor nodes =
cursors.allocateNodeCursor(executionContext.cursorContext(), executionContext.memoryTracker());
PropertyCursor properties = cursors.allocatePropertyCursor(
executionContext.cursorContext(), executionContext.memoryTracker())) {
singleNode(nodes);
return getProperty(key, nodes, properties);
}
}
@Override
public Object getProperty(String key, Object defaultValue) {
var cursors = executionContext.cursors();
try (NodeCursor nodes =
cursors.allocateNodeCursor(executionContext.cursorContext(), executionContext.memoryTracker());
PropertyCursor properties = cursors.allocatePropertyCursor(
executionContext.cursorContext(), executionContext.memoryTracker())) {
singleNode(nodes);
return getProperty(key, defaultValue, nodes, properties);
}
}
@Override
public Iterable getPropertyKeys() {
var cursors = executionContext.cursors();
try (NodeCursor nodes =
cursors.allocateNodeCursor(executionContext.cursorContext(), executionContext.memoryTracker());
PropertyCursor properties = cursors.allocatePropertyCursor(
executionContext.cursorContext(), executionContext.memoryTracker())) {
singleNode(nodes);
return getPropertyKeys(nodes, properties);
}
}
@Override
public Map getProperties(String... keys) {
var cursors = executionContext.cursors();
try (NodeCursor nodes =
cursors.allocateNodeCursor(executionContext.cursorContext(), executionContext.memoryTracker());
PropertyCursor properties = cursors.allocatePropertyCursor(
executionContext.cursorContext(), executionContext.memoryTracker())) {
singleNode(nodes);
return getProperties(nodes, properties, keys);
}
}
@Override
public Map getAllProperties() {
var cursors = executionContext.cursors();
try (NodeCursor nodes =
cursors.allocateNodeCursor(executionContext.cursorContext(), executionContext.memoryTracker());
PropertyCursor properties = cursors.allocatePropertyCursor(
executionContext.cursorContext(), executionContext.memoryTracker())) {
singleNode(nodes);
return getAllProperties(nodes, properties);
}
}
@Override
public ResourceIterable getRelationships(Direction direction, RelationshipType... types) {
int[] typeIds = relTypeIds(executionContext.tokenRead(), types);
return new RelationshipsIterable(executionContext, getId(), direction, typeIds, this::relationship);
}
@Override
public boolean hasRelationship(Direction direction, RelationshipType... types) {
int[] typeIds = relTypeIds(executionContext.tokenRead(), types);
return innerHasRelationships(direction, typeIds);
}
private boolean innerHasRelationships(Direction direction, int[] typeIds) {
try (ResourceIterator iterator =
getRelationshipSelectionIterator(executionContext, getId(), direction, typeIds, this::relationship)) {
return iterator.hasNext();
}
}
@Override
public ResourceIterable getRelationships(Direction direction) {
return new RelationshipsIterable(executionContext, getId(), direction, null, this::relationship);
}
@Override
public boolean hasRelationship(Direction direction) {
return innerHasRelationships(direction, null);
}
@Override
public Relationship getSingleRelationship(RelationshipType type, Direction dir) {
int[] typeIds = relTypeIds(executionContext.tokenRead(), type);
try (ResourceIterator relationships =
getRelationshipSelectionIterator(executionContext, getId(), dir, typeIds, this::relationship)) {
return getSingleRelationship(relationships, type, dir);
}
}
@Override
public Iterable getRelationshipTypes() {
try (NodeCursor nodes = executionContext
.cursors()
.allocateNodeCursor(executionContext.cursorContext(), executionContext.memoryTracker())) {
return getRelationshipTypes(nodes);
}
}
@Override
public int getDegree() {
try (NodeCursor nodes = executionContext
.cursors()
.allocateNodeCursor(executionContext.cursorContext(), executionContext.memoryTracker())) {
return getDegree(nodes);
}
}
@Override
public int getDegree(RelationshipType type) {
try (NodeCursor nodes = executionContext
.cursors()
.allocateNodeCursor(executionContext.cursorContext(), executionContext.memoryTracker())) {
return getDegree(type, nodes);
}
}
@Override
public int getDegree(Direction direction) {
try (NodeCursor nodes = executionContext
.cursors()
.allocateNodeCursor(executionContext.cursorContext(), executionContext.memoryTracker())) {
return getDegree(direction, nodes);
}
}
@Override
public int getDegree(RelationshipType type, Direction direction) {
try (NodeCursor nodes = executionContext
.cursors()
.allocateNodeCursor(executionContext.cursorContext(), executionContext.memoryTracker())) {
return getDegree(type, direction, nodes);
}
}
@Override
public boolean hasLabel(Label label) {
try (NodeCursor nodes = executionContext
.cursors()
.allocateNodeCursor(executionContext.cursorContext(), executionContext.memoryTracker())) {
return hasLabel(label, nodes);
}
}
@Override
public Iterable