/// <summary>
 /// Get an existing business object.
 /// </summary>
 /// <param name="objectType">Type of business object to retrieve.</param>
 /// <param name="criteria">Criteria object describing business object.</param>
 /// <param name="context">
 /// <see cref="Server.DataPortalContext" /> object passed to the server.
 /// </param>
 public DataPortalResult Fetch(Type objectType, object criteria, DataPortalContext context)
 {
     try
     {
         context.FactoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(objectType);
         if (context.FactoryInfo == null)
         {
             var dp = new SimpleDataPortal();
             return(dp.Fetch(objectType, criteria, context));
         }
         else
         {
             var dp = new FactoryDataPortal();
             return(dp.Fetch(objectType, criteria, context));
         }
     }
     catch (DataPortalException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new DataPortalException(
                   "DataPortal.Fetch " + Resources.FailedOnServer,
                   ex, new DataPortalResult());
     }
 }
 /// <summary>
 /// Update a business object.
 /// </summary>
 /// <param name="obj">Business object to update.</param>
 /// <param name="context">
 /// <see cref="Server.DataPortalContext" /> object passed to the server.
 /// </param>
 public DataPortalResult Update(object obj, DataPortalContext context)
 {
     try
     {
         context.FactoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(obj.GetType());
         if (context.FactoryInfo == null)
         {
             var dp = new SimpleDataPortal();
             return(dp.Update(obj, context));
         }
         else
         {
             var dp = new FactoryDataPortal();
             return(dp.Update(obj, context));
         }
     }
     catch (DataPortalException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new DataPortalException(
                   "DataPortal.Update " + Resources.FailedOnServer,
                   ex, new DataPortalResult(obj));
     }
 }
        /// <summary>
        /// Gets a reference to the DataPortal_Fetch method for
        /// the specified business object type.
        /// </summary>
        /// <param name="objectType">Type of the business object.</param>
        /// <param name="criteria">Criteria parameter value.</param>
        /// <remarks>
        /// If the criteria parameter value is an integer, that is a special
        /// flag indicating that the parameter should be considered missing
        /// (not Nothing/null - just not there).
        /// </remarks>
        internal static DataPortalMethodInfo GetFetchMethod(Type objectType, object criteria)
        {
            // an "Integer" criteria is a special flag indicating
            // that criteria is empty and should not be used
            DataPortalMethodInfo method = null;
            var factoryInfo             = ObjectFactoryAttribute.GetObjectFactoryAttribute(objectType);

            if (factoryInfo == null)
            {
                if (criteria is int)
                {
                    method = GetMethodInfo(objectType, "DataPortal_Fetch");
                }
                else
                {
                    method = GetMethodInfo(objectType, "DataPortal_Fetch", criteria);
                }
            }
            else
            {
                var factoryType = FactoryDataPortal.FactoryLoader.GetFactoryType(factoryInfo.FactoryTypeName);
                if (factoryType != null)
                {
                    if (criteria is int)
                    {
                        method = GetMethodInfo(
                            factoryType,
                            factoryInfo.FetchMethodName);
                    }
                    else
                    {
                        method = GetMethodInfo(
                            FactoryDataPortal.FactoryLoader.GetFactoryType(factoryInfo.FactoryTypeName),
                            factoryInfo.FetchMethodName,
                            criteria);
                    }
                }
                else
                {
                    method = new DataPortalMethodInfo();
                }
            }
            return(method);
        }
Exemplo n.º 4
0
        public DataPortalResult Update(object obj, DataPortalContext context)
        {
            try
            {
                SetContext(context);

                Authorize(new AuthorizeRequest(obj.GetType(), obj, DataPortalOperations.Update));

                DataPortalResult     result;
                DataPortalMethodInfo method;
                var factoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(obj.GetType());
                if (factoryInfo != null)
                {
                    var factoryType = FactoryDataPortal.FactoryLoader.GetFactoryType(factoryInfo.FactoryTypeName);
                    var bbase       = obj as Core.BusinessBase;
                    if (bbase != null && bbase.IsDeleted)
                    {
                        method = Server.DataPortalMethodCache.GetMethodInfo(factoryType, factoryInfo.DeleteMethodName, new object[] { obj });
                    }
                    else
                    {
                        method = Server.DataPortalMethodCache.GetMethodInfo(factoryType, factoryInfo.UpdateMethodName, new object[] { obj });
                    }
                }
                else
                {
                    string methodName;
                    var    bbase = obj as Core.BusinessBase;
                    if (bbase != null)
                    {
                        if (bbase.IsDeleted)
                        {
                            methodName = "DataPortal_DeleteSelf";
                        }
                        else
                        if (bbase.IsNew)
                        {
                            methodName = "DataPortal_Insert";
                        }
                        else
                        {
                            methodName = "DataPortal_Update";
                        }
                    }
                    else if (obj is CommandBase)
                    {
                        methodName = "DataPortal_Execute";
                    }
                    else
                    {
                        methodName = "DataPortal_Update";
                    }
                    method = DataPortalMethodCache.GetMethodInfo(obj.GetType(), methodName);
                }

                context.TransactionalType = method.TransactionalType;
                IDataPortalServer portal;
                switch (method.TransactionalType)
                {
                case TransactionalTypes.EnterpriseServices:
                    portal = new ServicedDataPortal();
                    try
                    {
                        result = portal.Update(obj, context);
                    }
                    finally
                    {
                        ((ServicedDataPortal)portal).Dispose();
                    }
                    break;

                case TransactionalTypes.TransactionScope:
                    portal = new TransactionalDataPortal();
                    result = portal.Update(obj, context);
                    break;

                default:
                    portal = new DataPortalSelector();
                    result = portal.Update(obj, context);
                    break;
                }
                return(result);
            }
            catch (YYT.Server.DataPortalException ex)
            {
                Exception tmp = ex;
                throw;
            }
            catch (Exception ex)
            {
                throw new DataPortalException(
                          "DataPortal.Update " + Resources.FailedOnServer,
                          ex, new DataPortalResult());
            }
            finally
            {
                ClearContext(context);
            }
        }