KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > db > CmsSqlManager


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/db/CmsSqlManager.java,v $
3  * Date : $Date: 2006/03/27 14:52:27 $
4  * Version: $Revision: 1.10 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.db;
33
34 import java.sql.Connection JavaDoc;
35 import java.sql.DriverManager JavaDoc;
36 import java.sql.SQLException JavaDoc;
37 import java.util.List JavaDoc;
38
39 /**
40  * Superclass for all SQL manager implementations.<p>
41  *
42  * @author Carsten Weinholz
43  *
44  * @version $Revision: 1.10 $
45  *
46  * @since 6.0.0
47  */

48 public class CmsSqlManager {
49
50     /** the driver manager. */
51     private CmsDriverManager m_driverManager;
52
53     /**
54      * Protected constructor to allow only subclassing.<p>
55      */

56     protected CmsSqlManager() {
57
58         // hides the public constructor
59
}
60
61     /**
62      * Creates a new SQL manager from the provided driver manager.<p>
63      *
64      * @param driverManager the low level database driver manager
65      */

66     protected CmsSqlManager(CmsDriverManager driverManager) {
67
68         m_driverManager = driverManager;
69     }
70
71     /**
72      * Returns a connection to the database using the given pool identified by its name.<p>
73      *
74      * @param dbPoolName the pool name
75      * @return a database connection
76      * @throws SQLException if something goes wrong
77      */

78     public Connection JavaDoc getConnection(String JavaDoc dbPoolName) throws SQLException JavaDoc {
79
80         return getConnectionByUrl(CmsDbPool.DBCP_JDBC_URL_PREFIX + CmsDbPool.OPENCMS_URL_PREFIX + dbPoolName);
81     }
82
83     /**
84      * Returns a connection to the database using the given pool identified by its full url.<p>
85      *
86      * @param dbPoolUrl the pool url
87      * @return a database connection
88      * @throws SQLException if something goes wrong
89      */

90     public Connection JavaDoc getConnectionByUrl(String JavaDoc dbPoolUrl) throws SQLException JavaDoc {
91
92         return DriverManager.getConnection(dbPoolUrl);
93     }
94
95     /**
96      * Returns a list of available database connection pool names.<p>
97      *
98      * @return a list of database connection pool names
99      */

100     public List JavaDoc getDbPoolNames() {
101
102         return CmsDbPool.getDbPoolNames(m_driverManager.getConfigurations());
103     }
104
105     /**
106      * Returns the name of the default database connection pool.<p>
107      *
108      * @return the name of the default database connection pool
109      */

110     public String JavaDoc getDefaultDbPoolName() {
111
112         return CmsDbPool.getDefaultDbPoolName();
113     }
114     
115     /**
116      * Returns the number of active connections managed by a pool.<p>
117      *
118      * @param dbPoolUrl the url of a pool
119      * @return the number of active connections
120      * @throws CmsDbException if something goes wrong
121      */

122     public int getActiveConnections (String JavaDoc dbPoolUrl) throws CmsDbException {
123  
124         return m_driverManager.getActiveConnections(dbPoolUrl);
125     }
126  
127     /**
128      * Returns the number of idle connections managed by a pool.<p>
129      *
130      * @param dbPoolUrl the url of a pool
131      * @return the number of idle connections
132      * @throws CmsDbException if something goes wrong
133      */

134     public int getIdleConnections (String JavaDoc dbPoolUrl) throws CmsDbException {
135  
136         return m_driverManager.getIdleConnections(dbPoolUrl);
137     }
138 }
Popular Tags