KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > lib > sql > ConnectionPoolManager


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: ConnectionPoolManager.java,v 1.7 2004/02/11 17:56:35 minchau Exp $
18  */

19
20
21  package org.apache.xalan.lib.sql;
22
23 import java.util.Hashtable JavaDoc;
24
25 import org.apache.xalan.res.XSLMessages;
26 import org.apache.xalan.res.XSLTErrorResources;
27
28 /**
29  */

30 public class ConnectionPoolManager
31 {
32   /**
33    */

34   static Hashtable JavaDoc m_poolTable = null;
35   /**
36    */

37   static boolean m_isInit = false;
38
39   /**
40    */

41   public ConnectionPoolManager( )
42   {
43     init();
44   }
45
46   /**
47    * Initialize the internal structures of the Pool Manager
48    *
49    */

50   public synchronized void init( )
51   {
52     // Only do this process once
53
if (m_isInit == true) return;
54
55
56     //
57
// Initialize the pool table
58
//
59
m_poolTable = new Hashtable JavaDoc();
60
61     m_isInit = true;
62   }
63
64   /**
65    * Register a nuew connection pool to the global pool table.
66    * If a pool by that name currently exists, then throw an
67    * IllegalArgumentException stating that the pool already
68    * exist.
69    * @param name
70    * @param pool
71    *
72    * @link org.apache.xalan.lib.sql.ConnectionPool}
73    *
74    * @throws <code>IllegalArgumentException</code>, throw this exception
75    * if a pool with the same name currently exists.
76    */

77   public synchronized void registerPool( String JavaDoc name, ConnectionPool pool )
78   {
79     if ( m_poolTable.containsKey(name) )
80     {
81       throw new IllegalArgumentException JavaDoc(XSLMessages.createMessage(XSLTErrorResources.ER_POOL_EXISTS, null)); //"Pool already exists");
82
}
83
84     m_poolTable.put(name, pool);
85   }
86
87   /**
88    * Remove a pool from the global table. If the pool still has
89    * active connections, then only mark this pool as inactive and
90    * leave it around until all the existing connections are closed.
91    * @param name
92    *
93    */

94   public synchronized void removePool( String JavaDoc name )
95   {
96     ConnectionPool pool = getPool(name);
97
98     if (null != pool)
99     {
100       //
101
// Disable future use of this pool under the Xalan
102
// extension only. This flag should only exist in the
103
// wrapper and not in the actual pool implementation.
104
pool.setPoolEnabled(false);
105
106
107       //
108
// Remove the pool from the Hashtable if we don'd have
109
// any active connections.
110
//
111
if ( ! pool.hasActiveConnections() ) m_poolTable.remove(name);
112     }
113
114   }
115
116
117   /**
118    * Return the connection pool referenced by the name
119    * @param name
120    *
121    * @return <code>ConnectionPool</code> a reference to the ConnectionPool
122    * object stored in the Pool Table. If the named pool does not exist, return
123    * null
124    */

125   public synchronized ConnectionPool getPool( String JavaDoc name )
126   {
127     return (ConnectionPool) m_poolTable.get(name);
128   }
129
130 }
131
Popular Tags