internal QConClass(Transaction trans, QCon parent, QField field, IReflectClass claxx ) : base(trans, parent, field, null) { // C/S if (claxx != null) { ObjectContainerBase container = trans.Container(); _classMetadata = container.ClassMetadataForReflectClass(claxx); if (_classMetadata == null) { // could be an aliased class, try to resolve. string className = claxx.GetName(); string aliasRunTimeName = container.Config().ResolveAliasStoredName(className); if (!className.Equals(aliasRunTimeName)) { _classMetadata = container.ClassMetadataForName(aliasRunTimeName); } } if (claxx.Equals(container._handlers.IclassObject)) { _classMetadata = (ClassMetadata)_classMetadata.TypeHandler(); } } _claxx = claxx; }
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); }
public void Apply(object arg) { QCon qCon = (QCon)arg; qCon.SetCandidates(this._enclosing); qCon.EvaluateSelf(); }
public virtual QQueryBase.CreateCandidateCollectionResult CreateCandidateCollection () { List4 candidatesList = CreateQCandidatesList(); bool checkDuplicates = false; bool topLevel = true; IEnumerator i = IterateConstraints(); while (i.MoveNext()) { QCon constraint = (QCon)i.Current; QCon old = constraint; constraint = constraint.GetRoot(); if (constraint != old) { checkDuplicates = true; topLevel = false; } ClassMetadata classMetadata = constraint.GetYapClass(); if (classMetadata == null) { break; } AddConstraintToCandidatesList(candidatesList, constraint); } return(new QQueryBase.CreateCandidateCollectionResult(candidatesList, checkDuplicates , topLevel)); }
public object Apply(object obj) { QCon constr = (QCon)obj; constr.i_joins = null; return(false); }
private bool ForEachConstraintRecursively(IFunction4 block) { IQueue4 queue = new NoDuplicatesQueue(new NonblockingQueue()); IEnumerator constrIter = IterateConstraints(); while (constrIter.MoveNext()) { queue.Add(constrIter.Current); } while (queue.HasNext()) { QCon constr = (QCon)queue.Next(); bool cancel = (bool)block.Apply(constr); if (cancel) { return(true); } IEnumerator childIter = constr.IterateChildren(); while (childIter.MoveNext()) { queue.Add(childIter.Current); } IEnumerator joinIter = constr.IterateJoins(); while (joinIter.MoveNext()) { queue.Add(joinIter.Current); } } return(false); }
private bool AttachToExistingConstraints(Collection4 newConstraintsCollector, object obj, bool onlyForPaths) { bool found = false; IEnumerator j = IterateConstraints(); while (j.MoveNext()) { QCon existingConstraint = (QCon)j.Current; BooleanByRef removeExisting = new BooleanByRef(false); if (!onlyForPaths || (existingConstraint is QConPath)) { QCon newConstraint = existingConstraint.ShareParent(obj, removeExisting); if (newConstraint != null) { newConstraintsCollector.Add(newConstraint); AddConstraint(newConstraint); if (removeExisting.value) { RemoveConstraint(existingConstraint); } found = true; if (!onlyForPaths) { break; } } } } return(found); }
// 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); }
internal QPending(QConJoin a_join, QCon a_constraint, bool a_firstResult) { // Constants, so QConJoin.evaluatePending is made easy: _join = a_join; _constraint = a_constraint; _result = a_firstResult ? True : False; }
public override bool OnSameFieldAs(QCon other) { if (!(other is Db4objects.Db4o.Internal.Query.Processor.QConObject)) { return(false); } return(i_field == ((Db4objects.Db4o.Internal.Query.Processor.QConObject)other).i_field); }
internal QConPath(Transaction a_trans, QCon a_parent, QField a_field) : base(a_trans , a_parent, a_field, null) { if (a_field != null) { _classMetadata = a_field.GetFieldType(); } }
public override bool OnSameFieldAs(QCon other) { if (!(other is QConObject)) { return(false); } return(i_field == ((QConObject)other).i_field); }
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); }
internal QConJoin(Transaction a_trans, QCon a_c1, QCon a_c2, bool a_and) : base(a_trans ) { // FIELDS MUST BE PUBLIC TO BE REFLECTED ON UNDER JDK <= 1.1 // C/S i_constraint1 = a_c1; i_constraint2 = a_c2; i_and = a_and; }
public static IIndexedNode NewParentPath(IIndexedNode next, QCon constraint) { if (!CanFollowParent(constraint)) { return null; } return new IndexedPath((QConObject) constraint .Parent(), next); }
public static IIndexedNode NewParentPath(IIndexedNode next, QCon constraint) { if (!CanFollowParent(constraint)) { return null; } return new Db4objects.Db4o.Internal.Fieldindex.IndexedPath((QConObject)constraint .Parent(), next); }
private static FieldMetadata GetYapField(QCon con) { QField field = con.GetField(); if (null == field) { return null; } return field.GetFieldMetadata(); }
internal virtual bool Attach(QQuery query, string a_field) { Db4objects.Db4o.Internal.Query.Processor.QCon qcon = this; ClassMetadata yc = GetYapClass(); bool[] foundField = new bool[] { false }; ForEachChildField(a_field, new _IVisitor4_101(foundField, query)); if (foundField[0]) { return(true); } QField qf = null; if (yc == null || yc.HoldsAnyClass()) { int[] count = new int[] { 0 }; FieldMetadata[] yfs = new FieldMetadata[] { null }; i_trans.Container().ClassCollection().AttachQueryNode(a_field, new _IVisitor4_119 (yfs, count)); if (count[0] == 0) { return(false); } if (count[0] == 1) { qf = yfs[0].QField(i_trans); } else { qf = new QField(i_trans, a_field, null, 0, 0); } } else { if (yc.IsTranslated()) { i_trans.Container()._handlers.DiagnosticProcessor().DescendIntoTranslator(yc, a_field ); } FieldMetadata yf = yc.FieldMetadataForName(a_field); if (yf != null) { qf = yf.QField(i_trans); } if (qf == null) { qf = new QField(i_trans, a_field, null, 0, 0); } } QConPath qcp = new QConPath(i_trans, qcon, qf); query.AddConstraint(qcp); qcon.AddConstraint(qcp); return(true); }
public JoinedLeaf(QCon constraint, IIndexedNodeWithRange leaf1, IBTreeRange range ) { if (null == constraint || null == leaf1 || null == range) { throw new ArgumentNullException(); } _constraint = constraint; _leaf1 = leaf1; _range = range; }
public virtual QCon GetOtherConstraint(QCon a_constraint) { if (a_constraint == Constraint1()) { return(Constraint2()); } if (a_constraint == Constraint2()) { return(Constraint1()); } throw new ArgumentException(); }
internal virtual bool RemoveForParent(QCon a_constraint) { if (i_and) { QCon other = GetOtherConstraint(a_constraint); other.RemoveJoin(this); // prevents circular call other.Remove(); return(true); } return(false); }
internal override void ExchangeConstraint(QCon a_exchange, QCon a_with) { base.ExchangeConstraint(a_exchange, a_with); if (a_exchange == Constraint1()) { i_constraint1 = a_with; } if (a_exchange == Constraint2()) { i_constraint2 = a_with; } }
internal void Collect(Db4objects.Db4o.Internal.Query.Processor.QCandidates a_candidates ) { IEnumerator i = IterateConstraints(); while (i.MoveNext()) { QCon qCon = (QCon)i.Current; SetCurrentConstraint(qCon); qCon.Collect(a_candidates); } SetCurrentConstraint(null); }
private void ForEachConstraint(IProcedure4 proc) { IEnumerator i = IterateConstraints(); while (i.MoveNext()) { QCon constraint = (QCon)i.Current; if (!constraint.ProcessedByIndex()) { proc.Apply(constraint); } } }
private void AddConstraintToCandidatesList(List4 candidatesList, QCon qcon) { if (candidatesList == null) { return; } IEnumerator j = new Iterator4Impl(candidatesList); while (j.MoveNext()) { QCandidates candidates = (QCandidates)j.Current; candidates.AddConstraint(qcon); } }
internal QConClass(Transaction a_trans, QCon a_parent, QField a_field, IReflectClass claxx) : base(a_trans, a_parent, a_field, null) { // C/S if (claxx != null) { _classMetadata = a_trans.Container().ProduceClassMetadata(claxx); if (claxx.Equals(a_trans.Container()._handlers.IclassObject)) { _classMetadata = (ClassMetadata)_classMetadata.TypeHandler(); } } _claxx = claxx; }
public object Apply(object obj) { QCon constr = (QCon)obj; IEnumerator joinIter = constr.IterateJoins(); while (joinIter.MoveNext()) { QConJoin join = (QConJoin)joinIter.Current; if (join.IsOr()) { return(true); } } return(false); }
private bool ConstraintCanBeAddedToExisting(List4 candidatesList, QCon constraint ) { IEnumerator j = new Iterator4Impl(candidatesList); while (j.MoveNext()) { QCandidates candidates = (QCandidates)j.Current; if (candidates.FitsIntoExistingConstraintHierarchy(constraint)) { return(true); } } return(false); }
public override string ToString() { StringBuilder sb = new StringBuilder(); sb.Append("QQueryBase\n"); IEnumerator i = IterateConstraints(); while (i.MoveNext()) { QCon constraint = (QCon)i.Current; sb.Append(constraint); sb.Append("\n"); } return(sb.ToString()); }
internal virtual void EvaluateCreateChildrenCandidates() { i_childrenCandidates = new Collection4(); IEnumerator i = IterateChildren(); while (i.MoveNext()) { Db4objects.Db4o.Internal.Query.Processor.QCon constraint = (Db4objects.Db4o.Internal.Query.Processor.QCon )i.Current; if (!constraint.ResolvedByIndex()) { constraint.CreateCandidates(i_childrenCandidates); } } }
// 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); } }
private bool HasJoins(QCon con) { if (con.HasJoins()) { return true; } IEnumerator childIter = con.IterateChildren(); while (childIter.MoveNext()) { if (HasJoins((QCon)childIter.Current)) { return true; } } return false; }
public QConObject(Transaction a_trans, QCon a_parent, QField a_field, object a_object ) : base(a_trans) { // the constraining object // cache for the db4o object ID // the YapClass // needed for marshalling the request // C/S only i_parent = a_parent; if (a_object is ICompare) { a_object = ((ICompare)a_object).Compare(); } i_object = a_object; i_field = a_field; }
private static bool CanFollowParent(QCon con) { QCon parent = con.Parent(); FieldMetadata parentField = GetYapField(parent); if (null == parentField) { return false; } FieldMetadata conField = GetYapField(con); if (null == conField) { return false; } return parentField.HasIndex() && parentField.FieldType().IsAssignableFrom(conField .ContainingClass()); }
internal virtual void EvaluateSimpleChildren() { // TODO: sort the constraints for YapFields first, // so we stay with the same YapField if (_children == null) { return; } IEnumerator i = IterateChildren(); while (i.MoveNext()) { Db4objects.Db4o.Internal.Query.Processor.QCon qcon = (Db4objects.Db4o.Internal.Query.Processor.QCon )i.Current; i_candidates.SetCurrentConstraint(qcon); qcon.SetCandidates(i_candidates); qcon.EvaluateSimpleExec(i_candidates); } i_candidates.SetCurrentConstraint(null); }
internal virtual void Visit1(QCandidate root, Db4objects.Db4o.Internal.Query.Processor.QCon reason, bool res) { // The a_reason parameter makes it eays to distinguish // between calls from above (a_reason == this) and below. if (HasJoins()) { // this should probably be on the Join IEnumerator i = IterateJoins(); while (i.MoveNext()) { root.Evaluate(new QPending((QConJoin)i.Current, this, res)); } } else { if (!res) { DoNotInclude(root); } } }
private void CollectLeavesFromJoinConstraint(Collection4 leaves, QCon constraint) { if (constraint is QConJoin) { CollectLeavesFromJoin(leaves, (QConJoin)constraint); } else { if (!leaves.ContainsByIdentity(constraint)) { leaves.Add(constraint); } } }
private void CollectTopLevelJoins(Collection4 joins, QCon constraintWithJoins) { IEnumerator i = constraintWithJoins.IterateJoins(); while (i.MoveNext()) { QConJoin join = (QConJoin)i.Current; if (!join.HasJoins()) { if (!joins.ContainsByIdentity(join)) { joins.Add(join); } } else { CollectTopLevelJoins(joins, join); } } }
private IIndexedNodeWithRange NodeForConstraint(QCon con) { IIndexedNodeWithRange node = (IIndexedNodeWithRange)_nodeCache.Get(con); if (null != node || _nodeCache.ContainsKey(con)) { return node; } node = NewNodeForConstraint(con); _nodeCache.Put(con, node); return node; }
private IIndexedNodeWithRange NewNodeForConstraint(QCon con) { if (con is QConJoin) { return NewNodeForConstraint((QConJoin)con); } return new IndexedLeaf((QConObject)con); }
private void CollectImplicitAnd(QCon constraint, IIndexedNodeWithRange x, IIndexedNodeWithRange y) { _nodes.Remove(x); _nodes.Remove(y); _nodes.Add(new AndIndexedLeaf(constraint, x, y)); }
internal void AddConstraint(QCon a_constraint) { _constraints = new List4(_constraints, a_constraint); }
public virtual QCon GetOtherConstraint(QCon a_constraint) { if (a_constraint == Constraint1()) { return Constraint2(); } else { if (a_constraint == Constraint2()) { return Constraint1(); } } throw new ArgumentException(); }
internal virtual bool RemoveForParent(QCon a_constraint) { if (i_and) { QCon other = GetOtherConstraint(a_constraint); other.RemoveJoin(this); // prevents circular call other.Remove(); return true; } return false; }
internal virtual void ChangeConstraint() { _constraint = _join.GetOtherConstraint(_constraint); }
internal virtual void SetParent(Db4objects.Db4o.Internal.Query.Processor.QCon a_newParent ) { i_parent = a_newParent; }
private bool HaveSamePath(QCon x, QCon y) { if (x == y) { return true; } if (!x.OnSameFieldAs(y)) { return false; } if (!x.HasParent()) { return !y.HasParent(); } return HaveSamePath(x.Parent(), y.Parent()); }
private bool IsLeaf(QCon qcon) { return !qcon.HasChildren(); }
internal void SetCurrentConstraint(QCon a_constraint) { i_currentConstraint = a_constraint; }
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; }
public AndIndexedLeaf(QCon constraint, IIndexedNodeWithRange leaf1, IIndexedNodeWithRange leaf2) : base(constraint, leaf1, leaf1.GetRange().Intersect(leaf2.GetRange())) { }
// 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; }