Ejemplo n.º 1
0
        public override bool HasProperty(string key)
        {
            if (null == key)
            {
                return(false);
            }

            KernelTransaction transaction = _spi.kernelTransaction();
            int propertyKey = transaction.TokenRead().propertyKey(key);

            if (propertyKey == [email protected]_Fields.NO_TOKEN)
            {
                return(false);
            }

            RelationshipScanCursor relationships = transaction.AmbientRelationshipCursor();
            PropertyCursor         properties    = transaction.AmbientPropertyCursor();

            SingleRelationship(transaction, relationships);
            relationships.Properties(properties);
            while (properties.Next())
            {
                if (propertyKey == properties.PropertyKey())
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public override object GetProperty(string key, object defaultValue)
        {
            if (null == key)
            {
                throw new System.ArgumentException("(null) property key is not allowed");
            }
            KernelTransaction      transaction   = _spi.kernelTransaction();
            RelationshipScanCursor relationships = transaction.AmbientRelationshipCursor();
            PropertyCursor         properties    = transaction.AmbientPropertyCursor();
            int propertyKey = transaction.TokenRead().propertyKey(key);

            if (propertyKey == [email protected]_Fields.NO_TOKEN)
            {
                return(defaultValue);
            }
            SingleRelationship(transaction, relationships);
            relationships.Properties(properties);
            while (properties.Next())
            {
                if (propertyKey == properties.PropertyKey())
                {
                    Value value = properties.PropertyValue();
                    return(value == Values.NO_VALUE ? defaultValue : value.AsObjectCopy());
                }
            }
            return(defaultValue);
        }
Ejemplo n.º 4
0
        public override RelationshipScanCursor AllocateRelationshipScanCursor()
        {
            RelationshipScanCursor n = _cursors.allocateRelationshipScanCursor();

            _allCursors.Add(n);
            return(n);
        }
Ejemplo n.º 5
0
 private void SingleRelationship(KernelTransaction transaction, RelationshipScanCursor relationships)
 {
     transaction.DataRead().singleRelationship(_id, relationships);
     if (!relationships.Next())
     {
         throw new NotFoundException(new EntityNotFoundException(EntityType.RELATIONSHIP, _id));
     }
 }
 internal virtual FulltextIndexTransactionStateVisitor Init(AllStoreHolder read, NodeCursor nodeCursor, RelationshipScanCursor relationshipCursor, PropertyCursor propertyCursor)
 {
     this._read               = read;
     this._nodeCursor         = nodeCursor;
     this._relationshipCursor = relationshipCursor;
     this._propertyCursor     = propertyCursor;
     return(this);
 }
Ejemplo n.º 7
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();
            }
        }
Ejemplo n.º 8
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());
            }
        }
Ejemplo n.º 9
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());
            }
        }
Ejemplo n.º 10
0
        public override IDictionary <string, object> GetProperties(params string[] keys)
        {
            Objects.requireNonNull(keys, "Properties keys should be not null array.");

            if (keys.Length == 0)
            {
                return(Collections.emptyMap());
            }

            KernelTransaction transaction = _spi.kernelTransaction();

            int       itemsToReturn = keys.Length;
            TokenRead token         = transaction.TokenRead();

            //Find ids, note we are betting on that the number of keys
            //is small enough not to use a set here.
            int[] propertyIds = new int[itemsToReturn];
            for (int i = 0; i < itemsToReturn; i++)
            {
                string key = keys[i];
                if (string.ReferenceEquals(key, null))
                {
                    throw new System.NullReferenceException(string.Format("Key {0:D} was null", i));
                }
                propertyIds[i] = token.PropertyKey(key);
            }

            IDictionary <string, object> properties    = new Dictionary <string, object>(itemsToReturn);
            RelationshipScanCursor       relationships = transaction.AmbientRelationshipCursor();
            PropertyCursor propertyCursor = transaction.AmbientPropertyCursor();

            SingleRelationship(transaction, relationships);
            relationships.Properties(propertyCursor);
            int propertiesToFind = itemsToReturn;

            while (propertiesToFind > 0 && propertyCursor.Next())
            {
                //Do a linear check if this is a property we are interested in.
                int currentKey = propertyCursor.PropertyKey();
                for (int i = 0; i < itemsToReturn; i++)
                {
                    if (propertyIds[i] == currentKey)
                    {
                        properties[keys[i]] = propertyCursor.PropertyValue().asObjectCopy();
                        propertiesToFind--;
                        break;
                    }
                }
            }
            return(properties);
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
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());
                }
            }
        }
Ejemplo n.º 14
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);
 }
Ejemplo n.º 15
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);
         }
     }
 }
Ejemplo n.º 16
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());
            }
        }
Ejemplo n.º 17
0
 public override void RelationshipTypeScan(int type, RelationshipScanCursor cursor)
 {
     throw new System.NotSupportedException();
 }
Ejemplo n.º 18
0
 public override void AllRelationshipsScan(RelationshipScanCursor cursor)
 {
     throw new System.NotSupportedException();
 }
Ejemplo n.º 19
0
 public override void SingleRelationship(long reference, RelationshipScanCursor cursor)
 {
     throw new System.NotSupportedException();
 }
Ejemplo n.º 20
0
 public override void RelationshipTypeScan(int type, RelationshipScanCursor cursor)
 {
     Ktx.assertOpen();
     (( DefaultRelationshipScanCursor )cursor).Scan(type, this);
 }
Ejemplo n.º 21
0
 public override void AllRelationshipsScan(RelationshipScanCursor cursor)
 {
     Ktx.assertOpen();
     (( DefaultRelationshipScanCursor )cursor).Scan(-1, this);
 }
Ejemplo n.º 22
0
 public override void SingleRelationship(long reference, RelationshipScanCursor cursor)
 {
     Ktx.assertOpen();
     (( DefaultRelationshipScanCursor )cursor).Single(reference, this);
 }