Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAccessRelationshipLabels()
        public virtual void ShouldAccessRelationshipLabels()
        {
            // given
            IDictionary <int, int> counts = new Dictionary <int, int>();

            using (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor())
            {
                // when
                read.allRelationshipsScan(relationships);
                while (relationships.Next())
                {
                    Counts.compute(relationships.Type(), (k, v) => v == null ? 1 : v + 1);
                }
            }

            // then
            assertEquals(3, Counts.Count);
            int[] values = new int[3];
            int   i      = 0;

            foreach (int value in Counts.Values)
            {
                values[i++] = value;
            }
            Arrays.sort(values);
            assertArrayEquals(new int[] { 1, 6, 6 }, values);
        }
Example #2
0
 private void SingleRelationship(KernelTransaction transaction, RelationshipScanCursor relationships)
 {
     transaction.DataRead().singleRelationship(_id, relationships);
     if (!relationships.Next())
     {
         throw new NotFoundException(new EntityNotFoundException(EntityType.RELATIONSHIP, _id));
     }
 }
Example #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAccessRelationshipByReference()
        public virtual void ShouldAccessRelationshipByReference()
        {
            // given
            using (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor())
            {
                foreach (long id in _relationshipIds)
                {
                    // when
                    read.singleRelationship(id, relationships);

                    // then
                    assertTrue("should access defined relationship", relationships.Next());
                    assertEquals("should access the correct relationship", id, relationships.RelationshipReference());
                    assertFalse("should only access a single relationship", relationships.Next());
                }
            }
        }
Example #4
0
        private void ScanEverythingBelongingToRelationships(RelationshipMappings relMappings)
        {
            using (RelationshipScanCursor relationshipScanCursor = _cursors.allocateRelationshipScanCursor(), PropertyCursor propertyCursor = _cursors.allocatePropertyCursor())
            {
                _dataRead.allRelationshipsScan(relationshipScanCursor);
                while (relationshipScanCursor.Next())
                {
                    int typeId = relationshipScanCursor.Type();
                    relationshipScanCursor.Properties(propertyCursor);
                    MutableIntSet propertyIds = IntSets.mutable.empty();

                    while (propertyCursor.Next())
                    {
                        int propertyKey = propertyCursor.PropertyKey();

                        Value           currentValue = propertyCursor.PropertyValue();
                        Pair <int, int> key          = Pair.of(typeId, propertyKey);
                        UpdateValueTypeInMapping(currentValue, key, relMappings.RelationshipTypeIdANDPropertyTypeIdToValueType);

                        propertyIds.add(propertyKey);
                    }
                    propertyCursor.Close();

                    MutableIntSet oldPropertyKeySet = relMappings.RelationshipTypeIdToPropertyKeys.getOrDefault(typeId, _emptyPropertyIdSet);

                    // find out which old properties we did not visited and mark them as nullable
                    if (oldPropertyKeySet == _emptyPropertyIdSet)
                    {
                        if (propertyIds.size() == 0)
                        {
                            // Even if we find property key on other rels with this type, set all of them nullable
                            relMappings.NullableRelationshipTypes.Add(typeId);
                        }

                        propertyIds.addAll(oldPropertyKeySet);
                    }
                    else
                    {
                        MutableIntSet currentPropertyIdsHelperSet = new IntHashSet(propertyIds.size());
                        currentPropertyIdsHelperSet.addAll(propertyIds);
                        propertyIds.removeAll(oldPropertyKeySet);                                     // only the brand new ones in propIds now
                        oldPropertyKeySet.removeAll(currentPropertyIdsHelperSet);                     // only the old ones that are not on the new rel

                        propertyIds.addAll(oldPropertyKeySet);
                        propertyIds.forEach(id =>
                        {
                            Pair <int, int> key = Pair.of(typeId, id);
                            relMappings.RelationshipTypeIdANDPropertyTypeIdToValueType[key].setNullable();
                        });

                        propertyIds.addAll(currentPropertyIdsHelperSet);
                    }

                    relMappings.RelationshipTypeIdToPropertyKeys[typeId] = propertyIds;
                }
                relationshipScanCursor.Close();
            }
        }
Example #5
0
        // This is functionality which is only required for the hacky db.schema not to leak real data
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAccessNegativeReferences()
        public virtual void ShouldNotAccessNegativeReferences()
        {
            // given
            using (RelationshipScanCursor relationship = cursors.allocateRelationshipScanCursor())
            {
                // when
                read.singleRelationship(-2L, relationship);

                // then
                assertFalse("should not access negative reference relationship", relationship.Next());
            }
        }
Example #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAccessDeletedRelationship()
        public virtual void ShouldNotAccessDeletedRelationship()
        {
            // given
            using (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor())
            {
                // when
                read.singleRelationship(_none, relationships);

                // then
                assertFalse("should not access deleted relationship", relationships.Next());
            }
        }
Example #7
0
        internal static int CountRelationships(Transaction transaction)
        {
            int result = 0;

            using (RelationshipScanCursor cursor = transaction.Cursors().allocateRelationshipScanCursor())
            {
                transaction.DataRead().allRelationshipsScan(cursor);
                while (cursor.Next())
                {
                    result++;
                }
            }
            return(result);
        }
Example #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAccessNodes()
        public virtual void ShouldAccessNodes()
        {
            // given
            using (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor())
            {
                // when
                read.singleRelationship(_one, relationships);

                // then
                assertTrue(relationships.Next());
                assertEquals(_c, relationships.SourceNodeReference());
                assertEquals(_d, relationships.TargetNodeReference());
                assertFalse(relationships.Next());

                // when
                read.singleRelationship(_loop, relationships);

                // then
                assertTrue(relationships.Next());
                assertEquals(relationships.SourceNodeReference(), relationships.TargetNodeReference());
                assertFalse(relationships.Next());
            }
        }
Example #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldScanRelationships()
        public virtual void ShouldScanRelationships()
        {
            // given
            IList <long> ids = new List <long>();

            using (RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor())
            {
                // when
                read.allRelationshipsScan(relationships);
                while (relationships.Next())
                {
                    ids.Add(relationships.RelationshipReference());
                }
            }

            assertEquals(_relationshipIds, ids);
        }
Example #10
0
 public virtual bool InitializeData()
 {
     // It enough to check only start node, since it's absence will indicate that data was not yet loaded.
     if (_startNode == AbstractBaseRecord.NO_ID)
     {
         KernelTransaction transaction = _spi.kernelTransaction();
         using (Statement ignore = transaction.AcquireStatement())
         {
             RelationshipScanCursor relationships = transaction.AmbientRelationshipCursor();
             transaction.DataRead().singleRelationship(_id, relationships);
             // At this point we don't care if it is there or not just load what we got.
             bool wasPresent = relationships.Next();
             this._type      = relationships.Type();
             this._startNode = relationships.SourceNodeReference();
             this._endNode   = relationships.TargetNodeReference();
             // But others might care, e.g. the Bolt server needs to know for serialisation purposes.
             return(wasPresent);
         }
     }
     return(true);
 }
Example #11
0
 internal virtual Value RelationshipGetProperty(Transaction transaction, long relationship, int property)
 {
     using (RelationshipScanCursor cursor = transaction.Cursors().allocateRelationshipScanCursor(), PropertyCursor properties = transaction.Cursors().allocatePropertyCursor())
     {
         transaction.DataRead().singleRelationship(relationship, cursor);
         if (!cursor.Next())
         {
             return(NO_VALUE);
         }
         else
         {
             cursor.Properties(properties);
             while (properties.Next())
             {
                 if (properties.PropertyKey() == property)
                 {
                     return(properties.PropertyValue());
                 }
             }
             return(NO_VALUE);
         }
     }
 }