Exemple #1
0
        /// <summary>
        /// Removes property with given {@code propertyKey} from property chain owner by the primitive found in
        /// {@code primitiveProxy}.
        /// </summary>
        /// <param name="primitiveProxy"> access to the primitive record pointing to the start of the property chain. </param>
        /// <param name="propertyKey"> the property key token id to look for and remove. </param>
        /// <param name="propertyRecords"> access to records. </param>
        /// <exception cref="IllegalStateException"> if property key was not found in the property chain. </exception>
        public virtual void RemoveProperty <P>(RecordAccess_RecordProxy <P, Void> primitiveProxy, int propertyKey, RecordAccess <PropertyRecord, PrimitiveRecord> propertyRecords) where P : Org.Neo4j.Kernel.impl.store.record.PrimitiveRecord
        {
            PrimitiveRecord primitive  = primitiveProxy.ForReadingData();
            long            propertyId = _traverser.findPropertyRecordContaining(primitive, propertyKey, propertyRecords, true);

            RemoveProperty(primitiveProxy, propertyKey, propertyRecords, primitive, propertyId);
        }
Exemple #2
0
 private void RemoveProperty(PrimitiveRecord primitive, PropertyRecord host, PropertyBlock block)
 {
     host.RemovePropertyBlock(block.KeyIndexId);
     host.Changed = primitive;
     foreach (DynamicRecord record in block.ValueRecords)
     {
         Debug.Assert(record.InUse());
         record.SetInUse(false, block.Type.intValue());
         host.AddDeletedRecord(record);
     }
 }
Exemple #3
0
        /// <summary>
        /// Removes property with given {@code propertyKey} from property chain owner by the primitive found in
        /// {@code primitiveProxy} if it exists.
        /// </summary>
        /// <param name="primitiveProxy"> access to the primitive record pointing to the start of the property chain. </param>
        /// <param name="propertyKey"> the property key token id to look for and remove. </param>
        /// <param name="propertyRecords"> access to records. </param>
        /// <returns> {@code true} if the property was found and removed, otherwise {@code false}. </returns>
        public virtual bool RemovePropertyIfExists <P>(RecordAccess_RecordProxy <P, Void> primitiveProxy, int propertyKey, RecordAccess <PropertyRecord, PrimitiveRecord> propertyRecords) where P : Org.Neo4j.Kernel.impl.store.record.PrimitiveRecord
        {
            PrimitiveRecord primitive  = primitiveProxy.ForReadingData();
            long            propertyId = _traverser.findPropertyRecordContaining(primitive, propertyKey, propertyRecords, false);

            if (!Record.NO_NEXT_PROPERTY.@is(propertyId))
            {
                RemoveProperty(primitiveProxy, propertyKey, propertyRecords, primitive, propertyId);
                return(true);
            }
            return(false);
        }
Exemple #4
0
        public virtual void DeletePropertyChain(PrimitiveRecord primitive, RecordAccess <PropertyRecord, PrimitiveRecord> propertyRecords)
        {
            long nextProp = primitive.NextProp;

            while (nextProp != Record.NO_NEXT_PROPERTY.intValue())
            {
                RecordAccess_RecordProxy <PropertyRecord, PrimitiveRecord> propertyChange = propertyRecords.GetOrLoad(nextProp, primitive);

                // TODO forChanging/forReading piggy-backing
                PropertyRecord propRecord = propertyChange.ForChangingData();
                DeletePropertyRecordIncludingValueRecords(propRecord);
                nextProp           = propRecord.NextProp;
                propRecord.Changed = primitive;
            }
            primitive.NextProp = Record.NO_NEXT_PROPERTY.intValue();
        }
Exemple #5
0
        /// <summary>
        /// Traverses a property record chain and finds the record containing the property with key {@code propertyKey}.
        /// If none is found and {@code strict} is {@code true} then <seealso cref="System.InvalidOperationException"/> is thrown,
        /// otherwise id value of <seealso cref="Record.NO_NEXT_PROPERTY"/> is returned.
        /// </summary>
        /// <param name="primitive"> <seealso cref="PrimitiveRecord"/> which is the owner of the chain. </param>
        /// <param name="propertyKey"> property key token id to look for. </param>
        /// <param name="propertyRecords"> access to records. </param>
        /// <param name="strict"> dictates behavior on property key not found. If {@code true} then <seealso cref="System.InvalidOperationException"/>
        /// is thrown, otherwise value of <seealso cref="Record.NO_NEXT_PROPERTY"/> is returned. </param>
        /// <returns> property record id containing property with the given {@code propertyKey}, otherwise if
        /// {@code strict} is false value of <seealso cref="Record.NO_NEXT_PROPERTY"/>. </returns>
        public virtual long FindPropertyRecordContaining(PrimitiveRecord primitive, int propertyKey, RecordAccess <PropertyRecord, PrimitiveRecord> propertyRecords, bool strict)
        {
            long propertyRecordId = primitive.NextProp;

            while (!Record.NO_NEXT_PROPERTY.@is(propertyRecordId))
            {
                PropertyRecord propertyRecord = propertyRecords.GetOrLoad(propertyRecordId, primitive).forReadingLinkage();
                if (propertyRecord.GetPropertyBlock(propertyKey) != null)
                {
                    return(propertyRecordId);
                }
                propertyRecordId = propertyRecord.NextProp;
            }

            if (strict)
            {
                throw new System.InvalidOperationException("No property record in property chain for " + primitive + " contained property with key " + propertyKey);
            }

            return(Record.NO_NEXT_PROPERTY.intValue());
        }
Exemple #6
0
        public virtual bool AssertPropertyChain(PrimitiveRecord primitive, RecordAccess <PropertyRecord, PrimitiveRecord> propertyRecords)
        {
            IList <PropertyRecord> toCheck = new LinkedList <PropertyRecord>();
            long nextIdToFetch             = primitive.NextProp;

            while (nextIdToFetch != Record.NO_NEXT_PROPERTY.intValue())
            {
                PropertyRecord propRecord = propertyRecords.GetOrLoad(nextIdToFetch, primitive).forReadingLinkage();
                toCheck.Add(propRecord);
                Debug.Assert(propRecord.InUse(), primitive + "->");
                +Arrays.ToString(toCheck.ToArray());
                Debug.Assert(propRecord.Size() <= PropertyType.PayloadSize, propRecord + " size " + propRecord.Size());
                nextIdToFetch = propRecord.NextProp;
            }
            if (toCheck.Count == 0)
            {
                Debug.Assert(primitive.NextProp == Record.NO_NEXT_PROPERTY.intValue(), primitive);
                return(true);
            }
            PropertyRecord first = toCheck[0];
            PropertyRecord last  = toCheck[toCheck.Count - 1];

            Debug.Assert(first.PrevProp == Record.NO_PREVIOUS_PROPERTY.intValue(), primitive + "->");
            +Arrays.ToString(toCheck.ToArray());
            Debug.Assert(last.NextProp == Record.NO_NEXT_PROPERTY.intValue(), primitive + "->");
            +Arrays.ToString(toCheck.ToArray());
            PropertyRecord current;
            PropertyRecord previous = first;

            for (int i = 1; i < toCheck.Count; i++)
            {
                current = toCheck[i];
                Debug.Assert(current.PrevProp == previous.Id, primitive + "->");
                +Arrays.ToString(toCheck.ToArray());
                Debug.Assert(previous.NextProp == current.Id, primitive + "->");
                +Arrays.ToString(toCheck.ToArray());
                previous = current;
            }
            return(true);
        }
Exemple #7
0
        private long CreatePropertyChain(PrimitiveRecord owner, IEnumerator <PropertyBlock> properties, RecordAccess <PropertyRecord, PrimitiveRecord> propertyRecords, System.Action <PropertyRecord> createdPropertyRecords)
        {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            if (properties == null || !properties.hasNext())
            {
                return(Record.NO_NEXT_PROPERTY.intValue());
            }
            PropertyRecord currentRecord = propertyRecords.Create(_propertyRecordIdGenerator.nextId(), owner).forChangingData();

            createdPropertyRecords(currentRecord);
            currentRecord.InUse = true;
            currentRecord.SetCreated();
            PropertyRecord firstRecord = currentRecord;

            while (properties.MoveNext())
            {
                PropertyBlock block = properties.Current;
                if (currentRecord.Size() + block.Size > PropertyType.PayloadSize)
                {
                    // Here it means the current block is done for
                    PropertyRecord prevRecord = currentRecord;
                    // Create new record
                    long propertyId = _propertyRecordIdGenerator.nextId();
                    currentRecord = propertyRecords.Create(propertyId, owner).forChangingData();
                    createdPropertyRecords(currentRecord);
                    currentRecord.InUse = true;
                    currentRecord.SetCreated();
                    // Set up links
                    prevRecord.NextProp    = propertyId;
                    currentRecord.PrevProp = prevRecord.Id;
                    // Now current is ready to start picking up blocks
                }
                currentRecord.AddPropertyBlock(block);
            }
            return(firstRecord.Id);
        }
Exemple #8
0
 public virtual long CreatePropertyChain(PrimitiveRecord owner, IEnumerator <PropertyBlock> properties, RecordAccess <PropertyRecord, PrimitiveRecord> propertyRecords)
 {
     return(CreatePropertyChain(owner, properties, propertyRecords, p =>
     {
     }));
 }
Exemple #9
0
        private void RemoveProperty <P>(RecordAccess_RecordProxy <P, Void> primitiveProxy, int propertyKey, RecordAccess <PropertyRecord, PrimitiveRecord> propertyRecords, PrimitiveRecord primitive, long propertyId) where P : Org.Neo4j.Kernel.impl.store.record.PrimitiveRecord
        {
            RecordAccess_RecordProxy <PropertyRecord, PrimitiveRecord> recordChange = propertyRecords.GetOrLoad(propertyId, primitive);
            PropertyRecord propRecord = recordChange.ForChangingData();

            if (!propRecord.InUse())
            {
                throw new System.InvalidOperationException("Unable to delete property[" + propertyId + "] since it is already deleted.");
            }

            PropertyBlock block = propRecord.RemovePropertyBlock(propertyKey);

            if (block == null)
            {
                throw new System.InvalidOperationException("Property with index[" + propertyKey + "] is not present in property[" + propertyId + "]");
            }

            foreach (DynamicRecord valueRecord in block.ValueRecords)
            {
                Debug.Assert(valueRecord.InUse());
                valueRecord.SetInUse(false, block.Type.intValue());
                propRecord.AddDeletedRecord(valueRecord);
            }
            if (propRecord.Size() > 0)
            {
                /*
                 * There are remaining blocks in the record. We do not unlink yet.
                 */
                propRecord.Changed = primitive;
                Debug.Assert(_traverser.assertPropertyChain(primitive, propertyRecords));
            }
            else
            {
                UnlinkPropertyRecord(propRecord, propertyRecords, primitiveProxy);
            }
        }
        private Command.PropertyCommand Property(PrimitiveRecord owner)
        {
            long propertyId = _nextPropertyId++;

            return(new Command.PropertyCommand(new PropertyRecord(propertyId, owner), new PropertyRecord(propertyId, owner)));
        }