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