Exemplo n.º 1
0
        public void CascadeActivation(IActivationContext context)
        {
            if (!Handlers4.IsCascading(_handler))
            {
                return;
            }
            ObjectContainerBase container = context.Container();
            IEnumerator         all       = AllElements(container, context.TargetObject());

            while (all.MoveNext())
            {
                context.CascadeActivationToChild(all.Current);
            }
        }
        public virtual void Delete(ITypeHandler4 handler)
        {
            ITypeHandler4 correctHandlerVersion = HandlerRegistry.CorrectHandlerVersion(this,
                                                                                        handler);
            int preservedCascadeDepth = CascadeDeleteDepth();

            CascadeDeleteDepth(AdjustedDepth());
            if (Handlers4.HandleAsObject(correctHandlerVersion))
            {
                DeleteObject();
            }
            else
            {
                correctHandlerVersion.Delete(this);
            }
            CascadeDeleteDepth(preservedCascadeDepth);
        }
 public virtual void WriteObjectWithCurrentState(ITypeHandler4 handler, object obj
                                                 )
 {
     if (Handlers4.UseDedicatedSlot(this, handler))
     {
         WriteObject(obj);
     }
     else
     {
         if (obj == null)
         {
             WriteNullReference(handler);
         }
         else
         {
             CreateIndirectionWithinSlot(handler);
             handler.Write(this, obj);
         }
     }
 }
Exemplo n.º 4
0
        public virtual IEnumerator ReferencesFrom(int id)
        {
            CollectIdContext context       = CollectIdContext.ForID(_transaction, id);
            ClassMetadata    classMetadata = context.ClassMetadata();

            if (null == classMetadata)
            {
                // most probably ClassMetadata reading
                return(Iterators.EmptyIterator);
            }
            if (!classMetadata.HasIdentity())
            {
                throw new InvalidOperationException(classMetadata.ToString());
            }
            if (!Handlers4.IsCascading(classMetadata.TypeHandler()))
            {
                return(Iterators.EmptyIterator);
            }
            classMetadata.CollectIDs(context);
            return(new TreeKeyIterator(context.Ids()));
        }
Exemplo n.º 5
0
        private object WriteAndRead(object obj)
        {
            int             imaginativeID = 500;
            ObjectReference @ref          = new ObjectReference(ClassMetadataForObject(obj), imaginativeID
                                                                );

            @ref.SetObject(obj);
            MarshallingContext marshallingContext = new MarshallingContext(Trans(), @ref, Container
                                                                               ().UpdateDepthProvider().ForDepth(int.MaxValue), true);

            Handlers4.Write(@ref.ClassMetadata().TypeHandler(), marshallingContext, obj);
            Pointer4        pointer = marshallingContext.AllocateSlot();
            ByteArrayBuffer buffer  = marshallingContext.ToWriteBuffer(pointer);

            buffer.Seek(0);
            //        String str = new String(buffer._buffer);
            //        System.out.println(str);
            UnmarshallingContext unmarshallingContext = new UnmarshallingContext(Trans(), @ref
                                                                                 , Const4.AddToIdTree, false);

            unmarshallingContext.Buffer(buffer);
            unmarshallingContext.ActivationDepth(new LegacyActivationDepth(5));
            return(unmarshallingContext.Read());
        }
Exemplo n.º 6
0
        private bool HasValueTypeBehavior(object obj)
        {
            bool isSimple = Platform4.IsSimple(obj.GetType());

            if (isSimple)
            {
                return(true);
            }
            IReflectClass reflectClass = _container.Reflector().ForObject(obj);

            if (Platform4.IsStruct(reflectClass))
            {
                return(true);
            }
            bool isEnum = Platform4.IsEnum(_container.Reflector(), reflectClass);

            if (isEnum)
            {
                return(true);
            }
            ITypeHandler4 typeHandler = _container.TypeHandlerForClass(reflectClass);

            return(Handlers4.IsValueType(typeHandler));
        }
Exemplo n.º 7
0
 public override bool IsIndirectedWithinSlot(ITypeHandler4 handler)
 {
     return(Handlers4.IsVariableLength(handler));
 }
Exemplo n.º 8
0
 internal virtual bool CreateChild(QCandidates a_candidates)
 {
     if (!_include)
     {
         return(false);
     }
     if (_fieldMetadata != null)
     {
         ITypeHandler4 handler = _fieldMetadata.GetHandler();
         if (handler != null)
         {
             QueryingReadContext queryingReadContext = new QueryingReadContext(Transaction(),
                                                                               MarshallerFamily().HandlerVersion(), _bytes, _key);
             ITypeHandler4 arrayElementHandler = Handlers4.ArrayElementHandler(handler, queryingReadContext
                                                                               );
             if (arrayElementHandler != null)
             {
                 int  offset   = queryingReadContext.Offset();
                 bool outerRes = true;
                 // The following construct is worse than not ideal.
                 // For each constraint it completely reads the
                 // underlying structure again. The structure could b
                 // kept fairly easy. TODO: Optimize!
                 IEnumerator i = a_candidates.IterateConstraints();
                 while (i.MoveNext())
                 {
                     QCon   qcon = (QCon)i.Current;
                     QField qf   = qcon.GetField();
                     if (qf == null || qf.Name().Equals(_fieldMetadata.GetName()))
                     {
                         QCon tempParent = qcon.Parent();
                         qcon.SetParent(null);
                         QCandidates candidates = new QCandidates(a_candidates.i_trans, null, qf);
                         candidates.AddConstraint(qcon);
                         qcon.SetCandidates(candidates);
                         ReadArrayCandidates(handler, queryingReadContext.Buffer(), arrayElementHandler, candidates
                                             );
                         queryingReadContext.Seek(offset);
                         bool isNot = qcon.IsNot();
                         if (isNot)
                         {
                             qcon.RemoveNot();
                         }
                         candidates.Evaluate();
                         ByRef  pending  = ByRef.NewInstance();
                         bool[] innerRes = new bool[] { isNot };
                         candidates.Traverse(new _IVisitor4_160(innerRes, isNot, pending));
                         // Collect all pending subresults.
                         // We need to change
                         // the
                         // constraint here, so
                         // our
                         // pending collector
                         // uses
                         // the right
                         // comparator.
                         // We only keep one
                         // pending result
                         // for
                         // all array
                         // elements.
                         // and memorize,
                         // whether we had a
                         // true or a false
                         // result.
                         // or both.
                         if (isNot)
                         {
                             qcon.Not();
                         }
                         // In case we had pending subresults, we
                         // need to communicate
                         // them up to our root.
                         if (((Tree)pending.value) != null)
                         {
                             ((Tree)pending.value).Traverse(new _IVisitor4_229(this));
                         }
                         if (!innerRes[0])
                         {
                             // Again this could be double triggering.
                             //
                             // We want to clean up the "No route"
                             // at some stage.
                             qcon.Visit(GetRoot(), qcon.Evaluator().Not(false));
                             outerRes = false;
                         }
                         qcon.SetParent(tempParent);
                     }
                 }
                 return(outerRes);
             }
             // We may get simple types here too, if the YapField was null
             // in the higher level simple evaluation. Evaluate these
             // immediately.
             if (Handlers4.IsQueryLeaf(handler))
             {
                 a_candidates.i_currentConstraint.Visit(this);
                 return(true);
             }
         }
     }
     if (_fieldMetadata == null)
     {
         return(false);
     }
     if (_fieldMetadata is NullFieldMetadata)
     {
         return(false);
     }
     _classMetadata.SeekToField(Transaction(), _bytes, _fieldMetadata);
     Db4objects.Db4o.Internal.Query.Processor.QCandidate candidate = ReadSubCandidate(
         a_candidates);
     if (candidate == null)
     {
         return(false);
     }
     // fast early check for ClassMetadata
     if (a_candidates.i_classMetadata != null && a_candidates.i_classMetadata.IsStronglyTyped
             ())
     {
         ITypeHandler4 handler = _fieldMetadata.GetHandler();
         if (Handlers4.IsUntyped(handler))
         {
             handler = TypeHandlerFor(candidate);
         }
         if (handler == null)
         {
             return(false);
         }
     }
     AddDependant(a_candidates.Add(candidate));
     return(true);
 }
Exemplo n.º 9
0
 public virtual object ReadObject(ITypeHandler4 handler)
 {
     return(Handlers4.ReadValueType(this, handler));
 }
Exemplo n.º 10
0
 private bool IsTyped(FieldMetadata field)
 {
     return(!Handlers4.IsUntyped(field.GetHandler()));
 }
Exemplo n.º 11
0
 internal virtual bool IsArray()
 {
     return(_fieldMetadata != null && Handlers4.HandlesArray(_fieldMetadata.GetHandler
                                                                 ()));
 }
Exemplo n.º 12
0
 private bool IsUntypedByteArray(IBufferContext context)
 {
     return(Handlers4.IsUntyped(_handler) && HandleAsByteArray(context));
 }
Exemplo n.º 13
0
 public virtual IReflectClass PrimitiveClassReflector(IReflector reflector)
 {
     return(Handlers4.PrimitiveClassReflector(_handler, reflector));
 }
Exemplo n.º 14
0
 private bool CascadeDelete(IDeleteContext context)
 {
     // FIXME: ValueType could reference objects, shouldn't they be deleted too?
     return(context.CascadeDelete() && Handlers4.IsCascading(_handler));
 }
Exemplo n.º 15
0
 internal virtual bool IsQueryLeaf()
 {
     return(_fieldMetadata != null && Handlers4.IsQueryLeaf(_fieldMetadata.GetHandler(
                                                                )));
 }
Exemplo n.º 16
0
 internal virtual bool IsClass()
 {
     return(_fieldMetadata == null || Handlers4.HandlesClass(_fieldMetadata.GetHandler
                                                                 ()));
 }
Exemplo n.º 17
0
 public virtual IReflectClass ClassReflector(IReflector reflector, ClassMetadata classMetadata
                                             , bool isPrimitive)
 {
     return(isPrimitive ? Handlers4.PrimitiveClassReflector(classMetadata, reflector) :
            classMetadata.ClassReflector());
 }
Exemplo n.º 18
0
 public virtual void WriteObject(ITypeHandler4 handler, object obj)
 {
     Handlers4.Write(handler, this, obj);
 }