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));
        }
        public SoodaObjectListSnapshot(SoodaTransaction tran, SoodaObjectFilter filter, ClassInfo ci)
        {
            this.classInfo = ci;
            List <WeakSoodaObject> al = tran.GetObjectsByClassName(ci.Name);

            if (al != null)
            {
                // al.Clone() is needed because
                // the filter expression may materialize new objects
                // during checking. This way we avoid "collection modified" exception

                List <SoodaObject> clonedArray = new List <SoodaObject>();
                foreach (WeakSoodaObject wr in al)
                {
                    SoodaObject obj = wr.TargetSoodaObject;
                    if (obj != null)
                    {
                        clonedArray.Add(obj);
                    }
                }

                foreach (SoodaObject obj in clonedArray)
                {
                    if (filter(obj))
                    {
                        items.Add(obj);
                    }
                }
                count = items.Count;
            }
        }
Esempio n. 3
0
 void DoUpdates(SoodaObject obj, bool isPrecommit)
 {
     foreach (TableInfo table in obj.GetClassInfo().DatabaseTables)
     {
         DoUpdatesForTable(obj, table, isPrecommit);
     }
 }
Esempio n. 4
0
        private SoodaObject BeginObjectDeserialization(ISoodaObjectFactory factory, object pkValue, string mode)
        {
            SoodaObject retVal = factory.TryGet(this, pkValue);

            if (retVal == null)
            {
                if (mode == "update")
                {
                    transactionLogger.Debug("Object not found. GetRef() ing");
                    retVal = factory.GetRef(this, pkValue);
                }
                else
                {
                    transactionLogger.Debug("Object not found. Getting new raw object.");
                    retVal = factory.GetRawObject(this);
                    Statistics.RegisterObjectUpdate();
                    SoodaStatistics.Global.RegisterObjectUpdate();
                    retVal.SetPrimaryKeyValue(pkValue);
                    retVal.SetInsertMode();
                }
            }
            else if (mode == "insert")
            {
                retVal.SetInsertMode();
            }

            return(retVal);
        }
        int IComparer.Compare(object o1, object o2)
        {
            SoodaObject dbo1 = o1 as SoodaObject;
            SoodaObject dbo2 = o2 as SoodaObject;

            return(Compare(dbo1, dbo2));
        }
        public void InternalAdd(SoodaObject c)
        {
            if (!childType.IsInstanceOfType(c))
            {
                return;
            }

            if (items == null)
            {
                if (tempItems == null)
                {
                    tempItems = new Dictionary <SoodaObject, CollectionChange>();
                }
                tempItems[c] = CollectionChange.Added;
                return;
            }

            if (items.ContainsKey(c))
            {
                return;
            }

            items.Add(c, itemsArray.Count);
            itemsArray.Add(c);
        }
Esempio n. 7
0
        object GetFieldValue(SoodaObject obj, FieldInfo fi, bool isPrecommit)
        {
            object val = obj.GetFieldValue(fi.ClassUnifiedOrdinal);

            if (!fi.IsNullable && SqlBuilder.IsNullValue(val, fi))
            {
                if (!isPrecommit)
                {
                    throw new SoodaDatabaseException(obj.GetObjectKeyString() + "." + fi.Name + " cannot be null on commit.");
                }
                val = fi.PrecommitTypedValue;
                if (val == null)
                {
                    throw new SoodaDatabaseException(obj.GetObjectKeyString() + "." + fi.Name + " is null on precommit and no 'precommitValue' has been defined for it.");
                }
                if (val == SchemaInfo.NullPrecommitValue)
                {
                    val = null;
                }
                if (logger.IsDebugEnabled)
                {
                    logger.Debug("Using precommit value of {0} for {1}.{2}", val, fi.Table.NameToken, fi.Name);
                }
            }
            return(val);
        }
Esempio n. 8
0
        public override IDataReader LoadObjectTable(SoodaObject obj, object keyVal, int tableNumber, out TableInfo[] loadedTables)
        {
            ClassInfo  classInfo = obj.GetClassInfo();
            IDbCommand cmd       = Connection.CreateCommand();

            try
            {
                cmd.CommandTimeout = CommandTimeout;
            }
            catch (NotSupportedException e)
            {
                logger.Debug("CommandTimeout not supported. {0}", e.Message);
            }

            if (Transaction != null)
            {
                cmd.Transaction = this.Transaction;
            }

            SqlBuilder.BuildCommandWithParameters(cmd, false, GetLoadingSelectStatement(classInfo, classInfo.UnifiedTables[tableNumber], out loadedTables), SoodaTuple.GetValuesArray(keyVal), false);
            IDataReader reader = TimedExecuteReader(cmd);

            if (reader.Read())
            {
                return(reader);
            }
            else
            {
                reader.Dispose();
                return(null);
            }
        }
Esempio n. 9
0
        internal NameValueCollection GetPersistentValues(SoodaObject obj)
        {
            NameValueCollection dict;

            _persistentValues.TryGetValue(obj, out dict);
            return(dict);
        }
Esempio n. 10
0
        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);
            }
        }
        public void InternalRemove(SoodaObject c)
        {
            if (!childType.IsInstanceOfType(c))
            {
                return;
            }

            if (items == null)
            {
                if (tempItems == null)
                {
                    tempItems = new Dictionary <SoodaObject, CollectionChange>();
                }
                tempItems[c] = CollectionChange.Removed;
                return;
            }

            int pos;

            if (!items.TryGetValue(c, out pos))
            {
                throw new InvalidOperationException("Attempt to remove object not in collection");
            }

            SoodaObject lastObj = itemsArray[itemsArray.Count - 1];

            if (lastObj != c)
            {
                itemsArray[pos] = lastObj;
                items[lastObj]  = pos;
            }
            itemsArray.RemoveAt(itemsArray.Count - 1);
            items.Remove(c);
        }
Esempio n. 12
0
        internal void PrecommitClasses(IEnumerable <string> classes)
        {
            if (classes == null)
            {
                // don't know what to precommit - precommit everything
                SaveObjectChanges(true, null);
                return;
            }

            List <SoodaObject> objectsToPrecommit = new List <SoodaObject>();

            foreach (string className in classes)
            {
                List <WeakSoodaObject> dirtyObjects = GetDirtyObjectsByClassName(className);
                if (dirtyObjects != null)
                {
                    foreach (WeakSoodaObject wr in dirtyObjects)
                    {
                        SoodaObject o = wr.TargetSoodaObject;
                        if (o != null)
                        {
                            objectsToPrecommit.Add(o);
                        }
                    }
                }
            }
            SaveObjectChanges(true, objectsToPrecommit);
        }
Esempio n. 13
0
        public override void Insert(IDictionary values, DataSourceViewOperationCallback callback)
        {
            try
            {
                ISoodaObjectFactory fact = SoodaTransaction.ActiveTransaction.GetFactory(_owner.ClassName);
                SoodaObject         obj  = fact.CreateNew(SoodaTransaction.ActiveTransaction);
                Type type = obj.GetType();

                foreach (DictionaryEntry v in values)
                {
                    PropertyInfo pi = type.GetProperty((string)v.Key, BindingFlags.Public | BindingFlags.Instance);
                    if (pi == null)
                    {
                        throw new SoodaException(v.Key + " not found in " + type.FullName);
                    }

                    pi.SetValue(obj, v.Value, null);
                }
                callback(1, null);
            }
            catch (Exception ex)
            {
                callback(0, ex);
            }
        }
Esempio n. 14
0
        public override void Delete(IDictionary keys, IDictionary oldValues, DataSourceViewOperationCallback callback)
        {
            try
            {
                if (keys.Count == 0)
                {
                    throw new SoodaException("No keys passed to SoodaObjectDataSourceView.Update");
                }

                if (keys.Count > 1)
                {
                    throw new SoodaException("More than one key passed to SoodaObjectDataSourceView.Update");
                }

                ISoodaObjectFactory fact = SoodaTransaction.ActiveTransaction.GetFactory(_owner.ClassName);

                // we just want to get the first key from "keys"
                // therefore we break at the end of the loop

                foreach (DictionaryEntry de in keys)
                {
                    SoodaObject obj = SoodaTransaction.ActiveTransaction.GetObject(_owner.ClassName, Convert.ToString(de.Value));
                    obj.MarkForDelete();
                    break;
                }
                callback(1, null);
            }
            catch (Exception ex)
            {
                callback(0, ex);
            }
        }
 public override bool ShouldCacheObject(SoodaObject theObject)
 {
     if (theObject.GetClassInfo().Cardinality == ClassCardinality.Small)
         return true;
     else
         return false;
 }
Esempio n. 16
0
 public static SoqlBooleanExpression FieldEquals(string field, SoodaObject obj)
 {
     return(new SoqlBooleanRelationalExpression(
                new SoqlPathExpression(field),
                new SoqlLiteralExpression(obj.GetPrimaryKeyValue()),
                SoqlRelationalOperator.Equal));
 }
Esempio n. 17
0
        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);
            }
        }
Esempio n. 18
0
 internal void AddToPostCommitQueue(SoodaObject o)
 {
     if (transactionLogger.IsTraceEnabled)
     {
         transactionLogger.Trace("Adding {0} to post-commit queue", o.GetObjectKeyString());
     }
     _postCommitQueue.Add(o);
 }
Esempio n. 19
0
        private SoodaObject LoadObject(ISoodaObjectFactory factory, string keyString)
        {
            object      keyValue = factory.GetPrimaryKeyFieldHandler().RawDeserialize(keyString) ?? string.Empty;
            SoodaObject obj      = factory.GetRef(this, keyValue);

            obj.LoadAllData();
            return(obj);
        }
Esempio n. 20
0
 internal void PrecommitObject(SoodaObject o)
 {
     if (!o.VisitedOnCommit && !o.IsMarkedForDelete())
     {
         MarkPrecommitted(o);
         o.SaveObjectChanges();
     }
 }
Esempio n. 21
0
        void DoDeletes(SoodaObject obj)
        {
            List <TableInfo> tables = obj.GetClassInfo().UnifiedTables;

            for (int i = tables.Count - 1; i >= 0; --i)
            {
                DoDeletesForTable(obj, tables[i]);
            }
        }
 public SoodaObjectOneToManyCollection(SoodaTransaction tran, Type childType, SoodaObject parentObject, string childRefField, Sooda.Schema.ClassInfo classInfo, SoodaWhereClause additionalWhereClause, bool cached)
     : base(tran, classInfo)
 {
     this.childType = childType;
     this.parentObject = parentObject;
     this.childRefField = childRefField;
     this.additionalWhereClause = additionalWhereClause;
     this.cached = cached;
 }
Esempio n. 23
0
        void DoDeletesForTable(SoodaObject obj, TableInfo table)
        {
            StringBuilder builder     = new StringBuilder();
            ArrayList     queryParams = new ArrayList();

            builder.Append("delete from ");
            builder.Append(table.DBTableName);
            DoWithWhere(obj, builder, queryParams, true);
        }
 public SoodaObjectOneToManyCollection(SoodaTransaction tran, Type childType, SoodaObject parentObject, string childRefField, Sooda.Schema.ClassInfo classInfo, SoodaWhereClause additionalWhereClause, bool cached)
     : base(tran, classInfo)
 {
     this.childType             = childType;
     this.parentObject          = parentObject;
     this.childRefField         = childRefField;
     this.additionalWhereClause = additionalWhereClause;
     this.cached = cached;
 }
Esempio n. 25
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);
 }
Esempio n. 26
0
        void DoInsertsForTable(SoodaObject obj, TableInfo table, bool isPrecommit)
        {
            if (table.IsDynamic && obj.GetFieldValue(table.Fields[table.Fields.Count - 1].ClassUnifiedOrdinal) == null)
            {
                // optimization: don't insert null dynamic fields
                return;
            }

            StringBuilder builder = new StringBuilder(500);

            builder.Append("insert into ");
            builder.Append(table.DBTableName);
            builder.Append('(');

            ArrayList par = new ArrayList();

            bool comma = false;

            foreach (FieldInfo fi in table.Fields)
            {
                if (fi.ReadOnly)
                {
                    continue;
                }
                if (comma)
                {
                    builder.Append(',');
                }
                comma = true;
                builder.Append(fi.DBColumnName);
            }

            builder.Append(") values (");
            comma = false;
            foreach (FieldInfo fi in table.Fields)
            {
                if (fi.ReadOnly)
                {
                    continue;
                }
                if (comma)
                {
                    builder.Append(',');
                }
                comma = true;
                object val = GetFieldValue(obj, fi, isPrecommit);
                builder.Append('{');
                builder.Append(par.Add(val));
                builder.Append(':');
                builder.Append(fi.DataType);
                builder.Append('}');
            }
            builder.Append(')');
            SqlBuilder.BuildCommandWithParameters(_updateCommand, true, builder.ToString(), par.ToArray(), false);
            FlushUpdateCommand(false);
        }
Esempio n. 27
0
        internal string GetPersistentValue(SoodaObject obj, string name)
        {
            NameValueCollection dict;

            if (!_persistentValues.TryGetValue(obj, out dict))
            {
                return(null);
            }
            return(dict[name]);
        }
Esempio n. 28
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()));
        }
Esempio n. 29
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;
        }
Esempio n. 30
0
 public override bool ShouldCacheObject(SoodaObject theObject)
 {
     if (theObject.GetClassInfo().Cardinality == ClassCardinality.Small)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 31
0
        public static SoodaObject TryGetRefFieldValue(ref SoodaObject refCache, object fieldValue, SoodaTransaction tran, ISoodaObjectFactory factory)
        {
            if (refCache != null)
                return refCache;

            if (fieldValue == null)
                return null;

            refCache = factory.TryGet(tran, fieldValue);
            return refCache;
        }
        public bool InternalContains(SoodaObject obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (itemsArray == null)
            {
                LoadData();
            }
            return(items.ContainsKey(obj));
        }
 protected int InternalAdd(SoodaObject obj)
 {
     if (itemsArray == null)
     {
         return(-1);
     }
     if (!items.ContainsKey(obj))
     {
         items.Add(obj, itemsArray.Count);
         itemsArray.Add(obj);
     }
     return(-1);
 }
Esempio n. 34
0
        public static SoodaObject GetRefFieldValue(ref SoodaObject refCache, SoodaObject theObject, int tableNumber, int fieldOrdinal, SoodaTransaction tran, ISoodaObjectFactory factory)
        {
            if (refCache != null)
                return refCache;

            theObject.EnsureDataLoaded(tableNumber);

            if (theObject._fieldValues.IsNull(fieldOrdinal))
                return null;

            refCache = factory.GetRef(tran, theObject._fieldValues.GetBoxedFieldValue(fieldOrdinal));
            return refCache;
        }
 public override bool ShouldCacheObject(SoodaObject theObject)
 {
     return false;
 }
 protected Sooda.QL.TypedWrappers.SoqlBooleanWrapperExpression ContainsImpl(SoodaObject obj)
 {
     return new SoqlBooleanWrapperExpression(new SoqlContainsExpression(_left, _collectionName, new SoqlLiteralExpression(obj == null ? null : obj.GetPrimaryKeyValue())));
 }
Esempio n. 37
0
 object GetFieldValue(SoodaObject obj, FieldInfo fi, bool isPrecommit)
 {
     object val = obj.GetFieldValue(fi.ClassUnifiedOrdinal);
     if (!fi.IsNullable && SqlBuilder.IsNullValue(val, fi))
     {
         if (!isPrecommit)
             throw new SoodaDatabaseException(obj.GetObjectKeyString() + "." + fi.Name + " cannot be null on commit.");
         val = fi.PrecommitTypedValue;
         if (val == null)
             throw new SoodaDatabaseException(obj.GetObjectKeyString() + "." + fi.Name + " is null on precommit and no 'precommitValue' has been defined for it.");
         if (val == SchemaInfo.NullPrecommitValue)
             val = null;
         if (logger.IsDebugEnabled)
         {
             logger.Debug("Using precommit value of {0} for {1}.{2}", val, fi.Table.NameToken, fi.Name);
         }
     }
     return val;
 }
Esempio n. 38
0
 void DoUpdates(SoodaObject obj, bool isPrecommit)
 {
     foreach (TableInfo table in obj.GetClassInfo().DatabaseTables)
     {
         DoUpdatesForTable(obj, table, isPrecommit);
     }
 }
        protected void InternalRemove(SoodaObject obj)
        {
            if (itemsArray == null)
                return;

            int pos;
            if (!items.TryGetValue(obj, out pos))
                return;

            SoodaObject lastObj = itemsArray[itemsArray.Count - 1];
            if (lastObj != obj)
            {
                itemsArray[pos] = lastObj;
                items[lastObj] = pos;
            }
            itemsArray.RemoveAt(itemsArray.Count - 1);
            items.Remove(obj);
        }
 protected int InternalAdd(SoodaObject obj)
 {
     if (itemsArray == null)
         return -1;
     if (!items.ContainsKey(obj))
     {
         items.Add(obj, itemsArray.Count);
         itemsArray.Add(obj);
     }
     return -1;
 }
Esempio n. 41
0
 public static void LoadAllData(SoodaObject theObject)
 {
     theObject.LoadAllData();
 }
Esempio n. 42
0
 public static object GetBoxedFieldValue(SoodaObject theObject, int tableNumber, int fieldOrdinal)
 {
     theObject.EnsureDataLoaded(tableNumber);
     return theObject._fieldValues.GetBoxedFieldValue(fieldOrdinal);
 }
Esempio n. 43
0
 public static bool IsFieldNull(SoodaObject theObject, int tableNumber, int fieldOrdinal)
 {
     theObject.EnsureDataLoaded(tableNumber);
     return theObject._fieldValues.IsNull(fieldOrdinal);
 }
Esempio n. 44
0
 public static bool IsFieldDirty(SoodaObject theObject, int tableNumber, int fieldOrdinal)
 {
     return theObject.IsFieldDirty(fieldOrdinal);
 }
Esempio n. 45
0
 public static SoodaObjectFieldValues GetFieldValuesForRead(SoodaObject t, int tableNumber)
 {
     t.EnsureDataLoaded(tableNumber);
     return t._fieldValues;
 }
Esempio n. 46
0
 public WeakSoodaObject(SoodaObject target)
     : base(target)
 {
 }
Esempio n. 47
0
 public static void SetPlainFieldValue(SoodaObject theObject, int tableNumber, string fieldName, int fieldOrdinal, object newValue, SoodaFieldUpdateDelegate before, SoodaFieldUpdateDelegate after)
 {
     theObject.SetPlainFieldValue(tableNumber, fieldName, fieldOrdinal, newValue, before, after);
 }
Esempio n. 48
0
 public static void SetRefFieldValue(SoodaObject theObject, int tableNumber, string fieldName, int fieldOrdinal, SoodaObject newValue, SoodaObject[] refcache, int refcacheOrdinal, ISoodaObjectFactory factory)
 {
     theObject.SetRefFieldValue(tableNumber, fieldName, fieldOrdinal, newValue, refcache, refcacheOrdinal, factory);
 }
 protected void AddObjectToSnapshot(SoodaObject o)
 {
     items.Add(o);
     count = items.Count;
 }
Esempio n. 50
0
 public static SoqlBooleanExpression FieldEquals(string field, SoodaObject obj)
 {
     return new SoqlBooleanRelationalExpression(
         new SoqlPathExpression(field),
         new SoqlLiteralExpression(obj.GetPrimaryKeyValue()),
         SoqlRelationalOperator.Equal);
 }
        public bool InternalContains(SoodaObject obj)
        {
            if (obj == null)
                return false;

            if (itemsArray == null)
                LoadData();
            return items.ContainsKey(obj);
        }
Esempio n. 52
0
 public static SoqlBooleanExpression CollectionFor(CollectionManyToManyInfo coll, SoodaObject parent)
 {
     SoqlPathExpression needle = new SoqlPathExpression(coll.GetItemClass().GetFirstPrimaryKeyField().Name);
     RelationInfo relation = coll.GetRelationInfo();
     SoqlQueryExpression query = new SoqlQueryExpression();
     query.SelectExpressions.Add(new SoqlPathExpression(relation.Table.Fields[coll.MasterField].Name));
     query.SelectAliases.Add(string.Empty);
     query.From.Add(relation.Name);
     query.FromAliases.Add(string.Empty);
     query.WhereClause = FieldEquals(relation.Table.Fields[1 - coll.MasterField].Name, parent);
     SoqlExpressionCollection haystack = new SoqlExpressionCollection();
     haystack.Add(query);
     return new SoqlBooleanInExpression(needle, haystack);
 }
Esempio n. 53
0
        void DoUpdatesForTable(SoodaObject obj, TableInfo table, bool isPrecommit)
        {
            if (table.IsDynamic)
            {
                // For dynamic fields do DELETE+INSERT instead of UPDATE.
                // This is because if a dynamic field is added to an existing object, there is no dynamic field row to update.
                // Another reason is that we never store null dynamic fields in the database - an INSERT will be ommitted in this case.
                DoDeletesForTable(obj, table);
                DoInsertsForTable(obj, table, true);
                return;
            }

            StringBuilder builder = new StringBuilder(500);
            builder.Append("update ");
            builder.Append(table.DBTableName);
            builder.Append(" set ");

            ArrayList par = new ArrayList();
            bool anyChange = false;
            foreach (FieldInfo fi in table.Fields)
            {
                if (obj.IsFieldDirty(fi.ClassUnifiedOrdinal))
                {
                    if (anyChange)
                        builder.Append(", ");
                    FieldEquals(fi, GetFieldValue(obj, fi, isPrecommit), builder, par);
                    anyChange = true;
                }
            }
            if (!anyChange)
                return;

            DoWithWhere(obj, builder, par, false);
        }
        public void InternalRemove(SoodaObject c)
        {
            if (!childType.IsInstanceOfType(c))
                return;

            if (items == null)
            {
                if (tempItems == null)
                    tempItems = new Dictionary<SoodaObject, CollectionChange>();
                tempItems[c] = CollectionChange.Removed;
                return;
            }

            int pos;
            if (!items.TryGetValue(c, out pos))
                throw new InvalidOperationException("Attempt to remove object not in collection");

            SoodaObject lastObj = itemsArray[itemsArray.Count - 1];
            if (lastObj != c)
            {
                itemsArray[pos] = lastObj;
                items[lastObj] = pos;
            }
            itemsArray.RemoveAt(itemsArray.Count - 1);
            items.Remove(c);
        }
Esempio n. 55
0
        void DoInsertsForTable(SoodaObject obj, TableInfo table, bool isPrecommit)
        {
            if (table.IsDynamic && obj.GetFieldValue(table.Fields[table.Fields.Count - 1].ClassUnifiedOrdinal) == null)
            {
                // optimization: don't insert null dynamic fields
                return;
            }

            StringBuilder builder = new StringBuilder(500);
            builder.Append("insert into ");
            builder.Append(table.DBTableName);
            builder.Append('(');

            ArrayList par = new ArrayList();

            bool comma = false;
            foreach (FieldInfo fi in table.Fields)
            {
                if (fi.ReadOnly)
                    continue;
                if (comma)
                    builder.Append(',');
                comma = true;
                builder.Append(fi.DBColumnName);
            }

            builder.Append(") values (");
            comma = false;
            foreach (FieldInfo fi in table.Fields)
            {
                if (fi.ReadOnly)
                    continue;
                if (comma)
                    builder.Append(',');
                comma = true;
                object val = GetFieldValue(obj, fi, isPrecommit);
                builder.Append('{');
                builder.Append(par.Add(val));
                builder.Append(':');
                builder.Append(fi.DataType);
                builder.Append('}');
            }
            builder.Append(')');
            SqlBuilder.BuildCommandWithParameters(_updateCommand, true, builder.ToString(), par.ToArray(), false);
            FlushUpdateCommand(false);
        }
 public bool GetExpirationTimeout(SoodaObject theObject, out TimeSpan expirationTimeout, out bool slidingExpiration)
 {
     expirationTimeout = _expirationTimeout;
     slidingExpiration = _slidingExpiration;
     return true;
 }
Esempio n. 57
0
 public override IDataReader LoadObject(SoodaObject obj, object keyVal, out TableInfo[] loadedTables)
 {
     return LoadObjectTable(obj, keyVal, 0, out loadedTables);
 }
        public void InternalAdd(SoodaObject c)
        {
            if (!childType.IsInstanceOfType(c))
                return;

            if (items == null)
            {
                if (tempItems == null)
                    tempItems = new Dictionary<SoodaObject, CollectionChange>();
                tempItems[c] = CollectionChange.Added;
                return;
            }

            if (items.ContainsKey(c))
                return;

            items.Add(c, itemsArray.Count);
            itemsArray.Add(c);
        }
Esempio n. 59
0
 bool predicate1(SoodaObject c0)
 {
     Contact c = (Contact)c0;
     return (string)c.Name != "Mary Manager";
 }
 public abstract bool ShouldCacheObject(SoodaObject theObject);