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.kernel.dao.shard;
016    
017    import com.liferay.portal.kernel.util.StringPool;
018    
019    import javax.sql.DataSource;
020    
021    /**
022     * @author Alexander Chow
023     */
024    public class ShardUtil {
025    
026            public static String[] getAvailableShardNames() {
027                    if (_shard != null) {
028                            String[] availableShardNames = _shard.getAvailableShardNames();
029    
030                            if (availableShardNames != null) {
031                                    return availableShardNames;
032                            }
033                    }
034    
035                    return _DEFAULT_SHARD_ARRAY;
036            }
037    
038            public static String getCurrentShardName() {
039                    if (_shard != null) {
040                            return _shard.getCurrentShardName();
041                    }
042    
043                    return StringPool.BLANK;
044            }
045    
046            public static DataSource getDataSource() {
047                    if (_shard != null) {
048                            return _shard.getDataSource();
049                    }
050    
051                    return null;
052            }
053    
054            public static String getDefaultShardName() {
055                    if (_shard != null) {
056                            return _shard.getDefaultShardName();
057                    }
058    
059                    return null;
060            }
061    
062            public static boolean isEnabled() {
063                    if (_shard != null) {
064                            return _shard.isEnabled();
065                    }
066    
067                    return false;
068            }
069    
070            public static String popCompanyService() {
071                    String value = null;
072    
073                    if (_shard != null) {
074                            value = _shard.popCompanyService();
075                    }
076    
077                    return value;
078            }
079    
080            public static void pushCompanyService(long companyId) {
081                    if (_shard != null) {
082                            _shard.pushCompanyService(companyId);
083                    }
084            }
085    
086            public static void pushCompanyService(String shardName) {
087                    if (_shard != null) {
088                            _shard.pushCompanyService(shardName);
089                    }
090            }
091    
092            public void setShard(Shard shard) {
093                    _shard = shard;
094            }
095    
096            private static final String[] _DEFAULT_SHARD_ARRAY = new String[0];
097    
098            private static Shard _shard;
099    
100    }