예제 #1
0
        }         // proc Reset

        /// <summary>Updates to next id.</summary>
        /// <param name="key">Value for a primary column</param>
        public void UpdateNextId(long key)
        {
            lock (nextPrimaryLock)
            {
                PpsDataTable.GetKey(key, out var type, out var value);
                if (type == DataSetDefinition.KeyType)
                {
                    if (lastPrimaryId < value)
                    {
                        lastPrimaryId = value;
                    }
                }
            }
        }         // proc UpdateNextId
        }         // func PullData

        /// <summary>Push dataset to the object.</summary>
        /// <param name="obj"></param>
        /// <param name="data"></param>
        /// <param name="release"></param>
        /// <returns></returns>
        protected override PpsPushDataResult PushData(PpsObjectAccess obj, PpsDataSetServer data, bool release)
        {
            // fire triggers
            CallTableMethodsWithExceptions(LuaOnBeforePush, obj, data);

            // move all to original row
            data.Commit();

            if (obj.IsNew)
            {
                InsertNewObject(obj, data);
            }
            else             // check rev, to in base implementation?
            {
                var headRevId = obj.HeadRevId;
                if (headRevId > obj.RevId)
                {
                    return(PpsPushDataResult.PulledRevIsToOld);                    // head revision is newer than pulled revision -> return this fact
                }
                else if (headRevId < obj.RevId)
                {
                    throw new ArgumentException($"Push failed. Pulled revision is greater than head revision.");
                }
            }

            // update head id
            CheckHeadObjectId(obj, data);

            // update all local generated id's to server id's
            foreach (var dt in data.Tables)
            {
                if (dt.TableDefinition.PrimaryKey == null)
                {
                    continue;
                }

                var idxPrimaryKey = dt.TableDefinition.PrimaryKey.Index;
                if (dt.TableDefinition.PrimaryKey.IsIdentity)                 // auto incr => getnext
                {
                    foreach (var row in dt)
                    {
                        PpsDataTable.GetKey(row[idxPrimaryKey].ChangeType <long>(), out var type, out var value);
                        if (type == PpsTablePrimaryKeyType.Local)
                        {
                            row[idxPrimaryKey] = data.GetNextId();
                        }
                    }
                }
                else                 // self set => abs(nr)
                {
                    // absolute
                    foreach (var row in dt)
                    {
                        PpsDataTable.GetKey(row[idxPrimaryKey].ChangeType <long>(), out var type, out var value);
                        if (type == PpsTablePrimaryKeyType.Local)
                        {
                            row[idxPrimaryKey] = PpsDataTable.MakeKey(PpsTablePrimaryKeyType.Server, value);
                        }
                    }
                }
            }

            // commit all to orignal
            data.Commit();

            // update tags
            obj.UpdateRevisionTags(data.GetAutoTags());

            // actions after push
            CallTableMethodsWithExceptions(LuaOnAfterPush, obj, data);

            obj[nameof(PpsObjectAccess.MimeType)] = "text/dataset";
            using (var src = GetStreamFromData(data))
                obj.UpdateData(src);
            obj.Update(PpsObjectUpdateFlag.All);

            return(PpsPushDataResult.PushedAndChanged);
        }         // func PushData