1 23 package com.sun.enterprise.repository; 24 25 import java.io.Serializable ; 26 import java.util.Iterator ; 27 28 import com.sun.enterprise.util.Utility; 29 30 35 public class JdbcConnectionPool extends J2EEResourceBase implements Serializable { 36 37 private String userName_; 38 private String password_; 39 40 private String datasourceClassname_; 41 private String steadyPoolSize_; 42 private String maxPoolSize_; 43 private String maxWaitTimeInMillis_; 44 private String poolResizeQuantity_; 47 private String idleTimeoutInSeconds_; 49 private boolean isConnectionValidationRequired_; 50 private String connectionValidationMethod_; 51 private String validationTableName_; 52 private boolean failAllConnections_; 53 54 private boolean perfMonitor = false; 56 58 private String resType_; 61 private String transactionIsolationLevel_; 62 private boolean isIsolationLevelGuaranteed_; 63 65 private transient Object cachedVendorDataSource = null; 67 69 public JdbcConnectionPool(String name) { 70 super(name); 71 } 72 73 protected J2EEResource doClone(String name) { 74 JdbcConnectionPool clone = new JdbcConnectionPool(name); 75 76 clone.setUserName(getUserName()); 77 clone.setPassword(getPassword()); 78 79 clone.setDatasourceClassname(getDatasourceClassname()); 80 clone.setMaxPoolSize(getMaxPoolSize()); 81 clone.setMaxWaitTimeInMillis(getMaxWaitTimeInMillis()); 82 clone.setPoolResizeQuantity(getPoolResizeQuantity()); 83 clone.setIdleTimeoutInSeconds(getIdleTimeoutInSeconds()); 84 clone.setIsConnectionValidationRequired(isIsConnectionValidationRequired()); 85 clone.setConnectionValidationMethod(getConnectionValidationMethod()); 86 clone.setValidationTableName(getValidationTableName()); 87 clone.setFailAllConnections(isFailAllConnections()); 88 89 clone.setResType(getResType()); 91 clone.setTransactionIsolationLevel(getTransactionIsolationLevel()); 92 clone.setIsIsolationLevelGuaranteed(isIsolationLevelGuaranteed()); 93 95 return clone; 96 } 97 98 public int getType() { 99 return J2EEResource.JDBC_CONNECTION_POOL; 100 } 101 102 public String getUserName() { 103 return userName_; 104 } 105 106 public void setUserName(String userName) { 107 userName_ = userName; 108 } 109 110 public String getPassword() { 111 return password_; 112 } 113 114 public void setPassword(String password) { 115 password_ = password; 116 } 117 118 public String getDatasourceClassname() { 119 return datasourceClassname_; 120 } 121 122 public void setDatasourceClassname(String datasourceClassname) { 123 datasourceClassname_ = datasourceClassname; 124 } 125 126 public String getSteadyPoolSize() { 127 return steadyPoolSize_; 128 } 129 130 public void setSteadyPoolSize(String steadyPoolSize) { 131 steadyPoolSize_ = steadyPoolSize; 132 } 133 134 public String getMaxPoolSize() { 135 return maxPoolSize_; 136 } 137 138 public void setMaxPoolSize(String maxPoolSize) { 139 maxPoolSize_ = maxPoolSize; 140 } 141 142 public String getMaxWaitTimeInMillis() { 143 return maxWaitTimeInMillis_; 144 } 145 146 public void setMaxWaitTimeInMillis(String maxWaitTimeInMillis) { 147 maxWaitTimeInMillis_ = maxWaitTimeInMillis; 148 } 149 150 153 public String getPoolResizeQuantity() { 154 return poolResizeQuantity_; 155 } 156 157 public void setPoolResizeQuantity(String poolResizeQuantity) { 158 poolResizeQuantity_ = poolResizeQuantity; 159 } 160 161 163 public String getIdleTimeoutInSeconds() { 164 return idleTimeoutInSeconds_; 165 } 166 167 public void setIdleTimeoutInSeconds(String idleTimeoutInSeconds) { 168 idleTimeoutInSeconds_ = idleTimeoutInSeconds; 169 } 170 public boolean isIsConnectionValidationRequired() { 171 return isConnectionValidationRequired_; 172 } 173 174 public void setIsConnectionValidationRequired(boolean isConnectionValidationRequired) { 175 isConnectionValidationRequired_ = isConnectionValidationRequired; 176 } 177 public String getConnectionValidationMethod() { 178 return connectionValidationMethod_; 179 } 180 181 public void setConnectionValidationMethod(String connectionValidationMethod) { 182 connectionValidationMethod_ = connectionValidationMethod; 183 } 184 public String getValidationTableName() { 185 return validationTableName_; 186 } 187 188 public void setValidationTableName(String validationTableName) { 189 validationTableName_ = validationTableName; 190 } 191 public boolean isFailAllConnections() { 192 return failAllConnections_; 193 } 194 195 public void setFailAllConnections(boolean failAllConnections) { 196 failAllConnections_ = failAllConnections; 197 } 198 199 201 public String getResType() { 202 return resType_; 203 } 204 205 public void setResType(String resType) { 206 resType_ = resType; 207 } 208 209 public String getTransactionIsolationLevel() { 210 return transactionIsolationLevel_; 211 } 212 213 public void setTransactionIsolationLevel(String transactionIsolationLevel) { 214 transactionIsolationLevel_ = transactionIsolationLevel; 215 } 216 217 public boolean isIsolationLevelGuaranteed() { 218 return isIsolationLevelGuaranteed_; 219 } 220 221 public void setIsIsolationLevelGuaranteed(boolean isIsolationLevelGuaranteed) { 222 isIsolationLevelGuaranteed_ = isIsolationLevelGuaranteed; 223 } 224 226 public String toString() { 227 return "< JDBC Connection Pool : " + getName() + "... >"; 228 } 229 230 232 237 public Object createDataSource() throws J2EEResourceException { 238 synchronized(this) { 241 if (cachedVendorDataSource == null) { 242 try { 243 Class dataSourceClass = Utility.loadClass(getDatasourceClassname()); 247 cachedVendorDataSource = dataSourceClass.newInstance(); 249 ResourceProperty next; 250 for(Iterator iter = getProperties().iterator(); iter.hasNext(); ) { 251 next = (ResourceProperty) iter.next(); 252 Utility.invokeSetMethodCaseInsensitive(cachedVendorDataSource, next.getName(), 253 next.getValue().toString()); 254 } 255 } catch(Exception e) { 256 e.printStackTrace(); 257 throw new J2EEResourceException(e); 258 } 259 } 260 } 261 return cachedVendorDataSource; 262 } 263 264 266 272 public boolean isXA() { 273 274 boolean tf = false; 275 276 if (this.resType_ == null) { 278 return false; 280 } 281 282 if (this.resType_.equals("javax.sql.XADataSource") 283 && this.datasourceClassname_ != null) { 284 285 try { 286 Class dsClass = Utility.loadClass(getDatasourceClassname()); 292 if (javax.sql.XADataSource .class.isAssignableFrom(dsClass)) { 294 tf = true; 295 } 296 } catch (ClassNotFoundException e) { 297 } 299 } 300 301 return tf; 302 } 303 304 311 public boolean isCP() { 312 313 boolean tf = false; 314 if (this.resType_ == null) { 316 return false; 318 } 319 320 if (this.resType_.equals("javax.sql.ConnectionPoolDataSource") 321 && this.datasourceClassname_ != null) { 322 323 try { 324 Class dsClass = Utility.loadClass(getDatasourceClassname()); 328 if (javax.sql.ConnectionPoolDataSource .class.isAssignableFrom(dsClass)) { 330 tf = true; 331 } 332 } catch (ClassNotFoundException e) { 333 } 335 } 336 337 return tf; 338 } 339 340 343 public void addProperty(ResourceProperty property) { 344 346 String propName = property.getName(); 347 348 if (propName.equalsIgnoreCase("user")) { 349 setUserName((String )property.getValue()); 350 } else if (propName.equalsIgnoreCase("password")) { 351 setPassword((String )property.getValue()); 352 } 353 354 if (propName.equalsIgnoreCase("xa-driver-does-not-support-non-tx-operations")) { 356 if (((String )property.getValue()).equalsIgnoreCase("true")) { 357 this.noNonTxOps = true; 358 } 359 return; 360 } 361 if (propName.equalsIgnoreCase("perf-monitor")) { 365 if (((String )property.getValue()).equalsIgnoreCase("true")) { 366 this.perfMonitor = true; 367 } 368 return; 369 } 370 372 373 super.addProperty(property); 374 } 375 376 public boolean isPerfMonitor() { 379 return perfMonitor; 380 } 381 383 private boolean noNonTxOps = false; 385 386 public boolean getNoNonTxOps() { 387 return noNonTxOps; 388 } 389 } 391 | Popular Tags |