001
014
015 package com.liferay.portal.dao.shard;
016
017 import com.liferay.portal.dao.shard.advice.ShardAdvice;
018 import com.liferay.portal.kernel.dao.shard.Shard;
019 import com.liferay.portal.kernel.security.pacl.DoPrivileged;
020 import com.liferay.portal.kernel.util.InfrastructureUtil;
021 import com.liferay.portal.util.PropsValues;
022
023 import javax.sql.DataSource;
024
025
028 @DoPrivileged
029 public class ShardImpl implements Shard {
030
031 public String[] getAvailableShardNames() {
032 ShardDataSourceTargetSource shardDataSourceTargetSource =
033 (ShardDataSourceTargetSource)
034 InfrastructureUtil.getShardDataSourceTargetSource();
035
036 if (shardDataSourceTargetSource != null) {
037 return shardDataSourceTargetSource.getAvailableShardNames();
038 }
039
040 return null;
041 }
042
043 public String getCurrentShardName() {
044 return _shardAdvice.getCurrentShardName();
045 }
046
047 public DataSource getDataSource() {
048 return _shardAdvice.getDataSource();
049 }
050
051 public String getDefaultShardName() {
052 return PropsValues.SHARD_DEFAULT_NAME;
053 }
054
055 public boolean isEnabled() {
056 if (_shardAdvice != null) {
057 return true;
058 }
059 else {
060 return false;
061 }
062 }
063
064 public String popCompanyService() {
065 String value = null;
066
067 if (_shardAdvice != null) {
068 value = _shardAdvice.popCompanyService();
069 }
070
071 return value;
072 }
073
074 public void pushCompanyService(long companyId) {
075 if (_shardAdvice != null) {
076 _shardAdvice.pushCompanyService(companyId);
077 }
078 }
079
080 public void pushCompanyService(String shardName) {
081 if (_shardAdvice != null) {
082 _shardAdvice.pushCompanyService(shardName);
083 }
084 }
085
086 public void setShardAdvice(ShardAdvice shardAdvice) {
087 _shardAdvice = shardAdvice;
088 }
089
090 public String setTargetSource(String shardName) {
091 if (_shardAdvice == null) {
092 return null;
093 }
094
095 String currentShardName = getCurrentShardName();
096
097 ShardDataSourceTargetSource shardDataSourceTargetSource =
098 _shardAdvice.getShardDataSourceTargetSource();
099
100 shardDataSourceTargetSource.setDataSource(shardName);
101
102 ShardSessionFactoryTargetSource shardSessionFactoryTargetSource =
103 _shardAdvice.getShardSessionFactoryTargetSource();
104
105 shardSessionFactoryTargetSource.setSessionFactory(shardName);
106
107 return currentShardName;
108 }
109
110 private static ShardAdvice _shardAdvice;
111
112 }