Example #1
0
        public static void EncodeValue(PropertyBlock block, int keyId, Value value, DynamicRecordAllocator stringAllocator, DynamicRecordAllocator arrayAllocator, bool allowStorePointsAndTemporal)
        {
            if (value is ArrayValue)
            {
                object asObject = value.AsObject();

                // Try short array first, i.e. inlined in the property block
                if (ShortArray.encode(keyId, asObject, block, PropertyType.PayloadSize))
                {
                    return;
                }

                // Fall back to dynamic array store
                IList <DynamicRecord> arrayRecords = new List <DynamicRecord>();
                AllocateArrayRecords(arrayRecords, asObject, arrayAllocator, allowStorePointsAndTemporal);
                SetSingleBlockValue(block, keyId, PropertyType.Array, Iterables.first(arrayRecords).Id);
                foreach (DynamicRecord valueRecord in arrayRecords)
                {
                    valueRecord.SetType(PropertyType.Array.intValue());
                }
                block.ValueRecords = arrayRecords;
            }
            else
            {
                value.WriteTo(new PropertyBlockValueWriter(block, keyId, stringAllocator, allowStorePointsAndTemporal));
            }
        }
Example #2
0
 internal PropertyBlockValueWriter(PropertyBlock block, int keyId, DynamicRecordAllocator stringAllocator, bool allowStorePointsAndTemporal)
 {
     this.Block                       = block;
     this.KeyId                       = keyId;
     this.StringAllocator             = stringAllocator;
     this.AllowStorePointsAndTemporal = allowStorePointsAndTemporal;
 }
Example #3
0
 internal PropertyCreator(DynamicRecordAllocator stringRecordAllocator, DynamicRecordAllocator arrayRecordAllocator, IdSequence propertyRecordIdGenerator, PropertyTraverser traverser, bool allowStorePointsAndTemporal)
 {
     this._stringRecordAllocator     = stringRecordAllocator;
     this._arrayRecordAllocator      = arrayRecordAllocator;
     this._propertyRecordIdGenerator = propertyRecordIdGenerator;
     this._traverser = traverser;
     this._allowStorePointsAndTemporal = allowStorePointsAndTemporal;
 }
Example #4
0
 public PropertyValueRecordSizeCalculator(int propertyRecordSize, int stringRecordSize, int stringRecordDataSize, int arrayRecordSize, int arrayRecordDataSize)
 {
     this._propertyRecordSize  = propertyRecordSize;
     this._stringRecordSize    = stringRecordSize;
     this._arrayRecordSize     = arrayRecordSize;
     this._stringRecordCounter = new StandardDynamicRecordAllocator(_stringRecordIds, stringRecordDataSize);
     this._arrayRecordCounter  = new StandardDynamicRecordAllocator(_arrayRecordIds, arrayRecordDataSize);
 }
Example #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void allocateReusableRecordsAndSwitchToDefaultWhenExhausted()
        public virtual void AllocateReusableRecordsAndSwitchToDefaultWhenExhausted()
        {
            DynamicRecord          dynamicRecord1  = new DynamicRecord(1);
            DynamicRecord          dynamicRecord2  = new DynamicRecord(2);
            DynamicRecordAllocator recordAllocator = mock(typeof(DynamicRecordAllocator));

            Mockito.when(recordAllocator.NextRecord()).thenReturn(dynamicRecord2);
            ReusableRecordsCompositeAllocator compositeAllocator = new ReusableRecordsCompositeAllocator(singletonList(dynamicRecord1), recordAllocator);

            assertSame("Same as pre allocated record.", dynamicRecord1, compositeAllocator.NextRecord());
            assertSame("Same as expected allocated record.", dynamicRecord2, compositeAllocator.NextRecord());
        }
Example #6
0
 protected internal EntityImporter(BatchingNeoStores stores, Monitor monitor)
 {
     this._propertyStore = stores.PropertyStore;
     this._propertyKeyTokenRepository = stores.PropertyKeyRepository;
     this.Monitor = monitor;
     for (int i = 0; i < _propertyBlocks.Length; i++)
     {
         _propertyBlocks[i] = new PropertyBlock();
     }
     this._propertyRecord = _propertyStore.newRecord();
     this._propertyIds    = new BatchingIdGetter(_propertyStore);
     this._dynamicStringRecordAllocator = new StandardDynamicRecordAllocator(new BatchingIdGetter(_propertyStore.StringStore, _propertyStore.StringStore.RecordsPerPage), _propertyStore.StringStore.RecordDataSize);
     this._dynamicArrayRecordAllocator  = new StandardDynamicRecordAllocator(new BatchingIdGetter(_propertyStore.ArrayStore, _propertyStore.ArrayStore.RecordsPerPage), _propertyStore.StringStore.RecordDataSize);
 }
Example #7
0
 private static void AllocateStringRecords(ICollection <DynamicRecord> target, sbyte[] chars, DynamicRecordAllocator allocator)
 {
     AbstractDynamicStore.AllocateRecordsFromBytes(target, chars, allocator);
 }
Example #8
0
 private static void AllocateArrayRecords(ICollection <DynamicRecord> target, object array, DynamicRecordAllocator allocator, bool allowStorePoints)
 {
     DynamicArrayStore.AllocateRecords(target, array, allocator, allowStorePoints);
 }
Example #9
0
        internal static ICollection <DynamicRecord> PutSorted(NodeRecord node, long[] labelIds, NodeStore nodeStore, DynamicRecordAllocator allocator)
        {
            long existingLabelsField = node.LabelField;
            long existingLabelsBits  = parseLabelsBody(existingLabelsField);

            ICollection <DynamicRecord> changedDynamicRecords = node.DynamicLabelRecords;

            long labelField = node.LabelField;

            if (fieldPointsToDynamicRecordOfLabels(labelField))
            {
                // There are existing dynamic label records, get them
                nodeStore.EnsureHeavy(node, existingLabelsBits);
                changedDynamicRecords = node.DynamicLabelRecords;
                NotInUse = changedDynamicRecords;
            }

            if (!InlineNodeLabels.TryInlineInNodeRecord(node, labelIds, changedDynamicRecords))
            {
                IEnumerator <DynamicRecord> recycledRecords  = changedDynamicRecords.GetEnumerator();
                ICollection <DynamicRecord> allocatedRecords = AllocateRecordsForDynamicLabels(node.Id, labelIds, new ReusableRecordsCompositeAllocator(recycledRecords, allocator));
                // Set the rest of the previously set dynamic records as !inUse
                while (recycledRecords.MoveNext())
                {
                    DynamicRecord removedRecord = recycledRecords.Current;
                    removedRecord.InUse = false;
                    allocatedRecords.Add(removedRecord);
                }
                node.SetLabelField(DynamicPointer(allocatedRecords), allocatedRecords);
                changedDynamicRecords = allocatedRecords;
            }

            return(changedDynamicRecords);
        }
Example #10
0
        public static ICollection <DynamicRecord> AllocateRecordsForDynamicLabels(long nodeId, long[] labels, DynamicRecordAllocator allocator)
        {
            long[] storedLongs = LabelIdArray.PrependNodeId(nodeId, labels);
            ICollection <DynamicRecord> records = new List <DynamicRecord>();

            // since we can't store points in long array we passing false as possibility to store points
            DynamicArrayStore.AllocateRecords(records, storedLongs, allocator, false);
            return(records);
        }
 public ReusableRecordsCompositeAllocator(ICollection <DynamicRecord> records, DynamicRecordAllocator recordAllocator) : this(records.GetEnumerator(), recordAllocator)
 {
 }
 public ReusableRecordsCompositeAllocator(IEnumerator <DynamicRecord> recordsIterator, DynamicRecordAllocator recordAllocator)
 {
     this._reusableRecordsAllocator = new ReusableRecordsAllocator(recordAllocator.RecordDataSize, recordsIterator);
     this._recordAllocator          = recordAllocator;
 }
Example #13
0
        public static ICollection <DynamicRecord> PutSorted(NodeRecord node, long[] labelIds, NodeStore nodeStore, DynamicRecordAllocator allocator)
        {
            if (TryInlineInNodeRecord(node, labelIds, node.DynamicLabelRecords))
            {
                return(Collections.emptyList());
            }

            return(DynamicNodeLabels.PutSorted(node, labelIds, nodeStore, allocator));
        }
Example #14
0
        public override ICollection <DynamicRecord> Add(long labelId, NodeStore nodeStore, DynamicRecordAllocator allocator)
        {
            long[] augmentedLabelIds = LabelCount(_node.LabelField) == 0 ? new long[] { labelId } : concatAndSort(ParseInlined(_node.LabelField), labelId);

            return(PutSorted(_node, augmentedLabelIds, nodeStore, allocator));
        }
Example #15
0
        public override ICollection <DynamicRecord> Add(long labelId, NodeStore nodeStore, DynamicRecordAllocator allocator)
        {
            nodeStore.EnsureHeavy(_node, firstDynamicLabelRecordId(_node.LabelField));
            long[] existingLabelIds = GetDynamicLabelsArray(_node.UsedDynamicLabelRecords, nodeStore.DynamicLabelStore);
            long[] newLabelIds      = LabelIdArray.ConcatAndSort(existingLabelIds, labelId);
            ICollection <DynamicRecord> existingRecords       = _node.DynamicLabelRecords;
            ICollection <DynamicRecord> changedDynamicRecords = AllocateRecordsForDynamicLabels(_node.Id, newLabelIds, new ReusableRecordsCompositeAllocator(existingRecords, allocator));

            _node.setLabelField(DynamicPointer(changedDynamicRecords), changedDynamicRecords);
            return(changedDynamicRecords);
        }
Example #16
0
 public static void AllocateFromNumbers(ICollection <DynamicRecord> target, object array, DynamicRecordAllocator recordAllocator)
 {
     sbyte[] bytes = EncodeFromNumbers(array, 0);
     AllocateRecordsFromBytes(target, bytes, recordAllocator);
 }
Example #17
0
        public static void AllocateRecords(ICollection <DynamicRecord> target, object array, DynamicRecordAllocator recordAllocator, bool allowStorePointsAndTemporal)
        {
            if (!array.GetType().IsArray)
            {
                throw new System.ArgumentException(array + " not an array");
            }

            Type type = array.GetType().GetElementType();

            if (type.Equals(typeof(string)))
            {
                AllocateFromString(target, ( string[] )array, recordAllocator);
            }
            else if (type.Equals(typeof(PointValue)))
            {
                AllocateFromCompositeType(target, GeometryType.encodePointArray(( PointValue[] )array), recordAllocator, allowStorePointsAndTemporal, Capability.POINT_PROPERTIES);
            }
            else if (type.Equals(typeof(LocalDate)))
            {
                AllocateFromCompositeType(target, TemporalType.encodeDateArray(( LocalDate[] )array), recordAllocator, allowStorePointsAndTemporal, Capability.TEMPORAL_PROPERTIES);
            }
            else if (type.Equals(typeof(LocalTime)))
            {
                AllocateFromCompositeType(target, TemporalType.encodeLocalTimeArray(( LocalTime[] )array), recordAllocator, allowStorePointsAndTemporal, Capability.TEMPORAL_PROPERTIES);
            }
            else if (type.Equals(typeof(DateTime)))
            {
                AllocateFromCompositeType(target, TemporalType.encodeLocalDateTimeArray(( DateTime[] )array), recordAllocator, allowStorePointsAndTemporal, Capability.TEMPORAL_PROPERTIES);
            }
            else if (type.Equals(typeof(OffsetTime)))
            {
                AllocateFromCompositeType(target, TemporalType.encodeTimeArray(( OffsetTime[] )array), recordAllocator, allowStorePointsAndTemporal, Capability.TEMPORAL_PROPERTIES);
            }
            else if (type.Equals(typeof(ZonedDateTime)))
            {
                AllocateFromCompositeType(target, TemporalType.encodeDateTimeArray(( ZonedDateTime[] )array), recordAllocator, allowStorePointsAndTemporal, Capability.TEMPORAL_PROPERTIES);
            }
            else if (type.Equals(typeof(DurationValue)))
            {
                AllocateFromCompositeType(target, TemporalType.encodeDurationArray(( DurationValue[] )array), recordAllocator, allowStorePointsAndTemporal, Capability.TEMPORAL_PROPERTIES);
            }
            else
            {
                AllocateFromNumbers(target, array, recordAllocator);
            }
        }
Example #18
0
        private static void AllocateFromString(ICollection <DynamicRecord> target, string[] array, DynamicRecordAllocator recordAllocator)
        {
            sbyte[][] stringsAsBytes     = new sbyte[array.Length][];
            int       totalBytesRequired = STRING_HEADER_SIZE;         // 1b type + 4b array length

            for (int i = 0; i < array.Length; i++)
            {
                string  @string = array[i];
                sbyte[] bytes   = PropertyStore.EncodeString(@string);
                stringsAsBytes[i]   = bytes;
                totalBytesRequired += 4 + bytes.Length;
            }

            ByteBuffer buf = ByteBuffer.allocate(totalBytesRequired);

            buf.put(PropertyType.String.byteValue());
            buf.putInt(array.Length);
            foreach (sbyte[] stringAsBytes in stringsAsBytes)
            {
                buf.putInt(stringAsBytes.Length);
                buf.put(stringAsBytes);
            }
            AllocateRecordsFromBytes(target, buf.array(), recordAllocator);
        }
Example #19
0
 private static void AllocateFromCompositeType(ICollection <DynamicRecord> target, sbyte[] bytes, DynamicRecordAllocator recordAllocator, bool allowsStorage, Capability storageCapability)
 {
     if (allowsStorage)
     {
         AllocateRecordsFromBytes(target, bytes, recordAllocator);
     }
     else
     {
         throw new UnsupportedFormatCapabilityException(storageCapability);
     }
 }
Example #20
0
 public override ICollection <DynamicRecord> Put(long[] labelIds, NodeStore nodeStore, DynamicRecordAllocator allocator)
 {
     Arrays.sort(labelIds);
     return(PutSorted(_node, labelIds, nodeStore, allocator));
 }
Example #21
0
        public static void AllocateRecordsFromBytes(ICollection <DynamicRecord> recordList, sbyte[] src, DynamicRecordAllocator dynamicRecordAllocator)
        {
            Debug.Assert(src != null, "Null src argument");
            DynamicRecord nextRecord = dynamicRecordAllocator.NextRecord();
            int           srcOffset  = 0;
            int           dataSize   = dynamicRecordAllocator.RecordDataSize;

            do
            {
                DynamicRecord record = nextRecord;
                record.StartRecord = srcOffset == 0;
                if (src.Length - srcOffset > dataSize)
                {
                    sbyte[] data = new sbyte[dataSize];
                    Array.Copy(src, srcOffset, data, 0, dataSize);
                    record.Data      = data;
                    nextRecord       = dynamicRecordAllocator.NextRecord();
                    record.NextBlock = nextRecord.Id;
                    srcOffset       += dataSize;
                }
                else
                {
                    sbyte[] data = new sbyte[src.Length - srcOffset];
                    Array.Copy(src, srcOffset, data, 0, data.Length);
                    record.Data      = data;
                    nextRecord       = null;
                    record.NextBlock = Record.NO_NEXT_BLOCK.intValue();
                }
                recordList.Add(record);
                Debug.Assert(record.Data != null);
            } while (nextRecord != null);
        }