⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmssqlmanager.java

📁 cms是开源的框架
💻 JAVA
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/db/CmsSqlManager.java,v $
 * Date   : $Date: 2006/03/27 14:52:27 $
 * Version: $Revision: 1.10 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Mananagement System
 *
 * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software GmbH, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;

/**
 * Superclass for all SQL manager implementations.<p>
 * 
 * @author Carsten Weinholz 
 * 
 * @version $Revision: 1.10 $
 * 
 * @since 6.0.0
 */
public class CmsSqlManager {

    /** the driver manager. */
    private CmsDriverManager m_driverManager;

    /**
     * Protected constructor to allow only subclassing.<p> 
     */
    protected CmsSqlManager() {

        // hides the public constructor
    }

    /**
     * Creates a new SQL manager from the provided driver manager.<p> 
     * 
     * @param driverManager the low level database driver manager 
     */
    protected CmsSqlManager(CmsDriverManager driverManager) {

        m_driverManager = driverManager;
    }

    /**
     * Returns a connection to the database using the given pool identified by its name.<p>
     * 
     * @param dbPoolName the pool name
     * @return a database connection
     * @throws SQLException if something goes wrong
     */
    public Connection getConnection(String dbPoolName) throws SQLException {

        return getConnectionByUrl(CmsDbPool.DBCP_JDBC_URL_PREFIX + CmsDbPool.OPENCMS_URL_PREFIX + dbPoolName);
    }

    /**
     * Returns a connection to the database using the given pool identified by its full url.<p>
     * 
     * @param dbPoolUrl the pool url
     * @return a database connection
     * @throws SQLException if something goes wrong
     */
    public Connection getConnectionByUrl(String dbPoolUrl) throws SQLException {

        return DriverManager.getConnection(dbPoolUrl);
    }

    /**
     * Returns a list of available database connection pool names.<p>
     * 
     * @return a list of database connection pool names
     */
    public List getDbPoolNames() {

        return CmsDbPool.getDbPoolNames(m_driverManager.getConfigurations());
    }

    /**
     * Returns the name of the default database connection pool.<p>
     * 
     * @return the name of the default database connection pool
     */
    public String getDefaultDbPoolName() {

        return CmsDbPool.getDefaultDbPoolName();
    }
    
    /** 
     * Returns the number of active connections managed by a pool.<p> 
     * 
     * @param dbPoolUrl the url of a pool 
     * @return the number of active connections 
     * @throws CmsDbException if something goes wrong 
     */ 
    public int getActiveConnections (String dbPoolUrl) throws CmsDbException { 
 
        return m_driverManager.getActiveConnections(dbPoolUrl); 
    } 
 
    /** 
     * Returns the number of idle connections managed by a pool.<p> 
     * 
     * @param dbPoolUrl the url of a pool 
     * @return the number of idle connections 
     * @throws CmsDbException if something goes wrong 
     */ 
    public int getIdleConnections (String dbPoolUrl) throws CmsDbException { 
 
        return m_driverManager.getIdleConnections(dbPoolUrl); 
    } 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -