001
014
015 package com.liferay.portal.service.impl;
016
017 import com.liferay.portal.kernel.cache.MultiVMPoolUtil;
018 import com.liferay.portal.kernel.cache.PortalCache;
019 import com.liferay.portlet.BasePreferencesImpl;
020
021 import java.io.Serializable;
022
023 import java.util.HashMap;
024 import java.util.Map;
025
026
031 public class PortletPreferencesLocalUtil {
032
033 public static Map<Serializable, BasePreferencesImpl> getPreferencesPool(
034 long ownerId, int ownerType) {
035
036 Serializable key = new PreferencesPoolKey(ownerId, ownerType);
037
038 Map<Serializable, BasePreferencesImpl> preferencesPool =
039 (Map<Serializable, BasePreferencesImpl>)_portalCache.get(key);
040
041 if (preferencesPool == null) {
042 preferencesPool = new HashMap<Serializable, BasePreferencesImpl>();
043
044 _portalCache.put(key, preferencesPool);
045 }
046
047 return preferencesPool;
048 }
049
050 protected static void clearPreferencesPool() {
051 _portalCache.removeAll();
052 }
053
054 protected static void clearPreferencesPool(long ownerId, int ownerType) {
055 Serializable key = new PreferencesPoolKey(ownerId, ownerType);
056
057 _portalCache.remove(key);
058 }
059
060 private static final String _CACHE_NAME =
061 PortletPreferencesLocalUtil.class.getName();
062
063 private static PortalCache _portalCache = MultiVMPoolUtil.getCache(
064 _CACHE_NAME);
065
066 private static class PreferencesPoolKey implements Serializable {
067
068 public PreferencesPoolKey(long ownerId, int ownerType) {
069 _ownerId = ownerId;
070 _ownerType = ownerType;
071 }
072
073 @Override
074 public boolean equals(Object obj) {
075 PreferencesPoolKey preferencesPoolKey = (PreferencesPoolKey)obj;
076
077 if ((preferencesPoolKey._ownerId == _ownerId) &&
078 (preferencesPoolKey._ownerType == _ownerType)) {
079
080 return true;
081 }
082 else {
083 return false;
084 }
085 }
086
087 @Override
088 public int hashCode() {
089 return (int)(_ownerId * 11 + _ownerType);
090 }
091
092 private static final long serialVersionUID = 1L;
093
094 private final long _ownerId;
095 private final int _ownerType;
096
097 }
098
099 }