001    /**
002     * Copyright (c) 2000-present 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.db;
016    
017    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
018    
019    import javax.sql.DataSource;
020    
021    /**
022     * @author Brian Wing Shun Chan
023     */
024    public class DBManagerUtil {
025    
026            public static DB getDB() {
027                    return getDBManager().getDB();
028            }
029    
030            public static DB getDB(DBType dbType, DataSource dataSource) {
031                    return getDBManager().getDB(dbType, dataSource);
032            }
033    
034            public static DB getDB(Object dialect, DataSource dataSource) {
035                    DBManager dbManager = getDBManager();
036    
037                    return dbManager.getDB(dbManager.getDBType(dialect), dataSource);
038            }
039    
040            public static DBManager getDBManager() {
041                    PortalRuntimePermission.checkGetBeanProperty(DBManagerUtil.class);
042    
043                    return _dbManager;
044            }
045    
046            public static DBType getDBType(Object dialect) {
047                    return getDBManager().getDBType(dialect);
048            }
049    
050            public static void reset() {
051                    setDBManager(null);
052            }
053    
054            public static void setDB(DBType dbType, DataSource dataSource) {
055                    DBManager dbManager = getDBManager();
056    
057                    dbManager.setDB(dbManager.getDB(dbType, dataSource));
058            }
059    
060            public static void setDB(Object dialect, DataSource dataSource) {
061                    DBManager dbManager = getDBManager();
062    
063                    dbManager.setDB(
064                            dbManager.getDB(dbManager.getDBType(dialect), dataSource));
065            }
066    
067            public static void setDBManager(DBManager dbManager) {
068                    PortalRuntimePermission.checkSetBeanProperty(DBManagerUtil.class);
069    
070                    _dbManager = dbManager;
071            }
072    
073            private static DBManager _dbManager;
074    
075    }