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); }
public void afterPropertiesSet() { CacheRegistryUtil.register(this); ServiceDependencyManager serviceDependencyManager = new ServiceDependencyManager(); serviceDependencyManager.addServiceDependencyListener( new ServiceDependencyListener() { @Override public void dependenciesFulfilled() { Registry registry = RegistryUtil.getRegistry(); _multiVMPool = registry.getService(MultiVMPool.class); PortalCacheManager<? extends Serializable, ? extends Serializable> portalCacheManager = _multiVMPool.getPortalCacheManager(); portalCacheManager.registerPortalCacheManagerListener(EntityCacheImpl.this); } @Override public void destroy() {} }); serviceDependencyManager.registerDependencies(MultiVMPool.class); }
@Override public void run() { for (UpgradeInfo upgradeInfo : _upgradeInfos) { UpgradeStep upgradeStep = upgradeInfo.getUpgradeStep(); try { upgradeStep.upgrade( new DBProcessContext() { @Override public DBContext getDBContext() { return new DBContext(); } @Override public OutputStream getOutputStream() { return _outputStream; } }); _releaseLocalService.updateRelease( _bundleSymbolicName, upgradeInfo.getToSchemaVersionString(), upgradeInfo.getFromSchemaVersionString()); } catch (Exception e) { throw new RuntimeException(e); } } CacheRegistryUtil.clear(); }
/** * Clears the cache for all tickets. * * <p>The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link * com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method. */ @Override public void clearCache() { if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) { CacheRegistryUtil.clear(TicketImpl.class.getName()); } EntityCacheUtil.clearCache(TicketImpl.class.getName()); FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY); FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST); }
/** * Clears the cache for all projects entries. * * <p>The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link * com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method. */ @Override public void clearCache() { if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) { CacheRegistryUtil.clear(ProjectsEntryImpl.class.getName()); } EntityCacheUtil.clearCache(ProjectsEntryImpl.class); FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY); FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); }
@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); }
private static void _reloadServletContext( HttpServletRequest request, UnicodeProperties unicodeProperties) throws Exception { // Data sources Properties jdbcProperties = new Properties(); jdbcProperties.putAll(unicodeProperties); jdbcProperties = PropertiesUtil.getProperties(jdbcProperties, "jdbc.default.", true); DataSourceSwapper.swapCounterDataSource(jdbcProperties); DataSourceSwapper.swapLiferayDataSource(jdbcProperties); // Caches CacheRegistryUtil.clear(); MultiVMPoolUtil.clear(); WebCachePoolUtil.clear(); CentralizedThreadLocal.clearShortLivedThreadLocals(); // Persistence beans _reconfigurePersistenceBeans(); // Quartz QuartzLocalServiceUtil.checkQuartzTables(); // Startup StartupAction startupAction = new StartupAction(); startupAction.run(null); // Servlet context HttpSession session = request.getSession(); PortalInstances.reload(session.getServletContext()); }
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 static void verify() throws Exception { // Check release Release release = null; try { release = ReleaseLocalServiceUtil.getRelease( ReleaseConstants.DEFAULT_SERVLET_CONTEXT_NAME, ReleaseInfo.getParentBuildNumber()); } catch (PortalException pe) { release = ReleaseLocalServiceUtil.addRelease( ReleaseConstants.DEFAULT_SERVLET_CONTEXT_NAME, ReleaseInfo.getParentBuildNumber()); } _checkReleaseState(); // Update indexes if (PropsValues.DATABASE_INDEXES_UPDATE_ON_STARTUP) { StartupHelperUtil.setDropIndexes(true); StartupHelperUtil.updateIndexes(); } else if (StartupHelperUtil.isUpgraded()) { StartupHelperUtil.updateIndexes(); } // Verify if (PropsValues.VERIFY_DATABASE_TRANSACTIONS_DISABLED) { _disableTransactions(); } try { StartupHelperUtil.verifyProcess(release.isVerified()); } catch (Exception e) { _updateReleaseState(ReleaseConstants.STATE_VERIFY_FAILURE); throw e; } finally { if (PropsValues.VERIFY_DATABASE_TRANSACTIONS_DISABLED) { _enableTransactions(); } } // Update indexes if (PropsValues.DATABASE_INDEXES_UPDATE_ON_STARTUP || StartupHelperUtil.isUpgraded()) { StartupHelperUtil.updateIndexes(false); } // Update release boolean verified = StartupHelperUtil.isVerified(); if (release.isVerified()) { verified = true; } ReleaseLocalServiceUtil.updateRelease( release.getReleaseId(), ReleaseInfo.getParentBuildNumber(), ReleaseInfo.getBuildDate(), verified); // Enable database caching after verify CacheRegistryUtil.setActive(true); }
public void afterPropertiesSet() { CacheRegistryUtil.register(this); }
public static void upgrade() throws Exception { // Disable database caching before upgrade if (_log.isDebugEnabled()) { _log.debug("Disable cache registry"); } CacheRegistryUtil.setActive(false); // Check release int buildNumber = ReleaseLocalServiceUtil.getBuildNumberOrCreate(); if (buildNumber > ReleaseInfo.getParentBuildNumber()) { StringBundler sb = new StringBundler(6); sb.append("Attempting to deploy an older Liferay Portal version. "); sb.append("Current build version is "); sb.append(buildNumber); sb.append(" and attempting to deploy version "); sb.append(ReleaseInfo.getParentBuildNumber()); sb.append("."); throw new IllegalStateException(sb.toString()); } else if (buildNumber < ReleaseInfo.RELEASE_5_2_3_BUILD_NUMBER) { String msg = "You must first upgrade to Liferay Portal 5.2.3"; System.out.println(msg); throw new RuntimeException(msg); } // Reload SQL CustomSQLUtil.reloadCustomSQL(); SQLTransformer.reloadSQLTransformer(); // Upgrade if (_log.isDebugEnabled()) { _log.debug("Update build " + buildNumber); } _checkPermissionAlgorithm(); _checkReleaseState(); if (PropsValues.UPGRADE_DATABASE_TRANSACTIONS_DISABLED) { _disableTransactions(); } try { StartupHelperUtil.upgradeProcess(buildNumber); } catch (Exception e) { _updateReleaseState(ReleaseConstants.STATE_UPGRADE_FAILURE); throw e; } finally { if (PropsValues.UPGRADE_DATABASE_TRANSACTIONS_DISABLED) { _enableTransactions(); } } // Update company key if (StartupHelperUtil.isUpgraded()) { if (_log.isDebugEnabled()) { _log.debug("Update company key"); } _updateCompanyKey(); } // Check class names if (_log.isDebugEnabled()) { _log.debug("Check class names"); } ClassNameLocalServiceUtil.checkClassNames(); // Check resource actions if (_log.isDebugEnabled()) { _log.debug("Check resource actions"); } ResourceActionLocalServiceUtil.checkResourceActions(); // Delete temporary images if (_log.isDebugEnabled()) { _log.debug("Delete temporary images"); } _deleteTempImages(); // Clear the caches only if the upgrade process was run if (_log.isDebugEnabled()) { _log.debug("Clear cache if upgrade process was run"); } if (StartupHelperUtil.isUpgraded()) { MultiVMPoolUtil.clear(); } }
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); } }
public static synchronized void init() { if (_initialized) { return; } StopWatch stopWatch = new StopWatch(); stopWatch.start(); // Set the default locale used by Liferay. This locale is no longer set // at the VM level. See LEP-2584. String userLanguage = SystemProperties.get("user.language"); String userCountry = SystemProperties.get("user.country"); String userVariant = SystemProperties.get("user.variant"); LocaleUtil.setDefault(userLanguage, userCountry, userVariant); // Set the default time zone used by Liferay. This time zone is no // longer set at the VM level. See LEP-2584. String userTimeZone = SystemProperties.get("user.timezone"); TimeZoneUtil.setDefault(userTimeZone); // Shared class loader try { PortalClassLoaderUtil.setClassLoader(ClassLoaderUtil.getContextClassLoader()); } catch (Exception e) { e.printStackTrace(); } // Properties com.liferay.portal.kernel.util.PropsUtil.setProps(new PropsImpl()); // Log4J if (GetterUtil.getBoolean(SystemProperties.get("log4j.configure.on.startup"), true)) { ClassLoader classLoader = InitUtil.class.getClassLoader(); Log4JUtil.configureLog4J(classLoader); } // Shared log try { LogFactoryUtil.setLogFactory(new Log4jLogFactoryImpl()); } catch (Exception e) { e.printStackTrace(); } // Log sanitizer SanitizerLogWrapper.init(); // Java properties JavaDetector.isJDK5(); // Security manager SecurityManagerUtil.init(); if (SecurityManagerUtil.ENABLED) { com.liferay.portal.kernel.util.PropsUtil.setProps( DoPrivilegedUtil.wrap(com.liferay.portal.kernel.util.PropsUtil.getProps())); LogFactoryUtil.setLogFactory(DoPrivilegedUtil.wrap(LogFactoryUtil.getLogFactory())); } // Cache registry CacheRegistryUtil.setCacheRegistry(DoPrivilegedUtil.wrap(new CacheRegistryImpl())); // Configuration factory ConfigurationFactoryUtil.setConfigurationFactory( DoPrivilegedUtil.wrap(new ConfigurationFactoryImpl())); // Data source factory DataSourceFactoryUtil.setDataSourceFactory(DoPrivilegedUtil.wrap(new DataSourceFactoryImpl())); // DB factory DBFactoryUtil.setDBFactory(DoPrivilegedUtil.wrap(new DBFactoryImpl())); // ROME XmlReader.setDefaultEncoding(StringPool.UTF8); if (_PRINT_TIME) { System.out.println("InitAction takes " + stopWatch.getTime() + " ms"); } _initialized = true; }
protected void cacheDb() throws Exception { CacheRegistryUtil.clear(); }
@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); }
public void destroy() { CacheRegistryUtil.unregister(getRegistryName()); }