Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
 }