Exemple #1
0
        /// <summary>
        /// Finds the instance that represents this object in persistance tier. For this reaseon it is used the data component
        /// </summary>
        public ONInstance Find(ONFilterList onFilterList)
        {
            ONData       lData       = ONContext.GetComponent_Data(ClassName, OnContext);
            ONCollection lCollection = lData.ExecuteQuery(new ONLinkedToList(), onFilterList, null, null, null, 0);

            ONInstance lInstance = null;

            if (lCollection.Count > 0)
            {
                lInstance = lCollection[0];
                Copy(lInstance);
            }
            return(lInstance);
        }
Exemple #2
0
        public override void FilterInData(ONSqlSelect onSql, ONDBData data)
        {
            if (InLegacy)
            {
                return;
            }

            data.InhAddPath(onSql, mRelatedOid.ClassName, ONPath, "");

            //Fix Instance
            ONDBData lData = ONContext.GetComponent_Data(mRelatedOid.ClassName, data.OnContext) as ONDBData;

            lData.InhFixInstance(onSql, null, ONPath, mRelatedOid);
        }
Exemple #3
0
        /// <summary>
        /// Fix related instance
        /// </summary>
        /// <param name="onSql">Sentence SQL to be executed</param>
        /// <param name="linkedTo">List to reach the class to retrieve the related instance</param>
        protected bool AddLinkedTo(ONSqlSelect onSql, ONLinkedToList linkedTo)
        {
            // Fix related instance
            foreach (KeyValuePair <ONPath, ONOid> lDictionaryEntry in linkedTo)
            {
                ONPath lPath = lDictionaryEntry.Key as ONPath;
                ONOid  lOID  = lDictionaryEntry.Value as ONOid;

                string lAliasRelated = InhAddPath(onSql, lOID.ClassName, lPath, "", true);

                // Check Visibility
                if (!ONInstance.IsVisibleInv(ONContext.GetType_Instance(ClassName), lPath, OnContext))
                {
                    return(false);
                }

                ONDBData lData = ONContext.GetComponent_Data(lOID.ClassName, OnContext) as ONDBData;
                lData.InhFixInstance(onSql, null, lPath, lOID, true);
            }

            return(true);
        }
Exemple #4
0
        /// <summary>
        /// PostProcess method of the AOP
        /// </summary>
        /// <param name="inst">Instance</param>
        /// <param name="msg">Message</param>
        /// <param name="msgReturn">Return Message</param>
        public void Postprocess(MarshalByRefObject inst, IMessage msg, ref IMessage msgReturn)
        {
            IMethodCallMessage   lMsgIn  = msg as IMethodCallMessage;
            IMethodReturnMessage lMsgOut = msgReturn as IMethodReturnMessage;

            // Extract Action
            ONAction lAction = inst as ONAction;

            // Update Data
            if ((ServiceType == ServiceTypeEnumeration.New) || (ServiceType == ServiceTypeEnumeration.Destroy))
            {
                // Add ModifiedClass
                lAction.OnContext.AddModifiedClass(lAction);
            }
            else
            {
                if ((ServiceType == ServiceTypeEnumeration.Carrier) || (ServiceType == ServiceTypeEnumeration.Liberator))
                {
                    // Add ModifiedClass
                    lAction.OnContext.AddModifiedClass(lAction);
                }
                else if (lAction.Instance.Modified)
                {
                    // Update Instance
                    ONData lData = ONContext.GetComponent_Data(lAction.ClassName, lAction.OnContext);
                    lData.UpdateEdited(lAction.Instance);

                    // Add ModifiedClass
                    lAction.OnContext.AddModifiedClass(lAction);
                }
                lAction.Instance.ModifiedInTransaction = false;

                // Update Inheritance net data
                foreach (ONInstance lNetInstance in lAction.Instance.GetFacets())
                {
                    if (((object)lNetInstance != null) && (lNetInstance.ClassName != lAction.Instance.ClassName) && lNetInstance.Modified)
                    {
                        // Update inheritance net Instance
                        ONData lData = ONContext.GetComponent_Data(lNetInstance.ClassName, lNetInstance.OnContext);
                        lData.UpdateEdited(lNetInstance);

                        // Create action class
                        ONAction lNetAction = ONContext.GetComponent_Action(lNetInstance.ClassName, lNetInstance.OnContext);
                        lNetAction.Instance = lNetInstance;

                        // Add inheritance net ModifiedClass
                        lAction.OnContext.AddModifiedClass(lNetAction);
                    }

                    if ((object)lNetInstance != null)
                    {
                        lNetInstance.ModifiedInTransaction = false;
                    }
                }

                if (lAction.OnContext.ModifiedClass.ContainsKey(lAction.Instance.Oid))
                {
                    ONAction lNetAction = ONContext.GetComponent_Action(lAction.Instance.Root().ClassName, lAction.Instance.Root().OnContext);
                    lNetAction.Instance = lAction.Instance.Root();

                    lAction.OnContext.AddUnmodifiedClass(lNetAction);
                }
            }

            lAction.Instance.CleanDerivationCache();

            // Calculate OutboundArgumets
            object[] lArgs = lMsgOut.Args;
            mServiceCacheItem.InvoqueOutboundArguments(lAction, lArgs);

            // Pop the OID from Class Stack
            lAction.OnContext.TransactionStack.Pop();
            mInStack = false;

            // Restoing the old context of the This instance
            if (mThisOnContext != null)
            {
                lAction.Instance.OnContext = mThisOnContext;
            }

            msgReturn = new ReturnMessage(lMsgOut.ReturnValue, lArgs, lArgs.Length, lMsgOut.LogicalCallContext, lMsgIn);
            if (lAction.OnContext.TransactionStack.Count == 0)
            {
                // Check triggers
                lAction.OnContext.CheckTriggers();

                // Check integrity constraints
                lAction.OnContext.CheckIntegrityConstraints();
            }
        }
Exemple #5
0
 /// <summary>
 /// Comprobation that instance exists in the persistence tier
 /// </summary>
 public bool Exist(ONFilterList onFilterList)
 {
     return(ONContext.GetComponent_Data(ClassName, OnContext).Exist(Oid, onFilterList));
 }
Exemple #6
0
        /// <summary>
        /// Retrieve all the instances of a determinate class that fulfil a determinate formula of searching
        /// </summary>
        /// <param name="linkedTo">List to reach the class to retrieve the related instance</param>
        /// <param name="filters">Formula to search concrete instances</param>
        /// <param name="comparer">Order Criteria that must be followed by the query</param>
        /// <param name="startRowOID">OID frontier</param>
        /// <param name="blockSize">Number of instances to be returned</param>
        public override ONCollection ExecuteQuery(ONLinkedToList linkedTo, ONFilterList filters, ONDisplaySet displaySet, ONOrderCriteria comparer, ONOid startRowOid, int blockSize)
        {
            try
            {
                ONCollection lInstances    = null;
                Type         lTypeInstance = ONContext.GetType_Instance(ClassName);
                Type         lTypeQuery    = ONContext.GetType_Query(ClassName);

                // Initialize the list of related queries
                if (linkedTo == null)
                {
                    linkedTo = new ONLinkedToList();
                }

                // Initialize the filter list
                if (filters == null)
                {
                    filters = new ONFilterList();
                }

                ONLinkedToList lLinkedToLegacy = new ONLinkedToList();
                ONLinkedToList lLinkedToLocal  = new ONLinkedToList();
                ONLinkedToList lLinkedToMixed  = new ONLinkedToList();

                #region Treatment of LinkedTo
                foreach (KeyValuePair <ONPath, ONOid> lDictionaryEntry in linkedTo)
                {
                    ONPath lPath = lDictionaryEntry.Key as ONPath;
                    ONOid  lOid  = lDictionaryEntry.Value as ONOid;

                    ONPath lInversePath             = new ONPath(ONInstance.InversePath(lTypeInstance, lPath));
                    Type   lTypeTargetClassInstance = ONContext.GetType_Instance(ONInstance.GetTargetClass(OnContext, lTypeInstance, lPath));
                    if ((lInversePath.Count == 0) || (!ONInstance.IsVisible(lTypeTargetClassInstance, lInversePath, OnContext)))
                    {
                        return(ONContext.GetComponent_Collection(ClassName, OnContext));
                    }

                    bool   lexistLV = false;
                    ONData lData    = ONContext.GetComponent_Data(InhGetTargetClassName(lPath), OnContext);

                    if (lData.GetType().BaseType == typeof(ONLVData))
                    {
                        if (!lOid.Exist(OnContext, null))
                        {
                            return(ONContext.GetComponent_Collection(ClassName, OnContext));
                        }
                    }

                    foreach (string lRole in lInversePath.Roles)
                    {
                        lData = ONContext.GetComponent_Data(lData.InhGetTargetClassName(new ONPath(lRole)), OnContext);
                        if (lData.GetType().BaseType == typeof(ONLVData))
                        {
                            lexistLV = true;
                        }
                    }
                    if (!lexistLV)
                    {
                        lLinkedToLocal.mLinkedToList.Add(lPath, lOid);
                    }
                    else
                    {
                        lLinkedToMixed.mLinkedToList.Add(lPath, lOid);
                    }
                }
                #endregion

                #region displaySet
                if (!filters.PreloadRelatedAttributes)
                {
                    displaySet = null;
                }
                #endregion displaySet

                #region No link item
                if ((linkedTo.mLinkedToList.Count == 0) || (lLinkedToMixed.mLinkedToList.Count > 0))
                {
                    if ((GetType().BaseType != typeof(ONLVData)) || (filters.InData))
                    {
                        lInstances = SolveQuery(new ONLinkedToList(), filters, displaySet, comparer, startRowOid, blockSize);
                    }
                }
                #endregion

                #region Local Link
                if (lLinkedToLocal.mLinkedToList.Count > 0)
                {
                    ONCollection lInstancesAux = SolveQuery(lLinkedToLocal, filters, displaySet, comparer, startRowOid, blockSize);
                    if (lInstances != null)
                    {
                        lInstances.Intersection(lInstancesAux);
                    }
                    else
                    {
                        lInstances = lInstancesAux;
                    }
                }
                #endregion

                #region Hybrid Link
                if (lLinkedToMixed.mLinkedToList.Count > 0)
                {
                    ONCollection lInstancesAux = null;

                    foreach (KeyValuePair <ONPath, ONOid> lDictionaryEntry in lLinkedToMixed)
                    {
                        ONPath lPath = lDictionaryEntry.Key as ONPath;
                        ONOid  lOid  = lDictionaryEntry.Value as ONOid;

                        if (lPath.Roles.Count == 1)
                        {
                            ONLinkedToList lLinked = new ONLinkedToList();
                            lLinked[lPath] = lOid;
                            ONCollection lInstanceColl = SolveQuery(lLinked, filters, displaySet, comparer, startRowOid, blockSize);
                            if (lInstances != null)
                            {
                                lInstances.Intersection(lInstanceColl);
                            }
                            else
                            {
                                lInstances = lInstanceColl;
                            }
                            continue;
                        }

                        #region Optimized Path
                        ONLinkedToList linkedToOptimized    = new ONLinkedToList();
                        ONPath         lInversePath         = new ONPath(ONInstance.InversePath(lTypeInstance, lPath));
                        ONPath         lOptimizedRole       = new ONPath(lInversePath.RemoveHead() as string);
                        Type           lTypeInstanceDestiny = ONContext.GetType_Instance(InhGetTargetClassName(lPath));

                        bool   lBeginIsLegacy = (ONInstance.IsLegacy(lTypeInstanceDestiny, lOptimizedRole));
                        bool   lEnterLoop     = true;
                        ONData lData          = ONContext.GetComponent_Data(InhGetTargetClassName(lPath), OnContext);
                        if (lData.GetType().BaseType != typeof(ONLVData))
                        {
                            if (ONContext.GetType_Data(lData.InhGetTargetClassName(lOptimizedRole)).BaseType == typeof(ONLVData))
                            {
                                lEnterLoop = false;
                            }
                        }

                        lPath.RemoveTail();
                        if (lEnterLoop)
                        {
                            while (lInversePath.Roles.Count > 0)
                            {
                                lData = ONContext.GetComponent_Data(InhGetTargetClassName(lPath), OnContext);
                                if ((!lBeginIsLegacy) && (ONContext.GetType_Data(lData.InhGetTargetClassName(new ONPath(lInversePath.Roles[0]))).BaseType == typeof(ONLVData)))
                                {
                                    break;
                                }
                                if ((lBeginIsLegacy) && (ONContext.GetType_Data(lData.InhGetTargetClassName(new ONPath(lInversePath.Roles[0]))).BaseType != typeof(ONLVData)))
                                {
                                    break;
                                }

                                lOptimizedRole.Roles.Add(lInversePath.RemoveHead());
                                lPath.RemoveTail();
                            }
                        }

                        linkedToOptimized[ONInstance.InversePath(lTypeInstanceDestiny, lOptimizedRole)] = lOid;
                        if ((lPath.Count > 0) || (lBeginIsLegacy))
                        {
                            // It is not the last role or it is leged
                            lInstancesAux = ONContext.GetComponent_Data(InhGetTargetClassName(lPath), OnContext).ExecuteQuery(linkedToOptimized, null, null, comparer, startRowOid, blockSize);
                        }
                        else
                        {
                            // It is the last role and it is local
                            lInstancesAux = ONContext.GetComponent_Data(InhGetTargetClassName(lPath), OnContext).ExecuteQuery(linkedToOptimized, null, displaySet, comparer, startRowOid, blockSize);
                        }
                        #endregion

                        #region Rest of the path
                        lInstancesAux = lInstancesAux[lInversePath] as ONCollection;
                        #endregion

                        if (lInstances != null)
                        {
                            lInstances.Intersection(lInstancesAux);
                        }
                        else
                        {
                            lInstances = lInstancesAux;
                        }
                    }
                }
                #endregion

                return(lInstances);
            }
            catch (Exception e)
            {
                string ltraceItem = "Method: SolveQuery, Component: ONDBData";
                if (e is ONSystemException)
                {
                    ONSystemException lException = e as ONSystemException;
                    lException.addTraceInformation(ltraceItem);
                    throw lException;
                }
                throw new ONSystemException(e, ltraceItem);
            }
        }
        /// <summary>
        /// Adds an instance to the collection in the order that the Order Criteria sets.
        /// </summary>
        /// <param name="instance">Instance to add</param>
        /// <param name="comparer">Order criteria to apply</param>
        /// <param name="onContext">context of the query</param>
        public void AddOrdered(ONInstance instance, ONOrderCriteria comparer, ONContext onContext)
        {
            // Empty lists
            if (Count == 0)
            {
                Add(instance);
                return;
            }

            int i            = 0;
            int j            = 0;
            int lComparation = 0;

            // Clone and clear collection
            ONCollection lList = Clone() as ONCollection;

            this.Clear();

            // Create data component for default comparation
            ONData lData = null;

            if (comparer == null)
            {
                lData = ONContext.GetComponent_Data(ClassName, onContext);
            }

            ONInstance lInstance1 = lList.Array[i];

            while ((i < lList.Count) && (j < 1))
            {
                if (comparer != null)
                {
                    lComparation = comparer.CompareUnion(lInstance1, instance);
                }
                else
                {
                    lComparation = lData.CompareUnionOID(lInstance1, instance);
                }

                if (lComparation < 0)
                {
                    Add(lInstance1);
                    i += 1;
                    if (lList.Count > i)
                    {
                        lInstance1 = lList.Array[i];
                    }
                }
                else if (lComparation > 0)
                {
                    Add(instance);
                    j += 1;
                }
                else
                {
                    Add(lInstance1);
                    Add(instance);
                    i += 1;
                    j += 1;
                }
            }

            AddRange(lList);
            if (j == 0)
            {
                Add(instance);
            }
        }
        public void Postprocess(MarshalByRefObject inst, IMessage msg, ref IMessage msgReturn)
        {
            IMethodCallMessage   lMsgIn  = msg as IMethodCallMessage;
            IMethodReturnMessage lMsgOut = msgReturn as IMethodReturnMessage;
            int lIndex = 0;

            // Extract Action
            ONAction lAction = inst as ONAction;

            // Shared Event Control
            if (mReflexivePrincipal == false) // No-Principal Shared Event
            {
                return;
            }
            lAction.OnContext.InSharedContext = false;

            if ((ServiceType != ServiceTypeEnumeration.Destroy) && (ServiceType != ServiceTypeEnumeration.New))
            {
                if (mReflexiveClass.Key.Instance.Modified)
                {
                    // Update Instance
                    ONData lData = ONContext.GetComponent_Data(mReflexiveClass.Key.ClassName, lAction.OnContext);
                    lData.UpdateEdited(mReflexiveClass.Key.Instance);

                    // Add ModifiedClass
                    lAction.OnContext.AddModifiedClass(mReflexiveClass.Key);
                }
                else if (ServiceType == ServiceTypeEnumeration.Insertion || ServiceType == ServiceTypeEnumeration.Deletion)
                {
                    // Add ModifiedClass
                    lAction.OnContext.AddUnmodifiedClass(mReflexiveClass.Key);
                }

                // Update Inheritance net data
                foreach (ONInstance lNetInstance in mReflexiveClass.Key.Instance.GetFacets())
                {
                    if (((object)lNetInstance != null) && (lNetInstance.ClassName != mReflexiveClass.Key.ClassName) && lNetInstance.Modified)
                    {
                        // Update inheritance net Instance
                        ONData lData = ONContext.GetComponent_Data(lNetInstance.ClassName, lNetInstance.OnContext);
                        lData.UpdateEdited(lNetInstance);

                        // Create action class
                        ONAction lNetAction = ONContext.GetComponent_Action(lNetInstance.ClassName, lNetInstance.OnContext);
                        lNetAction.Instance = lNetInstance;

                        // Add inheritance net ModifiedClass
                        lAction.OnContext.AddModifiedClass(mReflexiveClass.Key);
                    }
                }
            }

            if ((ServiceType != ServiceTypeEnumeration.Destroy) && (ServiceType != ServiceTypeEnumeration.New))
            {
                if (lAction.Instance.Modified)
                {
                    // Update Instance
                    ONData lData = ONContext.GetComponent_Data(lAction.ClassName, lAction.OnContext);
                    lData.UpdateEdited(lAction.Instance);

                    // Add ModifiedClass
                    lAction.OnContext.AddModifiedClass(lAction);
                }
                else
                {
                    // Add ModifiedClass
                    lAction.OnContext.AddUnmodifiedClass(lAction);
                }

                // Update Inheritance net data
                foreach (ONInstance lNetInstance in lAction.Instance.GetFacets())
                {
                    if (((object)lNetInstance != null) && (lNetInstance.ClassName != lAction.ClassName) && lNetInstance.Modified)
                    {
                        // Update inheritance net Instance
                        ONData lData = ONContext.GetComponent_Data(lNetInstance.ClassName, lNetInstance.OnContext);
                        lData.UpdateEdited(lNetInstance);

                        // Create action class
                        ONAction lNetAction = ONContext.GetComponent_Action(lNetInstance.ClassName, lNetInstance.OnContext);
                        lNetAction.Instance = lNetInstance;

                        // Add inheritance net ModifiedClass
                        lAction.OnContext.AddModifiedClass(lAction);
                    }
                }
            }

            // Calculate Shared OutboundArguments
            lIndex = 0;
            object[] lArgs = lMsgOut.Args;
            mServiceCacheItems[lIndex++].InvoqueOutboundArguments(mReflexiveClass.Key, mReflexiveClass.Value);

            // Copy outbound arguments (only not initialized)
            for (int i = lMsgOut.ArgCount - lMsgOut.OutArgCount; i < lMsgOut.ArgCount; i++)
            {
                if (new ONBool(mReflexiveClass.Value[i] as ONSimpleType != null) || mReflexiveClass.Value[i] as ONOid != null)
                {
                    lArgs[i] = mReflexiveClass.Value[i];
                }
            }

            // Pop the Shared OID from Class Stack
            lAction.OnContext.TransactionStack.Pop();

            // Calculate OutboundArgumets
            mServiceCacheItem.InvoqueOutboundArguments(lAction, lArgs);

            // Pop the OID from Class Stack
            lAction.OnContext.TransactionStack.Pop();
            mInStack = false;

            // Restoing the old context of the This instance
            if (mThisOnContext != null)
            {
                lAction.Instance.OnContext = mThisOnContext;
            }

            msgReturn = new ReturnMessage(lMsgOut.ReturnValue, lArgs, lArgs.Length, lMsgOut.LogicalCallContext, lMsgIn);
            if (lAction.OnContext.TransactionStack.Count == 0)
            {
                // Check triggers
                lAction.OnContext.CheckTriggers();

                // Check integrity constraints
                lAction.OnContext.CheckIntegrityConstraints();
            }

            lAction.OnContext.InstancesInitialValues.Clear();
        }
Exemple #9
0
        /// <summary>
        /// Checks if a determinate instance exists
        /// </summary>
        /// <param name="onContext">Context</param>
        /// <param name="onFilterList">Filters to theck</param>
        /// <returns>If exists</returns>
        public bool Exist(ONContext onContext, ONFilterList onFilterList)
        {
            ONData lData = ONContext.GetComponent_Data(ClassName, onContext);

            return(lData.Exist(this, onFilterList));
        }
Exemple #10
0
        public void Postprocess(MarshalByRefObject inst, IMessage msg, ref IMessage msgReturn)
        {
            IMethodCallMessage   lMsgIn  = msg as IMethodCallMessage;
            IMethodReturnMessage lMsgOut = msgReturn as IMethodReturnMessage;

            // Extract Action
            ONAction lAction = inst as ONAction;

            if ((lAction.Instance != null) && (lAction.Instance.ModifiedInTransaction))
            {
                foreach (string lActiveFacet in lAction.Instance.LeafActiveFacets())
                {
                    ONInstance lInstanceToModify;
                    if (lActiveFacet == lAction.ClassName)
                    {
                        lInstanceToModify = lAction.Instance;
                    }
                    else
                    {
                        lInstanceToModify = lAction.Instance.GetFacet(lActiveFacet);
                    }
                    // Update Instance
                    if (lInstanceToModify.ModifiedInTransaction)
                    {
                        ONData lData = ONContext.GetComponent_Data(lInstanceToModify.ClassName, lInstanceToModify.OnContext);
                        lData.UpdateEdited(lInstanceToModify);
                    }
                }
                foreach (ONInstance lInstance in lAction.Instance.GetFacets())
                {
                    if (lInstance != null)
                    {
                        lInstance.ModifiedInTransaction = false;
                    }
                }

                lAction.Instance.ModifiedInTransaction = false;
            }

            // Calculate OutputArgumets
            object[] lArgs = lMsgOut.Args;
            mServiceCacheItem.InvoqueOutboundArguments(lAction, lArgs);

            // Pop the OID from Class Stack
            lAction.OnContext.TransactionStack.Pop();
            mInStack = false;

            // Restoing the old context of the This instance
            if (mThisOnContext != null)
            {
                lAction.Instance.OnContext = mThisOnContext;
            }

            msgReturn = new ReturnMessage(lMsgOut.ReturnValue, lArgs, lArgs.Length, lMsgOut.LogicalCallContext, lMsgIn);
            if (lAction.OnContext.TransactionStack.Count == 0)
            {
                // Check triggers
                lAction.OnContext.CheckTriggers();

                // Check integrity constraints
                lAction.OnContext.CheckIntegrityConstraints();
            }
        }