use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class IntegrityValidator method validateSchemaRule.
void validateSchemaRule(SchemaRule schemaRule) throws TransactionFailureException {
Preconditions.checkState(indexValidator != null, "No index validator installed");
KernelVersion currentVersion = neoStores.getMetaDataStore().kernelVersion();
if (currentVersion.isLessThan(VERSION_IN_WHICH_TOKEN_INDEXES_ARE_INTRODUCED)) {
if (schemaRule instanceof IndexDescriptor) {
IndexDescriptor index = (IndexDescriptor) schemaRule;
if (index.isTokenIndex() || isBtreeRelationshipPropertyIndex(index)) {
throw new TransactionFailureException(Status.General.UpgradeRequired, "Index operation on index '%s' not allowed. " + "Required kernel version for this transaction is %s, but actual version was %s.", index, VERSION_IN_WHICH_TOKEN_INDEXES_ARE_INTRODUCED.name(), currentVersion.name());
}
}
}
if (schemaRule instanceof ConstraintDescriptor) {
ConstraintDescriptor constraint = (ConstraintDescriptor) schemaRule;
if (constraint.isIndexBackedConstraint()) {
long ownedIndex = constraint.asIndexBackedConstraint().ownedIndexId();
try {
indexValidator.validateIndex(ownedIndex);
} catch (KernelException e) {
// and have recovery performed. It's the safest bet to avoid loosing data.
throw new TransactionFailureException(Status.Transaction.TransactionValidationFailed, e, "Index validation of " + schemaRule + " failed, specifically for its owned index " + ownedIndex, e);
}
}
}
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class TxStateTest method shouldAddUniquenessConstraint.
@Test
void shouldAddUniquenessConstraint() {
// when
LabelSchemaDescriptor schema = forLabel(1, 17);
UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForSchema(schema);
state.constraintDoAdd(constraint, IndexPrototype.uniqueForSchema(schema).withName("constraint_7").materialise(7));
// then
DiffSets<ConstraintDescriptor> diff = state.constraintsChangesForLabel(1);
assertEquals(singleton(constraint), diff.getAdded());
assertTrue(diff.getRemoved().isEmpty());
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class TxStateTest method shouldAddRelationshipPropertyExistenceConstraint.
@Test
void shouldAddRelationshipPropertyExistenceConstraint() {
// Given
ConstraintDescriptor constraint = ConstraintDescriptorFactory.existsForRelType(1, 42);
// When
state.constraintDoAdd(constraint);
// Then
assertEquals(singleton(constraint), state.constraintsChangesForRelationshipType(1).getAdded());
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class SchemaStatementProcedureTest method schemaStatementsMustNotIncludeIndexBackedConstraintsWithFailedIndexIndex.
@Test
void schemaStatementsMustNotIncludeIndexBackedConstraintsWithFailedIndexIndex() throws IndexNotFoundKernelException, ProcedureException {
IndexDescriptor index = someOrphanedIndex();
ConstraintDescriptor constraint = indexBackedConstraint(index);
index = indexBoundToConstraint(index, constraint);
InternalIndexState internalIndexState = InternalIndexState.FAILED;
SchemaReadCore schemaReadCore = getSchemaReadCore(constraint, index, internalIndexState);
TokenRead tokenRead = mock(TokenRead.class);
Collection<BuiltInProcedures.SchemaStatementResult> result = createSchemaStatementResults(schemaReadCore, tokenRead);
assertEquals(0, result.size());
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class CompositeIndexingIT method setup.
void setup(PrototypeFactory prototypeFactory) throws Exception {
var prototype = prototypeFactory.build(labelId, relTypeId, propIds);
try (Transaction tx = graphDatabaseAPI.beginTx()) {
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
if (prototype.isUnique()) {
ConstraintDescriptor constraint = ktx.schemaWrite().uniquePropertyConstraintCreate(prototype);
index = ktx.schemaRead().indexGetForName(constraint.getName());
} else {
index = ktx.schemaWrite().indexCreate(prototype.schema(), null);
}
tx.commit();
}
try (Transaction tx = graphDatabaseAPI.beginTx()) {
tx.schema().awaitIndexesOnline(5, MINUTES);
tx.commit();
}
}
Aggregations