Ejemplo n.º 1
0
        public int Upsert(ISqlConnectionProvider connectionProvider, string fr8AccountId, MtObject newObject, AstNode @where)
        {
            if (where == null)
            {
                _mtObjects.Add(newObject);
                return(1);
            }

            int changed = 0;

            for (int index = 0; index < _mtObjects.Count; index++)
            {
                var obj  = _mtObjects[index];
                var eval = new AstEvaluator(obj, _converter);
                if (eval.Evaluate(@where))
                {
                    _mtObjects[index] = newObject;
                    changed++;
                }
            }

            if (changed == 0)
            {
                _mtObjects.Add(newObject);
            }

            return(changed);
        }
Ejemplo n.º 2
0
 public IEnumerable <MtObject> Query(ISqlConnectionProvider connectionProvider, string fr8AccountId, MtTypeDefinition type, AstNode @where)
 {
     for (int index = 0; index < _mtObjects.Count; index++)
     {
         var obj  = _mtObjects[index];
         var eval = new AstEvaluator(obj, _converter);
         if (eval.Evaluate(@where))
         {
             yield return(obj);
         }
     }
 }
Ejemplo n.º 3
0
        public int Delete(ISqlConnectionProvider connectionProvider, string fr8AccountId, MtTypeDefinition type, AstNode @where)
        {
            int changed = 0;

            for (int index = _mtObjects.Count - 1; index >= 0; index--)
            {
                var obj  = _mtObjects[index];
                var eval = new AstEvaluator(obj, _converter);
                if (eval.Evaluate(@where))
                {
                    _mtObjects.RemoveAt(index);
                }
            }

            return(changed);
        }
Ejemplo n.º 4
0
        public int QueryScalar(ISqlConnectionProvider connectionProvider, string fr8AccountId, MtTypeDefinition type, AstNode @where)
        {
            int count = 0;

            for (int index = 0; index < _mtObjects.Count; index++)
            {
                var obj  = _mtObjects[index];
                var eval = new AstEvaluator(obj, _converter);
                if (eval.Evaluate(@where))
                {
                    count++;
                }
            }

            return(count);
        }
Ejemplo n.º 5
0
        public int Insert(ISqlConnectionProvider connectionProvider, string fr8AccountId, MtObject newObject, AstNode uniqueConstraint)
        {
            if (uniqueConstraint != null)
            {
                foreach (var obj in _mtObjects)
                {
                    var eval = new AstEvaluator(obj, _converter);
                    if (eval.Evaluate(uniqueConstraint))
                    {
                        throw new Exception("Object already exists");
                    }
                }
            }

            _mtObjects.Add(newObject);

            return(1);
        }