private ConstraintDescriptor RelationshipPropertyExistenceDescriptor(RelationshipType relType, string propertyKey) { int relTypeId = RelationshipTypeId(relType); int propKeyId = PropertyKeyId(propertyKey); return(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))); }
//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))); }
//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))); }
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 ReadRelPropertyExistenceConstraintRule(long id, int relTypeId, ByteBuffer buffer) { return(new ConstraintRule(id, ConstraintDescriptorFactory.existsForRelType(relTypeId, ReadPropertyKey(buffer)), NO_OWNED_INDEX_RULE)); }
//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))); }
private ConstraintRule RelPropertyExistenceConstraintRule(long ruleId, int relTypeId, int propertyId) { return(constraintRule(ruleId, ConstraintDescriptorFactory.existsForRelType(relTypeId, propertyId))); }