//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldListAllConstraints() public virtual void ShouldListAllConstraints() { // Given SchemaHelper.createUniquenessConstraint(Db, Label1, PropertyKey); SchemaHelper.createUniquenessConstraint(Db, Label2, PropertyKey); SchemaHelper.createNodeKeyConstraint(Db, Label1, OtherPropertyKey); SchemaHelper.createNodeKeyConstraint(Db, Label2, OtherPropertyKey); SchemaHelper.createNodePropertyExistenceConstraint(Db, Label2, PropertyKey); SchemaHelper.createRelPropertyExistenceConstraint(Db, RelType1, PropertyKey); SchemaHelper.awaitIndexes(Db); // When ISet <ConstraintDescriptor> constraints = asSet(StorageReader.constraintsGetAll()); // Then int labelId1 = LabelId(Label1); int labelId2 = LabelId(Label2); int relTypeId = RelationshipTypeId(RelType1); int propKeyId = PropertyKeyId(PropertyKey); int propKeyId2 = PropertyKeyId(OtherPropertyKey); assertThat(constraints, containsInAnyOrder(ConstraintDescriptorFactory.uniqueForLabel(labelId1, propKeyId), ConstraintDescriptorFactory.uniqueForLabel(labelId2, propKeyId), ConstraintDescriptorFactory.nodeKeyForLabel(labelId1, propKeyId2), ConstraintDescriptorFactory.nodeKeyForLabel(labelId2, propKeyId2), ConstraintDescriptorFactory.existsForLabel(labelId2, propKeyId), ConstraintDescriptorFactory.existsForRelType(relTypeId, propKeyId))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void should_list_constraints() public virtual void ShouldListConstraints() { // GIVEN SchemaCache cache = NewSchemaCache(); // WHEN cache.AddSchemaRule(UniquenessConstraintRule(0L, 1, 2, 133L)); cache.AddSchemaRule(UniquenessConstraintRule(1L, 3, 4, 133L)); cache.AddSchemaRule(RelPropertyExistenceConstraintRule(2L, 5, 6)); cache.AddSchemaRule(NodePropertyExistenceConstraintRule(3L, 7, 8)); // THEN ConstraintDescriptor unique1 = uniqueForLabel(1, 2); ConstraintDescriptor unique2 = uniqueForLabel(3, 4); ConstraintDescriptor existsRel = ConstraintDescriptorFactory.existsForRelType(5, 6); ConstraintDescriptor existsNode = ConstraintDescriptorFactory.existsForLabel(7, 8); assertEquals(asSet(unique1, unique2, existsRel, existsNode), asSet(cache.Constraints())); assertEquals(asSet(unique1), asSet(cache.ConstraintsForLabel(1))); assertEquals(asSet(unique1), asSet(cache.ConstraintsForSchema(unique1.Schema()))); assertEquals(asSet(), asSet(cache.ConstraintsForSchema(forLabel(1, 3)))); assertEquals(asSet(existsRel), asSet(cache.ConstraintsForRelationshipType(5))); }
private ConstraintDescriptor UniqueConstraintDescriptor(Label label, string propertyKey) { int labelId = labelId(label); int propKeyId = PropertyKeyId(propertyKey); return(ConstraintDescriptorFactory.uniqueForLabel(labelId, propKeyId)); }
private ConstraintDescriptor NodePropertyExistenceDescriptor(Label label, string propertyKey) { int labelId = labelId(label); int propKeyId = PropertyKeyId(propertyKey); return(ConstraintDescriptorFactory.existsForLabel(labelId, propKeyId)); }
private void GivenNodePropExistenceConstraint(string label, string propKey) { int labelId = Token(label, _labels).Value; int propId = Token(propKey, _propKeys).Value; _constraints.Add(ConstraintDescriptorFactory.existsForLabel(labelId, propId)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private org.neo4j.internal.kernel.api.IndexReference getOrCreateUniquenessConstraintIndex(org.neo4j.internal.kernel.api.SchemaRead schemaRead, org.neo4j.internal.kernel.api.TokenRead tokenRead, org.neo4j.internal.kernel.api.schema.SchemaDescriptor schema, String provider) throws org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException, org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException private IndexReference GetOrCreateUniquenessConstraintIndex(SchemaRead schemaRead, TokenRead tokenRead, SchemaDescriptor schema, string provider) { IndexReference descriptor = schemaRead.Index(schema); if (descriptor != IndexReference.NO_INDEX) { if (descriptor.Unique) { // OK so we found a matching constraint index. We check whether or not it has an owner // because this may have been a left-over constraint index from a previously failed // constraint creation, due to crash or similar, hence the missing owner. if (schemaRead.IndexGetOwningUniquenessConstraintId(descriptor) == null) { return(descriptor); } throw new AlreadyConstrainedException(ConstraintDescriptorFactory.uniqueForSchema(schema), SchemaKernelException.OperationContext.CONSTRAINT_CREATION, new SilentTokenNameLookup(tokenRead)); } // There's already an index for this schema descriptor, which isn't of the type we're after. throw new AlreadyIndexedException(schema, CONSTRAINT_CREATION); } IndexDescriptor indexDescriptor = CreateConstraintIndex(schema, provider); IndexProxy indexProxy = _indexingService.getIndexProxy(indexDescriptor.Schema()); return(indexProxy.Descriptor); }
private ConstraintDescriptor RelationshipPropertyExistenceDescriptor(RelationshipType relType, string propertyKey) { int relTypeId = RelationshipTypeId(relType); int propKeyId = PropertyKeyId(propertyKey); return(ConstraintDescriptorFactory.existsForRelType(relTypeId, propKeyId)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void validate() throws org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException public override void Validate() { if (_failures.Count > 0) { SchemaDescriptor descriptor = Descriptor.schema(); throw new UniquePropertyValueValidationException(ConstraintDescriptorFactory.uniqueForSchema(descriptor), ConstraintValidationException.Phase.VERIFICATION, new HashSet <>(_failures) ); } }
private void GivenUniqueConstraint(string label, string propKey) { int labelId = Token(label, _labels).Value; int propId = Token(propKey, _propKeys).Value; IndexReference index = IndexDescriptorFactory.uniqueForSchema(forLabel(labelId, propId), EMPTY.ProviderDescriptor); _uniqueIndexes.Add(index); _constraints.Add(ConstraintDescriptorFactory.uniqueForLabel(labelId, propId)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldThrowExceptionOnRelationshipRuleNotFound() throws org.neo4j.kernel.api.exceptions.schema.DuplicateSchemaRuleException, org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldThrowExceptionOnRelationshipRuleNotFound() { TokenNameLookup tokenNameLookup = DefaultTokenNameLookup; // EXPECT ExpectedException.expect(typeof(SchemaRuleNotFoundException)); ExpectedException.expect(new KernelExceptionUserMessageMatcher <>(tokenNameLookup, "No relationship property existence constraint was found for -[:Type1(prop1)]-.")); //WHEN _storage.constraintsGetSingle(ConstraintDescriptorFactory.existsForRelType(TypeId(TYPE1), PropId(PROP1))); }
private void GivenNodeKeys(string label, params string[] props) { int labelId = Token(label, _labels).Value; int[] propIds = new int[props.Length]; for (int i = 0; i < propIds.Length; i++) { propIds[i] = Token(props[i], _propKeys).Value; } _constraints.Add(ConstraintDescriptorFactory.nodeKeyForLabel(labelId, propIds)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldThrowExceptionOnNodeRuleNotFound() throws org.neo4j.kernel.api.exceptions.schema.DuplicateSchemaRuleException, org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldThrowExceptionOnNodeRuleNotFound() { // GIVEN TokenNameLookup tokenNameLookup = DefaultTokenNameLookup; // EXPECT ExpectedException.expect(typeof(SchemaRuleNotFoundException)); ExpectedException.expect(new KernelExceptionUserMessageMatcher(tokenNameLookup, "No node property existence constraint was found for :Label1(prop1).")); // WHEN _storage.constraintsGetSingle(ConstraintDescriptorFactory.existsForLabel(LabelId(LABEL1), PropId(PROP1))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReturnCorrectUniquenessRuleForLabelAndProperty() throws org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException, org.neo4j.kernel.api.exceptions.schema.DuplicateSchemaRuleException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldReturnCorrectUniquenessRuleForLabelAndProperty() { // Given CreateSchema(UniquenessConstraint(LABEL1, PROP1), UniquenessConstraint(LABEL2, PROP1)); // When ConstraintRule rule = _storage.constraintsGetSingle(ConstraintDescriptorFactory.uniqueForLabel(LabelId(LABEL1), PropId(PROP1))); // Then assertNotNull(rule); AssertRule(rule, LABEL1, PROP1, Org.Neo4j.@internal.Kernel.Api.schema.constraints.ConstraintDescriptor_Type.Unique); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void constraintPropertyIdsNotUpdatedByConstraintEnforcer() public virtual void ConstraintPropertyIdsNotUpdatedByConstraintEnforcer() { UniquenessConstraintDescriptor uniquenessConstraint = ConstraintDescriptorFactory.uniqueForLabel(1, 1, 70, 8); NodeKeyConstraintDescriptor nodeKeyConstraint = ConstraintDescriptorFactory.nodeKeyForLabel(2, 12, 7, 13); RelExistenceConstraintDescriptor relTypeConstraint = ConstraintDescriptorFactory.existsForRelType(3, 5, 13, 8); IList <ConstraintDescriptor> descriptors = Arrays.asList(uniquenessConstraint, nodeKeyConstraint, relTypeConstraint); StorageReader storageReader = PrepareStorageReaderMock(descriptors); PropertyExistenceEnforcer.GetOrCreatePropertyExistenceEnforcerFrom(storageReader); assertArrayEquals("Property ids should remain untouched.", new int[] { 1, 70, 8 }, uniquenessConstraint.Schema().PropertyIds); assertArrayEquals("Property ids should remain untouched.", new int[] { 12, 7, 13 }, nodeKeyConstraint.Schema().PropertyIds); assertArrayEquals("Property ids should remain untouched.", new int[] { 5, 13, 8 }, relTypeConstraint.Schema().PropertyIds); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldThrowExceptionOnRelationshipDuplicateRuleFound() throws org.neo4j.kernel.api.exceptions.schema.DuplicateSchemaRuleException, org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldThrowExceptionOnRelationshipDuplicateRuleFound() { // GIVEN TokenNameLookup tokenNameLookup = DefaultTokenNameLookup; SchemaStorage schemaStorageSpy = Mockito.spy(_storage); Mockito.when(schemaStorageSpy.LoadAllSchemaRules(any(), any(), anyBoolean())).thenReturn(Iterators.iterator(GetRelationshipPropertyExistenceConstraintRule(1L, TYPE1, PROP1), GetRelationshipPropertyExistenceConstraintRule(2L, TYPE1, PROP1))); //EXPECT ExpectedException.expect(typeof(DuplicateSchemaRuleException)); ExpectedException.expect(new KernelExceptionUserMessageMatcher(tokenNameLookup, "Multiple relationship property existence constraints found for -[:Type1(prop1)]-.")); // WHEN schemaStorageSpy.ConstraintsGetSingle(ConstraintDescriptorFactory.existsForRelType(TypeId(TYPE1), PropId(PROP1))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void committedConstraintRuleShouldCrossReferenceTheCorrespondingIndexRule() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void CommittedConstraintRuleShouldCrossReferenceTheCorrespondingIndexRule() { // when SchemaWrite statement = schemaWriteInNewTransaction(); statement.UniquePropertyConstraintCreate(Descriptor); commit(); // then SchemaStorage schema = new SchemaStorage(NeoStores().SchemaStore); StoreIndexDescriptor indexRule = Schema.indexGetForSchema(TestIndexDescriptorFactory.uniqueForLabel(TypeId, PropertyKeyId)); ConstraintRule constraintRule = Schema.constraintsGetSingle(ConstraintDescriptorFactory.uniqueForLabel(TypeId, PropertyKeyId)); assertEquals(constraintRule.Id, indexRule.OwningConstraint.Value); assertEquals(indexRule.Id, constraintRule.OwnedIndex); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldThrowExceptionOnNodeDuplicateRuleFound() throws org.neo4j.kernel.api.exceptions.schema.DuplicateSchemaRuleException, org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldThrowExceptionOnNodeDuplicateRuleFound() { // GIVEN TokenNameLookup tokenNameLookup = DefaultTokenNameLookup; SchemaStorage schemaStorageSpy = Mockito.spy(_storage); Mockito.when(schemaStorageSpy.LoadAllSchemaRules(any(), any(), anyBoolean())).thenReturn(Iterators.iterator(GetUniquePropertyConstraintRule(1L, LABEL1, PROP1), GetUniquePropertyConstraintRule(2L, LABEL1, PROP1))); //EXPECT ExpectedException.expect(typeof(DuplicateSchemaRuleException)); ExpectedException.expect(new KernelExceptionUserMessageMatcher(tokenNameLookup, "Multiple uniqueness constraints found for :Label1(prop1).")); // WHEN schemaStorageSpy.ConstraintsGetSingle(ConstraintDescriptorFactory.uniqueForLabel(LabelId(LABEL1), PropId(PROP1))); }
private void ExerciseVisitor(System.Func <object, DbStructureVisitor> visitor) { visitor(null).visitLabel(0, "Person"); visitor(null).visitLabel(1, "Party"); visitor(null).visitPropertyKey(0, "name"); visitor(null).visitPropertyKey(2, "lastName"); visitor(null).visitPropertyKey(1, "age"); visitor(null).visitRelationshipType(0, "ACCEPTS"); visitor(null).visitRelationshipType(1, "REJECTS"); visitor(null).visitIndex(TestIndexDescriptorFactory.forLabel(0, 1), ":Person(age)", 0.5d, 1L); visitor(null).visitIndex(TestIndexDescriptorFactory.uniqueForLabel(0, 0, 2), ":Person(name, lastName)", 0.5d, 1L); visitor(null).visitUniqueConstraint(ConstraintDescriptorFactory.uniqueForLabel(1, 0), ":Party(name)"); visitor(null).visitNodeKeyConstraint(ConstraintDescriptorFactory.nodeKeyForLabel(0, 1, 2), ":Person(name, lastName)"); visitor(null).visitAllNodesCount(55); visitor(null).visitNodeCount(0, "Person", 50); visitor(null).visitNodeCount(0, "Party", 5); visitor(null).visitRelCount(0, 1, -1, "MATCH (:Person)-[:REJECTS]->() RETURN count(*)", 5); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldGetRelatedNodeConstraints() public virtual void ShouldGetRelatedNodeConstraints() { // given ConstraintRule constraint1 = ConstraintRule.constraintRule(1L, ConstraintDescriptorFactory.uniqueForLabel(1, 5, 6), null); ConstraintRule constraint2 = ConstraintRule.constraintRule(2L, ConstraintDescriptorFactory.uniqueForLabel(1, 5), null); ConstraintRule constraint3 = ConstraintRule.constraintRule(3L, ConstraintDescriptorFactory.uniqueForLabel(2, 5), null); _indexMap.putUniquenessConstraint(constraint1); _indexMap.putUniquenessConstraint(constraint2); _indexMap.putUniquenessConstraint(constraint3); // when/then assertEquals(asSet(constraint2.ConstraintDescriptor), _indexMap.getRelatedConstraints(EntityTokens(1), EntityTokens(), Properties(5), true, NODE)); assertEquals(asSet(constraint1.ConstraintDescriptor, constraint2.ConstraintDescriptor), _indexMap.getRelatedConstraints(EntityTokens(1), EntityTokens(), Properties(5), false, NODE)); assertEquals(asSet(constraint1.ConstraintDescriptor, constraint2.ConstraintDescriptor), _indexMap.getRelatedConstraints(EntityTokens(1), EntityTokens(), Properties(5, 6), true, NODE)); assertEquals(asSet(constraint1.ConstraintDescriptor, constraint2.ConstraintDescriptor), _indexMap.getRelatedConstraints(EntityTokens(), EntityTokens(1), Properties(5), false, NODE)); assertEquals(asSet(constraint1.ConstraintDescriptor, constraint2.ConstraintDescriptor, constraint3.ConstraintDescriptor), _indexMap.getRelatedConstraints(EntityTokens(1, 2), EntityTokens(), Properties(), false, NODE)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldAbortConstraintCreationWhenDuplicatesExist() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldAbortConstraintCreationWhenDuplicatesExist() { // given Transaction transaction = newTransaction(AnonymousContext.writeToken()); // name is not unique for Foo in the existing data int foo = transaction.TokenWrite().labelGetOrCreateForName("Foo"); int name = transaction.TokenWrite().propertyKeyGetOrCreateForName("name"); long node1 = transaction.DataWrite().nodeCreate(); transaction.DataWrite().nodeAddLabel(node1, foo); transaction.DataWrite().nodeSetProperty(node1, name, Values.of("foo")); long node2 = transaction.DataWrite().nodeCreate(); transaction.DataWrite().nodeAddLabel(node2, foo); transaction.DataWrite().nodeSetProperty(node2, name, Values.of("foo")); commit(); // when LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(foo, name); try { SchemaWrite schemaWriteOperations = schemaWriteInNewTransaction(); schemaWriteOperations.UniquePropertyConstraintCreate(descriptor); fail("expected exception"); } // then catch (CreateConstraintFailureException ex) { assertEquals(ConstraintDescriptorFactory.uniqueForSchema(descriptor), ex.Constraint()); Exception cause = ex.InnerException; assertThat(cause, instanceOf(typeof(ConstraintValidationException))); string expectedMessage = string.Format("Both Node({0:D}) and Node({1:D}) have the label `Foo` and property `name` = 'foo'", node1, node2); string actualMessage = UserMessage(( ConstraintValidationException )cause); assertEquals(expectedMessage, actualMessage); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldRemoveNodeConstraints() public virtual void ShouldRemoveNodeConstraints() { // given ConstraintRule constraint1 = ConstraintRule.constraintRule(1L, ConstraintDescriptorFactory.uniqueForLabel(1, 5, 6), null); ConstraintRule constraint2 = ConstraintRule.constraintRule(2L, ConstraintDescriptorFactory.uniqueForLabel(1, 5), null); ConstraintRule constraint3 = ConstraintRule.constraintRule(3L, ConstraintDescriptorFactory.uniqueForLabel(2, 5), null); _indexMap.putUniquenessConstraint(constraint1); _indexMap.putUniquenessConstraint(constraint2); _indexMap.putUniquenessConstraint(constraint3); assertEquals(asSet(constraint2.ConstraintDescriptor), _indexMap.getRelatedConstraints(EntityTokens(1), EntityTokens(), Properties(5), true, NODE)); // and when _indexMap.removeUniquenessConstraint(constraint1.Id); _indexMap.removeUniquenessConstraint(constraint2.Id); _indexMap.removeUniquenessConstraint(constraint3.Id); // then assertTrue(_indexMap.getRelatedConstraints(EntityTokens(1), EntityTokens(), Properties(5), true, NODE).Count == 0); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @After public void clean() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void Clean() { if (_transaction != null) { _transaction.close(); } NewTransaction(); _transaction.schemaWrite().constraintDrop(ConstraintDescriptorFactory.uniqueForLabel(LABEL, PropertyIds())); Commit(); using (Transaction tx = Kernel.beginTransaction([email protected]_Type.Implicit, LoginContext.AUTH_DISABLED), NodeCursor node = tx.Cursors().allocateNodeCursor()) { tx.DataRead().allNodesScan(node); while (node.Next()) { tx.DataWrite().nodeDelete(node.NodeReference()); } tx.Success(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotDropPropertyExistenceConstraintThatDoesNotExistWhenThereIsAUniquePropertyConstraint() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotDropPropertyExistenceConstraintThatDoesNotExistWhenThereIsAUniquePropertyConstraint() { // given ConstraintDescriptor constraint; { SchemaWrite statement = schemaWriteInNewTransaction(); constraint = statement.UniquePropertyConstraintCreate(Descriptor); commit(); } // when try { SchemaWrite statement = schemaWriteInNewTransaction(); statement.ConstraintDrop(ConstraintDescriptorFactory.existsForSchema(constraint.Schema())); fail("expected exception"); } // then catch (DropConstraintFailureException e) { assertThat(e.InnerException, instanceOf(typeof(NoSuchConstraintException))); } finally { rollback(); } { // then Transaction transaction = newTransaction(); IEnumerator <ConstraintDescriptor> constraints = transaction.SchemaRead().constraintsGetForSchema(Descriptor); assertEquals(constraint, single(constraints)); commit(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldValidateUniquenessIndexes() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldValidateUniquenessIndexes() { // Given NeoStores store = mock( typeof( NeoStores ) ); IndexingService indexes = mock( typeof( IndexingService ) ); IntegrityValidator validator = new IntegrityValidator( store, indexes ); UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForLabel( 1, 1 ); doThrow( new UniquePropertyValueValidationException( constraint, ConstraintValidationException.Phase.VERIFICATION, new Exception() ) ).when(indexes).validateIndex(2L); ConstraintRule record = ConstraintRule.constraintRule( 1L, constraint, 2L ); // When try { validator.ValidateSchemaRule( record ); fail( "Should have thrown integrity error." ); } catch ( Exception ) { // good } }
public override void DropNodePropertyExistenceConstraint(Label label, string[] properties) { KernelTransaction transaction = SafeAcquireTransaction(TransactionSupplier); using (Statement ignore = transaction.AcquireStatement()) { try { TokenRead tokenRead = transaction.TokenRead(); int labelId = tokenRead.NodeLabel(label.Name()); int[] propertyKeyIds = ResolveAndValidatePropertyKeys(tokenRead, properties); transaction.SchemaWrite().constraintDrop(ConstraintDescriptorFactory.existsForLabel(labelId, propertyKeyIds)); } catch (DropConstraintFailureException e) { throw new ConstraintViolationException(e.GetUserMessage(new SilentTokenNameLookup(transaction.TokenRead())), e); } catch (Exception e) when(e is InvalidTransactionTypeKernelException || e is SchemaKernelException) { throw new ConstraintViolationException(e.Message, e); } } }
public override void DropRelationshipPropertyExistenceConstraint(RelationshipType type, string propertyKey) { KernelTransaction transaction = SafeAcquireTransaction(TransactionSupplier); using (Statement ignore = transaction.AcquireStatement()) { try { TokenRead tokenRead = transaction.TokenRead(); int typeId = tokenRead.RelationshipType(type.Name()); int propertyKeyId = tokenRead.PropertyKey(propertyKey); transaction.SchemaWrite().constraintDrop(ConstraintDescriptorFactory.existsForRelType(typeId, propertyKeyId)); } catch (DropConstraintFailureException e) { throw new ConstraintViolationException(e.GetUserMessage(new SilentTokenNameLookup(transaction.TokenRead())), e); } catch (Exception e) when(e is InvalidTransactionTypeKernelException || e is SchemaKernelException) { throw new ConstraintViolationException(e.Message, e); } } }
private ConstraintRule GetRelationshipPropertyExistenceConstraintRule(long id, string type, string property) { return(ConstraintRule.constraintRule(id, ConstraintDescriptorFactory.existsForRelType(TypeId(type), PropId(property)))); }
public static ConstraintRule ReadNodePropertyExistenceConstraintRule(long id, int labelId, ByteBuffer buffer) { return(new ConstraintRule(id, ConstraintDescriptorFactory.existsForLabel(labelId, ReadPropertyKey(buffer)), NO_OWNED_INDEX_RULE)); }
private ConstraintRule GetUniquePropertyConstraintRule(long id, string label, string property) { return(ConstraintRule.constraintRule(id, ConstraintDescriptorFactory.uniqueForLabel(LabelId(label), PropId(property)), 0L)); }
public static ConstraintRule ReadRelPropertyExistenceConstraintRule(long id, int relTypeId, ByteBuffer buffer) { return(new ConstraintRule(id, ConstraintDescriptorFactory.existsForRelType(relTypeId, ReadPropertyKey(buffer)), NO_OWNED_INDEX_RULE)); }