KickJava   Java API By Example, From Geeks To Geeks.

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


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 package com.sun.enterprise.management.config;
24
25 import java.util.Collections JavaDoc;
26 import java.util.Map JavaDoc;
27
28 import com.sun.appserv.management.base.Container;
29 import com.sun.appserv.management.base.XTypes;
30
31 import com.sun.appserv.management.config.AMXConfig;
32 import com.sun.appserv.management.config.DomainConfig;
33 import com.sun.appserv.management.config.JDBCConnectionPoolConfig;
34 import com.sun.appserv.management.config.JDBCResourceConfig;
35
36 /**
37  */

38 public final class JDBCResourceConfigTest extends ResourceConfigTestBase
39 {
40     private static final String JavaDoc JDBC_RESOURCE_POOL_NAME_BASE = "JDBCResourceConfigMgrTest.test-pool";
41     private static final String JavaDoc JDBC_DATASOURCE_CLASSNAME = "com.pointbase.xa.xaDataSource";
42     private static final Map JavaDoc<String JavaDoc,String JavaDoc> OPTIONAL = null;
43     
44     private JDBCConnectionPoolConfig mPool;
45     
46     public JDBCResourceConfigTest()
47     {
48         mPool = null;
49         if ( checkNotOffline( "ensureDefaultInstance" ) )
50         {
51             ensureDefaultInstance( getDomainConfig() );
52         }
53     }
54     
55         public static String JavaDoc
56     getDefaultInstanceName()
57     {
58         return getDefaultInstanceName( "JDBCResourceConfig" );
59     }
60     
61          public static JDBCResourceConfig
62     ensureDefaultInstance( final DomainConfig domainConfig )
63     {
64         JDBCResourceConfig result =
65             domainConfig.getJDBCResourceConfigMap().get( getDefaultInstanceName() );
66         
67         if ( result == null )
68         {
69             final JDBCConnectionPoolConfig pool =
70                 JDBCConnectionPoolConfigTest.ensureDefaultInstance( domainConfig );
71                 
72             result = createInstance( domainConfig,
73                 getDefaultInstanceName(), pool.getName(), OPTIONAL );
74         }
75         
76         return result;
77     }
78     
79         public static JDBCResourceConfig
80     createInstance(
81         final DomainConfig domainConfig,
82         final String JavaDoc name,
83         final String JavaDoc datasourceClassname,
84         final Map JavaDoc<String JavaDoc,String JavaDoc> optional )
85     {
86         return domainConfig.createJDBCResourceConfig(
87                 name, datasourceClassname, optional );
88     }
89     
90     
91         protected Container
92     getProgenyContainer()
93     {
94         return getDomainConfig();
95     }
96
97         protected String JavaDoc
98     getProgenyJ2EEType()
99     {
100         return XTypes.JDBC_RESOURCE_CONFIG;
101     }
102
103
104         protected void
105     removeProgeny( final String JavaDoc name )
106     {
107         getDomainConfig().removeJDBCConnectionPoolConfig( name );
108     }
109     
110         protected String JavaDoc
111     getProgenyTestName()
112     {
113         return( "jdbc/JDBCResourceConfigMgrTest" );
114     }
115     
116         private JDBCConnectionPoolConfig
117     createPool( final String JavaDoc name )
118     {
119         try
120         {
121             getDomainConfig().removeJDBCConnectionPoolConfig( name );
122         }
123         catch( Exception JavaDoc e )
124         {
125         }
126         
127         final JDBCConnectionPoolConfig config =
128             getDomainConfig().createJDBCConnectionPoolConfig( name, JDBC_DATASOURCE_CLASSNAME, null );
129         
130         return( config );
131     }
132     
133         protected final AMXConfig
134     createProgeny(final String JavaDoc name, final Map JavaDoc<String JavaDoc,String JavaDoc> options )
135     {
136         mPool = createPool( name + "-temppool" );
137         
138         final JDBCResourceConfig config =
139             getDomainConfig().createJDBCResourceConfig( name, mPool.getName(), options);
140         assert( config != null );
141                 
142         addReference( config );
143
144         return( config );
145     }
146     
147         protected final void
148     remove(String JavaDoc name)
149     {
150         getDomainConfig().removeJDBCResourceConfig( name );
151         
152         if ( mPool != null )
153         {
154             getDomainConfig().removeJDBCConnectionPoolConfig( mPool.getName() );
155             mPool = null;
156         }
157     }
158  
159 }
160
161
162
Popular Tags