001
014
015 package com.liferay.portal.dao.shard;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.util.PropsValues;
020
021 import javax.sql.DataSource;
022
023
026 public class ShardUtil {
027
028 public static String COMPANY_SCOPE = "COMPANY_SCOPE";
029
030 public static DataSource getDataSource() {
031 return _shardAdvice.getDataSource();
032 }
033
034 public static ShardSelector getShardSelector() {
035 return _shardSelector;
036 }
037
038 public static boolean isEnabled() {
039 if (_shardAdvice != null) {
040 return true;
041 }
042 else {
043 return false;
044 }
045 }
046
047 public static String popCompanyService() {
048 String value = null;
049
050 if (_shardAdvice != null) {
051 value = _shardAdvice.popCompanyService();
052 }
053
054 return value;
055 }
056
057 public static void pushCompanyService(long companyId) {
058 if (_shardAdvice != null) {
059 _shardAdvice.pushCompanyService(companyId);
060 }
061 }
062
063 public static void pushCompanyService(String shardName) {
064 if (_shardAdvice != null) {
065 _shardAdvice.pushCompanyService(shardName);
066 }
067 }
068
069 public void setShardAdvice(ShardAdvice shardAdvice) {
070 _shardAdvice = shardAdvice;
071 }
072
073 private static Log _log = LogFactoryUtil.getLog(ShardUtil.class);
074
075 private static ShardAdvice _shardAdvice;
076 private static ShardSelector _shardSelector;
077
078 static {
079 try {
080 _shardSelector = (ShardSelector)Class.forName(
081 PropsValues.SHARD_SELECTOR).newInstance();
082 }
083 catch (Exception e) {
084 _log.error(e, e);
085 }
086 }
087
088 }