1 23 package com.sun.enterprise.management.config; 24 25 import java.util.Collections ; 26 import java.util.Map ; 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 38 public final class JDBCResourceConfigTest extends ResourceConfigTestBase 39 { 40 private static final String JDBC_RESOURCE_POOL_NAME_BASE = "JDBCResourceConfigMgrTest.test-pool"; 41 private static final String JDBC_DATASOURCE_CLASSNAME = "com.pointbase.xa.xaDataSource"; 42 private static final Map <String ,String > 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 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 name, 83 final String datasourceClassname, 84 final Map <String ,String > 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 98 getProgenyJ2EEType() 99 { 100 return XTypes.JDBC_RESOURCE_CONFIG; 101 } 102 103 104 protected void 105 removeProgeny( final String name ) 106 { 107 getDomainConfig().removeJDBCConnectionPoolConfig( name ); 108 } 109 110 protected String 111 getProgenyTestName() 112 { 113 return( "jdbc/JDBCResourceConfigMgrTest" ); 114 } 115 116 private JDBCConnectionPoolConfig 117 createPool( final String name ) 118 { 119 try 120 { 121 getDomainConfig().removeJDBCConnectionPoolConfig( name ); 122 } 123 catch( Exception 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 name, final Map <String ,String > 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 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 |