001
014
015 package com.liferay.portal.cache.mvcc;
016
017 import com.liferay.portal.kernel.cache.LowLevelCache;
018 import com.liferay.portal.kernel.cache.PortalCache;
019 import com.liferay.portal.kernel.cache.PortalCacheWrapper;
020 import com.liferay.portal.model.MVCCModel;
021
022 import java.io.Serializable;
023
024
027 public class MVCCPortalCacheFactory {
028
029 public static <K extends Serializable>
030 PortalCache<K, ?> createMVCCEhcachePortalCache(
031 PortalCache<K, ?> portalCache) {
032
033 if (portalCache instanceof LowLevelCache) {
034 return new MVCCPortalCache<>(
035 (LowLevelCache<K, MVCCModel>)portalCache);
036 }
037
038 PortalCache<K, ?> currentPortalCache = portalCache;
039
040 while (currentPortalCache instanceof PortalCacheWrapper) {
041 PortalCacheWrapper<K, MVCCModel> portalCacheWrapper =
042 (PortalCacheWrapper<K, MVCCModel>)currentPortalCache;
043
044 PortalCache<K, MVCCModel> nextPortalCache =
045 portalCacheWrapper.getWrappedPortalCache();
046
047 if (nextPortalCache instanceof LowLevelCache) {
048 nextPortalCache = new MVCCPortalCache<>(
049 (LowLevelCache<K, MVCCModel>)nextPortalCache);
050
051 portalCacheWrapper.setPortalCache(nextPortalCache);
052
053 break;
054 }
055 else {
056 currentPortalCache = nextPortalCache;
057 }
058 }
059
060 return portalCache;
061 }
062
063 }