Exemplo n.º 1
0
		public static int SlotHandlerVersion(IExtObjectContainer objectContainer, object 
			obj)
		{
			int id = (int)objectContainer.GetID(obj);
			IObjectInfo objectInfo = objectContainer.GetObjectInfo(obj);
			ObjectContainerBase container = (ObjectContainerBase)objectContainer;
			Transaction trans = container.Transaction;
			ByteArrayBuffer buffer = container.ReadBufferById(trans, id);
			UnmarshallingContext context = new UnmarshallingContext(trans, (ObjectReference)objectInfo
				, Const4.Transient, false);
			context.Buffer(buffer);
			context.PersistentObject(obj);
			context.ActivationDepth(new LegacyActivationDepth(0));
			context.Read();
			return context.HandlerVersion();
		}
		public void ActivateAspects(UnmarshallingContext context)
		{
			BooleanByRef schemaUpdateDetected = new BooleanByRef();
			ContextState savedState = context.SaveState();
			ITraverseAspectCommand command = new _MarshallingInfoTraverseAspectCommand_63(context
				, schemaUpdateDetected, EnsureFieldList(context));
			// TODO: cant the aspect handle it itself?
			// Probably no because old aspect versions might not be able
			// to handle null...
			TraverseAllAspects(context, command);
			if (schemaUpdateDetected.value)
			{
				context.RestoreState(savedState);
				command = new _MarshallingInfoTraverseAspectCommand_94(context, EnsureFieldList(context
					));
				TraverseAllAspects(context, command);
			}
		}
Exemplo n.º 3
0
 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();
 }
Exemplo n.º 4
0
 internal virtual void InstantiateFields(UnmarshallingContext context)
 {
     var handler = CorrectHandlerVersion(context);
     Handlers4.Activate(context, handler);
 }
Exemplo n.º 5
0
 private object InstantiateWithCustomTypeHandlerIfEnabled(UnmarshallingContext context
     )
 {
     if (!_customTypeHandlerAspect.IsEnabledOn(context))
     {
         return InstantiateForVersionWithoutCustomTypeHandler(context);
     }
     return InstantiateWithCustomTypeHandler(context);
 }
Exemplo n.º 6
0
		public override void Activate(UnmarshallingContext context)
		{
			object obj = Read(context);
			// Activation of members is necessary on purpose here.
			// Classes like Hashtable need fully activated members
			// to be able to calculate hashCode()
			if (obj != null)
			{
				context.Container().Activate(context.Transaction(), obj, context.ActivationDepth(
					));
			}
			SetOn(context.Transaction(), context.PersistentObject(), obj);
		}
Exemplo n.º 7
0
			public _IClosure4_110(TypeHandlerAspect _enclosing, UnmarshallingContext context)
			{
				this._enclosing = _enclosing;
				this.context = context;
			}
Exemplo n.º 8
0
		public virtual void AttemptUpdate(UnmarshallingContext context)
		{
			if (!Updating())
			{
				IncrementOffset(context);
				return;
			}
			int savedOffset = context.Offset();
			try
			{
				object toSet = context.Read(GetHandler());
				if (toSet != null)
				{
					Set(context.PersistentObject(), toSet);
				}
			}
			catch (Exception)
			{
				// FIXME: COR-547 Diagnostics here please.
				context.Buffer().Seek(savedOffset);
				IncrementOffset(context);
			}
		}
Exemplo n.º 9
0
 public _MarshallingInfoTraverseAspectCommand_63(UnmarshallingContext context, BooleanByRef
     schemaUpdateDetected, IMarshallingInfo baseArg1) : base(baseArg1)
 {
     this.context = context;
     this.schemaUpdateDetected = schemaUpdateDetected;
 }
Exemplo n.º 10
0
		public object Get(Transaction trans, object onObject)
		{
			if (_containingClass == null)
			{
				return null;
			}
			ObjectContainerBase container = Container();
			if (container == null)
			{
				return null;
			}
			lock (container.Lock())
			{
				// FIXME: The following is not really transactional.
				//        This will work OK for normal C/S and for
				//        single local mode but the transaction will
				//        be wrong for MTOC.
				if (trans == null)
				{
					trans = container.Transaction;
				}
				container.CheckClosed();
				ObjectReference @ref = trans.ReferenceForObject(onObject);
				if (@ref == null)
				{
					return null;
				}
				int id = @ref.GetID();
				if (id <= 0)
				{
					return null;
				}
				UnmarshallingContext context = new UnmarshallingContext(trans, @ref, Const4.AddToIdTree
					, false);
				context.ActivationDepth(new LegacyActivationDepth(1));
				return context.ReadFieldValue(this);
			}
		}
Exemplo n.º 11
0
 public _IClosure4_2055(IInstantiatingTypeHandler customTypeHandler, UnmarshallingContext
     context)
 {
     this.customTypeHandler = customTypeHandler;
     this.context = context;
 }
Exemplo n.º 12
0
		public object Read(Db4objects.Db4o.Internal.Transaction trans, ByteArrayBuffer buffer
			, object obj, IActivationDepth instantiationDepth, int addToIDTree, bool checkIDTree
			)
		{
			UnmarshallingContext context = new UnmarshallingContext(trans, buffer, this, addToIDTree
				, checkIDTree);
			context.PersistentObject(obj);
			context.ActivationDepth(instantiationDepth);
			return context.Read();
		}
Exemplo n.º 13
0
		public virtual object ReadPrefetch(Db4objects.Db4o.Internal.Transaction trans, ByteArrayBuffer
			 buffer, int addToIDTree)
		{
			UnmarshallingContext context = new UnmarshallingContext(trans, buffer, this, addToIDTree
				, false);
			context.ActivationDepth(new FixedActivationDepth(1, ActivationMode.Prefetch));
			return context.Read();
		}
Exemplo n.º 14
0
 internal override void InstantiateFields(UnmarshallingContext context)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 15
0
 public override object InstantiateTransient(UnmarshallingContext context)
 {
     return Handlers4.ReadValueType(context, CorrectHandlerVersion(context));
 }
Exemplo n.º 16
0
 public override object Instantiate(UnmarshallingContext context)
 {
     var obj = context.PersistentObject();
     if (obj == null)
     {
         obj = context.Read(TypeHandler());
         context.SetObjectWeak(obj);
     }
     context.SetStateClean();
     return obj;
 }
Exemplo n.º 17
0
 private object InstantiateForVersionWithoutCustomTypeHandler(UnmarshallingContext
     context)
 {
     var oldVersionConstructor = CreateConstructor(null);
     if (null == oldVersionConstructor)
     {
         throw new InvalidOperationException();
     }
     return oldVersionConstructor.Apply(context);
 }
Exemplo n.º 18
0
		public abstract void Activate(UnmarshallingContext context);
Exemplo n.º 19
0
 private object InstantiateWithCustomTypeHandler(UnmarshallingContext context)
 {
     var contextState = context.SaveState();
     try
     {
         var fieldHasValue = SeekToField(context, _customTypeHandlerAspect);
         if (!fieldHasValue)
         {
             context.RestoreState(contextState);
             return InstantiateForVersionWithoutCustomTypeHandler(context);
         }
         var customTypeHandler = (IInstantiatingTypeHandler) _customTypeHandlerAspect
             ._typeHandler;
         return context.SlotFormat().DoWithSlotIndirection(context, new _IClosure4_2055(customTypeHandler
             , context));
     }
     finally
     {
         context.RestoreState(contextState);
     }
 }
Exemplo n.º 20
0
		private UnmarshallingContext DescendMarshallingContext(Transaction trans, ObjectReference
			 @ref)
		{
			UnmarshallingContext context = new UnmarshallingContext(trans, @ref, Const4.AddToIdTree
				, false);
			context.ActivationDepth(ActivationDepthProvider().ActivationDepth(1, ActivationMode
				.Activate));
			return context;
		}
Exemplo n.º 21
0
 public virtual object Instantiate(UnmarshallingContext context)
 {
     // overridden in PrimitiveTypeMetadata
     // never called for primitive YapAny
     // FIXME: [TA] no longer necessary?
     //        context.adjustInstantiationDepth();
     var obj = context.PersistentObject();
     var instantiating = (obj == null);
     if (instantiating)
     {
         obj = InstantiateObject(context);
         if (obj == null)
         {
             return null;
         }
         ShareTransaction(obj, context.Transaction());
         ShareObjectReference(obj, context.ObjectReference());
         OnInstantiate(context, obj);
         if (context.ActivationDepth().Mode().IsPrefetch())
         {
             context.ObjectReference().SetStateDeactivated();
             return obj;
         }
         if (!context.ActivationDepth().RequiresActivation())
         {
             context.ObjectReference().SetStateDeactivated();
             return obj;
         }
         return Activate(context);
     }
     if (ActivatingActiveObject(context.ActivationDepth().Mode(), context.ObjectReference
         ()))
     {
         var child = context.ActivationDepth().Descend(this);
         if (child.RequiresActivation())
         {
             CascadeActivation(new ActivationContext4(context.Transaction(), obj, child));
         }
         return obj;
     }
     return Activate(context);
 }
Exemplo n.º 22
0
		public override void Activate(UnmarshallingContext context)
		{
			if (!CheckAlive(context))
			{
				return;
			}
			if (!ShouldStoreField())
			{
				IncrementOffset(context);
				return;
			}
			object toSet = Read(context);
			InformAboutTransaction(toSet, context.Transaction());
			Set(context.PersistentObject(), toSet);
		}
Exemplo n.º 23
0
		public override object Instantiate(UnmarshallingContext context)
		{
			object @object = new object();
			OnInstantiate(context, @object);
			return @object;
		}
Exemplo n.º 24
0
 protected void OnInstantiate(UnmarshallingContext context, object obj)
 {
     context.SetObjectWeak(obj);
     context.Transaction().ReferenceSystem().AddExistingReference(context.ObjectReference
         ());
     ObjectOnInstantiate(context.Transaction(), context.ObjectReference());
 }
Exemplo n.º 25
0
		public override void Activate(UnmarshallingContext context)
		{
			context.ObjectReference().ProduceVirtualAttributes();
			Instantiate1(context);
		}
Exemplo n.º 26
0
 public virtual object InstantiateTransient(UnmarshallingContext context)
 {
     // overridden in YapClassPrimitive
     // never called for primitive YapAny
     var obj = InstantiateObject(context);
     if (obj == null)
     {
         return null;
     }
     context.Container().Peeked(context.ObjectId(), obj);
     if (context.ActivationDepth().RequiresActivation())
     {
         InstantiateFields(context);
     }
     return obj;
 }
Exemplo n.º 27
0
 public _MarshallingInfoTraverseAspectCommand_94(UnmarshallingContext context, IMarshallingInfo
     baseArg1) : base(baseArg1)
 {
     this.context = context;
 }
Exemplo n.º 28
0
 private object Activate(UnmarshallingContext context)
 {
     var obj = context.PersistentObject();
     var objectReference = context.ObjectReference();
     if (!ObjectCanActivate(context.Transaction(), obj))
     {
         objectReference.SetStateDeactivated();
         return obj;
     }
     objectReference.SetStateClean();
     if (context.ActivationDepth().RequiresActivation())
     {
         InstantiateFields(context);
     }
     ObjectOnActivate(context.Transaction(), objectReference);
     return obj;
 }
Exemplo n.º 29
0
		public static void Activate(UnmarshallingContext context, ITypeHandler4 handler)
		{
			if (handler is IReferenceTypeHandler)
			{
				((IReferenceTypeHandler)handler).Activate(context);
			}
		}
Exemplo n.º 30
0
 private object InstantiateObject(UnmarshallingContext context)
 {
     var obj = _constructor.Apply(context);
     context.PersistentObject(obj);
     return obj;
 }