public void Constrain(IQuery query) { IConstraint icon1 = query.Descend(InterfaceQueryTestCase.FieldA).Constrain(10); IConstraint icon2 = query.Descend(InterfaceQueryTestCase.FieldB).Constrain(10); icon1.And(icon2); }
public virtual void TestSingleIndexAndRange() { IQuery query = CreateItemQuery(); IConstraint c1 = query.Descend("foo").Constrain(3).Greater(); IConstraint c2 = query.Descend("foo").Constrain(9).Smaller(); c1.And(c2); AssertExpectedFoos(typeof(FieldIndexItem), new int[] { 4, 7 }, query); }
public virtual void TestSimpleAndExpectNone() { IQuery q = NewItemQuery(); IConstraint c1 = q.Descend("_id").Constrain(3); IConstraint c2 = q.Descend("_name").Constrain("B"); c1.And(c2); AssertResultSize(q, 0); }
public virtual void TestJointEqualsIdentity() { JointEqualsIdentityTestCase.TestSubject child = RetrieveChild(); IQuery query = NewQuery(typeof(JointEqualsIdentityTestCase.TestSubject)); IConstraint constraint = query.Descend("_name").Constrain("B").Equal(); constraint.And(query.Descend("_child").Constrain(child).Identity()); Assert.AreEqual(1, query.Execute().Count); }
public virtual void Visit(AndExpression expression) { expression.Left().Accept(this); IConstraint left = _constraint; expression.Right().Accept(this); left.And(_constraint); _constraint = left; }
public virtual void TestOrAnd() { IQuery q = NewItemQuery(); IConstraint c1 = q.Descend("_id").Constrain(1); IConstraint c2 = q.Descend("_name").Constrain("A"); IConstraint c3 = q.Descend("_name").Constrain("B"); c1.And(c2).Or(c3); AssertResultSize(q, 6); }
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 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); }
private void AddFieldConstraints(IQuery query, PersistentEntryTemplate template) { if (template.fieldNames.Length == 0) { return; } IConstraint c = AddFieldConstraint(query, template, 0); for (int i = 1; i < template.fieldNames.Length; ++i) { c = c.And(AddFieldConstraint(query, template, 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 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); }
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); } }
/// <summary> /// Retrieves all the references to the specified entity. The specified entity can be either the source or reference entity as references work both ways. /// </summary> /// <param name="entityType">The type of the entity to retrieve the corresponding references for.</param> /// <param name="entityID">The ID of the entity to retrieve the corresponding references for.</param> /// <param name="referenceType">The type of entity at the other side of the reference to the one specified.</param> /// <param name="activateAll">A value indicating whether to activate the references by loading the corresponding entities and setting them to the SourceEntity and ReferenceEntity properties.</param> /// <returns>A collection of references that match the provided parameters.</returns> public override EntityReferenceCollection GetReferences(Type entityType, Guid entityID, Type referenceType, bool activateAll) { EntityReferenceCollection collection = new EntityReferenceCollection(); using (LogGroup logGroup = LogGroup.StartDebug("Retrieving references.")) { if (entityType == null) { throw new ArgumentNullException("entityType"); } if (referenceType == null) { throw new ArgumentNullException("referenceType"); } LogWriter.Debug("Entity type: " + entityType.ToString()); LogWriter.Debug("Reference type: " + referenceType.ToString()); Db4oDataStore dataStore = (Db4oDataStore)GetDataStore(entityType.Name, referenceType.Name); if (dataStore.DoesExist) { EntityReferenceCollection list = new EntityReferenceCollection(); IQuery query1 = dataStore.ObjectContainer.Query(); query1.Constrain(typeof(EntityReference)); IConstraint constraint1 = query1.Descend("type1Name").Constrain(EntitiesUtilities.GetShortType(entityType.Name)).Equal().And( query1.Descend("type2Name").Constrain(EntitiesUtilities.GetShortType(referenceType.Name)).Equal()); if (entityID != Guid.Empty) { constraint1.And(query1.Descend("entity1ID").Constrain(entityID).Equal()); } IQuery query2 = dataStore.ObjectContainer.Query(); query2.Constrain(typeof(EntityReference)); IConstraint constraint2 = query2.Descend("type2Name").Constrain(EntitiesUtilities.GetShortType(entityType.Name)).Equal().And( query2.Descend("type1Name").Constrain(EntitiesUtilities.GetShortType(referenceType.Name)).Equal()); if (entityID != Guid.Empty) { constraint2.And(query2.Descend("entity2ID").Constrain(entityID).Equal()); } IObjectSet os1 = query1.Execute(); while (os1.HasNext()) { EntityReference reference = (EntityReference)os1.Next(); list.Add(reference); } IObjectSet os2 = query2.Execute(); while (os2.HasNext()) { EntityReference reference = (EntityReference)os2.Next(); list.Add(reference); } if (list.Count == 0) { LogWriter.Debug("No references loaded from the data store."); } else { LogWriter.Debug("Count: " + list.Count); foreach (EntityReference r in list) { using (LogGroup logGroup2 = LogGroup.StartDebug("Processing reference.")) { EntityReference reference = (EntityReference)r.SwitchFor(entityType, entityID); LogWriter.Debug("Loaded reference - Entity ID 1: " + reference.Entity1ID); LogWriter.Debug("Loaded reference - Entity ID 2: " + reference.Entity2ID); LogWriter.Debug("Loaded reference - Property 1 name: " + reference.Property1Name); LogWriter.Debug("Loaded reference - Property 2 name: " + reference.Property2Name); LogWriter.Debug("Loaded reference - Type name 1: " + reference.Type1Name); LogWriter.Debug("Loaded reference - Type name 2: " + reference.Type2Name); if (reference.Entity1ID != Guid.Empty && reference.Entity2ID != Guid.Empty) { // LogWriter.Debug("Adding to the collection."); collection.Add(reference); } else { LogWriter.Error("Reference not added to the collection. IDs are empty. This shouldn't happen but the system can ignore it and continue. Invalid references like these should probably be deleted."); } } } } } LogWriter.Debug("References #: " + collection.Count.ToString()); if (activateAll) { LogWriter.Debug("Activating references."); foreach (EntityReference reference in collection) { Provider.Activator.ActivateReference(reference); } } LogWriter.Debug("References #: " + collection.Count.ToString()); } return(collection); }