use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class RecordStorageReaderSchemaTest method shouldListAllConstraintsForLabelAtTimeOfSnapshot.
@Test
void shouldListAllConstraintsForLabelAtTimeOfSnapshot() throws Exception {
// Given
createUniquenessConstraint(label1, propertyKey);
createUniquenessConstraint(label2, propertyKey);
// When
StorageSchemaReader snapshot = storageReader.schemaSnapshot();
createUniquenessConstraint(label1, otherPropertyKey);
Set<ConstraintDescriptor> constraints = asSet(snapshot.constraintsGetForLabel(labelId(label1)));
// Then
Set<ConstraintDescriptor> expectedConstraints = asSet(uniqueConstraintDescriptor(label1, propertyKey));
assertEquals(expectedConstraints, constraints);
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class TxState method accept.
@Override
public void accept(final TxStateVisitor visitor) throws KernelException {
if (nodes != null) {
nodes.getAdded().each(visitor::visitCreatedNode);
}
if (relationships != null) {
try (HeapTrackingArrayList<NodeRelationshipIds> sortedNodeRelState = HeapTrackingArrayList.newArrayList(nodeStatesMap.size(), memoryTracker)) {
nodeStatesMap.forEachValue(nodeState -> {
if (nodeState.isDeleted() && nodeState.isAddedInThisTx()) {
return;
}
if (nodeState.hasAddedRelationships() || nodeState.hasRemovedRelationships()) {
sortedNodeRelState.add(StateNodeRelationshipIds.createStateNodeRelationshipIds(nodeState, this::relationshipVisit, memoryTracker));
}
});
sortedNodeRelState.sort(Comparator.comparingLong(NodeRelationshipIds::nodeId));
// Visit relationships, this will grab all the locks needed to do the updates
visitor.visitRelationshipModifications(new RelationshipModifications() {
@Override
public void forEachSplit(IdsVisitor visitor) {
sortedNodeRelState.forEach(visitor);
}
@Override
public RelationshipBatch creations() {
return idsAsBatch(relationships.getAdded(), TxState.this::relationshipVisit);
}
@Override
public RelationshipBatch deletions() {
return idsAsBatch(relationships.getRemoved());
}
});
}
}
if (nodes != null) {
nodes.getRemoved().each(visitor::visitDeletedNode);
}
for (NodeState node : modifiedNodes()) {
if (node.hasPropertyChanges()) {
visitor.visitNodePropertyChanges(node.getId(), node.addedProperties(), node.changedProperties(), node.removedProperties());
}
final LongDiffSets labelDiffSets = node.labelDiffSets();
if (!labelDiffSets.isEmpty()) {
visitor.visitNodeLabelChanges(node.getId(), labelDiffSets.getAdded(), labelDiffSets.getRemoved());
}
}
for (RelationshipState rel : modifiedRelationships()) {
visitor.visitRelPropertyChanges(rel.getId(), rel.addedProperties(), rel.changedProperties(), rel.removedProperties());
}
if (indexChanges != null) {
for (IndexDescriptor indexDescriptor : indexChanges.getAdded()) {
visitor.visitAddedIndex(indexDescriptor);
}
indexChanges.getRemoved().forEach(visitor::visitRemovedIndex);
}
if (constraintsChanges != null) {
for (ConstraintDescriptor added : constraintsChanges.getAdded()) {
visitor.visitAddedConstraint(added);
}
constraintsChanges.getRemoved().forEach(visitor::visitRemovedConstraint);
}
if (createdLabelTokens != null) {
createdLabelTokens.forEachKeyValue((id, token) -> visitor.visitCreatedLabelToken(id, token.name, token.internal));
}
if (createdPropertyKeyTokens != null) {
createdPropertyKeyTokens.forEachKeyValue((id, token) -> visitor.visitCreatedPropertyKeyToken(id, token.name, token.internal));
}
if (createdRelationshipTypeTokens != null) {
createdRelationshipTypeTokens.forEachKeyValue((id, token) -> visitor.visitCreatedRelationshipTypeToken(id, token.name, token.internal));
}
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class IntegrityValidatorTest method shouldValidateUniquenessIndexes.
@Test
void shouldValidateUniquenessIndexes() throws Exception {
// Given
NeoStores store = mock(NeoStores.class);
IndexUpdateListener indexes = mock(IndexUpdateListener.class);
IntegrityValidator validator = new IntegrityValidator(store);
validator.setIndexValidator(indexes);
UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForLabel(1, 1);
doThrow(new ConstraintViolationException("error", new RuntimeException())).when(indexes).validateIndex(2L);
ConstraintDescriptor record = constraint.withId(1).withOwnedIndexId(2);
// When
assertThrows(Exception.class, () -> validator.validateSchemaRule(record));
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class ConstraintTestBase method shouldFindConstraintsByLabel.
@Test
void shouldFindConstraintsByLabel() throws Exception {
// GIVEN
addConstraints("FOO", "prop1", "FOO", "prop2");
try (KernelTransaction tx = beginTransaction()) {
int label = tx.tokenWrite().labelGetOrCreateForName("FOO");
// WHEN
List<ConstraintDescriptor> constraints = asList(tx.schemaRead().constraintsGetForLabel(label));
// THEN
assertThat(constraints).hasSize(2);
}
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class ConstraintTestBase method shouldFindAllConstraints.
@Test
void shouldFindAllConstraints() throws Exception {
// GIVEN
addConstraints("FOO", "prop1", "BAR", "prop2", "BAZ", "prop3");
try (KernelTransaction tx = beginTransaction()) {
// WHEN
List<ConstraintDescriptor> constraints = asList(tx.schemaRead().constraintsGetAll());
// THEN
assertThat(constraints).hasSize(3);
}
}
Aggregations