示例#1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void processAllRelationshipProperties() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ProcessAllRelationshipProperties()
        {
            CreateAlistairAndStefanNodes();
            CopyUpdateVisitor     propertyUpdateVisitor = new CopyUpdateVisitor();
            RelationshipStoreScan relationshipStoreScan = new RelationshipStoreScan(new RecordStorageReader(_neoStores), _locks, propertyUpdateVisitor, new int[] { _relTypeId }, id => true);

            using (StorageRelationshipScanCursor relationshipScanCursor = _reader.allocateRelationshipScanCursor())
            {
                relationshipScanCursor.Single(1);
                relationshipScanCursor.Next();

                relationshipStoreScan.process(relationshipScanCursor);
            }

            EntityUpdates propertyUpdates = propertyUpdateVisitor.PropertyUpdates;

            assertNotNull("Visitor should contain container with updates.", propertyUpdates);

            RelationTypeSchemaDescriptor         index1  = SchemaDescriptorFactory.forRelType(0, 2);
            RelationTypeSchemaDescriptor         index2  = SchemaDescriptorFactory.forRelType(0, 3);
            RelationTypeSchemaDescriptor         index3  = SchemaDescriptorFactory.forRelType(0, 2, 3);
            RelationTypeSchemaDescriptor         index4  = SchemaDescriptorFactory.forRelType(1, 3);
            IList <RelationTypeSchemaDescriptor> indexes = Arrays.asList(index1, index2, index3, index4);

//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
            assertThat(Iterables.map(IndexEntryUpdate::indexKey, propertyUpdates.ForIndexKeys(indexes)), containsInAnyOrder(index1, index2, index3));
        }
示例#2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateExistsConstraintDescriptors()
        public virtual void ShouldCreateExistsConstraintDescriptors()
        {
            ConstraintDescriptor desc;

            desc = ConstraintDescriptorFactory.ExistsForLabel(LABEL_ID, 1);
            assertThat(desc.Type(), equalTo(ConstraintDescriptor.Type.EXISTS));
            assertThat(desc.Schema(), equalTo(SchemaDescriptorFactory.forLabel(LABEL_ID, 1)));

            desc = ConstraintDescriptorFactory.ExistsForRelType(REL_TYPE_ID, 1);
            assertThat(desc.Type(), equalTo(ConstraintDescriptor.Type.EXISTS));
            assertThat(desc.Schema(), equalTo(SchemaDescriptorFactory.forRelType(REL_TYPE_ID, 1)));
        }
示例#3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateConstraintDescriptorsFromSchema()
        public virtual void ShouldCreateConstraintDescriptorsFromSchema()
        {
            ConstraintDescriptor desc;

            desc = ConstraintDescriptorFactory.UniqueForSchema(SchemaDescriptorFactory.forLabel(LABEL_ID, 1));
            assertThat(desc.Type(), equalTo(ConstraintDescriptor.Type.UNIQUE));
            assertThat(desc.Schema(), equalTo(SchemaDescriptorFactory.forLabel(LABEL_ID, 1)));

            desc = ConstraintDescriptorFactory.NodeKeyForSchema(SchemaDescriptorFactory.forLabel(LABEL_ID, 1));
            assertThat(desc.Type(), equalTo(ConstraintDescriptor.Type.UNIQUE_EXISTS));
            assertThat(desc.Schema(), equalTo(SchemaDescriptorFactory.forLabel(LABEL_ID, 1)));

            desc = ConstraintDescriptorFactory.ExistsForSchema(SchemaDescriptorFactory.forRelType(REL_TYPE_ID, 1));
            assertThat(desc.Type(), equalTo(ConstraintDescriptor.Type.EXISTS));
            assertThat(desc.Schema(), equalTo(SchemaDescriptorFactory.forRelType(REL_TYPE_ID, 1)));
        }
示例#4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldListRelationshipIndexesInTheCoreAPI() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldListRelationshipIndexesInTheCoreAPI()
        {
            Transaction      transaction = NewTransaction(AUTH_DISABLED);
            SchemaDescriptor descriptor  = SchemaDescriptorFactory.forRelType(_relType, _propertyKeyId);

            transaction.SchemaWrite().indexCreate(descriptor);
            Commit();

            using (Org.Neo4j.Graphdb.Transaction tx = Db.beginTx())
            {
                ISet <IndexDefinition> indexes = Iterables.asSet(Db.schema().Indexes);

                // then
                assertEquals(1, indexes.Count);
                IndexDefinition index = indexes.GetEnumerator().next();
                try
                {
                    index.Label;
                    fail("index.getLabel() should have thrown. ");
                }
                catch (System.InvalidOperationException)
                {
                }
                try
                {
                    index.Labels;
                    fail("index.getLabels() should have thrown. ");
                }
                catch (System.InvalidOperationException)
                {
                }
                assertEquals(REL_TYPE, index.RelationshipType.name());
                assertEquals(singletonList(withName(REL_TYPE)), index.RelationshipTypes);
                assertFalse("should not be a constraint index", index.ConstraintIndex);
                assertFalse("should not be a multi-token index", index.MultiTokenIndex);
                assertFalse("should not be a composite index", index.CompositeIndex);
                assertFalse("should not be a node index", index.NodeIndex);
                assertTrue("should be a relationship index", index.RelationshipIndex);
                assertEquals(asSet(PROPERTY_KEY), Iterables.asSet(index.PropertyKeys));
            }
        }
示例#5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPopulateRelatonshipIndexWithASmallDataset() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldPopulateRelatonshipIndexWithASmallDataset()
        {
            // GIVEN
            string value = "Philip J.Fry";
            long   node1 = CreateNode(map(_name, value), _first);
            long   node2 = CreateNode(map(_name, value), _second);
            long   node3 = CreateNode(map(_age, 31), _first);
            long   node4 = CreateNode(map(_age, 35, _name, value), _first);

            long rel1 = CreateRelationship(map(_name, value), _likes, node1, node3);

            CreateRelationship(map(_name, value), _knows, node3, node1);
            CreateRelationship(map(_age, 31), _likes, node2, node1);
            long rel4 = CreateRelationship(map(_age, 35, _name, value), _likes, node4, node4);

            IndexDescriptor    descriptor = IndexDescriptorFactory.forSchema(SchemaDescriptorFactory.forRelType(0, 0));
            IndexPopulator     populator  = spy(IndexPopulator(descriptor));
            IndexPopulationJob job        = NewIndexPopulationJob(populator, new FlippableIndexProxy(), EntityType.RELATIONSHIP, descriptor);

            // WHEN
            job.Run();

            // THEN
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.kernel.api.index.IndexEntryUpdate<?> update1 = add(rel1, descriptor, org.neo4j.values.storable.Values.of(value));
            IndexEntryUpdate <object> update1 = add(rel1, descriptor, Values.of(value));
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.kernel.api.index.IndexEntryUpdate<?> update2 = add(rel4, descriptor, org.neo4j.values.storable.Values.of(value));
            IndexEntryUpdate <object> update2 = add(rel4, descriptor, Values.of(value));

            verify(populator).create();
            verify(populator).includeSample(update1);
            verify(populator).includeSample(update2);
            verify(populator, times(2)).add(anyCollection());
            verify(populator).sampleResult();
            verify(populator).close(true);
        }
示例#6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPopulateIndexWithOneRelationship() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldPopulateIndexWithOneRelationship()
        {
            // GIVEN
            string             value        = "Taylor";
            long               nodeId       = CreateNode(map(_name, value), _first);
            long               relationship = CreateRelationship(map(_name, _age), _likes, nodeId, nodeId);
            IndexDescriptor    descriptor   = IndexDescriptorFactory.forSchema(SchemaDescriptorFactory.forRelType(0, 0));
            IndexPopulator     populator    = spy(IndexPopulator(descriptor));
            IndexPopulationJob job          = NewIndexPopulationJob(populator, new FlippableIndexProxy(), EntityType.RELATIONSHIP, descriptor);

            // WHEN
            job.Run();

            // THEN
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.kernel.api.index.IndexEntryUpdate<?> update = org.neo4j.kernel.api.index.IndexEntryUpdate.add(relationship, descriptor, org.neo4j.values.storable.Values.of(age));
            IndexEntryUpdate <object> update = IndexEntryUpdate.add(relationship, descriptor, Values.of(_age));

            verify(populator).create();
            verify(populator).includeSample(update);
            verify(populator, times(2)).add(any(typeof(System.Collections.ICollection)));
            verify(populator).sampleResult();
            verify(populator).close(true);
        }
示例#7
0
            public override ConstraintDefinition CreatePropertyExistenceConstraint(RelationshipType type, string propertyKey)
            {
                KernelTransaction transaction = SafeAcquireTransaction(TransactionSupplier);

                using (Statement ignore = transaction.AcquireStatement())
                {
                    try
                    {
                        TokenWrite tokenWrite    = transaction.TokenWrite();
                        int        typeId        = tokenWrite.RelationshipTypeGetOrCreateForName(type.Name());
                        int[]      propertyKeyId = getOrCreatePropertyKeyIds(tokenWrite, propertyKey);
                        transaction.SchemaWrite().relationshipPropertyExistenceConstraintCreate(SchemaDescriptorFactory.forRelType(typeId, propertyKeyId));
                        return(new RelationshipPropertyExistenceConstraintDefinition(this, type, propertyKey));
                    }
                    catch (Exception e) when(e is AlreadyConstrainedException || e is CreateConstraintFailureException || e is RepeatedSchemaComponentException)
                    {
                        throw new ConstraintViolationException(e.getUserMessage(new SilentTokenNameLookup(transaction.TokenRead())), e);
                    }
                    catch (IllegalTokenNameException e)
                    {
                        throw new System.ArgumentException(e);
                    }
                    catch (Exception e) when(e is InvalidTransactionTypeKernelException || e is SchemaKernelException)
                    {
                        throw new ConstraintViolationException(e.Message, e);
                    }
                }
            }
示例#8
0
 internal override RelationTypeSchemaDescriptor MakeDescriptor(int typeId, int propertyKeyId)
 {
     return(SchemaDescriptorFactory.forRelType(typeId, propertyKeyId));
 }
示例#9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldListAllConstraintsForRelationshipTypeAndProperty()
        public virtual void ShouldListAllConstraintsForRelationshipTypeAndProperty()
        {
            // Given
            SchemaHelper.createRelPropertyExistenceConstraint(Db, RelType1, PropertyKey);
            SchemaHelper.createRelPropertyExistenceConstraint(Db, RelType1, OtherPropertyKey);

            SchemaHelper.createRelPropertyExistenceConstraint(Db, RelType2, PropertyKey);
            SchemaHelper.createRelPropertyExistenceConstraint(Db, RelType2, OtherPropertyKey);

            // When
            int relTypeId = RelationshipTypeId(RelType1);
            int propKeyId = PropertyKeyId(PropertyKey);
            ISet <ConstraintDescriptor> constraints = asSet(StorageReader.constraintsGetForSchema(SchemaDescriptorFactory.forRelType(relTypeId, propKeyId)));

            // Then
            ISet <ConstraintDescriptor> expectedConstraints = Iterators.asSet(RelationshipPropertyExistenceDescriptor(RelType1, PropertyKey));

            assertEquals(expectedConstraints, constraints);
        }
 public static RelExistenceConstraintDescriptor ExistsForRelType(int relTypeId, params int[] propertyIds)
 {
     return(new RelExistenceConstraintDescriptor(SchemaDescriptorFactory.forRelType(relTypeId, propertyIds)));
 }