use of org.neo4j.storageengine.api.NodeItem in project neo4j by neo4j.
the class NeoStoresTest method validateAndCountRelationships.
private int validateAndCountRelationships(long node, long rel1, long rel2, int relType1, int relType2) throws IOException {
int count = 0;
try (KernelStatement statement = (KernelStatement) tx.acquireStatement();
Cursor<NodeItem> nodeCursor = statement.getStoreStatement().acquireSingleNodeCursor(node)) {
nodeCursor.next();
NodeItem nodeItem = nodeCursor.get();
try (Cursor<RelationshipItem> relationships = statement.getStoreStatement().acquireNodeRelationshipCursor(nodeItem.isDense(), nodeItem.id(), nodeItem.nextRelationshipId(), BOTH, ALWAYS_TRUE_INT)) {
while (relationships.next()) {
long rel = relationships.get().id();
if (rel == rel1) {
assertEquals(node, relationships.get().startNode());
assertEquals(relType1, relationships.get().type());
} else if (rel == rel2) {
assertEquals(node, relationships.get().endNode());
assertEquals(relType2, relationships.get().type());
} else {
throw new IOException();
}
count++;
}
}
}
return count;
}
use of org.neo4j.storageengine.api.NodeItem in project neo4j by neo4j.
the class NeoStoresTest method validateNodeRel2.
private void validateNodeRel2(final long node, DefinedProperty prop1, DefinedProperty prop2, DefinedProperty prop3, long rel1, long rel2, final int relType1, final int relType2) throws IOException, RuntimeException {
assertTrue(nodeExists(node));
ArrayMap<Integer, Pair<DefinedProperty, Long>> props = new ArrayMap<>();
propertyLoader.nodeLoadProperties(node, newPropertyReceiver(props));
int count = 0;
for (int keyId : props.keySet()) {
long id = props.get(keyId).other();
PropertyRecord record = getRecord(pStore, id);
PropertyBlock block = record.getPropertyBlock(props.get(keyId).first().propertyKeyId());
DefinedProperty data = block.newPropertyData(pStore);
if (data.propertyKeyId() == prop1.propertyKeyId()) {
assertEquals("prop1", MyPropertyKeyToken.getIndexFor(keyId).name());
assertEquals("string2", data.value());
nodeAddProperty(node, prop1.propertyKeyId(), "-string2");
} else if (data.propertyKeyId() == prop2.propertyKeyId()) {
assertEquals("prop2", MyPropertyKeyToken.getIndexFor(keyId).name());
assertEquals(2, data.value());
nodeAddProperty(node, prop2.propertyKeyId(), -2);
} else if (data.propertyKeyId() == prop3.propertyKeyId()) {
assertEquals("prop3", MyPropertyKeyToken.getIndexFor(keyId).name());
assertEquals(false, data.value());
nodeAddProperty(node, prop3.propertyKeyId(), true);
} else {
throw new IOException();
}
count++;
}
assertEquals(3, count);
count = 0;
try (KernelStatement statement = (KernelStatement) tx.acquireStatement();
Cursor<NodeItem> nodeCursor = statement.getStoreStatement().acquireSingleNodeCursor(node)) {
nodeCursor.next();
NodeItem nodeItem = nodeCursor.get();
try (Cursor<RelationshipItem> relationships = statement.getStoreStatement().acquireNodeRelationshipCursor(nodeItem.isDense(), nodeItem.id(), nodeItem.nextRelationshipId(), BOTH, ALWAYS_TRUE_INT)) {
while (relationships.next()) {
long rel = relationships.get().id();
if (rel == rel1) {
assertEquals(node, relationships.get().endNode());
assertEquals(relType1, relationships.get().type());
} else if (rel == rel2) {
assertEquals(node, relationships.get().startNode());
assertEquals(relType2, relationships.get().type());
} else {
throw new IOException();
}
count++;
}
}
}
assertEquals(2, count);
}
use of org.neo4j.storageengine.api.NodeItem in project neo4j by neo4j.
the class StateHandlingStatementOperations method relationshipTypes.
@Override
public PrimitiveIntSet relationshipTypes(KernelStatement statement, NodeItem node) {
if (statement.hasTxStateWithChanges() && statement.txState().nodeIsAddedInThisTx(node.id())) {
return statement.txState().getNodeState(node.id()).relationshipTypes();
}
// Read types in the current transaction
PrimitiveIntSet types = statement.hasTxStateWithChanges() ? statement.txState().getNodeState(node.id()).relationshipTypes() : Primitive.intSet();
// Augment with types stored on disk, minus any types where all rels of that type are deleted
// in current tx.
types.addAll(filter(storeLayer.relationshipTypes(statement.getStoreStatement(), node).iterator(), (current) -> !types.contains(current) && degree(statement, node, Direction.BOTH, current) > 0));
return types;
}
use of org.neo4j.storageengine.api.NodeItem in project neo4j by neo4j.
the class StateHandlingStatementOperations method nodeRemoveProperty.
@Override
public Property nodeRemoveProperty(KernelStatement state, long nodeId, int propertyKeyId) throws EntityNotFoundException, InvalidTransactionTypeKernelException, AutoIndexingKernelException {
DataWriteOperations ops = state.dataWriteOperations();
try (Cursor<NodeItem> cursor = nodeCursorById(state, nodeId)) {
NodeItem node = cursor.get();
DefinedProperty existingProperty = NO_SUCH_PROPERTY;
try (Cursor<PropertyItem> properties = nodeGetPropertyCursor(state, node, propertyKeyId)) {
if (properties.next()) {
existingProperty = Property.property(properties.get().propertyKeyId(), properties.get().value());
autoIndexing.nodes().propertyRemoved(ops, nodeId, propertyKeyId);
state.txState().nodeDoRemoveProperty(node.id(), existingProperty);
indexTxStateUpdater.onPropertyRemove(state, node, existingProperty);
}
}
if (existingProperty == NO_SUCH_PROPERTY) {
return Property.noProperty(propertyKeyId, EntityType.NODE, node.id());
}
return existingProperty;
}
}
use of org.neo4j.storageengine.api.NodeItem in project neo4j by neo4j.
the class StateHandlingStatementOperations method nodeRemoveLabel.
@Override
public boolean nodeRemoveLabel(KernelStatement state, long nodeId, int labelId) throws EntityNotFoundException {
try (Cursor<NodeItem> cursor = nodeCursorById(state, nodeId)) {
NodeItem node = cursor.get();
if (!node.hasLabel(labelId)) {
// Label does not exist in state or in store, no-op
return false;
}
state.txState().nodeDoRemoveLabel(labelId, node.id());
indexTxStateUpdater.onLabelChange(state, labelId, node, REMOVED_LABEL);
return true;
}
}
Aggregations