KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > common > deploy > JdbcConnectionPool


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * JdbcConnectionPool.java
26  *
27  * Created on January 15, 2002, 12:15 PM
28  *
29  * @author Shirley Chiang
30  */

31
32 package com.sun.enterprise.tools.common.deploy;
33
34 import java.beans.*;
35 import java.util.List JavaDoc;
36 //import java.net.InetAddress;
37
import java.io.File JavaDoc;
38 //import com.netscape.server.deployment.PMFDescriptor;
39
import com.sun.enterprise.tools.common.deploy.IJdbcConnectionPool;
40 import com.sun.enterprise.tools.common.util.diagnostics.Reporter;
41
42 public class JdbcConnectionPool extends Object JavaDoc implements java.io.Serializable JavaDoc {
43   
44         private String JavaDoc name;
45         private String JavaDoc id;
46         private String JavaDoc JdbcFactoryClassName;
47         private String JavaDoc ResType;
48  /* private String DatabaseURL;
49         private String UserName;
50         private String Password;
51 */
private String JavaDoc MinConnectionsInPool;
52 // private String InitialConnectionsInPool;
53
private String JavaDoc MaxConnectionsInPool;
54     private String JavaDoc MaxConnectionWaitTimeInMillis;
55     private String JavaDoc ConnectionsIncrement;
56     private String JavaDoc ConnectionIdleTimeoutInSeconds;
57     private String JavaDoc IsConnectionValidationRequired;
58     private String JavaDoc ConnectionValidationType;
59     private String JavaDoc ValidationTableName;
60     private String JavaDoc FailAllConnections;
61         private String JavaDoc XIsolationLevel;
62         private String JavaDoc IsIsolationLevelGuaranteed;
63         private NameValuePair[] extParams;
64
65     transient private PropertyChangeSupport propertySupport;
66
67     public JdbcConnectionPool(List JavaDoc resource) {
68         propertySupport = new PropertyChangeSupport ( this );
69         
70             id = "PoolName"; //NOI18N
71
JdbcFactoryClassName = "DatasourceClassName";//NOI18N
72
ResType = "javax.sql.DataSource"; //NOI18N
73
/* DatabaseURL = "jdbc:";//NOI18N
74             UserName = "UserName";//NOI18N
75             Password = "Password";//NOI18N
76 */
MinConnectionsInPool = "8"; // NOI18N
77
// InitialConnectionsInPool = "2";
78
MaxConnectionsInPool = "32"; //NOI18N
79
MaxConnectionWaitTimeInMillis = "60000"; //NOI18N
80
ConnectionsIncrement = "2"; //NOI18N
81
ConnectionIdleTimeoutInSeconds = "300"; //NOI18N
82
IsConnectionValidationRequired = "false"; //NOI18N
83
ConnectionValidationType = "auto-commit"; //NOI18N
84
ValidationTableName = "TAB_NAME"; //NOI18N
85
FailAllConnections = "false"; //NOI18N
86
XIsolationLevel = ""; //NOI18N
87
IsIsolationLevelGuaranteed = "true"; //NOI18N
88
extParams = new NameValuePair[0];
89
90         //List cp = com.iplanet.ias.tools.forte.globalsettings.IasGlobalOptionsSettings.DEFAULT.getJdbcConnectionPoolList();
91
String JavaDoc t_name = null;
92         if(resource.size() != 0){
93            int num = resource.size()+1;
94            t_name = "JdbcConnectionPool_" + num;//NOI18N
95
boolean exists = FactoryName(t_name, resource);
96            while(exists){
97              num++;
98              t_name = "JdbcConnectionPool_" + num;//NOI18N
99
exists = FactoryName(t_name, resource);
100            }
101         } else {
102            t_name = "JdbcConnectionPool_1";//NOI18N
103
}
104         name = t_name;
105         id = t_name;
106     }
107    
108     private void initPropertyChangeSupport(){
109         if(propertySupport==null)
110             propertySupport = new PropertyChangeSupport ( this );
111
112     }
113     
114     public void addPropertyChangeListener (PropertyChangeListener listener) {
115         initPropertyChangeSupport();
116         propertySupport.addPropertyChangeListener (listener);
117     }
118
119     public void removePropertyChangeListener (PropertyChangeListener listener) {
120         initPropertyChangeSupport();
121         propertySupport.removePropertyChangeListener (listener);
122     }
123
124     public String JavaDoc getName() {
125         return name;
126     }
127     public void setName(String JavaDoc value) {
128         String JavaDoc oldValue = name;
129         this.name = value;
130         initPropertyChangeSupport();
131         propertySupport.firePropertyChange ("name", oldValue, name);//NOI18N
132
}
133     
134     public String JavaDoc getId() {
135         return id;
136     }
137
138     public void setId(String JavaDoc value) {
139         String JavaDoc oldValue = id;
140         this.id = value;
141         initPropertyChangeSupport();
142         propertySupport.firePropertyChange ("id", oldValue, id);//NOI18N
143
setName(id);
144     }
145     
146     public void simpleSetId(String JavaDoc value) {
147         this.id = value;
148         setName(id);
149     }
150 /*
151     public String PWD() {
152         String pw = getPassword();
153         String passw = "*";//NOI18N
154         for(int i=1; i<pw.length(); i++)
155             passw = passw + "*";//NOI18N
156         return passw;
157     }
158    
159     public String getPassword() {
160         return Password;
161     }
162     
163     public void setPassword(java.lang.String passwd) {
164         String prev = Password;
165         this.Password = passwd;
166         initPropertyChangeSupport();
167         propertySupport.firePropertyChange ("Password", prev, Password);//NOI18N
168     }
169  */

170     public String JavaDoc getJdbcFactoryClassName() {
171         return JdbcFactoryClassName;
172     }
173     public void setJdbcFactoryClassName(java.lang.String JavaDoc facname) {
174         String JavaDoc prev = JdbcFactoryClassName;
175         this.JdbcFactoryClassName = facname;
176         initPropertyChangeSupport();
177         propertySupport.firePropertyChange ("JdbcFactoryClassName", prev, JdbcFactoryClassName);//NOI18N
178
}
179     
180     public String JavaDoc getResType() {
181         return ResType;
182     }
183     public void setResType(java.lang.String JavaDoc val) {
184         String JavaDoc prev = this.ResType;
185         this.ResType = val;
186         initPropertyChangeSupport();
187         propertySupport.firePropertyChange ("ResType", prev, ResType);//NOI18N
188
}
189 /*
190     public String getDatabaseURL() {
191         return DatabaseURL;
192     }
193     public void setDatabaseURL(java.lang.String dburl) {
194         String prev = DatabaseURL;
195         this.DatabaseURL = dburl;
196         initPropertyChangeSupport();
197         propertySupport.firePropertyChange ("DatabaseURL", prev, DatabaseURL);//NOI18N
198     }
199
200     public String getUserName() {
201         return UserName;
202     }
203     public void setUserName(java.lang.String name) {
204         String prev = UserName;
205         this.UserName = name;
206         initPropertyChangeSupport();
207         propertySupport.firePropertyChange ("UserName", prev, UserName);//NOI18N
208     }
209 */

210     public void setMinConnectionsInPool(String JavaDoc value)
211     {
212         String JavaDoc oldValue = MinConnectionsInPool;
213         this.MinConnectionsInPool = value;
214         initPropertyChangeSupport();
215         propertySupport.firePropertyChange ("MinConnectionsInPool", oldValue, MinConnectionsInPool);//NOI18N
216
}
217
218     public String JavaDoc getMinConnectionsInPool()
219     {
220     return MinConnectionsInPool;
221     }
222 /*
223     public void setInitialConnectionsInPool(String value)
224     {
225         String oldValue = InitialConnectionsInPool;
226         this.InitialConnectionsInPool = value;
227         initPropertyChangeSupport();
228         propertySupport.firePropertyChange ("InitialConnectionsInPool", oldValue, InitialConnectionsInPool);//NOI18N
229     }
230
231     public String getInitialConnectionsInPool()
232     {
233     return InitialConnectionsInPool;
234     }
235 */

236     public void setMaxConnectionsInPool(String JavaDoc value)
237     {
238         String JavaDoc oldValue = MaxConnectionsInPool;
239         this.MaxConnectionsInPool = value;
240         initPropertyChangeSupport();
241         propertySupport.firePropertyChange ("MaxConnectionsInPool", oldValue, MaxConnectionsInPool);//NOI18N
242
}
243
244     //
245
public String JavaDoc getMaxConnectionsInPool()
246     {
247         return MaxConnectionsInPool;
248     }
249
250     public void setMaxConnectionWaitTimeInMillis(String JavaDoc value)
251     {
252         String JavaDoc oldValue = MaxConnectionWaitTimeInMillis;
253         this.MaxConnectionWaitTimeInMillis = value;
254         initPropertyChangeSupport();
255         propertySupport.firePropertyChange ("MaxConnectionWaitTimeInMillis", oldValue, MaxConnectionWaitTimeInMillis);//NOI18N
256
}
257
258     public String JavaDoc getMaxConnectionWaitTimeInMillis()
259     {
260     return MaxConnectionWaitTimeInMillis;
261     }
262
263     public void setConnectionsIncrement(String JavaDoc value)
264     {
265         String JavaDoc oldValue = ConnectionsIncrement;
266         this.ConnectionsIncrement = value;
267         initPropertyChangeSupport();
268         propertySupport.firePropertyChange ("ConnectionsIncrement", oldValue, ConnectionsIncrement);//NOI18N
269
}
270
271     public String JavaDoc getConnectionsIncrement()
272     {
273     return ConnectionsIncrement;
274     }
275
276     public void setConnectionIdleTimeoutInSeconds(String JavaDoc value)
277     {
278         String JavaDoc oldValue = ConnectionIdleTimeoutInSeconds;
279         this.ConnectionIdleTimeoutInSeconds = value;
280         initPropertyChangeSupport();
281         propertySupport.firePropertyChange ("ConnectionIdleTimeoutInSeconds", oldValue, ConnectionIdleTimeoutInSeconds);//NOI18N
282
}
283
284     public String JavaDoc getConnectionIdleTimeoutInSeconds()
285     {
286     return ConnectionIdleTimeoutInSeconds;
287     }
288
289     public void setIsConnectionValidationRequired(String JavaDoc value)
290     {
291         String JavaDoc oldValue = IsConnectionValidationRequired;
292         this.IsConnectionValidationRequired = value;
293         initPropertyChangeSupport();
294         propertySupport.firePropertyChange ("IsConnectionValidationRequired", oldValue, IsConnectionValidationRequired);//NOI18N
295
}
296
297     public String JavaDoc getIsConnectionValidationRequired()
298     {
299     return IsConnectionValidationRequired;
300     }
301
302     public void setConnectionValidationType(String JavaDoc value)
303     {
304         String JavaDoc oldValue = ConnectionValidationType;
305         this.ConnectionValidationType = value;
306         initPropertyChangeSupport();
307         propertySupport.firePropertyChange ("ConnectionValidationType", oldValue, ConnectionValidationType);//NOI18N
308
}
309
310     public String JavaDoc getConnectionValidationType()
311     {
312     return ConnectionValidationType;
313     }
314
315     public void setValidationTableName(String JavaDoc value)
316     {
317         String JavaDoc oldValue = ValidationTableName;
318         this.ValidationTableName = value;
319         initPropertyChangeSupport();
320         propertySupport.firePropertyChange ("ValidationTableName", oldValue, ValidationTableName);//NOI18N
321
}
322
323     public String JavaDoc getValidationTableName()
324     {
325     return ValidationTableName;
326     }
327
328     public void setFailAllConnections(String JavaDoc value)
329     {
330         String JavaDoc oldValue = FailAllConnections;
331         this.FailAllConnections = value;
332         initPropertyChangeSupport();
333         propertySupport.firePropertyChange ("FailAllConnections", oldValue, FailAllConnections);//NOI18N
334
}
335
336     public String JavaDoc getFailAllConnections()
337     {
338     return FailAllConnections;
339     }
340     
341     public String JavaDoc getXIsolationLevel() {
342         return XIsolationLevel;
343     }
344     public void setXIsolationLevel(java.lang.String JavaDoc val) {
345         String JavaDoc prev = this.XIsolationLevel;
346         this.XIsolationLevel = val;
347         initPropertyChangeSupport();
348         propertySupport.firePropertyChange ("XIsolationLevel", prev, XIsolationLevel);//NOI18N
349
}
350     
351     public String JavaDoc getIsIsolationLevelGuaranteed() {
352         return IsIsolationLevelGuaranteed;
353     }
354     public void setIsIsolationLevelGuaranteed(java.lang.String JavaDoc val) {
355         String JavaDoc prev = this.IsIsolationLevelGuaranteed;
356         this.IsIsolationLevelGuaranteed = val;
357         initPropertyChangeSupport();
358         propertySupport.firePropertyChange ("IsIsolationLevelGuaranteed", prev, IsIsolationLevelGuaranteed);//NOI18N
359
}
360     
361     public NameValuePair[] getExtParams() {
362         return extParams;
363     }
364
365     public void setExtParams(Object JavaDoc[] value) {
366         Reporter.info(new Integer JavaDoc(value.length)); //NOI18N
367
NameValuePair[] pairs = new NameValuePair[value.length];
368         for (int i = 0; i < value.length; i++) {
369             NameValuePair val = (NameValuePair)value[i];
370             NameValuePair pair = new NameValuePair();
371             pair.setParamName(val.getParamName());
372             pair.setParamValue(val.getParamValue());
373             pair.setParamDescription(val.getParamDescription());
374             Reporter.info(pair.getParamName() + " " + pair.getParamValue()); //NOI18N
375
pairs[i] = pair;
376         }
377         NameValuePair[] oldValue = extParams;
378         this.extParams = pairs;
379         initPropertyChangeSupport();
380         propertySupport.firePropertyChange ("extParams", oldValue, extParams);//NOI18N
381
}
382      
383    public boolean FactoryName(String JavaDoc value, List JavaDoc resources){
384       boolean exists = false;
385       //List pm1 = com.iplanet.ias.tools.forte.globalsettings.IasGlobalOptionsSettings.DEFAULT.getPMFactoryInsts();
386
for(int i=0; i<resources.size(); i++){
387         IJdbcConnectionPool instance = (IJdbcConnectionPool) resources.get(i);
388         String JavaDoc inst = instance.getName();
389         if(inst.equals(value))
390            exists = true;
391       }//for
392
return exists;
393     }
394 }
395
Popular Tags