001
014
015 package com.liferay.portal.dao.shard.advice;
016
017 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018 import com.liferay.portal.kernel.dao.shard.ShardUtil;
019 import com.liferay.portal.kernel.log.Log;
020 import com.liferay.portal.kernel.log.LogFactoryUtil;
021
022 import org.aopalliance.intercept.MethodInterceptor;
023 import org.aopalliance.intercept.MethodInvocation;
024
025
030 public class ShardIterativelyAdvice implements MethodInterceptor {
031
032
038 public Object invoke(MethodInvocation methodInvocation) throws Throwable {
039 if (_log.isInfoEnabled()) {
040 _log.info(
041 "Iterating through all shards for " +
042 methodInvocation.toString());
043 }
044
045 for (String shardName : ShardUtil.getAvailableShardNames()) {
046 _shardAdvice.pushCompanyService(shardName);
047
048 try {
049 methodInvocation.proceed();
050 }
051 finally {
052 _shardAdvice.popCompanyService();
053
054 CacheRegistryUtil.clear();
055 }
056 }
057
058 return null;
059 }
060
061 public void setShardAdvice(ShardAdvice shardAdvice) {
062 _shardAdvice = shardAdvice;
063 }
064
065 private static Log _log = LogFactoryUtil.getLog(
066 ShardIterativelyAdvice.class);
067
068 private ShardAdvice _shardAdvice;
069
070 }