Exemplo n.º 1
0
        public virtual void CreateToken(string name, long id, RecordAccess <R, Void> recordAccess)
        {
            R record = recordAccess.Create(id, null).forChangingData();

            record.InUse = true;
            record.setCreated();
            ICollection <DynamicRecord> nameRecords = _store.allocateNameRecords(encodeString(name));

            record.NameId = ( int )Iterables.first(nameRecords).Id;
            record.addNameRecords(nameRecords);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public virtual RecordAccess_RecordProxy <RelationshipGroupRecord, int> GetOrCreateRelationshipGroup(NodeRecord node, int type, RecordAccess <RelationshipGroupRecord, int> relGroupRecords)
        {
            RelationshipGroupPosition existingGroup = GetRelationshipGroup(node, type, relGroupRecords);
            RecordAccess_RecordProxy <RelationshipGroupRecord, int> change = existingGroup.Group();

            if (change == null)
            {
                Debug.Assert(node.Dense, "Node " + node + " should have been dense at this point");
                long id = _idGenerator.nextId();
                change = relGroupRecords.Create(id, type);
                RelationshipGroupRecord record = change.ForChangingData();
                record.InUse = true;
                record.SetCreated();
                record.OwningNode = node.Id;

                // Attach it...
                RecordAccess_RecordProxy <RelationshipGroupRecord, int> closestPreviousChange = existingGroup.ClosestPrevious();
                if (closestPreviousChange != null)
                {                         // ...after the closest previous one
                    RelationshipGroupRecord closestPrevious = closestPreviousChange.ForChangingLinkage();
                    record.Next          = closestPrevious.Next;
                    record.Prev          = closestPrevious.Id;
                    closestPrevious.Next = id;
                }
                else
                {                         // ...first in the chain
                    long firstGroupId = node.NextRel;
                    if (firstGroupId != Record.NO_NEXT_RELATIONSHIP.intValue())
                    {                              // There are others, make way for this new group
                        RelationshipGroupRecord previousFirstRecord = relGroupRecords.GetOrLoad(firstGroupId, type).forReadingData();
                        record.Next = previousFirstRecord.Id;
                        previousFirstRecord.Prev = id;
                    }
                    node.NextRel = id;
                }
            }
            return(change);
        }
Exemplo n.º 4
0
        public virtual void PrimitiveSetProperty <P>(RecordAccess_RecordProxy <P, Void> primitiveRecordChange, int propertyKey, Value value, RecordAccess <PropertyRecord, PrimitiveRecord> propertyRecords) where P : Org.Neo4j.Kernel.impl.store.record.PrimitiveRecord
        {
            PropertyBlock block     = EncodePropertyValue(propertyKey, value);
            P             primitive = primitiveRecordChange.ForReadingLinkage();

            Debug.Assert(_traverser.assertPropertyChain(primitive, propertyRecords));
            int newBlockSizeInBytes = block.Size;

            // Traverse the existing property chain. Tracking two things along the way:
            // - (a) Free space for this block (candidateHost)
            // - (b) Existence of a block with the property key
            // Chain traversal can be aborted only if:
            // - (1) (b) occurs and new property block fits where the current is
            // - (2) (a) occurs and (b) has occurred, but new property block didn't fit
            // - (3) (b) occurs and (a) has occurred
            // - (4) Chain ends
            RecordAccess_RecordProxy <PropertyRecord, PrimitiveRecord> freeHostProxy     = null;
            RecordAccess_RecordProxy <PropertyRecord, PrimitiveRecord> existingHostProxy = null;
            long prop = primitive.NextProp;

            while (prop != Record.NO_NEXT_PROPERTY.intValue())                 // <-- (4)
            {
                RecordAccess_RecordProxy <PropertyRecord, PrimitiveRecord> proxy = propertyRecords.GetOrLoad(prop, primitive);
                PropertyRecord propRecord = proxy.ForReadingLinkage();
                Debug.Assert(propRecord.InUse(), propRecord);

                // (a) search for free space
                if (PropertyFitsInside(newBlockSizeInBytes, propRecord))
                {
                    freeHostProxy = proxy;
                    if (existingHostProxy != null)
                    {
                        // (2)
                        PropertyRecord freeHost = proxy.ForChangingData();
                        freeHost.AddPropertyBlock(block);
                        freeHost.Changed = primitive;
                        Debug.Assert(_traverser.assertPropertyChain(primitive, propertyRecords));
                        return;
                    }
                }

                // (b) search for existence of property key
                PropertyBlock existingBlock = propRecord.GetPropertyBlock(propertyKey);
                if (existingBlock != null)
                {
                    // We found an existing property and whatever happens we have to remove the existing
                    // block so that we can add the new one, where ever we decide to place it
                    existingHostProxy = proxy;
                    PropertyRecord existingHost = existingHostProxy.ForChangingData();
                    RemoveProperty(primitive, existingHost, existingBlock);

                    // Now see if we at this point can add the new block
                    if (newBlockSizeInBytes <= existingBlock.Size || PropertyFitsInside(newBlockSizeInBytes, existingHost))                                  // fallback check
                    {
                        // (1) yes we could add it right into the host of the existing block
                        existingHost.AddPropertyBlock(block);
                        Debug.Assert(_traverser.assertPropertyChain(primitive, propertyRecords));
                        return;
                    }
                    else if (freeHostProxy != null)
                    {
                        // (3) yes we could add it to a previously found host with sufficiently free space in it
                        PropertyRecord freeHost = freeHostProxy.ForChangingData();
                        freeHost.AddPropertyBlock(block);
                        freeHost.Changed = primitive;
                        Debug.Assert(_traverser.assertPropertyChain(primitive, propertyRecords));
                        return;
                    }
                    // else we can't add it at this point
                }

                // Continue down the chain
                prop = propRecord.NextProp;
            }

            // At this point we haven't added the property block, although we may have found room for it
            // along the way. If we didn't then just create a new record, it's fine
            PropertyRecord freeHost;

            if (freeHostProxy == null)
            {
                // We couldn't find free space along the way, so create a new host record
                freeHost       = propertyRecords.Create(_propertyRecordIdGenerator.nextId(), primitive).forChangingData();
                freeHost.InUse = true;
                if (primitive.NextProp != Record.NO_NEXT_PROPERTY.intValue())
                {
                    // This isn't the first property record for the entity, re-shuffle the first one so that
                    // the new one becomes the first
                    PropertyRecord prevProp = propertyRecords.GetOrLoad(primitive.NextProp, primitive).forChangingLinkage();
                    Debug.Assert(prevProp.PrevProp == Record.NO_PREVIOUS_PROPERTY.intValue());
                    prevProp.PrevProp = freeHost.Id;
                    freeHost.NextProp = prevProp.Id;
                    prevProp.Changed  = primitive;
                }

                // By the way, this is the only condition where the primitive record also needs to change
                primitiveRecordChange.ForChangingLinkage().NextProp = freeHost.Id;
            }
            else
            {
                freeHost = freeHostProxy.ForChangingData();
            }

            // At this point we know that we have a host record with sufficient space in it for the block
            // to add, so simply add it
            freeHost.AddPropertyBlock(block);
            Debug.Assert(_traverser.assertPropertyChain(primitive, propertyRecords));
        }