public IConstraint FormulateFieldConstraints(IQuery query, OMQueryClause clause) { try { IConstraint cons = null; string[] str = clause.Fieldname.Split('.'); IQuery q = AddAsDescends(query, str); IType type = Db4oClient.TypeResolver.Resolve(clause.FieldType); switch (type.DisplayName) { case BusinessConstants.DATETIME: { IConstraint c1 = null, c2 = null; DateTimeFormatInfo dateTimeFormatterProvider = DateTimeFormatInfo.CurrentInfo.Clone() as DateTimeFormatInfo; dateTimeFormatterProvider.ShortDatePattern = "MM/dd/yyyy hh:mm:ss tt"; DateTime dt = DateTime.Parse(clause.Value.Trim(), dateTimeFormatterProvider); DateTime dt1 = dt.AddDays(-1); DateTime dt2 = dt.AddDays(1); if (clause.Operator.Equals(BusinessConstants.CONDITION_EQUALS)) { cons = q.Constrain(dt2).Smaller().And(q.Constrain(dt1).Greater()); } else if (clause.Operator.Equals(BusinessConstants.CONDITION_GREATERTHAN)) { c1 = q.Constrain(dt2).Greater(); c2 = q.Constrain(dt2.AddDays(1)).Smaller().And(q.Constrain(dt).Greater()); cons = c1.Or(c2); c1 = null; c2 = null; } else if (clause.Operator.Equals(BusinessConstants.CONDITION_LESSTHAN)) { c1 = q.Constrain(dt1).Smaller(); c2 = q.Constrain(dt).Smaller().And(q.Constrain(dt1.AddDays(-1)).Greater()); cons = c1.Or(c2); } break; } default: cons = q.Constrain(type.Cast(clause.Value)); break; } return(cons); } catch (Exception oEx) { LoggingHelper.HandleException(oEx); return(null); } }
public virtual void TestImplicitAndOnOrs() { IQuery query = CreateItemQuery(); IConstraint c1 = query.Descend("foo").Constrain(4).Smaller(); IConstraint c2 = query.Descend("foo").Constrain(3).Greater(); IConstraint c3 = query.Descend("foo").Constrain(4).Greater(); c1.Or(c2); c1.Or(c3); AssertExpectedFoos(typeof(FieldIndexItem), new int[] { 3, 4, 7, 9 }, query); }
public virtual void TestTwoJoinLegs() { IQuery query = NewQuery(typeof(CollectionIndexedJoinTestCase.DataHolder)).Descend (Collectionfieldname); IConstraint left = query.Descend(Idfieldname).Constrain(0); left.Or(query.Descend(Idfieldname).Constrain(1)); IConstraint right = query.Descend(Idfieldname).Constrain(2); right.Or(query.Descend(Idfieldname).Constrain(-1)); left.Or(right); IObjectSet result = query.Execute(); Assert.AreEqual(3, result.Count); }
private IConstraint AddInterfaceConstraint(IReflectClass claxx) { Collection4 classes = Stream().ClassCollection().ForInterface(claxx); if (classes.Size() == 0) { QConClass qcc = new QConClass(_trans, null, null, claxx); AddConstraint(qcc); return(qcc); } IEnumerator i = classes.GetEnumerator(); IConstraint constr = null; while (i.MoveNext()) { ClassMetadata classMetadata = (ClassMetadata)i.Current; IReflectClass classMetadataClaxx = classMetadata.ClassReflector(); if (classMetadataClaxx != null) { if (!classMetadataClaxx.IsInterface()) { if (constr == null) { constr = Constrain(classMetadataClaxx); } else { constr = constr.Or(Constrain(classMetadata.ClassReflector())); } } } } return(constr); }
public virtual void AssertIndexedOr(int[] values, int expectedResultCount, int rootIdx , bool connectLeft) { IQuery query = NewQuery(typeof(CollectionIndexedJoinTestCase.DataHolder)).Descend (Collectionfieldname); IConstraint constraint = query.Descend(Idfieldname).Constrain(values[rootIdx]); for (int idx = 0; idx < values.Length; idx++) { if (idx != rootIdx) { IConstraint curConstraint = query.Descend(Idfieldname).Constrain(values[idx]); if (connectLeft) { constraint.Or(curConstraint); } else { curConstraint.Or(constraint); } } } IObjectSet result = query.Execute(); Assert.AreEqual(expectedResultCount, result.Count); }
public void Constrain(IQuery query) { IConstraint icon1 = query.Descend(InterfaceQueryTestCase.FieldA).Constrain(10); IConstraint icon2 = query.Descend(InterfaceQueryTestCase.FieldB).Constrain(10); icon1.Or(icon2); }
public virtual void Test() { IQuery qBooks = NewQuery(); qBooks.Constrain(typeof(MultiFieldIndexQueryTestCase.Book)); qBooks.Descend("title").Constrain("Persistence").Like(); IQuery qAuthors = qBooks.Descend("authors"); IQuery qFirstName = qAuthors.Descend("firstName"); IQuery qLastName = qAuthors.Descend("lastName"); IConstraint cAaron = qFirstName.Constrain("Aaron").And(qLastName.Constrain("OneOK" )); IConstraint cBill = qFirstName.Constrain("Bill").And(qLastName.Constrain("TwoOK") ); cAaron.Or(cBill); IObjectSet results = qAuthors.Execute(); Assert.AreEqual(4, results.Count); while (results.HasNext()) { MultiFieldIndexQueryTestCase.Person person = (MultiFieldIndexQueryTestCase.Person )results.Next(); Assert.IsTrue(person.lastName.EndsWith("OK")); } }
public virtual void TestTwoLevelDescendOr() { IQuery query = CreateComplexItemQuery(); IConstraint c1 = query.Descend("child").Descend("foo").Constrain(4).Smaller(); IConstraint c2 = query.Descend("child").Descend("foo").Constrain(4).Greater(); c1.Or(c2); AssertExpectedFoos(typeof(ComplexFieldIndexItem), new int[] { 4, 9 }, query); }
public virtual void TestSimpleOrExpectNone() { IQuery q = NewItemQuery(); IConstraint c1 = q.Descend("_id").Constrain(11); IConstraint c2 = q.Descend("_id").Constrain(13); c1.Or(c2); AssertResultSize(q, 0); }
public virtual void _testOrOnDifferentFields() { IQuery query = CreateComplexItemQuery(); IConstraint c1 = query.Descend("foo").Constrain(3); IConstraint c2 = query.Descend("bar").Constrain(8); c1.Or(c2); AssertExpectedFoos(typeof(ComplexFieldIndexItem), new int[] { 3, 7, 9 }, query); }
public virtual void TestCantOptimizeDifferentLevels() { IQuery query = CreateComplexItemQuery(); IConstraint c1 = query.Descend("child").Descend("foo").Constrain(4).Smaller(); IConstraint c2 = query.Descend("foo").Constrain(7).Greater(); c1.Or(c2); AssertCantOptimize(query); }
public virtual void TestCantOptimizeJoinOnNonIndexedFields() { IQuery query = CreateQuery(typeof(NonIndexedFieldIndexItem)); IConstraint c1 = query.Descend("foo").Constrain(1); IConstraint c2 = query.Descend("foo").Constrain(2); c1.Or(c2); AssertCantOptimize(query); }
public virtual void TestSingleIndexOr() { IQuery query = CreateItemQuery(); IConstraint c1 = query.Descend("foo").Constrain(4).Smaller(); IConstraint c2 = query.Descend("foo").Constrain(7).Greater(); c1.Or(c2); AssertExpectedFoos(typeof(FieldIndexItem), new int[] { 3, 9 }, query); }
public virtual void Visit(OrExpression expression) { expression.Left().Accept(this); IConstraint left = _constraint; expression.Right().Accept(this); left.Or(_constraint); _constraint = left; }
public virtual void TestTwoLevelDescendOr() { IQuery query = CreateComplexItemQuery(); IConstraint c1 = query.Descend("child").Descend("foo").Constrain(4).Smaller(); IConstraint c2 = query.Descend("child").Descend("foo").Constrain(4).Greater(); c1.Or(c2); AssertSingleOrNode(query); }
public virtual void TestAndOr() { IQuery q = NewItemQuery(); IConstraint c1 = q.Descend("_id").Constrain(1); IConstraint c2 = q.Descend("_id").Constrain(2); IConstraint c3 = q.Descend("_name").Constrain("A"); c1.Or(c2).And(c3); AssertResultSize(q, 2); }
public virtual void TestThreeOrsExpectTen() { IQuery q = NewItemQuery(); IConstraint c1 = q.Descend("_name").Constrain("A"); IConstraint c2 = q.Descend("_name").Constrain("B"); IConstraint c3 = q.Descend("_name").Constrain("C"); c1.Or(c2).Or(c3); AssertResultSize(q, 10); }
public virtual void TestThreeOrs() { IQuery query = CreateItemQuery(); IConstraint c1 = query.Descend("foo").Constrain(3); IConstraint c2 = query.Descend("foo").Constrain(4); IConstraint c3 = query.Descend("foo").Constrain(7); c1.Or(c2).Or(c3); AssertExpectedFoos(typeof(FieldIndexItem), new int[] { 3, 4, 7 }, query); }
public static IConstraint GetJointByType(IConstraint own, IConstraint with, JoinType type) { if (type == JoinType.And) { return(own.And(with)); } if (type == JoinType.Or) { return(own.Or(with)); } throw new NotSupportedException(); }
public virtual void TestMultipleOrs() { IQuery query = CreateComplexItemQuery(); IConstraint c1 = query.Descend("foo").Constrain(4).Smaller(); for (int i = 0; i < 5; i++) { IConstraint c2 = query.Descend("foo").Constrain(4).Greater(); c1 = c1.Or(c2); } AssertSingleOrNode(query); }
public virtual void TestOrChildId() { IQuery q = NewQuery(typeof(DescendIndexQueryTestCase.Parent)); IQuery qChild = q.Descend("_child"); IQuery qId = qChild.Descend("_id"); IConstraint c1 = qId.Constrain(0); IConstraint c2 = qId.Constrain(10); IConstraint c3 = qId.Constrain(100); c1.Or(c2).Or(c3); AssertResultSize(q, 6); }
public virtual void TestSingleIndexOrRange() { IQuery query = CreateItemQuery(); IConstraint c1 = query.Descend("foo").Constrain(1).Greater(); IConstraint c2 = query.Descend("foo").Constrain(4).Smaller(); IConstraint c3 = query.Descend("foo").Constrain(4).Greater(); IConstraint c4 = query.Descend("foo").Constrain(10).Smaller(); IConstraint cc1 = c1.And(c2); IConstraint cc2 = c3.And(c4); cc1.Or(cc2); AssertExpectedFoos(typeof(FieldIndexItem), new int[] { 3, 7, 9 }, query); }
/// <summary> /// adds a constraint to the passed Query to query only for objects that were /// modified since the last replication process between this and the other /// ObjectContainer involved in the current replication process. /// </summary> /// <remarks> /// adds a constraint to the passed Query to query only for objects that were /// modified since the last replication process between this and the other /// ObjectContainer involved in the current replication process. /// </remarks> /// <param name="query">the Query to be constrained</param> public virtual void WhereModified(IQuery query) { IQuery qTimestamp = query.Descend(VirtualField.CommitTimestamp); IConstraint constraint = qTimestamp.Constrain(GetLastReplicationVersion()).Greater (); long[] concurrentTimestamps = _replicationRecord._concurrentTimestamps; if (concurrentTimestamps != null) { for (int i = 0; i < concurrentTimestamps.Length; i++) { constraint = constraint.Or(qTimestamp.Constrain(concurrentTimestamps[i])); } } }
private void AssertAndOverOrQuery(bool explicitAnd) { IQuery query = CreateItemQuery(); IConstraint c1 = query.Descend("foo").Constrain(3); IConstraint c2 = query.Descend("foo").Constrain(9); IConstraint c3 = query.Descend("foo").Constrain(3); IConstraint c4 = query.Descend("foo").Constrain(7); IConstraint cc1 = c1.Or(c2); IConstraint cc2 = c3.Or(c4); if (explicitAnd) { cc1.And(cc2); } AssertExpectedFoos(typeof(FieldIndexItem), new int[] { 3 }, query); }
public virtual void Test() { IQuery query = NewQuery(typeof(OrderedOrConstraintTestCase.Item)); IConstraint c1 = query.Descend("_int").Constrain(9).Greater(); IConstraint c2 = query.Descend("_boolean").Constrain(true); c1.Or(c2); query.Descend("_int").OrderAscending(); IObjectSet objectSet = query.Execute(); Assert.AreEqual(2, objectSet.Count); OrderedOrConstraintTestCase.Item item = ((OrderedOrConstraintTestCase.Item)objectSet .Next()); Assert.AreEqual(4, item._int); item = ((OrderedOrConstraintTestCase.Item)objectSet.Next()); Assert.AreEqual(10, item._int); }
public virtual void Test() { IQuery barQuery = Db().Query(); barQuery.Constrain(typeof(PreserveJoinsTestCase.Child)); barQuery.Descend("name").Constrain("bar"); object barObj = barQuery.Execute().Next(); IQuery query = Db().Query(); query.Constrain(typeof(PreserveJoinsTestCase.Parent)); IConstraint c1 = query.Descend("value").Constrain("dontexist"); IConstraint c2 = query.Descend("child").Constrain(barObj); IConstraint c1_and_c2 = c1.And(c2); IConstraint cParent = query.Descend("value").Constrain("parent"); c1_and_c2.Or(cParent); Assert.AreEqual(1, query.Execute().Count); }
protected IObjectSet RetrieveHoldersWith(params T[] values) { IConstraint lastConstraint = null; var query = NewQuery(typeof(ValueTypeHolder)); foreach (var value in values) { var constraint = query.Descend("Value").Constrain(value); if (lastConstraint != null) { lastConstraint.Or(constraint); } lastConstraint = constraint; } return(query.Execute()); }
protected override ICollection <TEdge> EdgesOf(TItem item) { ICollection <TEdge> result = null; try { // this doesn't optimize; it seems that the easiest way is to // override Graphs with concrete classes //result = _session.Query<TEdge>(delegate(TEdge e) { // return e.Leaf.Equals(item) || e.Root.Equals(item); //}); IQuery query = Session.Query(); query.Constrain(typeof(TEdge)); IConstraint constr = query.Descend("_root").Constrain(item); constr.Or(query.Descend("_leaf").Constrain(item)); result = new NativeQueryWrapper <TEdge>(query.Execute()); } catch (Exception e) { throw e; } finally { } return(result); }
public IObjectSet ExecuteOMQueryList() { try { IConstraint ConCatClauses = null; IConstraint buildClause; IConstraint conCatGroup = null; objectContainer = Db4oClient.Client; IQuery query = objectContainer.Query(); //ToCheckQueryDirectly(); FormulateRootConstraints(query, m_OmQuery.BaseClass); int Groupcount = 0; foreach (OMQueryGroup qmGroup in m_OmQuery.ListQueryGroup) { int clausecount = 0; Groupcount++; buildClause = null; foreach (OMQueryClause qmclause in qmGroup.ListQueryClauses) { clausecount++; buildClause = FormulateFieldConstraints(query, qmclause);//.Classname, qmclause.Fieldname, qmclause.Value); if (qmclause.Operator != null) { if (qmclause.FieldType != BusinessConstants.DATETIME) { buildClause = ApplyOperator(buildClause, qmclause.Operator); } } if (qmclause.ClauseLogicalOperator == CommonValues.LogicalOperators.OR) { if (buildClause != null) { if (clausecount == 1) { ConCatClauses = buildClause; } if (clausecount > 1) { ConCatClauses = buildClause.Or(ConCatClauses); } } } if (qmclause.ClauseLogicalOperator == CommonValues.LogicalOperators.AND) { if (buildClause != null) { if (clausecount == 1) { ConCatClauses = buildClause; } if (clausecount > 1) { ConCatClauses = buildClause.And(ConCatClauses); } } } } IConstraint buildGroup = ConCatClauses ?? buildClause; if (qmGroup.GroupLogicalOperator != CommonValues.LogicalOperators.EMPTY) { if (qmGroup.GroupLogicalOperator == CommonValues.LogicalOperators.OR) { if (buildGroup != null) { conCatGroup = conCatGroup.Or(buildGroup); } } if (qmGroup.GroupLogicalOperator == CommonValues.LogicalOperators.AND) { if (buildGroup != null) { conCatGroup = conCatGroup.And(buildGroup); } } } else { conCatGroup = buildGroup; } } IObjectSet objSet = query.Execute(); return(objSet); } catch (Exception oEx) { LoggingHelper.HandleException(oEx); return(null); } }