Esempio n. 1
0
        private ConstraintDescriptor NodePropertyExistenceDescriptor(Label label, string propertyKey)
        {
            int labelId   = labelId(label);
            int propKeyId = PropertyKeyId(propertyKey);

            return(ConstraintDescriptorFactory.existsForLabel(labelId, propKeyId));
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
//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)));
        }
Esempio n. 4
0
//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)));
        }
Esempio n. 5
0
            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 static ConstraintRule ReadNodePropertyExistenceConstraintRule(long id, int labelId, ByteBuffer buffer)
 {
     return(new ConstraintRule(id, ConstraintDescriptorFactory.existsForLabel(labelId, ReadPropertyKey(buffer)), NO_OWNED_INDEX_RULE));
 }
Esempio n. 7
0
//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)));
        }
Esempio n. 8
0
 private ConstraintRule ConstraintExistsRule(long ruleId, int labelId, params int[] propertyIds)
 {
     return(ConstraintRule.constraintRule(ruleId, ConstraintDescriptorFactory.existsForLabel(labelId, propertyIds)));
 }
Esempio n. 9
0
 private ConstraintRule NodePropertyExistenceConstraintRule(long ruleId, int labelId, int propertyId)
 {
     return(constraintRule(ruleId, ConstraintDescriptorFactory.existsForLabel(labelId, propertyId)));
 }