public void putResult( boolean entityCacheEnabled, Class<?> clazz, Serializable primaryKey, Object result) { if (!PropsValues.VALUE_OBJECT_ENTITY_CACHE_ENABLED || !entityCacheEnabled || !CacheRegistryUtil.isActive() || (result == null)) { return; } result = ((BaseModel<?>) result).toCacheModel(); if (_localCacheAvailable) { Map<Serializable, Object> localCache = _localCache.get(); Serializable localCacheKey = _encodeLocalCacheKey(clazz, primaryKey); localCache.put(localCacheKey, result); } PortalCache portalCache = _getPortalCache(clazz.getName(), true); Serializable cacheKey = _encodeCacheKey(primaryKey); portalCache.put(cacheKey, result); }
@Override public Serializable getResult( boolean entityCacheEnabled, Class<?> clazz, Serializable primaryKey) { if (!PropsValues.VALUE_OBJECT_ENTITY_CACHE_ENABLED || !entityCacheEnabled || !CacheRegistryUtil.isActive()) { return null; } Serializable result = null; Map<Serializable, Serializable> localCache = null; Serializable localCacheKey = null; if (_LOCAL_CACHE_AVAILABLE) { localCache = _localCache.get(); localCacheKey = _encodeLocalCacheKey(clazz, primaryKey); result = localCache.get(localCacheKey); } if (result == null) { PortalCache<Serializable, Serializable> portalCache = _getPortalCache(clazz, true); Serializable cacheKey = _encodeCacheKey(primaryKey); result = portalCache.get(cacheKey); if (result == null) { result = StringPool.BLANK; } if (_LOCAL_CACHE_AVAILABLE) { localCache.put(localCacheKey, result); } } return _toEntityModel(result); }
public void removeResult(boolean entityCacheEnabled, Class<?> clazz, Serializable primaryKey) { if (!PropsValues.VALUE_OBJECT_ENTITY_CACHE_ENABLED || !entityCacheEnabled || !CacheRegistryUtil.isActive()) { return; } if (_localCacheAvailable) { Map<Serializable, Object> localCache = _localCache.get(); Serializable localCacheKey = _encodeLocalCacheKey(clazz, primaryKey); localCache.remove(localCacheKey); } PortalCache portalCache = _getPortalCache(clazz.getName(), true); Serializable cacheKey = _encodeCacheKey(primaryKey); portalCache.remove(cacheKey); }
@Override public void putResult( boolean entityCacheEnabled, Class<?> clazz, Serializable primaryKey, Serializable result, boolean quiet) { if (!PropsValues.VALUE_OBJECT_ENTITY_CACHE_ENABLED || !entityCacheEnabled || !CacheRegistryUtil.isActive() || (result == null)) { return; } result = ((BaseModel<?>) result).toCacheModel(); if (_LOCAL_CACHE_AVAILABLE) { Map<Serializable, Serializable> localCache = _localCache.get(); Serializable localCacheKey = _encodeLocalCacheKey(clazz, primaryKey); localCache.put(localCacheKey, result); } PortalCache<Serializable, Serializable> portalCache = _getPortalCache(clazz, true); Serializable cacheKey = _encodeCacheKey(primaryKey); if (quiet) { PortalCacheHelperUtil.putWithoutReplicator(portalCache, cacheKey, result); } else { portalCache.put(cacheKey, result); } }
public Object loadResult( boolean entityCacheEnabled, Class<?> clazz, Serializable primaryKey, SessionFactory sessionFactory) { if (!PropsValues.VALUE_OBJECT_ENTITY_CACHE_ENABLED || !entityCacheEnabled || !CacheRegistryUtil.isActive()) { Session session = null; try { session = sessionFactory.openSession(); return session.load(clazz, primaryKey); } finally { sessionFactory.closeSession(session); } } Object result = null; Map<Serializable, Object> localCache = null; Serializable localCacheKey = null; if (_localCacheAvailable) { localCache = _localCache.get(); localCacheKey = _encodeLocalCacheKey(clazz, primaryKey); result = localCache.get(localCacheKey); } Object loadResult = null; if (result == null) { PortalCache portalCache = _getPortalCache(clazz.getName(), true); Serializable cacheKey = _encodeCacheKey(primaryKey); result = portalCache.get(cacheKey); if (result == null) { if (_log.isDebugEnabled()) { _log.debug("Load " + clazz + " " + primaryKey + " from session"); } Session session = null; try { session = sessionFactory.openSession(); loadResult = session.load(clazz, primaryKey); } finally { if (loadResult == null) { result = StringPool.BLANK; } else { result = ((BaseModel<?>) loadResult).toCacheModel(); } portalCache.put(cacheKey, result); sessionFactory.closeSession(session); } } if (_localCacheAvailable) { localCache.put(localCacheKey, result); } } if (loadResult != null) { return loadResult; } else { return _toEntityModel(result); } }
@Override public Serializable loadResult( boolean entityCacheEnabled, Class<?> clazz, Serializable primaryKey, SessionFactory sessionFactory) { if (!PropsValues.VALUE_OBJECT_ENTITY_CACHE_ENABLED || !entityCacheEnabled || !CacheRegistryUtil.isActive()) { Session session = null; try { session = sessionFactory.openSession(); return (Serializable) session.load(clazz, primaryKey); } finally { sessionFactory.closeSession(session); } } Serializable result = null; Map<Serializable, Serializable> localCache = null; Serializable localCacheKey = null; if (_LOCAL_CACHE_AVAILABLE) { localCache = _localCache.get(); localCacheKey = _encodeLocalCacheKey(clazz, primaryKey); result = localCache.get(localCacheKey); } Serializable loadResult = null; if (result == null) { PortalCache<Serializable, Serializable> portalCache = _getPortalCache(clazz, true); Serializable cacheKey = _encodeCacheKey(primaryKey); result = portalCache.get(cacheKey); if (result == null) { if (_log.isDebugEnabled()) { _log.debug("Load " + clazz + " " + primaryKey + " from session"); } Session session = null; try { session = sessionFactory.openSession(); loadResult = (Serializable) session.load(clazz, primaryKey); } finally { if (loadResult == null) { result = StringPool.BLANK; } else { result = ((BaseModel<?>) loadResult).toCacheModel(); } PortalCacheHelperUtil.putWithoutReplicator(portalCache, cacheKey, result); sessionFactory.closeSession(session); } } if (_LOCAL_CACHE_AVAILABLE) { localCache.put(localCacheKey, result); } } if (loadResult != null) { return loadResult; } return _toEntityModel(result); }