use of org.neo4j.storageengine.api.RelationshipItem in project neo4j by neo4j.
the class StateOperationsAutoIndexingTest method shouldSignalRelationshipPropertyRemovedToAutoIndex.
@Test
public void shouldSignalRelationshipPropertyRemovedToAutoIndex() throws Exception {
// Given
PropertyItem existingProperty = mock(PropertyItem.class);
int propertyKeyId = 1;
when(existingProperty.propertyKeyId()).thenReturn(propertyKeyId);
when(existingProperty.value()).thenReturn("Goodbye!");
RelationshipItem relationship = mock(RelationshipItem.class);
when(storeStmt.acquireSingleRelationshipCursor(1337)).thenReturn(cursor(relationship));
when(storeLayer.relationshipGetProperty(storeStmt, relationship, propertyKeyId)).thenReturn(cursor(existingProperty));
// When
context.relationshipRemoveProperty(stmt, 1337, existingProperty.propertyKeyId());
// Then
verify(relOps).propertyRemoved(writeOps, 1337L, existingProperty.propertyKeyId());
}
use of org.neo4j.storageengine.api.RelationshipItem in project neo4j by neo4j.
the class TxStateTest method shouldObserveCorrectAugmentedNodeRelationshipsState.
@Test
public void shouldObserveCorrectAugmentedNodeRelationshipsState() throws Exception {
// GIVEN random committed state
TxState state = new TxState();
for (int i = 0; i < 100; i++) {
state.nodeDoCreate(i);
}
for (int i = 0; i < 5; i++) {
state.relationshipTypeDoCreateForName("Type-" + i, i);
}
Map<Long, RelationshipItem> committedRelationships = new HashMap<>();
long relationshipId = 0;
int nodeCount = 100;
int relationshipTypeCount = 5;
for (int i = 0; i < 30; i++) {
RelationshipItem relationship = relationship(relationshipId++, random.nextInt(relationshipTypeCount), random.nextInt(nodeCount), random.nextInt(nodeCount));
committedRelationships.put(relationship.id(), relationship);
}
Map<Long, RelationshipItem> allRelationships = new HashMap<>(committedRelationships);
// and some random changes to that
for (int i = 0; i < 10; i++) {
if (random.nextBoolean()) {
RelationshipItem relationship = relationship(relationshipId++, random.nextInt(relationshipTypeCount), random.nextInt(nodeCount), random.nextInt(nodeCount));
allRelationships.put(relationship.id(), relationship);
state.relationshipDoCreate(relationship.id(), relationship.type(), relationship.startNode(), relationship.endNode());
} else {
RelationshipItem relationship = Iterables.fromEnd(committedRelationships.values(), random.nextInt(committedRelationships.size()));
state.relationshipDoDelete(relationship.id(), relationship.type(), relationship.startNode(), relationship.endNode());
allRelationships.remove(relationship.id());
}
}
// WHEN
for (int i = 0; i < nodeCount; i++) {
Direction direction = Direction.values()[random.nextInt(Direction.values().length)];
int[] relationshipTypes = randomTypes(relationshipTypeCount, random.random());
Cursor<RelationshipItem> committed = cursor(relationshipsForNode(i, committedRelationships, direction, relationshipTypes).values());
Cursor<RelationshipItem> augmented = relationshipTypes == null ? state.augmentNodeRelationshipCursor(committed, state.getNodeState(i), direction) : state.augmentNodeRelationshipCursor(committed, state.getNodeState(i), direction, relationshipTypes);
Map<Long, RelationshipItem> expectedRelationships = relationshipsForNode(i, allRelationships, direction, relationshipTypes);
// THEN
while (augmented.next()) {
RelationshipItem relationship = augmented.get();
RelationshipItem actual = expectedRelationships.remove(relationship.id());
assertNotNull("Augmented cursor returned relationship " + relationship + ", but shouldn't have", actual);
assertRelationshipEquals(actual, relationship);
}
assertTrue("Augmented cursor didn't return some expected relationships: " + expectedRelationships, expectedRelationships.isEmpty());
}
}
use of org.neo4j.storageengine.api.RelationshipItem in project neo4j by neo4j.
the class StateHandlingStatementOperations method nodeGetRelationships.
@Override
public Cursor<RelationshipItem> nodeGetRelationships(KernelStatement statement, NodeItem node, Direction direction, int[] relTypes) {
Cursor<RelationshipItem> cursor;
if (statement.hasTxStateWithChanges() && statement.txState().nodeIsAddedInThisTx(node.id())) {
cursor = empty();
} else {
cursor = storeLayer.nodeGetRelationships(statement.getStoreStatement(), node, direction, any(relTypes));
}
if (!statement.hasTxStateWithChanges()) {
return cursor;
}
NodeState nodeState = statement.txState().getNodeState(node.id());
return statement.txState().augmentNodeRelationshipCursor(cursor, nodeState, direction, relTypes);
}
use of org.neo4j.storageengine.api.RelationshipItem in project neo4j by neo4j.
the class StorageLayer method visitNode.
private void visitNode(StorageStatement statement, NodeItem nodeItem, DegreeVisitor visitor) {
try (Cursor<RelationshipItem> relationships = nodeGetRelationships(statement, nodeItem, Direction.BOTH)) {
while (relationships.next()) {
RelationshipItem rel = relationships.get();
int type = rel.type();
switch(directionOf(nodeItem.id(), rel.id(), rel.startNode(), rel.endNode())) {
case OUTGOING:
visitor.visitDegree(type, 1, 0);
break;
case INCOMING:
visitor.visitDegree(type, 0, 1);
break;
case BOTH:
visitor.visitDegree(type, 1, 1);
break;
default:
throw new IllegalStateException("You found the missing direction!");
}
}
}
}
use of org.neo4j.storageengine.api.RelationshipItem in project neo4j by neo4j.
the class RelationshipProxy method getAllProperties.
@Override
public Map<String, Object> getAllProperties() {
try (Statement statement = actions.statement()) {
try (Cursor<RelationshipItem> relationship = statement.readOperations().relationshipCursorById(getId())) {
try (Cursor<PropertyItem> propertyCursor = statement.readOperations().relationshipGetProperties(relationship.get())) {
Map<String, Object> properties = new HashMap<>();
// Get all properties
while (propertyCursor.next()) {
String name = statement.readOperations().propertyKeyGetName(propertyCursor.get().propertyKeyId());
properties.put(name, propertyCursor.get().value());
}
return properties;
}
} catch (EntityNotFoundException e) {
throw new NotFoundException("Relationship not found", e);
}
} catch (PropertyKeyIdNotFoundKernelException e) {
throw new IllegalStateException("Property key retrieved through kernel API should exist.", e);
}
}
Aggregations