示例#1
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);
            }
        }
示例#2
0
 public static SoqlBooleanExpression FieldEquals(string field, SoodaObject obj)
 {
     return(new SoqlBooleanRelationalExpression(
                new SoqlPathExpression(field),
                new SoqlLiteralExpression(obj.GetPrimaryKeyValue()),
                SoqlRelationalOperator.Equal));
 }
示例#3
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()));
        }
        public override void Remove(object obj)
        {
            SoodaObject        so  = (SoodaObject)obj;
            object             pk  = so.GetPrimaryKeyValue();
            SoodaRelationTable rel = this.GetSoodaRelationTable();

            if (masterColumn == 0)
            {
                rel.Remove(pk, this.masterValue);
            }
            else
            {
                rel.Remove(this.masterValue, pk);
            }
            this.InternalRemove(so);
        }
        public override int Add(object obj)
        {
            SoodaObject        so  = (SoodaObject)obj;
            object             pk  = so.GetPrimaryKeyValue();
            SoodaRelationTable rel = this.GetSoodaRelationTable();

            if (masterColumn == 0)
            {
                rel.Add(pk, this.masterValue);
            }
            else
            {
                rel.Add(this.masterValue, pk);
            }
            return(this.InternalAdd(so));
        }
示例#6
0
        void DoWithWhere(SoodaObject obj, StringBuilder builder, ArrayList queryParams, bool isRaw)
        {
            builder.Append(" where ");
            object primaryKeyValue = obj.GetPrimaryKeyValue();

            FieldInfo[] primaryKeyFields = obj.GetClassInfo().GetPrimaryKeyFields();
            for (int i = 0; i < primaryKeyFields.Length; i++)
            {
                if (i > 0)
                {
                    builder.Append(" and ");
                }
                FieldEquals(primaryKeyFields[i], SoodaTuple.GetValue(primaryKeyValue, i), builder, queryParams);
            }
            SqlBuilder.BuildCommandWithParameters(_updateCommand, true, builder.ToString(), queryParams.ToArray(), isRaw);
            FlushUpdateCommand(false);
        }
示例#7
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);
                }
            }
        }
 protected Sooda.QL.TypedWrappers.SoqlBooleanWrapperExpression ContainsImpl(SoodaObject obj)
 {
     return new SoqlBooleanWrapperExpression(new SoqlContainsExpression(_left, _collectionName, new SoqlLiteralExpression(obj == null ? null : obj.GetPrimaryKeyValue())));
 }
 private static int PrimaryKeyCompare(SoodaObject dbo1, SoodaObject dbo2)
 {
     return(((IComparable)dbo1.GetPrimaryKeyValue()).CompareTo(dbo2.GetPrimaryKeyValue()));
 }
示例#10
0
 public static SoqlBooleanExpression FieldEquals(string field, SoodaObject obj)
 {
     return new SoqlBooleanRelationalExpression(
         new SoqlPathExpression(field),
         new SoqlLiteralExpression(obj.GetPrimaryKeyValue()),
         SoqlRelationalOperator.Equal);
 }
        protected override void LoadData()
        {
            SoodaDataSource ds = transaction.OpenDataSource(classInfo.GetDataSource());

            TableInfo[] loadedTables;

            items      = new Dictionary <SoodaObject, int>();
            itemsArray = new List <SoodaObject>();

            ISoodaObjectFactory factory     = transaction.GetFactory(classInfo);
            SoodaWhereClause    whereClause = new SoodaWhereClause(Soql.FieldEqualsParam(childRefField, 0), parentObject.GetPrimaryKeyValue());

            if (additionalWhereClause != null)
            {
                whereClause = whereClause.Append(additionalWhereClause);
            }

            string cacheKey = null;

            if (cached)
            {
                // cache makes sense only on clean database
                if (!transaction.HasBeenPrecommitted(classInfo.GetRootClass()))
                {
                    cacheKey = SoodaCache.GetCollectionKey(classInfo, whereClause);
                }
            }
            IEnumerable keysCollection = transaction.LoadCollectionFromCache(cacheKey, logger);

            if (keysCollection != null)
            {
                foreach (object o in keysCollection)
                {
                    SoodaObject obj = factory.GetRef(transaction, o);
                    // this binds to cache
                    obj.EnsureFieldsInited();

                    if (tempItems != null)
                    {
                        CollectionChange change;
                        if (tempItems.TryGetValue(obj, out change) && change == CollectionChange.Removed)
                        {
                            continue;
                        }
                    }

                    items.Add(obj, itemsArray.Count);
                    itemsArray.Add(obj);
                }
            }
            else
            {
                using (IDataReader reader = ds.LoadObjectList(transaction.Schema, classInfo, whereClause, null, 0, -1, SoodaSnapshotOptions.Default, out loadedTables))
                {
                    List <SoodaObject> readObjects = null;

                    if (cached)
                    {
                        readObjects = new List <SoodaObject>();
                    }

                    while (reader.Read())
                    {
                        SoodaObject obj = SoodaObject.GetRefFromRecordHelper(transaction, factory, reader, 0, loadedTables, 0);
                        if (readObjects != null)
                        {
                            readObjects.Add(obj);
                        }

                        if (tempItems != null)
                        {
                            CollectionChange change;
                            if (tempItems.TryGetValue(obj, out change) && change == CollectionChange.Removed)
                            {
                                continue;
                            }
                        }

                        items.Add(obj, itemsArray.Count);
                        itemsArray.Add(obj);
                    }
                    if (cached)
                    {
                        TimeSpan expirationTimeout;
                        bool     slidingExpiration;

                        if (transaction.CachingPolicy.GetExpirationTimeout(
                                classInfo, whereClause, null, 0, -1, readObjects.Count,
                                out expirationTimeout, out slidingExpiration))
                        {
                            transaction.StoreCollectionInCache(cacheKey, classInfo, readObjects, null, true, expirationTimeout, slidingExpiration);
                        }
                    }
                }
            }

            if (tempItems != null)
            {
                foreach (KeyValuePair <SoodaObject, CollectionChange> entry in tempItems)
                {
                    if (entry.Value == CollectionChange.Added)
                    {
                        SoodaObject obj = (SoodaObject)entry.Key;

                        if (!items.ContainsKey(obj))
                        {
                            items.Add(obj, itemsArray.Count);
                            itemsArray.Add(obj);
                        }
                    }
                }
            }
        }
 protected Sooda.QL.TypedWrappers.SoqlBooleanWrapperExpression ContainsImpl(SoodaObject obj)
 {
     return(new SoqlBooleanWrapperExpression(new SoqlContainsExpression(_left, _collectionName, new SoqlLiteralExpression(obj == null ? null : obj.GetPrimaryKeyValue()))));
 }
示例#13
0
 void DoWithWhere(SoodaObject obj, StringBuilder builder, ArrayList queryParams, bool isRaw)
 {
     builder.Append(" where ");
     object primaryKeyValue = obj.GetPrimaryKeyValue();
     FieldInfo[] primaryKeyFields = obj.GetClassInfo().GetPrimaryKeyFields();
     for (int i = 0; i < primaryKeyFields.Length; i++)
     {
         if (i > 0)
             builder.Append(" and ");
         FieldEquals(primaryKeyFields[i], SoodaTuple.GetValue(primaryKeyValue, i), builder, queryParams);
     }
     SqlBuilder.BuildCommandWithParameters(_updateCommand, true, builder.ToString(), queryParams.ToArray(), isRaw);
     FlushUpdateCommand(false);
 }
示例#14
0
        protected internal bool IsRegistered(SoodaObject o)
        {
            object pkValue = o.GetPrimaryKeyValue();

            return(ExistsObjectWithKey(o.GetClassInfo().Name, pkValue));
        }