Пример #1
0
        private ConstraintDescriptor NodeKeyConstraintDescriptor(Label label, string propertyKey)
        {
            int labelId   = labelId(label);
            int propKeyId = PropertyKeyId(propertyKey);

            return(ConstraintDescriptorFactory.nodeKeyForLabel(labelId, propKeyId));
        }
Пример #2
0
        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));
        }
Пример #3
0
//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);
        }
Пример #4
0
 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);
 }
Пример #5
0
            public override void DropNodeKeyConstraint(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.nodeKeyForLabel(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);
                    }
                }
            }
Пример #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFormatNodeKeyConstraints()
        public virtual void ShouldFormatNodeKeyConstraints()
        {
            assertEquals("ConstraintDescriptorFactory.nodeKeyForLabel( 23, 42, 43 )", FormatArgument(ConstraintDescriptorFactory.nodeKeyForLabel(23, 42, 43)));
        }
Пример #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)));
        }