コード例 #1
0
ファイル: MergeProcess.cs プロジェクト: vogelb/ambeth
        protected void MergePhase1(Object objectToMerge, Object objectToDelete, ProceedWithMergeHook proceedHook, MergeFinishedCallback mergeFinishedCallback, bool addNewEntitiesToCache)
        {
            ICUDResult       cudResult;
            MergeHandle      mergeHandle;
            IDisposableCache childCache = CacheFactory.Create(CacheFactoryDirective.NoDCE, false, false, "MergeProcess.ORIGINAL");

            try
            {
                mergeHandle = BeanContext.RegisterBean <MergeHandle>() //
                              .PropertyValue("Cache", childCache)      //
                              .Finish();
                cudResult         = MergeController.MergeDeep(objectToMerge, mergeHandle);
                mergeHandle.Cache = null;
            }
            finally
            {
                childCache.Dispose();
                childCache = null;
            }
            if (GuiThreadHelper.IsInGuiThread())
            {
                MergePhase2(objectToMerge, objectToDelete, mergeHandle, cudResult, proceedHook, mergeFinishedCallback, addNewEntitiesToCache);
            }
            else
            {
                GuiThreadHelper.InvokeInGui(delegate()
                {
                    MergePhase2(objectToMerge, objectToDelete, mergeHandle, cudResult, proceedHook, mergeFinishedCallback, addNewEntitiesToCache);
                });
            }
        }
コード例 #2
0
 public void Destroy()
 {
     if (cache != null)
     {
         cache.Dispose();
         cache = null;
     }
 }
コード例 #3
0
 public void Init()
 {
     // Test entities have to come from an independent cache
     if (cache != null)
     {
         cache.Dispose();
         cache = null;
     }
     cache = CacheFactory.Create(CacheFactoryDirective.NoDCE, "test");
 }
コード例 #4
0
        public Object ProcessWrite(IPostProcessWriter writer)
        {
            ISet <Object> substitutedEntities = writer.SubstitutedEntities;

            if (substitutedEntities.Count == 0)
            {
                return(null);
            }

            IDisposableCache childCache   = CacheFactory.Create(CacheFactoryDirective.NoDCE, "XmlMerge");
            IServiceContext  mergeContext = BeanContext.CreateService(delegate(IBeanContextFactory childContextFactory)
            {
                childContextFactory.RegisterBean(typeof(MergeHandle)).Autowireable <MergeHandle>().PropertyValue("Cache", childCache);
            });

            try
            {
                IDictionary <Object, Int32> mutableToIdMap = writer.MutableToIdMap;
                IObjRefHelper  objRefHelper = ObjRefHelper;
                MergeHandle    mergeHandle  = mergeContext.GetService <MergeHandle>();
                IList <Object> toMerge      = new List <Object>(substitutedEntities.Count);
                foreach (Object entity in substitutedEntities)
                {
                    toMerge.Add(entity);
                    IObjRef ori = objRefHelper.EntityToObjRef(entity);
                    mergeHandle.objToOriDict.Add(entity, ori);
                    Int32 id = mutableToIdMap[entity];
                    mutableToIdMap.Add(ori, id);
                }
                ICUDResult cudResult = MergeController.MergeDeep(toMerge, mergeHandle);
                if (cudResult.AllChanges.Count != 0)
                {
                    return(cudResult);
                }
                else
                {
                    return(null);
                }
            }
            finally
            {
                mergeContext.Dispose();
            }
        }
コード例 #5
0
 public virtual void CleanupThreadLocal()
 {
     if (cacheTL != null)
     {
         IDisposableCache cache = cacheTL.Value;
         if (cache != null)
         {
             cacheTL.Value = null;
             cache.Dispose();
         }
     }
     if (privilegedCacheTL != null)
     {
         IDisposableCache cache = privilegedCacheTL.Value;
         if (cache != null)
         {
             privilegedCacheTL.Value = null;
             cache.Dispose();
         }
     }
 }
コード例 #6
0
        public void test_ValueHolderContainer()
        {
            MaterialType obj = EntityFactory.CreateEntity <MaterialType>();

            obj.Id      = 2;
            obj.Name    = "name2";
            obj.Version = 1;
            MaterialType obj2 = EntityFactory.CreateEntity <MaterialType>();

            obj2.Id      = 3;
            obj2.Name    = "name3";
            obj2.Version = 1;

            IEntityMetaData metaData      = EntityMetaDataProvider.GetMetaData(typeof(Material));
            int             relationIndex = metaData.GetIndexByRelationName("Types");

            Material parentEntity = EntityFactory.CreateEntity <Material>();

            Assert.IsInstanceOfType(parentEntity, typeof(IValueHolderContainer));
            Assert.AssertEquals(ValueHolderState.LAZY, ((IObjRefContainer)parentEntity).Get__State(relationIndex));
            Assert.AssertEquals(0, ((IObjRefContainer)parentEntity).Get__ObjRefs(relationIndex).Length);

            parentEntity.Id      = 1;
            parentEntity.Name    = "name1";
            parentEntity.Version = 1;
            parentEntity.Types.Add(obj);
            parentEntity.Types.Add(obj2);

            IObjRef typeObjRef = OriHelper.EntityToObjRef(obj);

            IDisposableCache cache = CacheFactory.Create(CacheFactoryDirective.NoDCE, "test");

            ((ICacheIntern)cache).AssignEntityToCache(parentEntity);
            ((IObjRefContainer)parentEntity).Set__ObjRefs(relationIndex, new IObjRef[] { typeObjRef });

            Assert.AssertEquals(ValueHolderState.INIT, ((IObjRefContainer)parentEntity).Get__State(relationIndex));
            Assert.AssertEquals(1, ((IObjRefContainer)parentEntity).Get__ObjRefs(relationIndex).Length);

            Object value = ValueHolderContainerMixin.GetValue((IValueHolderContainer)parentEntity, relationIndex);
        }
コード例 #7
0
        public ICache GetCurrentCache()
        {
            switch (CacheType)
            {
            case CacheType.PROTOTYPE:
            {
                if (!SecurityActive || !SecurityActivation.FilterActivated)
                {
                    return(CacheFactory.CreatePrivileged(CacheFactoryDirective.SubscribeTransactionalDCE, false, null, "CacheProvider.PROTOTYPE"));
                }
                return(CacheFactory.Create(CacheFactoryDirective.SubscribeTransactionalDCE, false, null, "CacheProvider.PROTOTYPE"));
            }

            case CacheType.SINGLETON:
            {
                writeLock.Lock();
                try
                {
                    if (!SecurityActive || !SecurityActivation.FilterActivated)
                    {
                        if (privilegedSingletonCache == null)
                        {
                            privilegedSingletonCache = CacheFactory.CreatePrivileged(CacheFactoryDirective.SubscribeTransactionalDCE, true, null, "CacheProvider.SINGLETON");
                        }
                        return(privilegedSingletonCache);
                    }
                    else
                    {
                        if (singletonCache == null)
                        {
                            singletonCache = CacheFactory.Create(CacheFactoryDirective.SubscribeTransactionalDCE, true, null, "CacheProvider.SINGLETON");
                        }
                        return(singletonCache);
                    }
                }
                finally
                {
                    writeLock.Unlock();
                }
            }

            case CacheType.THREAD_LOCAL:
            {
                if (!SecurityActive || !SecurityActivation.FilterActivated)
                {
                    IDisposableCache cache = privilegedCacheTL.Value;
                    if (cache == null)
                    {
                        cache = CacheFactory.CreatePrivileged(CacheFactoryDirective.SubscribeTransactionalDCE, false, false, "CacheProvider.THREAD_LOCAL");
                        privilegedCacheTL.Value = cache;
                    }
                    return(cache);
                }
                else
                {
                    IDisposableCache cache = cacheTL.Value;
                    if (cache == null)
                    {
                        cache         = CacheFactory.Create(CacheFactoryDirective.SubscribeTransactionalDCE, false, false, "CacheProvider.THREAD_LOCAL");
                        cacheTL.Value = cache;
                    }
                    return(cache);
                }
            }

            default:
                throw new Exception("Not supported type: " + CacheType);
            }
        }
コード例 #8
0
ファイル: MergeServiceRegistry.cs プロジェクト: vogelb/ambeth
        protected IOriCollection MergeIntern(ICUDResult cudResultOriginal, IMethodDescription methodDescription)
        {
            IResultingBackgroundWorkerDelegate <IOriCollection> runnable = new IResultingBackgroundWorkerDelegate <IOriCollection>(delegate()
            {
                IDisposableCache childCache = CacheFactory.CreatePrivileged(CacheFactoryDirective.SubscribeTransactionalDCE, false, false,
                                                                            "MergeServiceRegistry.STATE");
                try
                {
                    IncrementalMergeState state = null;
                    ICUDResult cudResultOfCache;
                    if (MergeProcess.IsAddNewlyPersistedEntities() || (Log.DebugEnabled && CudResultPrinter != null))
                    {
                        childCache = CacheFactory.CreatePrivileged(CacheFactoryDirective.SubscribeTransactionalDCE, false, false,
                                                                   "MergeServiceRegistry.STATE");
                        state            = (IncrementalMergeState)CudResultApplier.AcquireNewState(childCache);
                        cudResultOfCache = CudResultApplier.ApplyCUDResultOnEntitiesOfCache(cudResultOriginal, true, state);
                    }
                    else
                    {
                        cudResultOfCache = cudResultOriginal;
                    }
                    if (Log.DebugEnabled)
                    {
                        if (CudResultPrinter != null)
                        {
                            Log.Debug("Initial merge [" + RuntimeHelpers.GetHashCode(state) + "]:\n" + CudResultPrinter.PrintCUDResult(cudResultOfCache, state));
                        }
                        else
                        {
                            Log.Debug("Initial merge [" + RuntimeHelpers.GetHashCode(state) + "]. No Details available");
                        }
                    }
                    List <MergeOperation> mergeOperationSequence = new List <MergeOperation>();
                    ICUDResult extendedCudResult = WhatIfMerged(cudResultOfCache, methodDescription, mergeOperationSequence, state);

                    if (Log.DebugEnabled)
                    {
                        Log.Debug("Merge finished [" + RuntimeHelpers.GetHashCode(state) + "]");
                    }
                    if (MergeSecurityManager != null)
                    {
                        SecurityActive.ExecuteWithSecurityDirective(SecurityDirective.ENABLE_ENTITY_CHECK, delegate()
                        {
                            MergeSecurityManager.CheckMergeAccess(extendedCudResult, methodDescription);
                        });
                    }
                    List <Object> originalRefsOfCache  = new List <Object>(cudResultOfCache.GetOriginalRefs());
                    List <Object> originalRefsExtended = new List <Object>(extendedCudResult.GetOriginalRefs());
                    IOriCollection oriCollExtended     = Intern(extendedCudResult, methodDescription, mergeOperationSequence, state);

                    IList <IChangeContainer> allChangesOriginal = cudResultOriginal.AllChanges;
                    IList <IObjRef> allChangedObjRefsExtended   = oriCollExtended.AllChangeORIs;
                    IObjRef[] allChangedObjRefsResult           = new IObjRef[allChangesOriginal.Count];

                    IdentityHashMap <Object, int?> originalRefOfCacheToIndexMap = new IdentityHashMap <Object, int?>();
                    for (int a = originalRefsOfCache.Count; a-- > 0;)
                    {
                        originalRefOfCacheToIndexMap.Put(originalRefsOfCache[a], a);
                    }
                    for (int a = originalRefsExtended.Count; a-- > 0;)
                    {
                        int?indexOfCache = originalRefOfCacheToIndexMap.Get(originalRefsExtended[a]);
                        if (indexOfCache == null)
                        {
                            // this is a change implied by a rule or an persistence-implicit change
                            // we do not know about it in the outer original CUDResult
                            continue;
                        }
                        IObjRef objRefExtended = allChangedObjRefsExtended[a];
                        IObjRef objRefOriginal = allChangesOriginal[indexOfCache.Value].Reference;
                        if (objRefExtended == null)
                        {
                            // entity has been deleted
                            objRefOriginal.Id      = null;
                            objRefOriginal.Version = null;
                        }
                        else
                        {
                            objRefOriginal.Id      = objRefExtended.Id;
                            objRefOriginal.Version = objRefExtended.Version;
                        }
                        if (objRefOriginal is IDirectObjRef)
                        {
                            ((IDirectObjRef)objRefOriginal).Direct = null;
                        }
                        allChangedObjRefsResult[indexOfCache.Value] = objRefOriginal;
                    }
                    OriCollection oriCollection = new OriCollection(new List <IObjRef>(allChangedObjRefsResult));

                    return(oriCollection);
                }
                finally
                {
                    childCache.Dispose();
                }
            });

            if (SecurityActive == null || !SecurityActive.FilterActivated)
            {
                return(runnable());
            }
            else
            {
                return(SecurityActive.ExecuteWithoutFiltering(runnable));
            }
        }