public override ByteBuffer GetKeyBytes() { var keyWriter = new ByteBufferWriter(); keyWriter.WriteBlock(KeyBytes.Buffer, KeyBytes.Offset + ObjectDB.AllRelationsPKPrefix.Length, KeyBytes.Length - ObjectDB.AllRelationsPKPrefix.Length); keyWriter.WriteBlock(base.GetKeyBytes()); return(keyWriter.Data); }
protected virtual TValue CreateInstance(ByteBuffer prefixKeyBytes, ByteBuffer keyBytes) { var writer = new ByteBufferWriter(); writer.WriteBlock(_keyBytes.Buffer, _keyBytes.Offset + _lengthOfNonDataPrefix, _keyBytes.Length - _lengthOfNonDataPrefix); writer.WriteBlock(keyBytes); return((TValue)_manipulator.RelationInfo.CreateInstance(_tr, writer.Data, _keyValueTr.GetValue(), false)); }
protected override T CreateInstance(ByteBuffer keyBytes, ByteBuffer valueBytes) { var keyWriter = new ByteBufferWriter(); keyWriter.WriteBlock(KeyBytes.Buffer, KeyBytes.Offset + _skipBytes, KeyBytes.Length - _skipBytes); keyWriter.WriteBlock(keyBytes); return((T)RelationInfo.CreateInstance(Transaction, keyWriter.Data, valueBytes, false)); }
public IEnumerator <T> FindBySecondaryKey(uint secondaryKeyIndex, uint prefixFieldCount, ByteBuffer secKeyBytes) { var keyWriter = new ByteBufferWriter(); keyWriter.WriteBlock(secKeyBytes); return(new RelationSecondaryKeyEnumerator <T>(_transaction, _relationInfo, keyWriter.Data.ToAsyncSafe(), secondaryKeyIndex, prefixFieldCount, this)); }
void DeleteSecondaryKey(IKeyValueDBTransaction keyValueTr, uint prevIdx) { var writer = new ByteBufferWriter(); writer.WriteBlock(ObjectDB.AllRelationsSKPrefix); writer.WriteVUInt32(Id); writer.WriteVUInt32(prevIdx); keyValueTr.SetKeyPrefix(writer.Data); keyValueTr.EraseAll(); }
public int RemoveByKeyPrefixWithoutIterate(ByteBuffer keyBytesPrefix) { if (_hasSecondaryIndexes) { //keyBytePrefix contains [Index Relation, Primary key prefix] we need // [Index Relation, Secondary Key Index, Primary key prefix] int idBytesLength = ObjectDB.AllRelationsPKPrefix.Length + PackUnpack.LengthVUInt(_relationInfo.Id); var writer = new ByteBufferWriter(); foreach (var secKey in _relationInfo.ClientRelationVersionInfo.SecondaryKeys) { writer.WriteBlock(ObjectDB.AllRelationsSKPrefix); writer.WriteVUInt32(_relationInfo.Id); writer.WriteVUInt32(secKey.Key); writer.WriteBlock(keyBytesPrefix.Buffer, idBytesLength, keyBytesPrefix.Length - idBytesLength); _transaction.KeyValueDBTransaction.SetKeyPrefix(writer.Data); _transaction.KeyValueDBTransaction.EraseAll(); writer.Reset(); } } return(RemovePrimaryKeysByPrefix(keyBytesPrefix)); }
void SerializeIntoBuffer(object metadata, IReadOnlyList <object> events, out int startOffset, out IDescriptorSerializerContext serializerContext, out BlockType blockType, out int lenWithoutEndPadding, out ByteBuffer block) { startOffset = (int)EndBufferLen + HeaderSize; var writer = new ByteBufferWriter(); writer.WriteBlock(_zeroes.AsSpan(0, startOffset)); serializerContext = Mapping; if (metadata != null) { serializerContext = serializerContext.StoreNewDescriptors(writer, metadata); } if (events != null) { foreach (var o in events) { serializerContext = serializerContext.StoreNewDescriptors(writer, o); } if (events.Count == 0) { events = null; } } serializerContext.FinishNewDescriptors(writer); blockType = BlockType.FirstBlock; if (serializerContext.SomeTypeStored) { blockType |= BlockType.HasTypeDeclaration; } if (metadata != null) { serializerContext.StoreObject(writer, metadata); blockType |= BlockType.HasMetadata; } if (events != null) { if (events.Count == 1) { serializerContext.StoreObject(writer, events[0]); blockType |= BlockType.HasOneEvent; } else { writer.WriteVUInt32((uint)events.Count); foreach (var o in events) { serializerContext.StoreObject(writer, o); } blockType |= BlockType.HasMoreEvents; } } lenWithoutEndPadding = (int)writer.GetCurrentPosition(); writer.WriteBlock(_zeroes.AsSpan(0, (int)(SectorSize - 1))); block = writer.Data; if (CompressionStrategy.ShouldTryToCompress(lenWithoutEndPadding - startOffset)) { var compressedBlock = ByteBuffer.NewSync(block.Buffer, startOffset, lenWithoutEndPadding - startOffset); if (CompressionStrategy.Compress(ref compressedBlock)) { blockType |= BlockType.Compressed; Array.Copy(compressedBlock.Buffer, compressedBlock.Offset, block.Buffer, startOffset, compressedBlock.Length); lenWithoutEndPadding = startOffset + compressedBlock.Length; Array.Copy(_zeroes, 0, block.Buffer, lenWithoutEndPadding, (int)SectorSize - 1); } } }