use of org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor in project neo4j by neo4j.
the class TxStateTest method dataRevisionMustNotChangeOnSchemaChanges.
@Test
void dataRevisionMustNotChangeOnSchemaChanges() {
assertThat(state.getDataRevision()).isEqualTo(0L);
assertFalse(state.hasDataChanges());
state.indexDoAdd(indexOn_1_1);
assertThat(state.getDataRevision()).isEqualTo(0L);
assertFalse(state.hasDataChanges());
state.indexDoDrop(indexOn_1_1);
assertThat(state.getDataRevision()).isEqualTo(0L);
assertFalse(state.hasDataChanges());
state.indexDoUnRemove(indexOn_1_1);
assertThat(state.getDataRevision()).isEqualTo(0L);
assertFalse(state.hasDataChanges());
UniquenessConstraintDescriptor constraint1 = ConstraintDescriptorFactory.uniqueForLabel(1, 17);
state.constraintDoAdd(constraint1);
assertThat(state.getDataRevision()).isEqualTo(0L);
assertFalse(state.hasDataChanges());
state.constraintDoDrop(constraint1);
assertThat(state.getDataRevision()).isEqualTo(0L);
assertFalse(state.hasDataChanges());
state.constraintDoUnRemove(constraint1);
assertThat(state.getDataRevision()).isEqualTo(0L);
assertFalse(state.hasDataChanges());
IndexBackedConstraintDescriptor constraint2 = ConstraintDescriptorFactory.nodeKeyForLabel(0, 0);
state.constraintDoAdd(constraint2, IndexPrototype.uniqueForSchema(forLabel(0, 0)).withName("index").materialise(0));
assertThat(state.getDataRevision()).isEqualTo(0L);
assertFalse(state.hasDataChanges());
state.labelDoCreateForName("Label", false, 0);
assertThat(state.getDataRevision()).isEqualTo(0L);
assertFalse(state.hasDataChanges());
state.relationshipTypeDoCreateForName("REL", false, 0);
assertThat(state.getDataRevision()).isEqualTo(0L);
assertFalse(state.hasDataChanges());
state.propertyKeyDoCreateForName("prop", false, 0);
assertThat(state.getDataRevision()).isEqualTo(0L);
assertFalse(state.hasDataChanges());
// This is not strictly a schema-change, but it is a "non-data" change in that these will not transform into store updates.
// Or schema updates for that matter. We only do these to speed up the transaction state filtering of schema index query results.
state.indexDoUpdateEntry(indexOn_1_1.schema(), 0, ValueTuple.of(Values.booleanValue(true)), ValueTuple.of(Values.booleanValue(false)));
assertThat(state.getDataRevision()).isEqualTo(0L);
assertFalse(state.hasDataChanges());
}
use of org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor in project neo4j by neo4j.
the class IndexIT method shouldListAll.
@Test
void shouldListAll() throws Exception {
// given
SchemaWrite schemaWrite = schemaWriteInNewTransaction();
IndexDescriptor index1 = schemaWrite.indexCreate(schema, "my index");
IndexBackedConstraintDescriptor constraint = schemaWrite.uniquePropertyConstraintCreate(uniqueForSchema(schema2).withName("constraint name")).asIndexBackedConstraint();
commit();
// then/when
SchemaRead schemaRead = newTransaction().schemaRead();
IndexDescriptor index2 = Iterators.single(schemaRead.index(constraint.schema()));
List<IndexDescriptor> indexes = Iterators.asList(schemaRead.indexesGetAll());
assertThat(indexes).contains(index1, index2);
commit();
}
use of org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor in project neo4j by neo4j.
the class Operations method checkConstraintsAndAddLabelToNode.
private void checkConstraintsAndAddLabelToNode(long node, int nodeLabel) throws UniquePropertyValueValidationException, UnableToValidateConstraintException {
// Load the property key id list for this node. We may need it for constraint validation if there are any related constraints,
// but regardless we need it for tx state updating
int[] existingPropertyKeyIds = loadSortedNodePropertyKeyList();
// with the same label and property combination.
if (existingPropertyKeyIds.length > 0) {
for (IndexBackedConstraintDescriptor uniquenessConstraint : storageReader.uniquenessConstraintsGetRelated(new long[] { nodeLabel }, existingPropertyKeyIds, NODE)) {
PropertyIndexQuery.ExactPredicate[] propertyValues = getAllPropertyValues(uniquenessConstraint.schema(), StatementConstants.NO_SUCH_PROPERTY_KEY, Values.NO_VALUE);
if (propertyValues != null) {
validateNoExistingNodeWithExactValues(uniquenessConstraint, propertyValues, node);
}
}
}
// node is there and doesn't already have the label, let's add
ktx.txState().nodeDoAddLabel(nodeLabel, node);
updater.onLabelChange(nodeLabel, existingPropertyKeyIds, nodeCursor, propertyCursor, ADDED_LABEL);
}
use of org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor in project neo4j by neo4j.
the class PlainOperationsTest method uniqueIndexesMustBeNamedAfterTheirConstraints.
@Test
void uniqueIndexesMustBeNamedAfterTheirConstraints() throws KernelException {
when(creationContext.reserveSchema()).thenReturn(1L, 2L, 3L);
when(storageReader.constraintsGetForSchema(any())).thenReturn(Iterators.emptyResourceIterator());
when(storageReader.indexGetForSchema(any())).thenReturn(Iterators.emptyResourceIterator());
String constraintName = "my_constraint";
when(constraintIndexCreator.createUniquenessConstraintIndex(any(), any(), any())).thenAnswer(i -> {
IndexPrototype prototype = i.getArgument(2);
Optional<String> name = prototype.getName();
assertTrue(name.isPresent());
assertThat(name.get()).isEqualTo(constraintName);
return prototype.materialise(2);
});
IndexPrototype prototype = IndexPrototype.uniqueForSchema(schema).withName(constraintName);
IndexBackedConstraintDescriptor constraint = operations.uniquePropertyConstraintCreate(prototype).asIndexBackedConstraint();
assertThat(constraint.ownedIndexId()).isEqualTo(2L);
}
use of org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor in project neo4j by neo4j.
the class SchemaStatementProcedure method includeConstraint.
private static boolean includeConstraint(SchemaReadCore schemaRead, ConstraintDescriptor constraint) {
// - Owned index must have this constraint as owning constraint
if (constraint.isIndexBackedConstraint()) {
IndexBackedConstraintDescriptor indexBackedConstraint = constraint.asIndexBackedConstraint();
if (indexBackedConstraint.hasOwnedIndexId()) {
IndexDescriptor backingIndex = schemaRead.indexGetForName(constraint.getName());
if (backingIndex.getId() == indexBackedConstraint.ownedIndexId()) {
try {
InternalIndexState internalIndexState = schemaRead.indexGetState(backingIndex);
OptionalLong owningConstraintId = backingIndex.getOwningConstraintId();
return internalIndexState == InternalIndexState.ONLINE && owningConstraintId.orElse(-1) == constraint.getId();
} catch (IndexNotFoundKernelException e) {
return false;
}
}
}
return false;
}
return true;
}
Aggregations