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 Object returnValue = null;
040
041 for (String shardName : ShardUtil.getAvailableShardNames()) {
042 if (_log.isInfoEnabled()) {
043 _log.info(
044 "Invoking shard " + shardName + " for " +
045 methodInvocation.toString());
046 }
047
048 _shardAdvice.pushCompanyService(shardName);
049
050 try {
051 Object value = methodInvocation.proceed();
052
053 if (shardName.equals(ShardUtil.getDefaultShardName())) {
054 returnValue = value;
055 }
056 }
057 finally {
058 _shardAdvice.popCompanyService();
059
060 CacheRegistryUtil.clear();
061 }
062 }
063
064 return returnValue;
065 }
066
067 public void setShardAdvice(ShardAdvice shardAdvice) {
068 _shardAdvice = shardAdvice;
069 }
070
071 private static Log _log = LogFactoryUtil.getLog(
072 ShardIterativelyAdvice.class);
073
074 private ShardAdvice _shardAdvice;
075
076 }