001
014
015 package com.liferay.portal.dao.shard.advice;
016
017 import com.liferay.portal.dao.shard.ShardDataSourceTargetSource;
018 import com.liferay.portal.dao.shard.ShardSessionFactoryTargetSource;
019 import com.liferay.portal.kernel.dao.shard.ShardUtil;
020 import com.liferay.portal.kernel.log.Log;
021 import com.liferay.portal.kernel.log.LogFactoryUtil;
022
023 import org.aopalliance.intercept.MethodInterceptor;
024 import org.aopalliance.intercept.MethodInvocation;
025
026
031 public class ShardGloballyAdvice implements MethodInterceptor {
032
033
039 public Object invoke(MethodInvocation methodInvocation) throws Throwable {
040 Object returnValue = null;
041
042 _shardAdvice.setGlobalCall(new Object());
043
044 try {
045 if (_log.isInfoEnabled()) {
046 _log.info(
047 "All shards invoked for " + methodInvocation.toString());
048 }
049
050 for (String shardName : ShardUtil.getAvailableShardNames()) {
051 ShardDataSourceTargetSource dataSourceTargetSource =
052 _shardAdvice.getShardDataSourceTargetSource();
053
054 dataSourceTargetSource.setDataSource(shardName);
055
056 ShardSessionFactoryTargetSource
057 shardSessionFactoryTargetSource =
058 _shardAdvice.getShardSessionFactoryTargetSource();
059
060 shardSessionFactoryTargetSource.setSessionFactory(shardName);
061
062 Object value = methodInvocation.proceed();
063
064 if (shardName.equals(ShardUtil.getDefaultShardName())) {
065 returnValue = value;
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 }