private object WriteAndRead(object obj) { var imaginativeID = 500; var @ref = new ObjectReference(ClassMetadataForObject(obj), imaginativeID ); @ref.SetObject(obj); var marshallingContext = new MarshallingContext(Trans(), @ref, Container ().UpdateDepthProvider().ForDepth(int.MaxValue), true); Handlers4.Write(@ref.ClassMetadata().TypeHandler(), marshallingContext, obj); var pointer = marshallingContext.AllocateSlot(); var buffer = marshallingContext.ToWriteBuffer(pointer); buffer.Seek(0); // String str = new String(buffer._buffer); // System.out.println(str); var unmarshallingContext = new UnmarshallingContext(Trans(), @ref , Const4.AddToIdTree, false); unmarshallingContext.Buffer(buffer); unmarshallingContext.ActivationDepth(new LegacyActivationDepth(5)); return unmarshallingContext.Read(); }
public virtual void WriteUpdate(Db4objects.Db4o.Internal.Transaction transaction, IUpdateDepth updatedepth) { ContinueSet(transaction, updatedepth); // make sure, a concurrent new, possibly triggered by objectOnNew // is written to the file // preventing recursive if (!BeginProcessing()) { return; } object obj = GetObject(); if (!ObjectCanUpdate(transaction, obj) || !IsActive() || obj == null || !ClassMetadata ().IsModified(obj)) { EndProcessing(); return; } MarshallingContext context = new MarshallingContext(transaction, this, updatedepth , false); if (context.UpdateDepth().Negative()) { EndProcessing(); return; } ObjectContainerBase container = transaction.Container(); LogEvent(container, "update", Const4.State); SetStateClean(); context.PurgeFieldIndexEntriesOnUpdate(transaction, container._handlers.ArrayType (obj)); Handlers4.Write(_class.TypeHandler(), context, obj); if (context.UpdateDepth().CanSkip(this)) { EndProcessing(); return; } Pointer4 pointer = context.AllocateSlot(); ByteArrayBuffer buffer = context.ToWriteBuffer(pointer); container.WriteUpdate(transaction, pointer, _class, container._handlers.ArrayType (obj), buffer); if (IsActive()) { SetStateClean(); } EndProcessing(); container.Callbacks().ObjectOnUpdate(transaction, this); ClassMetadata().DispatchEvent(transaction, obj, EventDispatchers.Update); }
/// <summary>return false if class not completely initialized, otherwise true</summary> internal virtual bool ContinueSet(Db4objects.Db4o.Internal.Transaction trans, IUpdateDepth updateDepth) { if (!BitIsTrue(Const4.Continue)) { return true; } if (!_class.StateOK()) { return false; } if (!_class.AspectsAreInitialized()) { return false; } if (DTrace.enabled) { DTrace.Continueset.Log(GetID()); } BitFalse(Const4.Continue); MarshallingContext context = new MarshallingContext(trans, this, updateDepth, true ); Handlers4.Write(ClassMetadata().TypeHandler(), context, GetObject()); Pointer4 pointer = context.AllocateSlot(); ByteArrayBuffer buffer = context.ToWriteBuffer(pointer); ObjectContainerBase container = trans.Container(); container.WriteNew(trans, pointer, _class, buffer); object obj = _object; ObjectOnNew(trans, obj); if (_class.HasIdentity()) { _object = container.NewWeakReference(this, obj); } SetStateClean(); EndProcessing(); return true; }