public int Compare(SoodaObject dbo1, SoodaObject dbo2)
        {
            object v1 = dbo1.Evaluate(_propertyChain, false);
            object v2 = dbo2.Evaluate(_propertyChain, false);

            if (_sortOrder == SortOrder.Ascending)
                return DoCompare(v1, v2, dbo1, dbo2);
            else
                return -DoCompare(v1, v2, dbo1, dbo2);
        }
 internal void AddToPostCommitQueue(SoodaObject o)
 {
     if (transactionLogger.IsTraceEnabled)
         transactionLogger.Trace("Adding {0} to post-commit queue", o.GetObjectKeyString());
     _postCommitQueue.Add(o);
 }
 public abstract IDataReader LoadObject(SoodaObject obj, object keyValue, out TableInfo[] tables);
 public EvaluateContext()
 {
     _rootObject = null;
 }
        public int Compare(SoodaObject dbo1, SoodaObject dbo2)
        {
            _context1.SetRootObject(dbo1);
            _context2.SetRootObject(dbo2);

            foreach (ExpressionCompareInfo eci in expressions)
            {
                object v1 = eci.Expression.Evaluate(_context1);
                object v2 = eci.Expression.Evaluate(_context2);

                int result = DoCompare(v1, v2);
                if (result != 0)
                {
                    if (eci.SortOrder == SortOrder.Ascending)
                        return result;
                    else
                        return -result;
                }
            }

            return PrimaryKeyCompare(dbo1, dbo2);
        }
示例#6
0
        internal void SetRefFieldValue(int tableNumber, string fieldName, int fieldOrdinal, SoodaObject newValue, SoodaObject[] refcache, int refCacheOrdinal, ISoodaObjectFactory factory)
        {
            if (newValue != null)
            {
                // transaction check
                if (newValue.GetTransaction() != this.GetTransaction())
                    throw new SoodaException("Attempted to assign object " + newValue.GetObjectKeyString() + " from another transaction to " + this.GetObjectKeyString() + "." + fieldName);
            }

            EnsureFieldsInited();
            EnsureDataLoaded(tableNumber);

            SoodaObject oldValue = null;

            SoodaObjectImpl.GetRefFieldValue(ref oldValue, this, tableNumber, fieldOrdinal, GetTransaction(), factory);
            if (Object.Equals(oldValue, newValue))
                return;
            object[] triggerArgs = new object[] { oldValue, newValue };

            if (AreFieldUpdateTriggersEnabled())
            {
                MethodInfo mi = this.GetType().GetMethod("BeforeFieldUpdate_" + fieldName, BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Public);
                if (mi != null)
                    mi.Invoke(this, triggerArgs);
            }
            Sooda.Schema.FieldInfo fieldInfo = GetClassInfo().UnifiedFields[fieldOrdinal];
            StringCollection backRefCollections = GetTransaction().Schema.GetBackRefCollections(fieldInfo);
            if (oldValue != null && backRefCollections != null)
            {
                foreach (string collectionName in backRefCollections)
                {
                    PropertyInfo coll = oldValue.GetType().GetProperty(collectionName, BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.Public);
                    if (coll == null)
                        throw new Exception(collectionName + " not found in " + oldValue.GetType().Name + " while setting " + this.GetType().Name + "." + fieldName);
                    ISoodaObjectListInternal listInternal = (ISoodaObjectListInternal)coll.GetValue(oldValue, null);
                    listInternal.InternalRemove(this);
                }
            }
            SetFieldValue(fieldOrdinal, newValue != null ? newValue.GetPrimaryKeyValue() : null);
            refcache[refCacheOrdinal] = null;
            if (newValue != null && backRefCollections != null)
            {
                foreach (string collectionName in backRefCollections)
                {
                    PropertyInfo coll = newValue.GetType().GetProperty(collectionName, BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.Public);
                    if (coll == null)
                        throw new Exception(collectionName + " not found in " + newValue.GetType().Name + " while setting " + this.GetType().Name + "." + fieldName);
                    ISoodaObjectListInternal listInternal = (ISoodaObjectListInternal)coll.GetValue(newValue, null);
                    listInternal.InternalAdd(this);
                }
            }
            if (AreFieldUpdateTriggersEnabled())
            {
                MethodInfo mi = this.GetType().GetMethod("AfterFieldUpdate_" + fieldName, BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Public);
                if (mi != null)
                    mi.Invoke(this, triggerArgs);
            }
        }
        private static int DoCompare(object v1, object v2, SoodaObject dbo1, SoodaObject dbo2)
        {
            if (v1 == null)
            {
                if (v2 == null)
                    return PrimaryKeyCompare(dbo1, dbo2);
                else
                    return -1;  // null is less than anything
            };

            if (v2 == null)
            {
                return 1;   // not null is greater than anything
            }

            int v = ((IComparable)v1).CompareTo(v2);
            if (v == 0)
                return PrimaryKeyCompare(dbo1, dbo2);
            else
                return v;
        }
 public EvaluateContext(SoodaWhereClause whereClause, SoodaObject rootObject)
 {
     _whereClause = whereClause;
     _rootObject = rootObject;
 }
        protected internal void RegisterObject(SoodaObject o)
        {
            // Console.WriteLine("Registering object {0}...", o.GetObjectKey());

            object pkValue = o.GetPrimaryKeyValue();
            // Console.WriteLine("Adding key: " + o.GetObjectKey() + " of type " + o.GetType());
            for (ClassInfo ci = o.GetClassInfo(); ci != null; ci = ci.InheritsFromClass)
            {
                AddObjectWithKey(ci.Name, pkValue, o);

                List<WeakSoodaObject> al;
                if (!_objectsByClass.TryGetValue(ci.Name, out al))
                {
                    al = new List<WeakSoodaObject>();
                    _objectsByClass[ci.Name] = al;
                }
                al.Add(new WeakSoodaObject(o));
            }

            if (!UseWeakReferences)
                _strongReferences.Add(o);

            _objectList.Add(new WeakSoodaObject(o));

            if (_precommitQueue != null)
                _precommitQueue.Enqueue(o);

        }
示例#10
0
 private void AddObjectWithKey(string className, object keyValue, SoodaObject obj)
 {
     // Console.WriteLine("AddObjectWithKey('{0}',{1})", className, keyValue);
     if (keyValue == null) keyValue = "";
     GetObjectDictionaryForClass(className)[keyValue] = new WeakSoodaObject(obj);
 }
示例#11
0
 internal void SetPersistentValue(SoodaObject obj, string name, string value)
 {
     NameValueCollection dict;
     if (!_persistentValues.TryGetValue(obj, out dict))
     {
         dict = new NameValueCollection();
         _persistentValues.Add(obj, dict);
     }
     dict[name] = value;
 }
示例#12
0
 internal string GetPersistentValue(SoodaObject obj, string name)
 {
     NameValueCollection dict;
     if (!_persistentValues.TryGetValue(obj, out dict))
         return null;
     return dict[name];
 }
示例#13
0
 internal NameValueCollection GetPersistentValues(SoodaObject obj)
 {
     NameValueCollection dict;
     _persistentValues.TryGetValue(obj, out dict);
     return dict;
 }
示例#14
0
 public abstract IDataReader LoadObjectTable(SoodaObject obj, object keyValue, int tableNumber, out TableInfo[] tables);
示例#15
0
        static int Compare(SoodaObject o1, SoodaObject o2)
        {
            int retval = string.CompareOrdinal(o1.GetClassInfo().Name, o2.GetClassInfo().Name);
            if (retval != 0)
                return retval;

            return ((IComparable) o1.GetPrimaryKeyValue()).CompareTo(o2.GetPrimaryKeyValue());
        }
示例#16
0
        public bool Matches(SoodaObject obj, bool throwOnUnknown)
        {
            if (this.WhereExpression == null)
                return true;

            EvaluateContext context = new EvaluateContext(this, obj);
            object val = this.WhereExpression.Evaluate(context);
            if (val == null && throwOnUnknown)
                throw new SoqlException("Cannot evaluate expression '" + this.whereExpression.ToString() + " ' in memory.");

            if (val is bool)
                return (bool)val;
            else
                return false;
        }
示例#17
0
 protected internal void RegisterDirtyObject(SoodaObject o)
 {
     // transactionLogger.Debug("RegisterDirtyObject({0})", o.GetObjectKeyString());
     _dirtyObjects.Add(o);
     for (ClassInfo ci = o.GetClassInfo(); ci != null; ci = ci.InheritsFromClass)
     {
         List<WeakSoodaObject> al;
         if (!_dirtyObjectsByClass.TryGetValue(ci.Name, out al))
         {
             al = new List<WeakSoodaObject>();
             _dirtyObjectsByClass[ci.Name] = al;
         }
         al.Add(new WeakSoodaObject(o));
     }
 }
示例#18
0
        protected internal bool IsRegistered(SoodaObject o)
        {
            object pkValue = o.GetPrimaryKeyValue();

            return ExistsObjectWithKey(o.GetClassInfo().Name, pkValue);
        }
示例#19
0
 private static void RemoveWeakSoodaObjectFromCollection(List<WeakSoodaObject> collection, SoodaObject o)
 {
     for (int i = 0; i < collection.Count; ++i)
     {
         if (collection[i].TargetSoodaObject == o)
         {
             collection.RemoveAt(i);
             break;
         }
     }
 }
        public int Compare(SoodaObject dbo1, SoodaObject dbo2)
        {
            foreach (FieldCompareInfo fci in fields)
            {
                object v1 = dbo1.Evaluate(fci.propertyChain, false);
                object v2 = dbo2.Evaluate(fci.propertyChain, false);

                int result = DoCompare(v1, v2);
                if (result != 0)
                {
                    if (fci.sortOrder == SortOrder.Ascending)
                        return result;
                    else
                        return -result;
                }
            }

            return PrimaryKeyCompare(dbo1, dbo2);
        }
示例#21
0
        protected internal void UnregisterObject(SoodaObject o)
        {
            object pkValue = o.GetPrimaryKeyValue();

            if (ExistsObjectWithKey(o.GetClassInfo().Name, pkValue))
            {
                UnregisterObjectWithKey(o.GetClassInfo().Name, pkValue);
                for (ClassInfo ci = o.GetClassInfo().InheritsFromClass; ci != null; ci = ci.InheritsFromClass)
                {
                    UnregisterObjectWithKey(ci.Name, pkValue);
                }
                RemoveWeakSoodaObjectFromCollection(_objectList, o);

                List<WeakSoodaObject> al;
                if (_objectsByClass.TryGetValue(o.GetClassInfo().Name, out al))
                {
                    RemoveWeakSoodaObjectFromCollection(al, o);
                }
            }
        }
示例#22
0
 public EvaluateContext(SoodaObject rootObject)
 {
     _rootObject = rootObject;
 }
示例#23
0
 internal void MarkPrecommitted(SoodaObject o)
 {
     _precommittedClassOrRelation[o.GetClassInfo().GetRootClass().Name] = true;
 }
 private static int PrimaryKeyCompare(SoodaObject dbo1, SoodaObject dbo2)
 {
     return ((IComparable)dbo1.GetPrimaryKeyValue()).CompareTo(dbo2.GetPrimaryKeyValue());
 }
示例#25
0
 internal void PrecommitObject(SoodaObject o)
 {
     if (!o.VisitedOnCommit && !o.IsMarkedForDelete())
     {
         MarkPrecommitted(o);
         o.SaveObjectChanges();
     }
 }
 public void SetRootObject(SoodaObject o)
 {
     _rootObject = o;
 }
示例#27
0
 public abstract void SaveObjectChanges(SoodaObject obj, bool isPrecommit);