Ejemplo n.º 1
0
        // FIXME: This method should go completely.
        //        We changed the code to create the QCandidates graph in two steps:
        //        (1) call fitsIntoExistingConstraintHierarchy to determine whether
        //            or not we need more QCandidates objects
        //        (2) add all constraints
        //        This method tries to do both in one, which results in missing
        //        constraints. Not all are added to all QCandiates.
        //        Right methodology is in
        //        QQueryBase#createCandidateCollection
        //        and
        //        QQueryBase#createQCandidatesList
        internal bool TryAddConstraint(QCon a_constraint)
        {
            if (_field != null)
            {
                QField qf = a_constraint.GetField();
                if (qf != null)
                {
                    if (_field.Name() != null && !_field.Name().Equals(qf.Name()))
                    {
                        return(false);
                    }
                }
            }
            if (i_classMetadata == null || a_constraint.IsNullConstraint())
            {
                AddConstraint(a_constraint);
                return(true);
            }
            ClassMetadata yc = a_constraint.GetYapClass();

            if (yc != null)
            {
                yc = i_classMetadata.GetHigherOrCommonHierarchy(yc);
                if (yc != null)
                {
                    i_classMetadata = yc;
                    AddConstraint(a_constraint);
                    return(true);
                }
            }
            AddConstraint(a_constraint);
            return(false);
        }
Ejemplo n.º 2
0
        public bool FitsIntoExistingConstraintHierarchy(QCon constraint)
        {
            if (_field != null)
            {
                QField qf = constraint.GetField();
                if (qf != null)
                {
                    if (_field.Name() != null && !_field.Name().Equals(qf.Name()))
                    {
                        return(false);
                    }
                }
            }
            if (i_classMetadata == null || constraint.IsNullConstraint())
            {
                return(true);
            }
            ClassMetadata classMetadata = constraint.GetYapClass();

            if (classMetadata == null)
            {
                return(false);
            }
            classMetadata = i_classMetadata.GetHigherOrCommonHierarchy(classMetadata);
            if (classMetadata == null)
            {
                return(false);
            }
            i_classMetadata = classMetadata;
            return(true);
        }
Ejemplo n.º 3
0
        private bool CreateChildForDescendable(QCandidates parentCandidates, ITypeHandler4
                                               handler, QueryingReadContext queryingReadContext, ITypeHandler4 arrayElementHandler
                                               )
        {
            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 be kept fairly easy. TODO: Optimize!
            IEnumerator i = parentCandidates.IterateConstraints();

            while (i.MoveNext())
            {
                QCon   qcon = (QCon)i.Current;
                QField qf   = qcon.GetField();
                if (qf != null && !qf.Name().Equals(_fieldMetadata.GetName()))
                {
                    continue;
                }
                QCon tempParent = qcon.Parent();
                qcon.SetParent(null);
                QCandidates candidates = new QCandidates(parentCandidates.i_trans, null, qf, false
                                                         );
                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();
                BooleanByRef innerRes = new BooleanByRef(isNot);
                candidates.Traverse(new QCandidate.CreateDescendChildTraversingVisitor(pending, innerRes
                                                                                       , isNot));
                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_168(this));
                }
                if (!innerRes.value)
                {
                    // 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);
        }
Ejemplo n.º 4
0
 private FieldMetadata FieldMetadataFrom(QField qField, Db4objects.Db4o.Internal.ClassMetadata
     type)
 {
     FieldMetadata existingField = qField.GetFieldMetadata();
     if (existingField != null)
     {
         return existingField;
     }
     FieldMetadata field = type.FieldMetadataForName(qField.Name());
     if (field != null)
     {
         field.Alive();
     }
     return field;
 }
Ejemplo n.º 5
0
        // Our QConPath objects are just placeholders to fields,
        // so the parents are reachable.
        // If we find a "real" constraint, we throw the QPath
        // out and replace it with the other constraint.
        private void Morph(BooleanByRef removeExisting, QCon newConstraint, IReflectClass
                           claxx)
        {
            bool mayMorph = true;

            if (claxx != null)
            {
                ClassMetadata yc = i_trans.Container().ProduceClassMetadata(claxx);
                if (yc != null)
                {
                    IEnumerator i = IterateChildren();
                    while (i.MoveNext())
                    {
                        QField qf = ((QCon)i.Current).GetField();
                        if (!yc.HasField(i_trans.Container(), qf.Name()))
                        {
                            mayMorph = false;
                            break;
                        }
                    }
                }
            }
            // }
            if (mayMorph)
            {
                IEnumerator j = IterateChildren();
                while (j.MoveNext())
                {
                    newConstraint.AddConstraint((QCon)j.Current);
                }
                if (HasJoins())
                {
                    IEnumerator k = IterateJoins();
                    while (k.MoveNext())
                    {
                        QConJoin qcj = (QConJoin)k.Current;
                        qcj.ExchangeConstraint(this, newConstraint);
                        newConstraint.AddJoin(qcj);
                    }
                }
                i_parent.ExchangeConstraint(this, newConstraint);
                removeExisting.value = true;
            }
            else
            {
                i_parent.AddConstraint(newConstraint);
            }
        }
Ejemplo n.º 6
0
        private FieldMetadata FieldMetadataFrom(QField qField, ClassMetadata
                                                type)
        {
            var existingField = qField.GetFieldMetadata();

            if (existingField != null)
            {
                return(existingField);
            }
            var field = type.FieldMetadataForName(qField.Name());

            if (field != null)
            {
                field.Alive();
            }
            return(field);
        }
Ejemplo n.º 7
0
 private FieldMetadata FieldMetadataFrom(QField qField, ClassMetadata
     type)
 {
     var existingField = qField.GetFieldMetadata();
     if (existingField != null)
     {
         return existingField;
     }
     var field = type.FieldMetadataForName(qField.Name());
     if (field != null)
     {
         field.Alive();
     }
     return field;
 }
Ejemplo 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);
 }
Ejemplo n.º 9
0
		private FieldMetadata FieldMetadataFrom(QField qField, Db4objects.Db4o.Internal.ClassMetadata
			 type)
		{
			FieldMetadata existingField = qField.GetFieldMetadata();
			if (existingField != null)
			{
				return existingField;
			}
			FieldMetadata field = type.FieldMetadataForName(qField.Name());
			if (field != null)
			{
				field.Alive();
			}
			return field;
		}