Example #1
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);
        }
Example #2
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);
        }
Example #3
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 #4
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);
        }
Example #5
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);
         }
     }
 }