Search in sources :

Example 6 with ConstraintRule

use of org.neo4j.kernel.impl.store.record.ConstraintRule in project neo4j by neo4j.

the class NeoStoreTransactionApplierTest method shouldApplyCreateUniquenessConstraintRuleSchemaRuleCommandToTheStore.

@Test
public void shouldApplyCreateUniquenessConstraintRuleSchemaRuleCommandToTheStore() throws Exception {
    // given
    final BatchTransactionApplier applier = newApplier(false);
    final DynamicRecord record = DynamicRecord.dynamicRecord(21, true);
    record.setCreated();
    final Collection<DynamicRecord> recordsAfter = Arrays.asList(record);
    final ConstraintRule rule = uniquenessConstraintRule(0L, 1, 2, 3L);
    final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(Collections.<DynamicRecord>emptyList(), recordsAfter, rule);
    // when
    boolean result = apply(applier, command::handle, transactionToApply);
    // then
    assertFalse(result);
    verify(schemaStore, times(1)).updateRecord(record);
    verify(metaDataStore, times(1)).setLatestConstraintIntroducingTx(transactionId);
    verify(cacheAccess, times(1)).addSchemaRule(rule);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) RelationshipTypeTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand) LabelTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand) PropertyKeyTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) Test(org.junit.Test)

Example 7 with ConstraintRule

use of org.neo4j.kernel.impl.store.record.ConstraintRule in project neo4j by neo4j.

the class NeoStoreTransactionApplierTest method shouldApplyDeleteUniquenessConstraintRuleSchemaRuleCommandToTheStore.

@Test
public void shouldApplyDeleteUniquenessConstraintRuleSchemaRuleCommandToTheStore() throws Exception {
    // given
    final BatchTransactionApplier applier = newApplier(false);
    final DynamicRecord record = DynamicRecord.dynamicRecord(21, true);
    record.setInUse(false);
    final Collection<DynamicRecord> recordsAfter = Arrays.asList(record);
    final ConstraintRule rule = uniquenessConstraintRule(0L, 1, 2, 3L);
    final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(Collections.<DynamicRecord>emptyList(), recordsAfter, rule);
    // when
    boolean result = apply(applier, command::handle, transactionToApply);
    // then
    assertFalse(result);
    verify(schemaStore, times(1)).updateRecord(record);
    verify(metaDataStore, never()).setLatestConstraintIntroducingTx(transactionId);
    verify(cacheAccess, times(1)).removeSchemaRuleFromCache(command.getKey());
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) RelationshipTypeTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand) LabelTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand) PropertyKeyTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) Test(org.junit.Test)

Example 8 with ConstraintRule

use of org.neo4j.kernel.impl.store.record.ConstraintRule in project neo4j by neo4j.

the class NeoStoreTransactionApplierTest method shouldApplyUpdateUniquenessConstraintRuleSchemaRuleCommandToTheStore.

@Test
public void shouldApplyUpdateUniquenessConstraintRuleSchemaRuleCommandToTheStore() throws Exception {
    // given
    final BatchTransactionApplier applier = newApplier(false);
    final DynamicRecord record = DynamicRecord.dynamicRecord(21, true);
    final Collection<DynamicRecord> recordsAfter = Arrays.asList(record);
    final ConstraintRule rule = uniquenessConstraintRule(0L, 1, 2, 3L);
    final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(Collections.<DynamicRecord>emptyList(), recordsAfter, rule);
    // when
    boolean result = apply(applier, command::handle, transactionToApply);
    // then
    assertFalse(result);
    verify(schemaStore, times(1)).updateRecord(record);
    verify(metaDataStore, times(1)).setLatestConstraintIntroducingTx(transactionId);
    verify(cacheAccess, times(1)).addSchemaRule(rule);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) RelationshipTypeTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand) LabelTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand) PropertyKeyTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) Test(org.junit.Test)

Example 9 with ConstraintRule

use of org.neo4j.kernel.impl.store.record.ConstraintRule in project neo4j by neo4j.

the class NeoStoreTransactionApplierTest method shouldApplyDeleteUniquenessConstraintRuleSchemaRuleCommandToTheStoreInRecovery.

@Test
public void shouldApplyDeleteUniquenessConstraintRuleSchemaRuleCommandToTheStoreInRecovery() throws Exception {
    // given
    final BatchTransactionApplier applier = newApplier(true);
    final DynamicRecord record = DynamicRecord.dynamicRecord(21, true);
    record.setInUse(false);
    final Collection<DynamicRecord> recordsAfter = Arrays.asList(record);
    final ConstraintRule rule = uniquenessConstraintRule(0L, 1, 2, 3L);
    final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(Collections.<DynamicRecord>emptyList(), recordsAfter, rule);
    // when
    boolean result = apply(applier, command::handle, transactionToApply);
    // then
    assertFalse(result);
    verify(schemaStore, times(1)).setHighestPossibleIdInUse(record.getId());
    verify(schemaStore, times(1)).updateRecord(record);
    verify(metaDataStore, never()).setLatestConstraintIntroducingTx(transactionId);
    verify(cacheAccess, times(1)).removeSchemaRuleFromCache(command.getKey());
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) RelationshipTypeTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand) LabelTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand) PropertyKeyTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) Test(org.junit.Test)

Example 10 with ConstraintRule

use of org.neo4j.kernel.impl.store.record.ConstraintRule in project neo4j by neo4j.

the class SchemaStorage method constraintsGetSingle.

/**
     * Get the constraint rule that matches the given ConstraintDescriptor
     * @param descriptor the ConstraintDescriptor to match
     * @return the matching ConstrainRule
     * @throws SchemaRuleNotFoundException if no ConstraintRule matches the given descriptor
     * @throws DuplicateSchemaRuleException if two or more ConstraintRules match the given descriptor
     */
public ConstraintRule constraintsGetSingle(final ConstraintDescriptor descriptor) throws SchemaRuleNotFoundException, DuplicateSchemaRuleException {
    Iterator<ConstraintRule> rules = loadAllSchemaRules(descriptor::isSame, ConstraintRule.class, false);
    if (!rules.hasNext()) {
        throw new SchemaRuleNotFoundException(SchemaRule.Kind.map(descriptor), descriptor.schema());
    }
    ConstraintRule rule = rules.next();
    if (rules.hasNext()) {
        throw new DuplicateSchemaRuleException(SchemaRule.Kind.map(descriptor), descriptor.schema());
    }
    return rule;
}
Also used : ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) DuplicateSchemaRuleException(org.neo4j.kernel.api.exceptions.schema.DuplicateSchemaRuleException)

Aggregations

ConstraintRule (org.neo4j.kernel.impl.store.record.ConstraintRule)26 Test (org.junit.Test)20 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)16 SchemaRuleUtil.uniquenessConstraintRule (org.neo4j.consistency.checking.SchemaRuleUtil.uniquenessConstraintRule)8 IndexRule (org.neo4j.kernel.impl.store.record.IndexRule)8 BatchTransactionApplier (org.neo4j.kernel.impl.api.BatchTransactionApplier)6 LabelTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand)6 PropertyKeyTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand)6 RelationshipTypeTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand)6 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)5 LabelTokenRecord (org.neo4j.kernel.impl.store.record.LabelTokenRecord)5 PropertyKeyTokenRecord (org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord)5 SchemaRuleUtil.constraintIndexRule (org.neo4j.consistency.checking.SchemaRuleUtil.constraintIndexRule)3 SchemaRuleUtil.nodePropertyExistenceConstraintRule (org.neo4j.consistency.checking.SchemaRuleUtil.nodePropertyExistenceConstraintRule)3 SchemaRuleUtil.relPropertyExistenceConstraintRule (org.neo4j.consistency.checking.SchemaRuleUtil.relPropertyExistenceConstraintRule)3 ConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor)3 SchemaStore (org.neo4j.kernel.impl.store.SchemaStore)3 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)2 NodePropertyDescriptor (org.neo4j.kernel.api.schema.NodePropertyDescriptor)2 NeoStores (org.neo4j.kernel.impl.store.NeoStores)2