001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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.util.InfrastructureUtil;
020    import com.liferay.portal.util.PropsValues;
021    
022    import javax.sql.DataSource;
023    
024    /**
025     * @author Alexander Chow
026     */
027    public class ShardImpl implements Shard {
028    
029            public String[] getAvailableShardNames() {
030                    ShardDataSourceTargetSource shardDataSourceTargetSource =
031                            (ShardDataSourceTargetSource)
032                                    InfrastructureUtil.getShardDataSourceTargetSource();
033    
034                    if (shardDataSourceTargetSource != null) {
035                            return shardDataSourceTargetSource.getAvailableShardNames();
036                    }
037    
038                    return null;
039            }
040    
041            public String getCurrentShardName() {
042                    return _shardAdvice.getCurrentShardName();
043            }
044    
045            public DataSource getDataSource() {
046                    return _shardAdvice.getDataSource();
047            }
048    
049            public String getDefaultShardName() {
050                    return PropsValues.SHARD_DEFAULT_NAME;
051            }
052    
053            public boolean isEnabled() {
054                    if (_shardAdvice != null) {
055                            return true;
056                    }
057                    else {
058                            return false;
059                    }
060            }
061    
062            public String popCompanyService() {
063                    String value = null;
064    
065                    if (_shardAdvice != null) {
066                            value = _shardAdvice.popCompanyService();
067                    }
068    
069                    return value;
070            }
071    
072            public void pushCompanyService(long companyId) {
073                    if (_shardAdvice != null) {
074                            _shardAdvice.pushCompanyService(companyId);
075                    }
076            }
077    
078            public void pushCompanyService(String shardName) {
079                    if (_shardAdvice != null) {
080                            _shardAdvice.pushCompanyService(shardName);
081                    }
082            }
083    
084            public void setShardAdvice(ShardAdvice shardAdvice) {
085                    _shardAdvice = shardAdvice;
086            }
087    
088            private static ShardAdvice _shardAdvice;
089    
090    }