Пример #1
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);
        }
Пример #2
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;
        }
Пример #3
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);
        }
Пример #4
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;
        }
Пример #5
0
        static SoodaObject GetRefFromRecordHelper(SoodaTransaction tran, ISoodaObjectFactory factory, IDataRecord record, int firstColumnIndex, TableInfo[] loadedTables, int tableIndex, bool loadData)
        {
            object keyValue;
            Sooda.Schema.FieldInfo[] pkFields = factory.GetClassInfo().GetPrimaryKeyFields();
            if (pkFields.Length == 1)
            {
                int pkFieldOrdinal = loadData ? firstColumnIndex + pkFields[0].OrdinalInTable : 0;
                try
                {
                    keyValue = factory.GetPrimaryKeyFieldHandler().RawRead(record, pkFieldOrdinal);
                }
                catch (Exception ex)
                {
                    logger.Error("Error while reading field {0}.{1}: {2}", factory.GetClassInfo().Name, pkFieldOrdinal, ex);
                    throw ex;
                }
            }
            else
            {
                object[] pkParts = new object[pkFields.Length];
                for (int currentPkPart = 0; currentPkPart < pkFields.Length; currentPkPart++)
                {
                    int pkFieldOrdinal = loadData ? firstColumnIndex + pkFields[currentPkPart].OrdinalInTable : currentPkPart;
                    SoodaFieldHandler handler = factory.GetFieldHandler(pkFieldOrdinal);
                    pkParts[currentPkPart] = handler.RawRead(record, pkFieldOrdinal);
                }
                keyValue = new SoodaTuple(pkParts);
                //logger.Debug("Tuple: {0}", keyValue);
            }

            SoodaObject retVal = factory.TryGet(tran, keyValue);
            if (retVal != null)
            {
                if (loadData && !retVal.IsDataLoaded(0))
                    retVal.LoadDataFromRecord(record, firstColumnIndex, loadedTables, tableIndex);
                return retVal;
            }

            factory = GetFactoryFromRecord(tran, factory, record, firstColumnIndex, keyValue, loadData);
            retVal = factory.GetRawObject(tran);
            tran.Statistics.RegisterObjectUpdate();
            SoodaStatistics.Global.RegisterObjectUpdate();
            retVal.InsertMode = false;
            retVal.SetPrimaryKeyValue(keyValue);
            if (loadData)
                retVal.LoadDataFromRecord(record, firstColumnIndex, loadedTables, tableIndex);
            return retVal;
        }
Пример #6
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;
        }