Esempio n. 1
0
        public SoodaWhereClause Append(SoodaWhereClause other)
        {
            if (other.WhereExpression == null)
            {
                return(this);
            }
            if (this.WhereExpression == null)
            {
                return(other);
            }

            object[] newParams = this.Parameters;

            if (this.Parameters == null)
            {
                newParams = other.Parameters;
            }
            else if (other.Parameters != null)
            {
                throw new SoodaException("You cannot merge two where clauses when they both have parameters");
            }

            return(new SoodaWhereClause(new SoqlBooleanAndExpression(
                                            this.WhereExpression, other.WhereExpression), newParams));
        }
Esempio n. 2
0
 public EvaluateContext(SoodaWhereClause whereClause, SoodaObject rootObject)
 {
     _whereClause = whereClause;
     _rootObject  = rootObject;
 }
Esempio n. 3
0
 public abstract IDataReader LoadObjectList(SchemaInfo schemaInfo, ClassInfo classInfo, SoodaWhereClause whereClause, SoodaOrderBy orderBy, int startIdx, int pageCount, SoodaSnapshotOptions options, out TableInfo[] tables);
Esempio n. 4
0
        public void MarkForDelete(bool delete, bool recurse, bool savingChanges)
        {
            if (DeleteMarker != delete)
            {
                BeforeObjectDelete();
                DeleteMarker = delete;

                if (recurse)
                {
                    if (logger.IsTraceEnabled)
                    {
                        logger.Trace("Marking outer references of {0} for delete...", GetObjectKeyString());
                    }
                    for (ClassInfo ci = this.GetClassInfo(); ci != null; ci = ci.InheritsFromClass)
                    {
                        foreach (Sooda.Schema.FieldInfo fi in ci.OuterReferences)
                        {
                            logger.Trace("{0} Delete action: {1}", fi, fi.DeleteAction);
                            if (fi.DeleteAction == DeleteAction.Nothing)
                                continue;

                            ISoodaObjectFactory factory = GetTransaction().GetFactory(fi.ParentClass);

                            SoqlBooleanExpression whereExpression = Soql.FieldEquals(fi.Name, this);
                            SoodaWhereClause whereClause = new SoodaWhereClause(whereExpression);
                            // logger.Debug("loading list where: {0}", whereExpression);
                            IList referencingList = factory.GetList(GetTransaction(), whereClause, SoodaOrderBy.Unsorted, SoodaSnapshotOptions.KeysOnly);
                            switch (fi.DeleteAction)
                            {
                                case DeleteAction.Cascade:
                                    foreach (SoodaObject o in referencingList)
                                    {
                                        o.MarkForDelete(delete, recurse, savingChanges);
                                    }
                                    break;
                                case DeleteAction.Nullify:
                                    PropertyInfo pi = factory.TheType.GetProperty(fi.Name);
                                    foreach (SoodaObject o in referencingList)
                                    {
                                        pi.SetValue(o, null, null);
                                    }
                                    break;
                                default:
                                    throw new NotImplementedException(fi.DeleteAction.ToString());
                            }
                        }
                    }
                }
                GetTransaction().DeletedObjects.Add(this);
            }
        }
Esempio n. 5
0
 public abstract IDataReader LoadMatchingPrimaryKeys(SchemaInfo schemaInfo, ClassInfo classInfo, SoodaWhereClause whereClause, SoodaOrderBy orderBy, int startIdx, int pageCount);
Esempio n. 6
0
        public static SoodaObject GetRefHelper(SoodaTransaction tran, ISoodaObjectFactory factory, object keyValue)
        {
            SoodaObject retVal = factory.TryGet(tran, keyValue);
            if (retVal != null)
                return retVal;

            ClassInfo classInfo = factory.GetClassInfo();
            if (classInfo.InheritsFromClass != null && tran.ExistsObjectWithKey(classInfo.GetRootClass().Name, keyValue))
                throw new SoodaObjectNotFoundException();

            if (classInfo.GetSubclassesForSchema(tran.Schema).Count > 0)
            {
                ISoodaObjectFactory newFactory = null;

                if (!classInfo.DisableTypeCache)
                {
                    newFactory = SoodaTransaction.SoodaObjectFactoryCache.FindObjectFactory(classInfo.Name, keyValue);
                }

                if (newFactory != null)
                {
                    factory = newFactory;
                }
                else
                {
                    // if the class is actually inherited, we delegate the responsibility
                    // to the appropriate GetRefFromRecord which will be called by the snapshot

                    SoqlBooleanExpression where = null;
                    Sooda.Schema.FieldInfo[] pkFields = classInfo.GetPrimaryKeyFields();
                    object[] par = new object[pkFields.Length];
                    for (int i = 0; i < pkFields.Length; ++i)
                    {
                        par[i] = SoodaTuple.GetValue(keyValue, i);
                        SoqlBooleanExpression cmp = Soql.FieldEqualsParam(pkFields[i].Name, i);
                        where = where == null ? cmp : where.And(cmp);
                    }
                    SoodaWhereClause whereClause = new SoodaWhereClause(where, par);

                    IList list = factory.GetList(tran, whereClause, SoodaOrderBy.Unsorted, SoodaSnapshotOptions.NoTransaction | SoodaSnapshotOptions.NoWriteObjects | SoodaSnapshotOptions.NoCache);
                    if (list.Count == 1)
                        return (SoodaObject)list[0];
                    else if (list.Count == 0)
                        throw new SoodaObjectNotFoundException("No matching object.");
                    else
                        throw new SoodaObjectNotFoundException("More than one object found. Fatal error.");
                }
            }

            retVal = factory.GetRawObject(tran);
            tran.Statistics.RegisterObjectUpdate();
            SoodaStatistics.Global.RegisterObjectUpdate();
            if (factory.GetClassInfo().ReadOnly)
            {
                retVal.LoadReadOnlyObject(keyValue);
            }
            else
            {
                retVal.SetUpdateMode(keyValue);
            }
            return retVal;
        }
        public SoodaWhereClause Append(SoodaWhereClause other)
        {
            if (other.WhereExpression == null)
                return this;
            if (this.WhereExpression == null)
                return other;

            object[] newParams = this.Parameters;

            if (this.Parameters == null)
                newParams = other.Parameters;
            else if (other.Parameters != null)
                throw new SoodaException("You cannot merge two where clauses when they both have parameters");

            return new SoodaWhereClause(new SoqlBooleanAndExpression(
                this.WhereExpression, other.WhereExpression), newParams);
        }
 public EvaluateContext(SoodaWhereClause whereClause, SoodaObject rootObject)
 {
     _whereClause = whereClause;
     _rootObject = rootObject;
 }
Esempio n. 9
0
 public abstract IDataReader LoadObjectList(SchemaInfo schemaInfo, ClassInfo classInfo, SoodaWhereClause whereClause, SoodaOrderBy orderBy, int startIdx, int pageCount, SoodaSnapshotOptions options, out TableInfo[] tables);
Esempio n. 10
0
 public abstract IDataReader LoadMatchingPrimaryKeys(SchemaInfo schemaInfo, ClassInfo classInfo, SoodaWhereClause whereClause, SoodaOrderBy orderBy, int startIdx, int pageCount);