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 DBFactoryUtil {
025    
026            public static DB getDB() {
027                    return getDBFactory().getDB();
028            }
029    
030            public static DB getDB(Object dialect, DataSource dataSource) {
031                    return getDBFactory().getDB(dialect, dataSource);
032            }
033    
034            public static DB getDB(String type, DataSource dataSource) {
035                    return getDBFactory().getDB(type, dataSource);
036            }
037    
038            public static DBFactory getDBFactory() {
039                    PortalRuntimePermission.checkGetBeanProperty(DBFactoryUtil.class);
040    
041                    return _dbFactory;
042            }
043    
044            public static void reset() {
045                    setDBFactory(null);
046            }
047    
048            public static void setDB(Object dialect, DataSource dataSource) {
049                    getDBFactory().setDB(dialect, dataSource);
050            }
051    
052            public static void setDB(String type, DataSource dataSource) {
053                    getDBFactory().setDB(type, dataSource);
054            }
055    
056            public static void setDBFactory(DBFactory dbFactory) {
057                    PortalRuntimePermission.checkSetBeanProperty(DBFactoryUtil.class);
058    
059                    _dbFactory = dbFactory;
060            }
061    
062            private static DBFactory _dbFactory;
063    
064    }