/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * The contents of this file are subject to the terms of the Liferay Enterprise
 * Subscription License ("License"). You may not use this file except in
 * compliance with the License. You can obtain a copy of the License by
 * contacting Liferay, Inc. See the License for the specific language governing
 * permissions and limitations under the License, including but not limited to
 * distribution rights of the Software.
 *
 *
 *
 */

package com.liferay.portal.kernel.dao.db;

import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;

import java.util.Set;

import javax.sql.DataSource;

/**
 * @author Brian Wing Shun Chan
 */
public class DBManagerUtil {

	public static DB getDB() {
		DBManager dbManager = getDBManager();

		return dbManager.getDB();
	}

	public static DB getDB(DBType dbType, DataSource dataSource) {
		DBManager dbManager = getDBManager();

		return dbManager.getDB(dbType, dataSource);
	}

	public static DB getDB(Object dialect, DataSource dataSource) {
		DBManager dbManager = getDBManager();

		return dbManager.getDB(dbManager.getDBType(dialect), dataSource);
	}

	public static DBManager getDBManager() {
		PortalRuntimePermission.checkGetBeanProperty(DBManagerUtil.class);

		return _dbManager;
	}

	public static int getDBInMaxParameters() {
		DBManager dbManager = getDBManager();

		return dbManager.getDBMaxParameters();
	}

	public static int getDBMaxParameters() {
		DBManager dbManager = getDBManager();

		return dbManager.getDBMaxParameters();
	}

	public static DBType getDBType() {
		DBManager dbManager = getDBManager();

		return dbManager.getDBType();
	}

	public static DBType getDBType(Object dialect) {
		DBManager dbManager = getDBManager();

		return dbManager.getDBType(dialect);
	}

	public static Set<DBType> getDBTypes() {
		DBManager dbManager = getDBManager();

		return dbManager.getDBTypes();
	}

	public static void reset() {
		setDBManager(null);
	}

	public static void setDB(DBType dbType, DataSource dataSource) {
		DBManager dbManager = getDBManager();

		dbManager.setDB(dbManager.getDB(dbType, dataSource));
	}

	public static void setDB(Object dialect, DataSource dataSource) {
		DBManager dbManager = getDBManager();

		dbManager.setDB(
			dbManager.getDB(dbManager.getDBType(dialect), dataSource));
	}

	public static void setDBManager(DBManager dbManager) {
		PortalRuntimePermission.checkSetBeanProperty(DBManagerUtil.class);

		_dbManager = dbManager;
	}

	private static DBManager _dbManager;

}