use of org.neo4j.internal.schema.constraints.RelExistenceConstraintDescriptor in project neo4j by neo4j.
the class GraphDbStructureGuide method showUniqueConstraints.
private static void showUniqueConstraints(DbStructureVisitor visitor, KernelTransaction ktx, TokenNameLookup nameLookup) {
Iterator<ConstraintDescriptor> constraints = ktx.schemaRead().constraintsGetAll();
while (constraints.hasNext()) {
ConstraintDescriptor constraint = constraints.next();
String userDescription = constraint.userDescription(nameLookup);
if (constraint.isUniquenessConstraint()) {
visitor.visitUniqueConstraint(constraint.asUniquenessConstraint(), userDescription);
} else if (constraint.isNodePropertyExistenceConstraint()) {
NodeExistenceConstraintDescriptor existenceConstraint = constraint.asNodePropertyExistenceConstraint();
visitor.visitNodePropertyExistenceConstraint(existenceConstraint, userDescription);
} else if (constraint.isRelationshipPropertyExistenceConstraint()) {
RelExistenceConstraintDescriptor existenceConstraint = constraint.asRelationshipPropertyExistenceConstraint();
visitor.visitRelationshipPropertyExistenceConstraint(existenceConstraint, userDescription);
} else if (constraint.isNodeKeyConstraint()) {
NodeKeyConstraintDescriptor nodeKeyConstraint = constraint.asNodeKeyConstraint();
visitor.visitNodeKeyConstraint(nodeKeyConstraint, userDescription);
} else {
throw new IllegalArgumentException("Unknown constraint type: " + constraint.getClass() + ", " + "constraint: " + constraint);
}
}
}
use of org.neo4j.internal.schema.constraints.RelExistenceConstraintDescriptor in project neo4j by neo4j.
the class PlainOperationsTest method shouldNotAcquireSchemaReadLockLazilyBeforeGettingAllConstraintsFromSnapshot.
@Test
void shouldNotAcquireSchemaReadLockLazilyBeforeGettingAllConstraintsFromSnapshot() {
// given
int labelId = 1;
int relTypeId = 2;
UniquenessConstraintDescriptor uniquenessConstraint = uniqueForLabel(labelId, 2, 3, 3);
RelExistenceConstraintDescriptor existenceConstraint = existsForRelType(relTypeId, 3, 4, 5);
when(storageReaderSnapshot.constraintsGetAll()).thenReturn(Iterators.iterator(uniquenessConstraint, existenceConstraint));
// when
Iterator<ConstraintDescriptor> result = allStoreHolder.snapshot().constraintsGetAll();
// then
assertThat(Iterators.count(result)).isEqualTo(2L);
assertThat(asList(result)).isEmpty();
verify(storageReaderSnapshot).constraintsGetAll();
verifyNoMoreInteractions(locks);
}
use of org.neo4j.internal.schema.constraints.RelExistenceConstraintDescriptor in project neo4j by neo4j.
the class PlainOperationsTest method shouldAcquireSchemaReadLockLazilyBeforeGettingAllConstraints.
@Test
void shouldAcquireSchemaReadLockLazilyBeforeGettingAllConstraints() {
// given
int labelId = 1;
int relTypeId = 2;
UniquenessConstraintDescriptor uniquenessConstraint = uniqueForLabel(labelId, 2, 3, 3);
RelExistenceConstraintDescriptor existenceConstraint = existsForRelType(relTypeId, 3, 4, 5);
when(storageReader.constraintsGetAll()).thenReturn(Iterators.iterator(uniquenessConstraint, existenceConstraint));
when(storageReader.constraintExists(uniquenessConstraint)).thenReturn(true);
when(storageReader.constraintExists(existenceConstraint)).thenReturn(true);
// when
Iterator<ConstraintDescriptor> result = allStoreHolder.constraintsGetAll();
// then
assertThat(Iterators.count(result)).isEqualTo(2L);
assertThat(asList(result)).isEmpty();
order.verify(storageReader).constraintsGetAll();
order.verify(locks, atLeastOnce()).acquireShared(LockTracer.NONE, ResourceTypes.LABEL, labelId);
order.verify(locks, atLeastOnce()).acquireShared(LockTracer.NONE, ResourceTypes.RELATIONSHIP_TYPE, relTypeId);
}
use of org.neo4j.internal.schema.constraints.RelExistenceConstraintDescriptor in project neo4j by neo4j.
the class PlainOperationsTest method shouldReleaseAcquiredSchemaWriteLockIfRelationshipPropertyExistenceConstraintCreationFails.
@Test
void shouldReleaseAcquiredSchemaWriteLockIfRelationshipPropertyExistenceConstraintCreationFails() throws Exception {
// given
RelationTypeSchemaDescriptor descriptor = SchemaDescriptor.forRelType(11, 13);
RelExistenceConstraintDescriptor constraint = existsForSchema(descriptor);
storageReaderWithConstraints(constraint);
int relTypeId = descriptor.getRelTypeId();
int propertyId = descriptor.getPropertyId();
when(tokenHolders.relationshipTypeTokens().getTokenById(relTypeId)).thenReturn(new NamedToken("Label", relTypeId));
when(tokenHolders.propertyKeyTokens().getTokenById(propertyId)).thenReturn(new NamedToken("prop", relTypeId));
// when
try {
operations.relationshipPropertyExistenceConstraintCreate(descriptor, "constraint name");
fail("Expected an exception because this schema should already be constrained.");
} catch (AlreadyConstrainedException ignore) {
// Good.
}
// then
order.verify(locks).acquireExclusive(LockTracer.NONE, ResourceTypes.RELATIONSHIP_TYPE, relTypeId);
order.verify(storageReader).constraintsGetForSchema(descriptor);
order.verify(locks).releaseExclusive(ResourceTypes.RELATIONSHIP_TYPE, relTypeId);
}
use of org.neo4j.internal.schema.constraints.RelExistenceConstraintDescriptor in project neo4j by neo4j.
the class RecordStorageReaderTestBase method createRelPropertyExistenceConstraint.
protected void createRelPropertyExistenceConstraint(RelationshipType relationshipType, String propertyKey) throws Exception {
TxState txState = new TxState();
RelExistenceConstraintDescriptor constraint = ConstraintDescriptorFactory.existsForRelType(getOrCreateRelationshipTypeId(relationshipType), getOrCreatePropertyKeyId(propertyKey));
long id = commitContext.reserveSchema();
txState.constraintDoAdd(constraint.withId(id).withName("constraint_" + id));
apply(txState);
}
Aggregations