KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > config > JDBCConnectionPoolConfigFactory


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  * $Header: /cvs/glassfish/admin/mbeanapi-impl/src/java/com/sun/enterprise/management/config/JDBCConnectionPoolConfigFactory.java,v 1.5 2006/03/09 20:30:38 llc Exp $
26  * $Revision: 1.5 $
27  * $Date: 2006/03/09 20:30:38 $
28  */

29
30
31 package com.sun.enterprise.management.config;
32
33 import java.util.Set JavaDoc;
34 import java.util.Map JavaDoc;
35 import java.util.Collections JavaDoc;
36
37 import javax.management.ObjectName JavaDoc;
38 import javax.management.AttributeList JavaDoc;
39     
40 import com.sun.appserv.management.util.misc.GSetUtil;
41
42 import com.sun.appserv.management.config.JDBCConnectionPoolConfigKeys;
43 import com.sun.appserv.management.config.ResourceConfigKeys;
44
45 /**
46     MBean managing all instances of JDBC resource.
47  */

48
49 public final class JDBCConnectionPoolConfigFactory extends ResourceFactoryImplBase
50 {
51         public
52     JDBCConnectionPoolConfigFactory( final ConfigFactoryCallback callbacks )
53     {
54         super( callbacks );
55     }
56
57     private final Set JavaDoc<String JavaDoc> LEGAL_OPTIONAL_KEYS =
58         GSetUtil.newUnmodifiableStringSet(
59         JDBCConnectionPoolConfigKeys.CONNECTION_VALIDATION_METHOD_KEY,
60         JDBCConnectionPoolConfigKeys.VALIDATION_TABLE_NAME_KEY,
61         JDBCConnectionPoolConfigKeys.FAIL_ALL_CONNECTIONS_KEY,
62         JDBCConnectionPoolConfigKeys.IDLE_TIMEOUT_IN_SECONDS_KEY,
63         JDBCConnectionPoolConfigKeys.IS_CONNECTION_VALIDATION_REQUIRED_KEY,
64         JDBCConnectionPoolConfigKeys.IS_ISOLATION_LEVEL_GUARANTEED_KEY,
65         JDBCConnectionPoolConfigKeys.TRANSACTION_ISOLATION_LEVEL_KEY,
66         JDBCConnectionPoolConfigKeys.MAX_POOL_SIZE_KEY,
67         JDBCConnectionPoolConfigKeys.MAX_WAIT_TIME_MILLIS_KEY,
68         JDBCConnectionPoolConfigKeys.POOL_RESIZE_QUANTITY_KEY,
69         JDBCConnectionPoolConfigKeys.RES_TYPE_KEY,
70         JDBCConnectionPoolConfigKeys.STEADY_POOL_SIZE_KEY,
71         JDBCConnectionPoolConfigKeys.DATABASE_NAME_KEY,
72         JDBCConnectionPoolConfigKeys.DATABASE_USER_KEY,
73         JDBCConnectionPoolConfigKeys.DATABASE_PASSWORD_KEY );
74     
75         protected Set JavaDoc<String JavaDoc>
76     getLegalOptionalCreateKeys()
77     {
78         return( LEGAL_OPTIONAL_KEYS );
79     }
80                 
81                 
82         /**
83         The caller is responsible for dealing with any Properties.
84      */

85         protected ObjectName JavaDoc
86     createOldChildConfig(
87         final AttributeList JavaDoc translatedAttrs )
88     {
89         trace( "JDBCConnectionPoolConfigFactory.createOldChildConfig: creating using: " +
90             stringify( translatedAttrs ) );
91             
92         final ObjectName JavaDoc objectName =
93                 getOldResourcesMBean().createJdbcConnectionPool( translatedAttrs );
94         
95         return( objectName );
96     }
97
98            
99          /**
100         Create a new &lt;jdbc-connection-pool>. Name and datasource classname
101         are required parameters.
102         
103         @param name name of the &lt;jdbc-connection-pool&gt; to be created
104         @param datasourceClassname vendor supplied JDBC resource manager such
105                as javax.sql.XADatasource interface.
106         @param optional optional parameters for jdbc connection pool creation
107      */

108         public ObjectName JavaDoc
109     create(
110                 final String JavaDoc name,
111                 final String JavaDoc datasourceClassname,
112                 final Map JavaDoc<String JavaDoc,String JavaDoc> optional)
113     {
114         final String JavaDoc[] requiredParams = new String JavaDoc[]
115         {
116             JDBCConnectionPoolConfigKeys.DATASOURCE_CLASSNAME_KEY, datasourceClassname,
117         };
118                 
119         final Map JavaDoc<String JavaDoc,String JavaDoc> params = initParams( name, requiredParams, optional );
120         
121         final ObjectName JavaDoc amxName = createNamedChild( name, params );
122         
123         return( amxName );
124     }
125                 
126                 
127         public ObjectName JavaDoc
128     create(
129         final String JavaDoc name,
130         final String JavaDoc connectionValidationMethod,
131         final String JavaDoc datasourceClassname,
132         final boolean failAllConnections,
133         final int idleTimeoutSeconds,
134         final boolean connectionValidationRequired,
135         final boolean isolationLevelGuaranteed,
136         final String JavaDoc transactionIsolationLevel,
137         final int maxPoolSize,
138         final int maxWaitTimeMillis,
139         final int poolResizeQuantity,
140         final String JavaDoc resType,
141         final int steadyPoolSize,
142         final String JavaDoc databaseName,
143         final String JavaDoc databaseUserName,
144         final String JavaDoc databasePassword,
145         final Map JavaDoc<String JavaDoc,String JavaDoc> reserved )
146     {
147         final Map JavaDoc<String JavaDoc,String JavaDoc> optionalParams = new java.util.HashMap JavaDoc<String JavaDoc,String JavaDoc>();
148         optionalParams.put(JDBCConnectionPoolConfigKeys.CONNECTION_VALIDATION_METHOD_KEY,connectionValidationMethod);
149         optionalParams.put(JDBCConnectionPoolConfigKeys.FAIL_ALL_CONNECTIONS_KEY,Boolean.toString(failAllConnections));
150         optionalParams.put(JDBCConnectionPoolConfigKeys.IDLE_TIMEOUT_IN_SECONDS_KEY,Integer.toString(idleTimeoutSeconds));
151         optionalParams.put(JDBCConnectionPoolConfigKeys.IS_CONNECTION_VALIDATION_REQUIRED_KEY,Boolean.toString(connectionValidationRequired));
152         optionalParams.put(JDBCConnectionPoolConfigKeys.IS_ISOLATION_LEVEL_GUARANTEED_KEY,Boolean.toString(isolationLevelGuaranteed));
153         optionalParams.put(JDBCConnectionPoolConfigKeys.TRANSACTION_ISOLATION_LEVEL_KEY, transactionIsolationLevel);
154         optionalParams.put(JDBCConnectionPoolConfigKeys.MAX_POOL_SIZE_KEY,Integer.toString(maxPoolSize));
155         optionalParams.put(JDBCConnectionPoolConfigKeys.MAX_WAIT_TIME_MILLIS_KEY,Integer.toString(maxWaitTimeMillis));
156         optionalParams.put(JDBCConnectionPoolConfigKeys.POOL_RESIZE_QUANTITY_KEY,Integer.toString(poolResizeQuantity));
157         optionalParams.put(JDBCConnectionPoolConfigKeys.RES_TYPE_KEY,resType);
158         optionalParams.put(JDBCConnectionPoolConfigKeys.STEADY_POOL_SIZE_KEY,Integer.toString(steadyPoolSize));
159         optionalParams.put(JDBCConnectionPoolConfigKeys.DATABASE_NAME_KEY,databaseName);
160         optionalParams.put(JDBCConnectionPoolConfigKeys.DATABASE_USER_KEY,databaseUserName);
161         optionalParams.put(JDBCConnectionPoolConfigKeys.DATABASE_PASSWORD_KEY,databasePassword);
162
163         optionalParams.putAll( reserved );
164
165         final ObjectName JavaDoc amxName = create( name, datasourceClassname, optionalParams);
166         return( amxName );
167     }
168
169         protected void
170     removeByName( final String JavaDoc name )
171     {
172         getOldResourcesMBean().removeJdbcConnectionPoolByName( name );
173     }
174
175 }
176
177
Popular Tags