Ejemplo n.º 1
0
        public override PropertyCursor AllocatePropertyCursor()
        {
            PropertyCursor n = _cursors.allocatePropertyCursor();

            _allCursors.Add(n);
            return(n);
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public Object getProperty(String key) throws org.neo4j.graphdb.NotFoundException
        public override object GetProperty(string key)
        {
            if (null == key)
            {
                throw new System.ArgumentException("(null) property key is not allowed");
            }
            KernelTransaction transaction = SafeAcquireTransaction();
            int propertyKey = transaction.TokenRead().propertyKey(key);

            if (propertyKey == [email protected]_Fields.NO_TOKEN)
            {
                throw new NotFoundException(format("No such property, '%s'.", key));
            }

            NodeCursor     nodes      = transaction.AmbientNodeCursor();
            PropertyCursor properties = transaction.AmbientPropertyCursor();

            SingleNode(transaction, nodes);
            nodes.Properties(properties);
            while (properties.Next())
            {
                if (propertyKey == properties.PropertyKey())
                {
                    Value value = properties.PropertyValue();
                    if (value == Values.NO_VALUE)
                    {
                        throw new NotFoundException(format("No such property, '%s'.", key));
                    }
                    return(value.AsObjectCopy());
                }
            }
            throw new NotFoundException(format("No such property, '%s'.", key));
        }
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 bool HasProperty(string key)
        {
            if (null == key)
            {
                return(false);
            }

            KernelTransaction transaction = SafeAcquireTransaction();
            int propertyKey = transaction.TokenRead().propertyKey(key);

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

            NodeCursor     nodes      = transaction.AmbientNodeCursor();
            PropertyCursor properties = transaction.AmbientPropertyCursor();

            SingleNode(transaction, nodes);
            nodes.Properties(properties);
            while (properties.Next())
            {
                if (propertyKey == properties.PropertyKey())
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 5
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.º 6
0
 internal NodeValueClientFilter(IndexProgressor_NodeValueClient target, NodeCursor node, PropertyCursor property, Read read, params IndexQuery[] filters)
 {
     this._target   = target;
     this._node     = node;
     this._property = property;
     this._filters  = filters;
     this._read     = read;
 }
 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.º 8
0
 private bool HasKey(PropertyCursor propertyCursor, int key)
 {
     while (propertyCursor.Next())
     {
         if (propertyCursor.PropertyKey() == key)
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 9
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 = SafeAcquireTransaction();

            int itemsToReturn = keys.Length;
            IDictionary <string, object> properties = new Dictionary <string, object>(itemsToReturn);
            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);
            }

            NodeCursor     nodes          = transaction.AmbientNodeCursor();
            PropertyCursor propertyCursor = transaction.AmbientPropertyCursor();

            SingleNode(transaction, nodes);
            nodes.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.º 10
0
        internal virtual void OnPropertyRemove(NodeCursor node, PropertyCursor propertyCursor, long[] labels, int propertyKeyId, int[] existingPropertyKeyIds, Value value)
        {
            Debug.Assert(NoSchemaChangedInTx());
            ICollection <SchemaDescriptor> indexes = _indexingService.getRelatedIndexes(labels, propertyKeyId, NODE);

            if (indexes.Count > 0)
            {
                MutableIntObjectMap <Value> materializedProperties = IntObjectMaps.mutable.empty();
                NodeSchemaMatcher.OnMatchingSchema(indexes.GetEnumerator(), propertyKeyId, existingPropertyKeyIds, index =>
                {
                    Value[] values = GetValueTuple(node, propertyCursor, propertyKeyId, value, index.schema().PropertyIds, materializedProperties);
                    _read.txState().indexDoUpdateEntry(index.schema(), node.NodeReference(), ValueTuple.of(values), null);
                });
            }
        }
Ejemplo n.º 11
0
        private Value[] GetValueTuple(NodeCursor node, PropertyCursor propertyCursor, int changedPropertyKeyId, Value changedValue, int[] indexPropertyIds, MutableIntObjectMap <Value> materializedValues)
        {
            Value[] values  = new Value[indexPropertyIds.Length];
            int     missing = 0;

            // First get whatever values we already have on the stack, like the value change that provoked this update in the first place
            // and already loaded values that we can get from the map of materialized values.
            for (int k = 0; k < indexPropertyIds.Length; k++)
            {
                values[k] = indexPropertyIds[k] == changedPropertyKeyId ? changedValue : materializedValues.get(indexPropertyIds[k]);
                if (values[k] == null)
                {
                    missing++;
                }
            }

            // If we couldn't get all values that we wanted we need to load from the node. While we're loading values
            // we'll place those values in the map so that other index updates from this change can just used them.
            if (missing > 0)
            {
                node.Properties(propertyCursor);
                while (missing > 0 && propertyCursor.Next())
                {
                    int k = ArrayUtils.IndexOf(indexPropertyIds, propertyCursor.PropertyKey());
                    if (k >= 0 && values[k] == null)
                    {
                        int  propertyKeyId            = indexPropertyIds[k];
                        bool thisIsTheChangedProperty = propertyKeyId == changedPropertyKeyId;
                        values[k] = thisIsTheChangedProperty ? changedValue : propertyCursor.PropertyValue();
                        if (!thisIsTheChangedProperty)
                        {
                            materializedValues.put(propertyKeyId, values[k]);
                        }
                        missing--;
                    }
                }
            }

            return(values);
        }
Ejemplo n.º 12
0
        internal virtual void OnPropertyChange(NodeCursor node, PropertyCursor propertyCursor, long[] labels, int propertyKeyId, int[] existingPropertyKeyIds, Value beforeValue, Value afterValue)
        {
            Debug.Assert(NoSchemaChangedInTx());
            ICollection <SchemaDescriptor> indexes = _indexingService.getRelatedIndexes(labels, propertyKeyId, NODE);

            if (indexes.Count > 0)
            {
                MutableIntObjectMap <Value> materializedProperties = IntObjectMaps.mutable.empty();
                NodeSchemaMatcher.OnMatchingSchema(indexes.GetEnumerator(), propertyKeyId, existingPropertyKeyIds, index =>
                {
                    int[] propertyIds   = index.PropertyIds;
                    Value[] valuesAfter = GetValueTuple(node, propertyCursor, propertyKeyId, afterValue, propertyIds, materializedProperties);

                    // The valuesBefore tuple is just like valuesAfter, except is has the afterValue instead of the beforeValue
                    Value[] valuesBefore = valuesAfter.Clone();
                    int k           = ArrayUtils.IndexOf(propertyIds, propertyKeyId);
                    valuesBefore[k] = beforeValue;

                    _indexingService.validateBeforeCommit(index, valuesAfter);
                    _read.txState().indexDoUpdateEntry(index, node.NodeReference(), ValueTuple.of(valuesBefore), ValueTuple.of(valuesAfter));
                });
            }
        }
Ejemplo n.º 13
0
 public override void GraphProperties(PropertyCursor cursor)
 {
     Ktx.assertOpen();
     (( DefaultPropertyCursor )cursor).InitGraph(GraphPropertiesReference(), this, Ktx);
 }
Ejemplo n.º 14
0
 public override void RelationshipProperties(long relationshipReference, long reference, PropertyCursor cursor)
 {
     (( DefaultPropertyCursor )cursor).InitRelationship(relationshipReference, reference, this, Ktx);
 }
Ejemplo n.º 15
0
 public override void NodeProperties(long nodeReference, long reference, PropertyCursor cursor)
 {
     (( DefaultPropertyCursor )cursor).InitNode(nodeReference, reference, this, Ktx);
 }
Ejemplo n.º 16
0
 public override void Properties(PropertyCursor cursor)
 {
     throw new System.NotSupportedException("not implemented");
 }
Ejemplo n.º 17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCheckUniquenessWhenAddingProperties() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCheckUniquenessWhenAddingProperties()
        {
            // GIVEN
            long nodeConflicting, nodeNotConflicting;

            AddConstraints("FOO", "prop");
            using (Org.Neo4j.Graphdb.Transaction tx = graphDb.beginTx())
            {
                Node conflict = graphDb.createNode();
                conflict.AddLabel(Label.label("FOO"));
                nodeConflicting = conflict.Id;

                Node ok = graphDb.createNode();
                ok.AddLabel(Label.label("BAR"));
                nodeNotConflicting = ok.Id;

                //Existing node
                Node existing = graphDb.createNode();
                existing.AddLabel(Label.label("FOO"));
                existing.SetProperty("prop", 1337);
                tx.Success();
            }

            int property;

            using (Transaction tx = beginTransaction())
            {
                property = tx.tokenWrite().propertyKeyGetOrCreateForName("prop");

                //This is ok, since it will satisfy constraint
                tx.dataWrite().nodeSetProperty(nodeNotConflicting, property, intValue(1337));

                try
                {
                    tx.dataWrite().nodeSetProperty(nodeConflicting, property, intValue(1337));
                    fail();
                }
                catch (ConstraintValidationException)
                {
                    //ignore
                }
                tx.Success();
            }

            //Verify
            using (Transaction tx = beginTransaction(), NodeCursor nodeCursor = tx.cursors().allocateNodeCursor(), PropertyCursor propertyCursor = tx.cursors().allocatePropertyCursor())
            {
                //Node without conflict
                tx.dataRead().singleNode(nodeNotConflicting, nodeCursor);
                assertTrue(nodeCursor.Next());
                nodeCursor.Properties(propertyCursor);
                assertTrue(HasKey(propertyCursor, property));
                //Node with conflict
                tx.dataRead().singleNode(nodeConflicting, nodeCursor);
                assertTrue(nodeCursor.Next());
                nodeCursor.Properties(propertyCursor);
                assertFalse(HasKey(propertyCursor, property));
            }
        }
Ejemplo n.º 18
0
 private bool HasProperties(NodeCursor node, PropertyCursor props)
 {
     node.Properties(props);
     return(props.Next());
 }
Ejemplo n.º 19
0
 public override void RelationshipProperties(long relationshipReference, long reference, PropertyCursor cursor)
 {
     throw new System.NotSupportedException();
 }
Ejemplo n.º 20
0
 public override bool AcceptsValueAt(PropertyCursor property)
 {
     return(true);
 }
Ejemplo n.º 21
0
 public virtual bool AcceptsValueAt(PropertyCursor property)
 {
     return(AcceptsValue(property.PropertyValue()));
 }
Ejemplo n.º 22
0
 public override void NodeProperties(long nodeReference, long reference, PropertyCursor cursor)
 {
     throw new System.NotSupportedException();
 }
Ejemplo n.º 23
0
        /// <summary>
        /// A label has been changed, figure out what updates are needed to tx state.
        /// </summary>
        /// <param name="labelId"> The id of the changed label </param>
        /// <param name="existingPropertyKeyIds"> all property key ids the node has, sorted by id </param>
        /// <param name="node"> cursor to the node where the change was applied </param>
        /// <param name="propertyCursor"> cursor to the properties of node </param>
        /// <param name="changeType"> The type of change event </param>
        internal virtual void OnLabelChange(int labelId, int[] existingPropertyKeyIds, NodeCursor node, PropertyCursor propertyCursor, LabelChangeType changeType)
        {
            Debug.Assert(NoSchemaChangedInTx());

            // Check all indexes of the changed label
            ICollection <SchemaDescriptor> indexes = _indexingService.getRelatedIndexes(new long[] { labelId }, existingPropertyKeyIds, NODE);

            if (indexes.Count > 0)
            {
                MutableIntObjectMap <Value> materializedProperties = IntObjectMaps.mutable.empty();
                foreach (SchemaDescriptor index in indexes)
                {
                    int[]   indexPropertyIds = index.Schema().PropertyIds;
                    Value[] values           = GetValueTuple(node, propertyCursor, NO_SUCH_PROPERTY_KEY, NO_VALUE, indexPropertyIds, materializedProperties);
                    switch (changeType)
                    {
                    case Org.Neo4j.Kernel.Impl.Newapi.IndexTxStateUpdater.LabelChangeType.AddedLabel:
                        _indexingService.validateBeforeCommit(index.Schema(), values);
                        _read.txState().indexDoUpdateEntry(index.Schema(), node.NodeReference(), null, ValueTuple.of(values));
                        break;

                    case Org.Neo4j.Kernel.Impl.Newapi.IndexTxStateUpdater.LabelChangeType.RemovedLabel:
                        _read.txState().indexDoUpdateEntry(index.Schema(), node.NodeReference(), ValueTuple.of(values), null);
                        break;

                    default:
                        throw new System.InvalidOperationException(changeType + " is not a supported event");
                    }
                }
            }
        }
Ejemplo n.º 24
0
 public override void GraphProperties(PropertyCursor cursor)
 {
     throw new System.NotSupportedException();
 }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void updateReader(org.neo4j.kernel.impl.api.KernelTransactionImplementation kti) throws Exception
        private void UpdateReader(KernelTransactionImplementation kti)
        {
            _modifiedEntityIdsInThisTransaction.clear();               // Clear this so we don't filter out entities who have had their changes reversed since last time.
            _writer.resetWriterState();
            AllStoreHolder   read             = ( AllStoreHolder )kti.DataRead();
            TransactionState transactionState = kti.TxState();

            using (NodeCursor nodeCursor = _visitingNodes ? kti.Cursors().allocateNodeCursor() : null, RelationshipScanCursor relationshipCursor = _visitingNodes ? null : kti.Cursors().allocateRelationshipScanCursor(), PropertyCursor propertyCursor = kti.Cursors().allocatePropertyCursor())
            {
                transactionState.Accept(_txStateVisitor.init(read, nodeCursor, relationshipCursor, propertyCursor));
            }
            FulltextIndexReader baseReader         = ( FulltextIndexReader )read.IndexReader(_descriptor, false);
            FulltextIndexReader nearRealTimeReader = _writer.NearRealTimeReader;

            _currentReader      = new TransactionStateFulltextIndexReader(baseReader, nearRealTimeReader, _modifiedEntityIdsInThisTransaction);
            _lastUpdateRevision = kti.TransactionDataRevision;
        }
Ejemplo n.º 26
0
 private bool HasProperties(NodeCursor cursor, PropertyCursor props)
 {
     cursor.Properties(props);
     return(props.Next());
 }
Ejemplo n.º 27
0
 public override void Properties(PropertyCursor cursor)
 {
     (( StubPropertyCursor )cursor).Init(_nodes[_offset].properties);
 }