示例#1
0
        private RevisionedObject ResolveRDO(string rdo_type_name, string rdo_name, string rdo_revision, bool throwException)
        {
            RevisionedObject res = null;

            if (rdo_revision == null)
            {
                rdo_revision = "";
            }
            if (rdo_revision != "")
            {
                const string queryRDObyRevision = "ELEMENT (SELECT o FROM {0}Extent AS o WHERE o.RevBase.Name = $1 AND o.Revision = $2)";
                // Query from revision
                IQuery       oqlQuery = ObjScope.GetOqlQuery(string.Format(queryRDObyRevision, rdo_type_name));
                IQueryResult result   = oqlQuery.Execute(rdo_name, rdo_revision);
                if (result.Count > 0)
                {
                    res = result[0] as RevisionedObject;
                }
                result.Dispose();
            }
            else
            {
                res = (ResolveNDO(rdo_type_name + "Base", rdo_name, throwException) as RevisionBase).Current;
            }
            if (res == null && throwException == true)
            {
                throw new UOServiceException(string.Format(MSG.Object_not_found, string.Format("{0}({1})", rdo_name, rdo_revision), rdo_type_name));
            }
            return(res);
        }
示例#2
0
        virtual protected bool Update(RevisionedObject rdo_changes, out RevisionedObject to_change)
        {
            string idProperty_Name;

            to_change = ResolveRDO(rdo_changes, out idProperty_Name);

            if (to_change != null)
            {
                ObjScope.Transaction.Begin();
                foreach (PropertyInfo pi in rdo_changes.GetType().GetProperties())
                {
                    if (pi.Name == idProperty_Name || pi.Name == "RevBase")
                    {
                        continue;   // do not update Primary Property and RevBase
                    }
                    object v_changes = pi.GetValue(rdo_changes, null);
                    if (v_changes != null && (pi.CanWrite || v_changes.GetType().IsGenericType))
                    {
                        SetProperty(to_change, pi, v_changes);
                    }
                }
                ObjScope.Transaction.Commit();
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#3
0
        public override bool Remove(RevisionedObject rdo_obj)
        {
            bool success = base.Remove(rdo_obj);

            if (true == success)
            {
                success = RecordHistory(rdo_obj, ActionType.Delete);
            }
            return(success);
        }
示例#4
0
        protected override bool Update(RevisionedObject rdo_changes, out RevisionedObject to_change)
        {
            bool success = base.Update(rdo_changes, out to_change);

            if (true == success)
            {
                success = RecordHistory(to_change, ActionType.Update);
            }
            return(success);
        }
示例#5
0
        public override bool Add(RevisionedObject rdo_obj)
        {
            bool success = base.Add(rdo_obj);

            if (true == success)
            {
                success = RecordHistory(rdo_obj, ActionType.Insert);
            }
            return(success);
        }
示例#6
0
        private int RDOBaseUsageCount(RevisionedObject rdo_obj)
        {
            const string queryRDOBaseUsageCount = "SELECT COUNT(*) FROM {0}Extent AS o WHERE o.RevBase = $1";
            int          count    = 0;
            IQuery       oqlQuery = ObjScope.GetOqlQuery(string.Format(queryRDOBaseUsageCount, rdo_obj.GetType().Name));
            IQueryResult result   = oqlQuery.Execute(rdo_obj.RevBase);

            if (result.Count > 0)
            {
                count = (int)result[0];
            }
            result.Dispose();
            return(count);
        }
示例#7
0
        virtual public bool Dump(RevisionedObject rdo_obj)
        {
            object dump_obj = ResolveRDO(rdo_obj);

            if (dump_obj != null)
            {
                DumpCDOObject(dump_obj);
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#8
0
        protected RevisionedObject ResolveRDO(RevisionedObject rdo_changes, out string idProperty_Name)
        {
            object to_change        = null;
            string idProperty_Value = Service.GetIdentityFieldValue(rdo_changes, out idProperty_Name);

            if (idProperty_Value == null || idProperty_Value == "0")
            {
                to_change = ResolveCDO(rdo_changes.GetType(), rdo_changes.DisplayName);
            }
            else
            {
                to_change = ResolveCDOByID(rdo_changes.GetType(), idProperty_Value);
            }
            return(to_change as RevisionedObject);
        }
示例#9
0
        private bool RecordHistory(RevisionedObject rdo_obj, ActionType actionType)
        {
            Spec o = rdo_obj as Spec;
            SpecChangeHistory h;

            if (actionType == ActionType.Delete)
            {
                h = new SpecChangeHistory(null, this.TxnDate, actionType);
            }
            else
            {
                h = new SpecChangeHistory(rdo_obj, this.TxnDate, actionType);
            }
            o.AssignToSpecChangeHistory(h);
            ObjScope.Transaction.Begin();
            ObjScope.Add(h);
            ObjScope.Transaction.Commit();
            return(true);
        }
示例#10
0
        virtual public bool Remove(RevisionedObject rdo_obj)
        {
            RevisionedObject to_delete = ResolveRDO(rdo_obj);

            if (to_delete != null)
            {
                ObjScope.Transaction.Begin();
                if (1 == RDOBaseUsageCount(to_delete))
                {
                    ObjScope.Remove(to_delete.RevBase);
                }
                ObjScope.Remove(to_delete);
                ObjScope.Transaction.Commit();
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#11
0
        virtual public bool Add(RevisionedObject rdo_insert)
        {
            string idProperty_Name = null;
            object check_exist     = ResolveRDO(rdo_insert, out idProperty_Name);

            if (check_exist == null)
            {
                // Reuse exist RevBase if exist
                object rdo_base_exist = ResolveCDO(rdo_insert.RevBase.GetType(), rdo_insert.RevBase.Name);
                if (rdo_base_exist != null)
                {
                    rdo_insert.RevBase = rdo_base_exist as RevisionBase;
                }

                foreach (PropertyInfo pi in rdo_insert.GetType().GetProperties())
                {
                    if (pi.Name == idProperty_Name || pi.Name == "RevBase")
                    {
                        continue;   // do not update Primary Property and RevBase
                    }
                    object v_changes = pi.GetValue(rdo_insert, null);
                    if (v_changes != null && (pi.CanWrite || v_changes.GetType().IsGenericType))
                    {
                        SetProperty(rdo_insert, pi, v_changes);
                    }
                }

                ObjScope.Transaction.Begin();
                ObjScope.Add(rdo_insert);
                ObjScope.Transaction.Commit();
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#12
0
        protected RevisionedObject ResolveRDO(RevisionedObject rdo_changes)
        {
            string idProperty_Name;

            return(ResolveRDO(rdo_changes, out idProperty_Name));
        }
示例#13
0
        public bool Update(RevisionedObject rdo_changes)
        {
            RevisionedObject to_change = null;

            return(Update(rdo_changes, out to_change));
        }
示例#14
0
 public SpecChangeHistory(RevisionedObject toChangeRDO, DateTime actionDate, ActionType actionType) : base(actionDate, actionType)
 {
     spec = toChangeRDO as Spec;
 }