コード例 #1
0
ファイル: PropertyCreator.cs プロジェクト: Neo4Net/Neo4Net
        private bool PropertyFitsInside(int newBlockSizeInBytes, PropertyRecord propRecord)
        {
            int propSize = propRecord.Size();

            Debug.Assert(propSize >= 0, propRecord);
            return(propSize + newBlockSizeInBytes <= PropertyType.PayloadSize);
        }
コード例 #2
0
        protected internal virtual long CreateAndWritePropertyChain()
        {
            if (_hasPropertyId)
            {
                return(_propertyId);
            }

            if (_propertyBlocksCursor == 0)
            {
                return(Record.NO_NEXT_PROPERTY.longValue());
            }

            PropertyRecord currentRecord = PropertyRecord(_propertyIds.next());
            long           firstRecordId = currentRecord.Id;

            for (int i = 0; i < _propertyBlocksCursor; i++)
            {
                PropertyBlock block = _propertyBlocks[i];
                if (currentRecord.Size() + block.Size > PropertyType.PayloadSize)
                {
                    // This record is full or couldn't fit this block, write it to property store
                    long nextPropertyId = _propertyIds.next();
                    long prevId         = currentRecord.Id;
                    currentRecord.NextProp = nextPropertyId;
                    _propertyStore.updateRecord(currentRecord);
                    currentRecord          = PropertyRecord(nextPropertyId);
                    currentRecord.PrevProp = prevId;
                }

                // Add this block, there's room for it
                currentRecord.AddPropertyBlock(block);
            }

            if (currentRecord.Size() > 0)
            {
                _propertyStore.updateRecord(currentRecord);
            }

            return(firstRecordId);
        }
コード例 #3
0
ファイル: PropertyDeleter.cs プロジェクト: Neo4Net/Neo4Net
        private void UnlinkPropertyRecord <P>(PropertyRecord propRecord, RecordAccess <PropertyRecord, PrimitiveRecord> propertyRecords, RecordAccess_RecordProxy <P, Void> primitiveRecordChange) where P : Org.Neo4j.Kernel.impl.store.record.PrimitiveRecord
        {
            P primitive = primitiveRecordChange.ForReadingLinkage();

            Debug.Assert(_traverser.assertPropertyChain(primitive, propertyRecords));
            Debug.Assert(propRecord.Size() == 0);
            long prevProp = propRecord.PrevProp;
            long nextProp = propRecord.NextProp;

            if (primitive.NextProp == propRecord.Id)
            {
                Debug.Assert(propRecord.PrevProp == Record.NO_PREVIOUS_PROPERTY.intValue(), propRecord + " for ");
                +primitive;
                primitiveRecordChange.ForChangingLinkage().NextProp = nextProp;
            }
            if (prevProp != Record.NO_PREVIOUS_PROPERTY.intValue())
            {
                PropertyRecord prevPropRecord = propertyRecords.GetOrLoad(prevProp, primitive).forChangingLinkage();
                Debug.Assert(prevPropRecord.InUse(), prevPropRecord + "->" + propRecord + " for " + primitive);
                prevPropRecord.NextProp = nextProp;
                prevPropRecord.Changed  = primitive;
            }
            if (nextProp != Record.NO_NEXT_PROPERTY.intValue())
            {
                PropertyRecord nextPropRecord = propertyRecords.GetOrLoad(nextProp, primitive).forChangingLinkage();
                Debug.Assert(nextPropRecord.InUse(), propRecord + "->" + nextPropRecord + " for " + primitive);
                nextPropRecord.PrevProp = prevProp;
                nextPropRecord.Changed  = primitive;
            }
            propRecord.InUse = false;

            /*
             *  The following two are not needed - the above line does all the work (PropertyStore
             *  does not write out the prev/next for !inUse records). It is nice to set this
             *  however to check for consistency when assertPropertyChain().
             */
            propRecord.PrevProp = Record.NO_PREVIOUS_PROPERTY.intValue();
            propRecord.NextProp = Record.NO_NEXT_PROPERTY.intValue();
            propRecord.Changed  = primitive;
            Debug.Assert(_traverser.assertPropertyChain(primitive, propertyRecords));
        }
コード例 #4
0
ファイル: PropertyTraverser.cs プロジェクト: Neo4Net/Neo4Net
        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);
        }
コード例 #5
0
ファイル: PropertyCreator.cs プロジェクト: Neo4Net/Neo4Net
        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);
        }
コード例 #6
0
ファイル: PropertyDeleter.cs プロジェクト: Neo4Net/Neo4Net
        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);
            }
        }