예제 #1
0
파일: NotInOperator.cs 프로젝트: Vadi/sones
        public override IEnumerable<ObjectUUID> IndexSingleOperation(AAttributeIndex myIndex, ADBBaseObject myOperationValue, AttributeUUID myAttributeUUID, TypesOfBinaryExpression typeOfBinExpr, DBContext dbContext)
        {
            IndexKey lookup = new IndexKey(myAttributeUUID, myOperationValue, myIndex.IndexKeyDefinition);
            var currentType = dbContext.DBTypeManager.GetTypeByUUID(myIndex.IndexRelatedTypeUUID);

            var result = myIndex.Contains(lookup, currentType, dbContext);
            if (result.Value)
            {
                var interestingUUIDs = myIndex.GetValues(lookup, currentType, dbContext);

                foreach (var aIndexValue in myIndex.GetAllValues(currentType, dbContext))
                {
                    foreach (var aUUID in aIndexValue)
                    {
                        if (!interestingUUIDs.Contains(aUUID))
                        {
                            yield return aUUID;
                        }
                    }
                }
            }
            else
            {
                foreach (var aIndexValue in myIndex.GetKeyValues(currentType, dbContext).Select(kv => kv.Value))
                {
                    foreach (var aUUID in aIndexValue)
                    {
                        yield return aUUID;
                    }
                }
            }

            yield break;
        }
예제 #2
0
        public override IEnumerable<ObjectUUID> IndexSingleOperation(AAttributeIndex myIndex, ADBBaseObject myOperationValue, AttributeUUID myAttributeUUID, TypesOfBinaryExpression typeOfBinExpr, DBContext dbContext)
        {
            var myIndeyKey = new IndexKey(myAttributeUUID, myOperationValue, myIndex.IndexKeyDefinition);
            var currentType = dbContext.DBTypeManager.GetTypeByUUID(myIndex.IndexRelatedTypeUUID);

            if (myIndex.Contains(myIndeyKey, currentType, dbContext))
            {
                foreach (var aUUID in myIndex.GetValues(myIndeyKey, currentType, dbContext))
                {
                    yield return aUUID;
                }
            }

            yield break;
        }
예제 #3
0
파일: InOperator.cs 프로젝트: TheByte/sones
        public override IEnumerable<ObjectUUID> IndexOperation(AAttributeIndex myIndex, TupleDefinition myTuple, TypesOfBinaryExpression typeOfBinExpr, DBContext dbContext)
        {
            HashSet<ObjectUUID> interestingUUIDs = new HashSet<ObjectUUID>();
            IndexKey idxLookupKey = null;
            var currentType = dbContext.DBTypeManager.GetTypeByUUID(myIndex.IndexRelatedTypeUUID);

            var myOperationValues = myTuple;

            switch (typeOfBinExpr)
            {
                case TypesOfBinaryExpression.LeftComplex:

                    if (!myIndex.IsListOfBaseObjectsIndex)
                    {
                        foreach (var aItem in myOperationValues)
                        {
                            idxLookupKey = new IndexKey(myIndex.IndexKeyDefinition.IndexKeyAttributeUUIDs[0], (aItem.Value as ValueDefinition).Value, myIndex.IndexKeyDefinition);
                            interestingUUIDs.UnionWith(myIndex.GetValues(idxLookupKey, currentType, dbContext));
                        }
                    }
                    else
                    {
                        #region In case the index is from a set or list of baseobjects we use this way to get the values

                        foreach (var aItem in myOperationValues)
                        {
                            idxLookupKey = new IndexKey(myIndex.IndexKeyDefinition.IndexKeyAttributeUUIDs[0], (aItem.Value as ValueDefinition).Value, myIndex.IndexKeyDefinition);
                            interestingUUIDs.UnionWith(myIndex.GetValues(idxLookupKey, currentType, dbContext));
                        }

                        /* What the hack is that??? - This is too slow for any usual usage of in operator! */

                        var indexRelatedType = dbContext.DBTypeManager.GetTypeByUUID(myIndex.IndexRelatedTypeUUID);

                        foreach (var aKey in myIndex.GetKeys(currentType, dbContext).Where(item => !myOperationValues.Contains(new TupleElement(new ValueDefinition(item.IndexKeyValues[0])))))
                        {
                            foreach (var aMatch in myIndex.GetValues(aKey, indexRelatedType, dbContext).Intersect(interestingUUIDs))
                            {
                                interestingUUIDs.Remove(aMatch);
                            }
                        }

                        #endregion
                    }

                    break;

                case TypesOfBinaryExpression.RightComplex:

                    var myEnumerator = myOperationValues.GetEnumerator();

                    if (myEnumerator.MoveNext())
                    {
                        idxLookupKey = new IndexKey(myIndex.IndexKeyDefinition.IndexKeyAttributeUUIDs[0], (myEnumerator.Current.Value as ValueDefinition).Value, myIndex.IndexKeyDefinition);

                        interestingUUIDs.UnionWith(myIndex.GetValues(idxLookupKey, currentType, dbContext));

                        while (myEnumerator.MoveNext())
                        {
                            idxLookupKey = new IndexKey(myIndex.IndexKeyDefinition.IndexKeyAttributeUUIDs[0], (myEnumerator.Current.Value as ValueDefinition).Value, myIndex.IndexKeyDefinition);
                            interestingUUIDs.IntersectWith(myIndex.GetValues(idxLookupKey, currentType, dbContext));
                        }
                    }

                    break;

                case TypesOfBinaryExpression.Atom:
                case TypesOfBinaryExpression.Complex:
                case TypesOfBinaryExpression.Unknown:
                default:
                    break;
            }

            foreach (var aValidUUID in interestingUUIDs)
            {
                yield return aValidUUID;
            }

            yield break;
        }