//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldIterateOverBlocks() public virtual void ShouldIterateOverBlocks() { // GIVEN PropertyRecord record = new PropertyRecord(0); PropertyBlock[] blocks = new PropertyBlock[3]; for (int i = 0; i < blocks.Length; i++) { blocks[i] = new PropertyBlock(); record.AddPropertyBlock(blocks[i]); } // WHEN IEnumerator <PropertyBlock> iterator = record.GetEnumerator(); // THEN foreach (PropertyBlock block in blocks) { //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue(iterator.hasNext()); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertEquals(block, iterator.next()); } //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertFalse(iterator.hasNext()); }
public static PropertyCommand CreateProperty(long id, PropertyType type, int key, params long[] valueRecordIds) { PropertyRecord record = new PropertyRecord(id); record.InUse = true; record.SetCreated(); PropertyBlock block = new PropertyBlock(); if (valueRecordIds.Length == 0) { PropertyStore.encodeValue(block, key, Values.of(123), null, null, true); } else { PropertyStore.setSingleBlockValue(block, key, type, valueRecordIds[0]); block.ValueRecords = DynamicRecords(valueRecordIds); } record.AddPropertyBlock(block); return(new PropertyCommand(new PropertyRecord(id), record)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldBeAbleToRemoveBlocksDuringIteration() public virtual void ShouldBeAbleToRemoveBlocksDuringIteration() { // GIVEN PropertyRecord record = new PropertyRecord(0); ISet <PropertyBlock> blocks = new HashSet <PropertyBlock>(); for (int i = 0; i < 4; i++) { PropertyBlock block = new PropertyBlock(); record.AddPropertyBlock(block); blocks.Add(block); } // WHEN IEnumerator <PropertyBlock> iterator = record.GetEnumerator(); AssertIteratorRemoveThrowsIllegalState(iterator); // THEN int size = blocks.Count; for (int i = 0; i < size; i++) { //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue(iterator.hasNext()); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: PropertyBlock block = iterator.next(); if (i % 2 == 1) { //JAVA TO C# CONVERTER TODO TASK: .NET enumerators are read-only: iterator.remove(); AssertIteratorRemoveThrowsIllegalState(iterator); blocks.remove(block); } } //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertFalse(iterator.hasNext()); // and THEN there should only be the non-removed blocks left assertEquals(blocks, Iterables.asSet(record)); }
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); }
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); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private org.neo4j.kernel.impl.store.record.PropertyRecord readPropertyRecord(long id, org.neo4j.storageengine.api.ReadableChannel channel) throws java.io.IOException private PropertyRecord ReadPropertyRecord(long id, ReadableChannel channel) { // in_use(byte)+type(int)+key_indexId(int)+prop_blockId(long)+ // prev_prop_id(long)+next_prop_id(long) PropertyRecord record = new PropertyRecord(id); sbyte flags = channel.Get(); // 1 bool inUse = bitFlag(flags, Record.IN_USE.byteValue()); bool nodeProperty = !bitFlag(flags, Record.REL_PROPERTY.byteValue()); bool requireSecondaryUnit = bitFlag(flags, Record.REQUIRE_SECONDARY_UNIT); bool hasSecondaryUnit = bitFlag(flags, Record.HAS_SECONDARY_UNIT); bool usesFixedReferenceFormat = bitFlag(flags, Record.USES_FIXED_REFERENCE_FORMAT); record.RequiresSecondaryUnit = requireSecondaryUnit; record.UseFixedReferences = usesFixedReferenceFormat; long nextProp = channel.Long; // 8 long prevProp = channel.Long; // 8 record.NextProp = nextProp; record.PrevProp = prevProp; long primitiveId = channel.Long; // 8 if (primitiveId != -1 && nodeProperty) { record.NodeId = primitiveId; } else if (primitiveId != -1) { record.RelId = primitiveId; } if (hasSecondaryUnit) { record.SecondaryUnitId = channel.Long; } int nrPropBlocks = channel.Get(); Debug.Assert(nrPropBlocks >= 0); if (nrPropBlocks > 0) { record.InUse = true; } while (nrPropBlocks-- > 0) { PropertyBlock block = ReadPropertyBlock(channel); if (block == null) { return(null); } record.AddPropertyBlock(block); } int deletedRecords = ReadDynamicRecords(channel, record, PROPERTY_DELETED_DYNAMIC_RECORD_ADDER); if (deletedRecords == -1) { return(null); } Debug.Assert(deletedRecords >= 0); while (deletedRecords-- > 0) { DynamicRecord read = ReadDynamicRecord(channel); if (read == null) { return(null); } record.AddDeletedRecord(read); } if ((inUse && !record.InUse()) || (!inUse && record.InUse())) { throw new System.InvalidOperationException("Weird, inUse was read in as " + inUse + " but the record is " + record); } return(record); }
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)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private org.neo4j.kernel.impl.store.record.PropertyRecord readPropertyRecord(long id, org.neo4j.storageengine.api.ReadableChannel channel) throws java.io.IOException private PropertyRecord ReadPropertyRecord(long id, ReadableChannel channel) { // in_use(byte)+type(int)+key_indexId(int)+prop_blockId(long)+ // prev_prop_id(long)+next_prop_id(long) PropertyRecord record = new PropertyRecord(id); sbyte inUseFlag = channel.Get(); // 1 long nextProp = channel.Long; // 8 long prevProp = channel.Long; // 8 record.NextProp = nextProp; record.PrevProp = prevProp; bool inUse = false; if ((inUseFlag & Record.IN_USE.byteValue()) == Record.IN_USE.byteValue()) { inUse = true; } bool nodeProperty = true; if ((inUseFlag & Record.REL_PROPERTY.byteValue()) == Record.REL_PROPERTY.byteValue()) { nodeProperty = false; } long primitiveId = channel.Long; // 8 if (primitiveId != -1 && nodeProperty) { record.NodeId = primitiveId; } else if (primitiveId != -1) { record.RelId = primitiveId; } int nrPropBlocks = channel.Get(); Debug.Assert(nrPropBlocks >= 0); if (nrPropBlocks > 0) { record.InUse = true; } while (nrPropBlocks-- > 0) { PropertyBlock block = ReadPropertyBlock(channel); if (block == null) { return(null); } record.AddPropertyBlock(block); } int deletedRecords = ReadDynamicRecords(channel, record, PROPERTY_DELETED_DYNAMIC_RECORD_ADDER); if (deletedRecords == -1) { return(null); } Debug.Assert(deletedRecords >= 0); while (deletedRecords-- > 0) { DynamicRecord read = ReadDynamicRecord(channel); if (read == null) { return(null); } record.AddDeletedRecord(read); } if ((inUse && !record.InUse()) || (!inUse && record.InUse())) { throw new System.InvalidOperationException("Weird, inUse was read in as " + inUse + " but the record is " + record); } return(record); }