Example #1
0
        internal static IOdbComparable BuildIndexKey(string indexName, AttributeValuesMap values, IList <string> fields)
        {
            if (fields.Count == 1)
            {
                return(new SimpleCompareKey(values.GetComparable(fields[0])));
            }

            var keys = new IOdbComparable[fields.Count];

            for (var i = 0; i < fields.Count; i++)
            {
                try
                {
                    var @object = (IComparable)values[fields[i]];
                    keys[i] = new SimpleCompareKey(@object);
                }
                catch (Exception)
                {
                    throw new OdbRuntimeException(
                              NDatabaseError.IndexKeysMustImplementComparable.AddParameter(indexName).AddParameter(fields[i]).
                              AddParameter(values[fields[i]].GetType().FullName));
                }
            }

            return(new ComposedCompareKey(keys));
        }
Example #2
0
        public override void Execute(OID oid, AttributeValuesMap values)
        {
            var n = Convert.ToDecimal(values[AttributeName]);

            _totalValue = Decimal.Add(_totalValue, ValuesUtil.Convert(n));
            _nbValues++;
        }
 private void Compute(AttributeValuesMap values)
 {
     for (var i = 0; i < _returnArraySize; i++)
     {
         ((AbstractQueryFieldAction)_queryFieldActions[i]).Execute(values.GetObjectInfoHeader().GetOid(), values);
     }
 }
Example #4
0
        public override void Execute(OID oid, AttributeValuesMap values)
        {
            var candidate = values[AttributeName];

            if (candidate is OID)
            {
                var candidateOid = (OID)candidate;
                candidate = _query.GetQueryEngine().GetObjectFromOid(candidateOid);
            }

            if (!(candidate is IList || candidate is string))
            {
                throw new OdbRuntimeException(
                          NDatabaseError.UnsupportedOperation.AddParameter("Size() with string or collection as the argument"));
            }

            var candidateAsString = candidate as string;

            if (candidateAsString != null)
            {
                _size = candidateAsString.Length;
            }
            else
            {
                var list = (IList)candidate;
                _size = list.Count;
            }
        }
Example #5
0
        public override bool MatchObjectWithOid(NeoDatis.Odb.OID oid, bool returnObject,
                                                bool inMemory)
        {
            currentOid = oid;
            ITmpCache        tmpCache = session.GetTmpCache();
            ObjectInfoHeader oih      = null;

            try
            {
                if (!criteriaQuery.HasCriteria())
                {
                    // true, false = use cache, false = do not return object
                    // TODO Warning setting true to useCache will put all objects in
                    // the cache
                    // This is not a good idea for big queries!, But use cache=true
                    // resolves when object have not been committed yet!
                    // for big queries, user should use a LazyCache!
                    if (inMemory)
                    {
                        currentNnoi = objectReader.ReadNonNativeObjectInfoFromOid(classInfo, currentOid,
                                                                                  true, returnObject);
                        if (currentNnoi.IsDeletedObject())
                        {
                            return(false);
                        }
                        currentOid = currentNnoi.GetOid();
                        nextOID    = currentNnoi.GetNextObjectOID();
                    }
                    else
                    {
                        oih     = objectReader.ReadObjectInfoHeaderFromOid(currentOid, false);
                        nextOID = oih.GetNextObjectOID();
                    }
                    return(true);
                }
                // Gets a map with the values with the fields involved in the query
                AttributeValuesMap attributeValues = objectReader.ReadObjectInfoValuesFromOID(classInfo, currentOid, true, involvedFields, involvedFields
                                                                                              , 0, criteriaQuery.GetOrderByFieldNames());
                // Then apply the query on the field values
                bool objectMatches = CriteriaQueryManager.Match(criteriaQuery, attributeValues);
                if (objectMatches)
                {
                    // Then load the entire object
                    // true, false = use cache
                    currentNnoi = objectReader.ReadNonNativeObjectInfoFromOid(classInfo, currentOid,
                                                                              true, returnObject);
                    currentOid = currentNnoi.GetOid();
                }
                oih = attributeValues.GetObjectInfoHeader();
                // Stores the next position
                nextOID = oih.GetNextObjectOID();
                return(objectMatches);
            }
            finally
            {
                tmpCache.ClearObjectInfos();
            }
        }
Example #6
0
        public override AttributeValuesMap GetValues()
        {
            var map = new AttributeValuesMap();

            foreach (var constraint in Constraints)
            {
                map.PutAll(((IInternalConstraint)constraint).GetValues());
            }

            return(map);
        }
        private IObjectValues ConvertObject(AttributeValuesMap values)
        {
            var dov = new ObjectValues(_returnArraySize);

            for (var i = 0; i < _returnArraySize; i++)
            {
                var queryFieldAction = _queryFieldActions[i];
                ((AbstractQueryFieldAction)queryFieldAction).Execute(values.GetObjectInfoHeader().GetOid(), values);

                SetValue(i, dov, queryFieldAction);
            }
            return(dov);
        }
Example #8
0
        public override void Execute(OID oid, AttributeValuesMap values)
        {
            var number = Convert.ToDecimal(values[AttributeName]);
            var bd     = ValuesUtil.Convert(number);

            if (bd.CompareTo(_maxValue) <= 0)
            {
                return;
            }

            _oidOfMaxValues = oid;
            _maxValue       = bd;
        }
Example #9
0
        public override void Execute(OID oid, AttributeValuesMap values)
        {
            _value = values[AttributeName];
            if (!(_value is ICollection || IsGenericCollection(_value.GetType())))
            {
                return;
            }

            // For collection,we encapsulate it in an lazy load list that will create objects on demand
            var c = ((IEnumerable)_value).Cast <object>().ToList();
            var l = new LazySimpleListOfAoi <object>(GetInstanceBuilder(), ReturnInstance());

            l.AddRange(c);
            _value = l;
        }
Example #10
0
        public AttributeValuesMap GetValues()
        {
            var map = new AttributeValuesMap();

            if (_oid != null)
            {
                map.SetOid(_oid);
            }
            else
            {
                map.Add(AttributeName, TheObject);
            }

            return(map);
        }
        public override bool Match(object valueToMatch)
        {
            string regExp = null;

            if (valueToMatch == null)
            {
                return(false);
            }
            // If it is a AttributeValuesMap, then gets the real value from the map
            if (valueToMatch is AttributeValuesMap)
            {
                AttributeValuesMap attributeValues = (AttributeValuesMap)valueToMatch;
                valueToMatch = attributeValues[attributeName];
            }
            if (valueToMatch == null)
            {
                return(false);
            }
            // Like operator only work with String
            if (!(valueToMatch is string))
            {
                throw new ODBRuntimeException(NeoDatisError.QueryAttributeTypeNotSupportedInLikeExpression
                                              .AddParameter(valueToMatch.GetType().FullName));
            }
            string value = (string)valueToMatch;

            if (criterionValue.IndexOf("%") != -1)
            {
                regExp = OdbString.ReplaceToken(criterionValue, "%", "(.)*");
                if (isCaseSensitive)
                {
                    bool b = value != null && OdbString.Matches(regExp, value);
                    return(b);
                }
                return(value != null && OdbString.Matches(regExp.ToLower()
                                                          , value.ToLower()));
            }
            if (isCaseSensitive)
            {
                regExp = string.Format("(.)*%s(.)*", criterionValue);
                return(value != null && OdbString.Matches(regExp, value));
            }
            regExp = string.Format("(.)*%s(.)*", criterionValue.ToLower());
            return(value != null && OdbString.Matches(regExp, value.ToLower()));
        }
Example #12
0
        protected override bool MatchObjectWithOid(OID oid, bool returnObject, bool inMemory)
        {
            CurrentOid = oid;

            // Gets a map with the values with the fields involved in the query
            _values = ObjectReader.ReadObjectInfoValuesFromOID(ClassInfo, CurrentOid, true, _involvedFields,
                                                               _involvedFields, 0);

            var objectMatches = true;

            if (!_sodaQuery.IsForSingleOid())
            {
                // Then apply the query on the field values
                objectMatches = _sodaQuery.Match(_values);
            }

            var objectInfoHeader = _values.GetObjectInfoHeader();

            // Stores the next position
            NextOID = objectInfoHeader.GetNextObjectOID();
            return(objectMatches);
        }
Example #13
0
        public override void Execute(OID oid, AttributeValuesMap values)
        {
            var candidate = values[AttributeName];

            if (candidate is OID)
            {
                var candidateOid = (OID)candidate;
                candidate = _query.GetQueryEngine().GetObjectFromOid(candidateOid);
            }

            var l = ((IEnumerable)candidate).Cast <object>().ToList();
            var localFromIndex = _fromIndex;
            var localEndIndex  = _fromIndex + _size;

            // If not throw exception, we must implement
            // Index Out Of Bound protection
            if (!_throwExceptionIfOutOfBound)
            {
                // Check from index
                if (localFromIndex > l.Count - 1)
                {
                    localFromIndex = 0;
                }

                // Check end index
                if (localEndIndex > l.Count)
                {
                    localEndIndex = l.Count;
                }
            }

            _sublist = new LazySimpleListOfAoi <object>(GetInstanceBuilder(), ReturnInstance());
            var count   = localEndIndex - localFromIndex;
            var sublist = l.GetRange(localFromIndex, count);

            _sublist.AddAll(sublist);
        }
Example #14
0
 public override void Execute(OID oid, AttributeValuesMap values)
 {
     _count = Decimal.Add(_count, One);
 }
 private IOdbComparable BuildOrderByKey(AttributeValuesMap values)
 {
     return(IndexTool.BuildIndexKey("OrderBy", values, Query.GetOrderByFieldNames()));
 }
Example #16
0
 public abstract void Execute(OID oid, AttributeValuesMap values);
Example #17
0
        public override void Execute(OID oid, AttributeValuesMap values)
        {
            var number = Convert.ToDecimal(values[AttributeName]);

            _sum = Decimal.Add(_sum, ValuesUtil.Convert(number));
        }