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