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();
 }
示例#2
0
		// do nothing
		public override void Marshall(MarshallingContext context, object obj)
		{
			Marshall(context.Transaction(), context.Reference(), context, context.IsNew());
		}
示例#3
0
		private void BlockAlign(MarshallingContext context, int precedingLength)
		{
			int totalLength = context.Container().BlockConverter().BlockAlignedBytes(precedingLength
				 + Length());
			int newLength = totalLength - precedingLength;
			BlockAlign(newLength);
		}
示例#4
0
		public virtual MarshallingBuffer CheckBlockAlignment(MarshallingContext context, 
			MarshallingBuffer precedingBuffer, IntByRef precedingLength)
		{
			_lastOffSet = Offset();
			if (DoBlockAlign())
			{
				precedingBuffer.BlockAlign(context, precedingLength.value);
			}
			if (precedingBuffer != null)
			{
				precedingLength.value += precedingBuffer.Length();
			}
			precedingBuffer = this;
			if (_children != null)
			{
				IEnumerator i = new Iterator4Impl(_children);
				while (i.MoveNext())
				{
					precedingBuffer = ((MarshallingBuffer)i.Current).CheckBlockAlignment(context, precedingBuffer
						, precedingLength);
				}
			}
			return precedingBuffer;
		}
示例#5
0
		private void WriteIndex(MarshallingContext context, int masterAddress, int position
			)
		{
			if (_indexedField != null)
			{
				// for now this is a String index only, it takes the entire slot.
				StatefulBuffer buffer = new StatefulBuffer(context.Transaction(), UnblockedLength
					());
				int blockedPosition = context.Container().BlockConverter().BytesToBlocks(position
					);
				int indexID = masterAddress + blockedPosition;
				buffer.SetID(indexID);
				buffer.Address(indexID);
				TransferContentTo(buffer, UnblockedLength());
				_indexedField.AddIndexEntry(context.Transaction(), context.ObjectID(), buffer);
			}
		}
示例#6
0
		private static void Merge(MarshallingContext context, int masterAddress, MarshallingBuffer
			 writeBuffer, MarshallingBuffer parentBuffer, MarshallingBuffer childBuffer, int
			 linkOffset)
		{
			int childPosition = writeBuffer.Offset();
			writeBuffer.Reserve(childBuffer.BlockedLength());
			MergeChildren(context, masterAddress, writeBuffer, childBuffer, linkOffset);
			int savedWriteBufferOffset = writeBuffer.Offset();
			writeBuffer.Seek(childPosition);
			childBuffer.TransferContentTo(writeBuffer._delegate);
			writeBuffer.Seek(savedWriteBufferOffset);
			parentBuffer.WriteLink(childBuffer, childPosition + linkOffset, childBuffer.UnblockedLength
				());
			childBuffer.WriteIndex(context, masterAddress, childPosition + linkOffset);
		}
示例#7
0
		private static void MergeChildren(MarshallingContext context, int masterAddress, 
			MarshallingBuffer writeBuffer, MarshallingBuffer parentBuffer, int linkOffset)
		{
			if (parentBuffer._children == null)
			{
				return;
			}
			IEnumerator i = new Iterator4Impl(parentBuffer._children);
			while (i.MoveNext())
			{
				Merge(context, masterAddress, writeBuffer, parentBuffer, (MarshallingBuffer)i.Current
					, linkOffset);
			}
		}
示例#8
0
 public override void WriteUpdate(Transaction transaction, IUpdateDepth updatedepth
     )
 {
     if (!_firstUpdate)
     {
         base.WriteUpdate(transaction, updatedepth);
         return;
     }
     _firstUpdate = false;
     var container = transaction.Container();
     SetStateClean();
     var context = new MarshallingContext(transaction, this, updatedepth
         , false);
     Handlers4.Write(ClassMetadata().TypeHandler(), context, GetObject());
     var length = Container().BlockConverter().BlockAlignedBytes(context.MarshalledLength
         ());
     var slot = context.AllocateNewSlot(length);
     var pointer = new Pointer4(GetID(), slot);
     var buffer = context.ToWriteBuffer(pointer);
     container.WriteUpdate(transaction, pointer, ClassMetadata(), ArrayType.None,
         buffer);
     if (IsActive())
     {
         SetStateClean();
     }
 }
示例#9
0
		public abstract void Marshall(MarshallingContext context, object child);
示例#10
0
		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);
		}
示例#11
0
		/// <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;
		}
示例#12
0
			public override void WriteUpdate(Transaction transaction, IUpdateDepth updatedepth
				)
			{
				if (!this._firstUpdate)
				{
					base.WriteUpdate(transaction, updatedepth);
					return;
				}
				this._firstUpdate = false;
				ObjectContainerBase container = transaction.Container();
				this.SetStateClean();
				MarshallingContext context = new MarshallingContext(transaction, this, updatedepth
					, false);
				Handlers4.Write(this.ClassMetadata().TypeHandler(), context, this.GetObject());
				int length = this.Container().BlockConverter().BlockAlignedBytes(context.MarshalledLength
					());
				Slot slot = context.AllocateNewSlot(length);
				Pointer4 pointer = new Pointer4(this.GetID(), slot);
				ByteArrayBuffer buffer = context.ToWriteBuffer(pointer);
				container.WriteUpdate(transaction, pointer, this.ClassMetadata(), ArrayType.None, 
					buffer);
				if (this.IsActive())
				{
					this.SetStateClean();
				}
			}
		public override void Marshall(MarshallingContext context, object obj)
		{
			// alive needs to be checked by all callers: Done
			IUpdateDepth updateDepth = context.UpdateDepth();
			if (obj != null && CascadeOnUpdate(context.ClassConfiguration()))
			{
				context.UpdateDepth(AdjustUpdateDepthForCascade(obj, updateDepth));
			}
			context.WriteObjectWithCurrentState(GetHandler(), obj);
			context.UpdateDepth(updateDepth);
			if (HasIndex())
			{
				context.AddIndexEntry(this, obj);
			}
		}
示例#14
0
		private bool IsNotHandlingConcreteType(MarshallingContext context)
		{
			return context.ClassMetadata() != _ownerMetadata;
		}
示例#15
0
		public override void Marshall(MarshallingContext context, object obj)
		{
			context.CreateIndirectionWithinSlot();
			if (IsNotHandlingConcreteType(context))
			{
				_typeHandler.Write(context, obj);
				return;
			}
			if (_typeHandler is IInstantiatingTypeHandler)
			{
				IInstantiatingTypeHandler instantiating = (IInstantiatingTypeHandler)_typeHandler;
				instantiating.WriteInstantiation(context, obj);
				instantiating.Write(context, obj);
			}
			else
			{
				_typeHandler.Write(context, obj);
			}
		}
 public virtual void MarshallAspects(object obj, MarshallingContext context)
 {
     var trans = context.Transaction();
     ITraverseAspectCommand command = new _MarshallingInfoTraverseAspectCommand_122(context
         , obj, trans, EnsureFieldList(context));
     TraverseAllAspects(context, command);
 }
 public _MarshallingInfoTraverseAspectCommand_122(MarshallingContext context, object
     obj, Transaction trans, IMarshallingInfo baseArg1) : base(baseArg1)
 {
     this.context = context;
     this.obj = obj;
     this.trans = trans;
 }
示例#18
0
		public virtual void MergeChildren(MarshallingContext context, int masterAddress, 
			int linkOffset)
		{
			MergeChildren(context, masterAddress, this, this, linkOffset);
		}