JDBC cleaning 3
* Basic formatting
* Variable renaming
* Some generics being added
Signed-off-by: Arjan Tijms <arjan.tijms@gmail.com>
diff --git a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/deployer/DataSourceDefinitionDeployer.java b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/deployer/DataSourceDefinitionDeployer.java
index 9408757..566a326 100644
--- a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/deployer/DataSourceDefinitionDeployer.java
+++ b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/deployer/DataSourceDefinitionDeployer.java
@@ -16,18 +16,40 @@
package org.glassfish.jdbc.deployer;
-import com.sun.appserv.connectors.internal.api.ConnectorConstants;
-import com.sun.appserv.connectors.internal.api.ConnectorsUtil;
-import com.sun.enterprise.config.serverbeans.Resource;
-import com.sun.enterprise.config.serverbeans.Resources;
-import com.sun.enterprise.deployment.*;
+import static com.sun.appserv.connectors.internal.api.ConnectorConstants.JAVAX_SQL_CONNECTION_POOL_DATASOURCE;
+import static com.sun.appserv.connectors.internal.api.ConnectorConstants.JAVAX_SQL_DATASOURCE;
+import static com.sun.appserv.connectors.internal.api.ConnectorConstants.JAVAX_SQL_XA_DATASOURCE;
+import static com.sun.appserv.connectors.internal.api.ConnectorConstants.JAVA_SQL_DRIVER;
+import static com.sun.appserv.connectors.internal.api.ConnectorsUtil.deriveResourceName;
+import static com.sun.appserv.connectors.internal.api.ConnectorsUtil.getTransactionIsolationInt;
+import static java.util.logging.Level.FINE;
+import static java.util.logging.Level.FINEST;
+import static java.util.logging.Level.WARNING;
+import static org.glassfish.deployment.common.JavaEEResourceType.DSDPOOL;
+import static org.glassfish.resourcebase.resources.api.ResourceConstants.JAVA_APP_SCOPE_PREFIX;
+import static org.glassfish.resourcebase.resources.api.ResourceConstants.JAVA_GLOBAL_SCOPE_PREFIX;
+
+import java.beans.PropertyVetoException;
+import java.sql.Driver;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import javax.naming.NamingException;
+import javax.sql.ConnectionPoolDataSource;
+import javax.sql.DataSource;
+import javax.sql.XADataSource;
+
+import org.glassfish.deployment.common.Descriptor;
import org.glassfish.deployment.common.JavaEEResourceType;
+import org.glassfish.deployment.common.RootDeploymentDescriptor;
import org.glassfish.javaee.services.CommonResourceProxy;
import org.glassfish.jdbc.config.JdbcConnectionPool;
import org.glassfish.jdbc.config.JdbcResource;
-import com.sun.logging.LogDomains;
-import org.glassfish.deployment.common.Descriptor;
-import org.glassfish.deployment.common.RootDeploymentDescriptor;
import org.glassfish.resourcebase.resources.api.ResourceConflictException;
import org.glassfish.resourcebase.resources.api.ResourceDeployer;
import org.glassfish.resourcebase.resources.api.ResourceDeployerInfo;
@@ -39,16 +61,20 @@
import org.jvnet.hk2.config.TransactionFailure;
import org.jvnet.hk2.config.types.Property;
+import com.sun.enterprise.config.serverbeans.Application;
+import com.sun.enterprise.config.serverbeans.Resource;
+import com.sun.enterprise.config.serverbeans.Resources;
+import com.sun.enterprise.deployment.BundleDescriptor;
+import com.sun.enterprise.deployment.DataSourceDefinitionDescriptor;
+import com.sun.enterprise.deployment.EjbBundleDescriptor;
+import com.sun.enterprise.deployment.EjbDescriptor;
+import com.sun.enterprise.deployment.EjbInterceptor;
+import com.sun.enterprise.deployment.JndiNameEnvironment;
+import com.sun.enterprise.deployment.ManagedBeanDescriptor;
+import com.sun.logging.LogDomains;
+
import jakarta.inject.Inject;
import jakarta.inject.Provider;
-import javax.naming.NamingException;
-import java.beans.PropertyVetoException;
-import java.util.*;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import static org.glassfish.deployment.common.JavaEEResourceType.*;
-
/**
* @author Jagadish Ramu
@@ -57,6 +83,8 @@
@ResourceDeployerInfo(DataSourceDefinitionDescriptor.class)
public class DataSourceDefinitionDeployer implements ResourceDeployer {
+ private static Logger _logger = LogDomains.getLogger(DataSourceDefinitionDeployer.class, LogDomains.RSR_LOGGER);
+
@Inject
private Provider<ResourceManagerFactory> resourceManagerFactoryProvider;
@@ -66,29 +94,28 @@
@Inject
private Provider<ResourceNamingService> resourceNamingServiceProvider;
- private static Logger _logger = LogDomains.getLogger(DataSourceDefinitionDeployer.class, LogDomains.RSR_LOGGER);
-
+ @Override
public void deployResource(Object resource, String applicationName, String moduleName) throws Exception {
- //TODO ASR
+ // TODO ASR
}
+
+ @Override
public void deployResource(Object resource) throws Exception {
final DataSourceDefinitionDescriptor desc = (DataSourceDefinitionDescriptor) resource;
- String poolName = ConnectorsUtil.deriveResourceName(desc.getResourceId(), desc.getName(), DSDPOOL);
- String resourceName = ConnectorsUtil.deriveResourceName(desc.getResourceId(), desc.getName(), desc.getResourceType());
- //desc.getName();
+ String poolName = deriveResourceName(desc.getResourceId(), desc.getName(), DSDPOOL);
+ String resourceName = deriveResourceName(desc.getResourceId(), desc.getName(), desc.getResourceType());
- if(_logger.isLoggable(Level.FINE)) {
- _logger.log(Level.FINE, "DataSourceDefinitionDeployer.deployResource() : pool-name ["+poolName+"], " +
- " resource-name ["+resourceName+"]");
- }
+ _logger.log(FINE, () ->
+ "DataSourceDefinitionDeployer.deployResource() : pool-name [" + poolName + "], " +
+ " resource-name [" + resourceName + "]");
- JdbcConnectionPool jdbcCp = new MyJdbcConnectionPool(desc, poolName);
+ JdbcConnectionPool jdbcConnectionPool = new MyJdbcConnectionPool(desc, poolName);
- //deploy pool
- getDeployer(jdbcCp).deployResource(jdbcCp);
+ // deploy pool
+ getDeployer(jdbcConnectionPool).deployResource(jdbcConnectionPool);
- //deploy resource
+ // deploy resource
JdbcResource jdbcResource = new MyJdbcResource(poolName, resourceName);
getDeployer(jdbcResource).deployResource(jdbcResource);
}
@@ -96,26 +123,26 @@
/**
* {@inheritDoc}
*/
- public boolean canDeploy(boolean postApplicationDeployment, Collection<Resource> allResources, Resource resource){
- if(handles(resource)){
- if(!postApplicationDeployment){
+ @Override
+ public boolean canDeploy(boolean postApplicationDeployment, Collection<Resource> allResources, Resource resource) {
+ if (handles(resource)) {
+ if (!postApplicationDeployment) {
return true;
}
}
+
return false;
}
/**
* {@inheritDoc}
*/
- public void validatePreservedResource(com.sun.enterprise.config.serverbeans.Application oldApp,
- com.sun.enterprise.config.serverbeans.Application newApp, Resource resource,
- Resources allResources)
- throws ResourceConflictException {
- //do nothing.
+ @Override
+ public void validatePreservedResource(Application oldApp, Application newApp, Resource resource, Resources allResources)
+ throws ResourceConflictException {
+ // do nothing.
}
-
private ResourceDeployer getDeployer(Object resource) {
return resourceManagerFactoryProvider.get().getResourceDeployer(resource);
}
@@ -124,67 +151,65 @@
return new DataSourceProperty(name, value);
}
-
public void registerDataSourceDefinitions(com.sun.enterprise.deployment.Application application) {
String appName = application.getAppName();
Set<BundleDescriptor> bundles = application.getBundleDescriptors();
for (BundleDescriptor bundle : bundles) {
registerDataSourceDefinitions(appName, bundle);
- Collection<RootDeploymentDescriptor> dds = bundle.getExtensionsDescriptors();
- if(dds != null){
- for(RootDeploymentDescriptor dd : dds){
- registerDataSourceDefinitions(appName, dd);
+ Collection<RootDeploymentDescriptor> deploymentDescriptors = bundle.getExtensionsDescriptors();
+ if (deploymentDescriptors != null) {
+ for (RootDeploymentDescriptor deploymentDescriptor : deploymentDescriptors) {
+ registerDataSourceDefinitions(appName, deploymentDescriptor);
}
}
}
}
private void registerDataSourceDefinitions(String appName, Descriptor descriptor) {
-
if (descriptor instanceof JndiNameEnvironment) {
JndiNameEnvironment env = (JndiNameEnvironment) descriptor;
- for (Descriptor dsd : env.getResourceDescriptors(JavaEEResourceType.DSD)) {
- registerDSDReferredByApplication(appName,(DataSourceDefinitionDescriptor) dsd);
+ for (Descriptor resourceDescriptor : env.getResourceDescriptors(JavaEEResourceType.DSD)) {
+ registerDSDReferredByApplication(appName, (DataSourceDefinitionDescriptor) resourceDescriptor);
}
}
- //ejb descriptor
+ // EJB descriptor
if (descriptor instanceof EjbBundleDescriptor) {
EjbBundleDescriptor ejbDesc = (EjbBundleDescriptor) descriptor;
Set<? extends EjbDescriptor> ejbDescriptors = ejbDesc.getEjbs();
for (EjbDescriptor ejbDescriptor : ejbDescriptors) {
- for (Descriptor dsd : ejbDescriptor.getResourceDescriptors(JavaEEResourceType.DSD)) {
- registerDSDReferredByApplication(appName,(DataSourceDefinitionDescriptor) dsd);
+ for (Descriptor resourceDescriptor : ejbDescriptor.getResourceDescriptors(JavaEEResourceType.DSD)) {
+ registerDSDReferredByApplication(appName, (DataSourceDefinitionDescriptor) resourceDescriptor);
}
}
- //ejb interceptors
+
+ // ejb interceptors
Set<EjbInterceptor> ejbInterceptors = ejbDesc.getInterceptors();
for (EjbInterceptor ejbInterceptor : ejbInterceptors) {
- for (Descriptor dsd : ejbInterceptor.getResourceDescriptors(JavaEEResourceType.DSD)) {
- registerDSDReferredByApplication(appName,(DataSourceDefinitionDescriptor) dsd);
+ for (Descriptor resourceDescriptor : ejbInterceptor.getResourceDescriptors(JavaEEResourceType.DSD)) {
+ registerDSDReferredByApplication(appName, (DataSourceDefinitionDescriptor) resourceDescriptor);
}
}
}
- if(descriptor instanceof BundleDescriptor){
+ if (descriptor instanceof BundleDescriptor) {
// managed bean descriptors
- Set<ManagedBeanDescriptor> managedBeanDescriptors = ((BundleDescriptor)descriptor).getManagedBeans();
- for (ManagedBeanDescriptor mbd : managedBeanDescriptors) {
- for (Descriptor dsd : mbd.getResourceDescriptors(JavaEEResourceType.DSD)) {
- registerDSDReferredByApplication(appName, (DataSourceDefinitionDescriptor)dsd);
+ Set<ManagedBeanDescriptor> managedBeanDescriptors = ((BundleDescriptor) descriptor).getManagedBeans();
+ for (ManagedBeanDescriptor managedBeanDescriptor : managedBeanDescriptors) {
+ for (Descriptor resourceDescriptor : managedBeanDescriptor.getResourceDescriptors(JavaEEResourceType.DSD)) {
+ registerDSDReferredByApplication(appName, (DataSourceDefinitionDescriptor) resourceDescriptor);
}
}
}
}
-
- private void unregisterDSDReferredByApplication(DataSourceDefinitionDescriptor dsd){
- try{
- if(dsd.isDeployed()){
- undeployResource(dsd);
+ private void unregisterDSDReferredByApplication(DataSourceDefinitionDescriptor dataSourceDefinitionDescriptor) {
+ try {
+ if (dataSourceDefinitionDescriptor.isDeployed()) {
+ undeployResource(dataSourceDefinitionDescriptor);
}
- }catch(Exception e){
- _logger.log(Level.WARNING, "exception while unregistering DSD [ "+dsd.getName()+" ]", e);
+ } catch (Exception e) {
+ _logger.log(WARNING, "exception while unregistering DSD [ " + dataSourceDefinitionDescriptor.getName() + " ]", e);
}
}
@@ -192,10 +217,10 @@
Set<BundleDescriptor> bundles = application.getBundleDescriptors();
for (BundleDescriptor bundle : bundles) {
unRegisterDataSourceDefinitions(bundle);
- Collection<RootDeploymentDescriptor> dds = bundle.getExtensionsDescriptors();
- if(dds != null){
- for(RootDeploymentDescriptor dd : dds){
- unRegisterDataSourceDefinitions(dd);
+ Collection<RootDeploymentDescriptor> deploymentDescriptors = bundle.getExtensionsDescriptors();
+ if (deploymentDescriptors != null) {
+ for (RootDeploymentDescriptor deploymentDescriptor : deploymentDescriptors) {
+ unRegisterDataSourceDefinitions(deploymentDescriptor);
}
}
}
@@ -204,124 +229,129 @@
private void unRegisterDataSourceDefinitions(Descriptor descriptor) {
if (descriptor instanceof JndiNameEnvironment) {
JndiNameEnvironment env = (JndiNameEnvironment) descriptor;
- for (Descriptor dsd : env.getResourceDescriptors(JavaEEResourceType.DSD)) {
- unregisterDSDReferredByApplication((DataSourceDefinitionDescriptor)dsd);
+ for (Descriptor resourceDescriptor : env.getResourceDescriptors(JavaEEResourceType.DSD)) {
+ unregisterDSDReferredByApplication((DataSourceDefinitionDescriptor) resourceDescriptor);
}
}
- //ejb descriptor
+ // ejb descriptor
if (descriptor instanceof EjbBundleDescriptor) {
EjbBundleDescriptor ejbDesc = (EjbBundleDescriptor) descriptor;
Set<? extends EjbDescriptor> ejbDescriptors = ejbDesc.getEjbs();
for (EjbDescriptor ejbDescriptor : ejbDescriptors) {
- for (Descriptor dsd : ejbDescriptor.getResourceDescriptors(JavaEEResourceType.DSD)) {
- unregisterDSDReferredByApplication((DataSourceDefinitionDescriptor)dsd);
+ for (Descriptor resourceDescriptor : ejbDescriptor.getResourceDescriptors(JavaEEResourceType.DSD)) {
+ unregisterDSDReferredByApplication((DataSourceDefinitionDescriptor) resourceDescriptor);
}
}
- //ejb interceptors
+ // ejb interceptors
Set<EjbInterceptor> ejbInterceptors = ejbDesc.getInterceptors();
for (EjbInterceptor ejbInterceptor : ejbInterceptors) {
- for (Descriptor dsd : ejbInterceptor.getResourceDescriptors(JavaEEResourceType.DSD)) {
- unregisterDSDReferredByApplication((DataSourceDefinitionDescriptor)dsd);
+ for (Descriptor resourceDescriptor : ejbInterceptor.getResourceDescriptors(JavaEEResourceType.DSD)) {
+ unregisterDSDReferredByApplication((DataSourceDefinitionDescriptor) resourceDescriptor);
}
}
}
// managed bean descriptors
- if(descriptor instanceof BundleDescriptor){
- Set<ManagedBeanDescriptor> managedBeanDescriptors = ((BundleDescriptor)descriptor).getManagedBeans();
- for (ManagedBeanDescriptor mbd : managedBeanDescriptors) {
- for (Descriptor dsd : mbd.getResourceDescriptors(JavaEEResourceType.DSD)) {
- unregisterDSDReferredByApplication((DataSourceDefinitionDescriptor)dsd);
+ if (descriptor instanceof BundleDescriptor) {
+ Set<ManagedBeanDescriptor> managedBeanDescriptors = ((BundleDescriptor) descriptor).getManagedBeans();
+ for (ManagedBeanDescriptor managedBeanDescriptor : managedBeanDescriptors) {
+ for (Descriptor resourceDescriptor : managedBeanDescriptor.getResourceDescriptors(JavaEEResourceType.DSD)) {
+ unregisterDSDReferredByApplication((DataSourceDefinitionDescriptor) resourceDescriptor);
}
}
}
}
- private void registerDSDReferredByApplication(String appName,
- DataSourceDefinitionDescriptor dsd) {
- // It is possible that JPA might call this method multiple times in a single deployment,
- // when there are multiple PUs eg: one PU in each of war, ejb-jar. Make sure that
- // DSD is bound to JNDI only when it is not already deployed.
- if(!dsd.isDeployed()){
+ private void registerDSDReferredByApplication(String appName, DataSourceDefinitionDescriptor dataSourceDefinitionDescriptor) {
+
+ // It is possible that Jakarta Persistence might call this method multiple times in a single
+ // deployment, when there are multiple persistence units eg:
+ // one persistence units in each of war, ejb-jar.
+ // Make sure that DSD is bound to JNDI only when it is not already deployed.
+
+ if (!dataSourceDefinitionDescriptor.isDeployed()) {
CommonResourceProxy proxy = dataSourceDefinitionProxyProvider.get();
ResourceNamingService resourceNamingService = resourceNamingServiceProvider.get();
- proxy.setDescriptor(dsd);
+ proxy.setDescriptor(dataSourceDefinitionDescriptor);
- //String appName = application.getAppName();
- String dsdName = dsd.getName();
- if(dsdName.startsWith(ConnectorConstants.JAVA_APP_SCOPE_PREFIX)){
- dsd.setResourceId(appName);
+ String dsdName = dataSourceDefinitionDescriptor.getName();
+ if (dsdName.startsWith(JAVA_APP_SCOPE_PREFIX)) {
+ dataSourceDefinitionDescriptor.setResourceId(appName);
}
- if(dsdName.startsWith(ConnectorConstants.JAVA_GLOBAL_SCOPE_PREFIX)
- /*|| next.getName().startsWith("java:module/")*/
- || dsdName.startsWith(ConnectorConstants.JAVA_APP_SCOPE_PREFIX)){
+ if (dsdName.startsWith(JAVA_GLOBAL_SCOPE_PREFIX) || dsdName.startsWith(JAVA_APP_SCOPE_PREFIX)) {
ResourceInfo resourceInfo = new ResourceInfo(dsdName, appName, null);
try {
resourceNamingService.publishObject(resourceInfo, proxy, true);
- dsd.setDeployed(true);
+ dataSourceDefinitionDescriptor.setDeployed(true);
} catch (NamingException e) {
- Object params[] = new Object[]{appName, dsdName, e};
- _logger.log(Level.WARNING, "dsd.registration.failed", params);
+ _logger.log(WARNING, "dsd.registration.failed", new Object[] { appName, dsdName, e });
}
}
}
}
+ @Override
public void undeployResource(Object resource, String applicationName, String moduleName) throws Exception {
- //TODO ASR
+ // TODO ASR
}
+ @Override
public void undeployResource(Object resource) throws Exception {
+ final DataSourceDefinitionDescriptor dataSourceDefinitionDescriptor = (DataSourceDefinitionDescriptor) resource;
- final DataSourceDefinitionDescriptor desc = (DataSourceDefinitionDescriptor) resource;
+ String poolName = deriveResourceName(
+ dataSourceDefinitionDescriptor.getResourceId(),
+ dataSourceDefinitionDescriptor.getName(),
+ DSDPOOL);
- String poolName = ConnectorsUtil.deriveResourceName(desc.getResourceId(), desc.getName(), DSDPOOL);
- String resourceName = ConnectorsUtil.deriveResourceName(desc.getResourceId(), desc.getName(),desc.getResourceType());
+ String resourceName = deriveResourceName(
+ dataSourceDefinitionDescriptor.getResourceId(),
+ dataSourceDefinitionDescriptor.getName(),
+ dataSourceDefinitionDescriptor.getResourceType());
- if(_logger.isLoggable(Level.FINE)) {
- _logger.log(Level.FINE, "DataSourceDefinitionDeployer.undeployResource() : pool-name ["+poolName+"], " +
- " resource-name ["+resourceName+"]");
- }
+ _logger.log(FINE, () ->
+ "DataSourceDefinitionDeployer.undeployResource() : pool-name [" + poolName + "], " +
+ " resource-name [" + resourceName + "]");
- //undeploy resource
+ // Undeploy resource
JdbcResource jdbcResource = new MyJdbcResource(poolName, resourceName);
getDeployer(jdbcResource).undeployResource(jdbcResource);
- //undeploy pool
- JdbcConnectionPool jdbcCp = new MyJdbcConnectionPool(desc, poolName);
+ // Undeploy pool
+ JdbcConnectionPool jdbcCp = new MyJdbcConnectionPool(dataSourceDefinitionDescriptor, poolName);
getDeployer(jdbcCp).undeployResource(jdbcCp);
- desc.setDeployed(false);
+ dataSourceDefinitionDescriptor.setDeployed(false);
}
+ @Override
public void redeployResource(Object resource) throws Exception {
throw new UnsupportedOperationException("redeploy() not supported for datasource-definition type");
}
+ @Override
public void enableResource(Object resource) throws Exception {
throw new UnsupportedOperationException("enable() not supported for datasource-definition type");
}
+ @Override
public void disableResource(Object resource) throws Exception {
throw new UnsupportedOperationException("disable() not supported for datasource-definition type");
}
+ @Override
public boolean handles(Object resource) {
return resource instanceof DataSourceDefinitionDescriptor;
}
- /**
- * @inheritDoc
- */
+ @Override
public boolean supportsDynamicReconfiguration() {
return false;
}
- /**
- * @inheritDoc
- */
+ @Override
public Class[] getProxyClassesForDynamicReconfiguration() {
return new Class[0];
}
@@ -359,32 +389,38 @@
this.value = value;
}
+ @Override
public String getName() {
return name;
}
+ @Override
public void setName(String value) throws PropertyVetoException {
this.name = value;
}
+ @Override
public String getValue() {
return value;
}
+ @Override
public void setValue(String value) throws PropertyVetoException {
this.value = value;
}
+ @Override
public String getDescription() {
return description;
}
+ @Override
public void setDescription(String value) throws PropertyVetoException {
this.description = value;
}
public void injectedInto(Object o) {
- //do nothing
+ // do nothing
}
}
@@ -398,51 +434,64 @@
this.jndiName = jndiName;
}
+ @Override
public String getPoolName() {
return poolName;
}
+ @Override
public void setPoolName(String value) throws PropertyVetoException {
this.poolName = value;
}
+ @Override
public String getObjectType() {
return null;
}
+ @Override
public void setObjectType(String value) throws PropertyVetoException {
}
+ @Override
public String getIdentity() {
return jndiName;
}
+ @Override
public String getEnabled() {
return String.valueOf(true);
}
+ @Override
public void setEnabled(String value) throws PropertyVetoException {
}
+ @Override
public String getDescription() {
return null;
}
+ @Override
public void setDescription(String value) throws PropertyVetoException {
}
+ @Override
public List<Property> getProperty() {
return null;
}
+ @Override
public Property getProperty(String name) {
return null;
}
+ @Override
public String getPropertyValue(String name) {
return null;
}
+ @Override
public String getPropertyValue(String name, String defaultValue) {
return null;
}
@@ -450,20 +499,24 @@
public void injectedInto(Object o) {
}
+ @Override
public String getJndiName() {
return jndiName;
}
+ @Override
public void setJndiName(String value) throws PropertyVetoException {
this.jndiName = value;
}
+ @Override
public String getDeploymentOrder() {
return null;
}
+ @Override
public void setDeploymentOrder(String value) {
- //do nothing
+ // do nothing
}
@Override
@@ -489,480 +542,564 @@
class MyJdbcConnectionPool extends FakeConfigBean implements JdbcConnectionPool {
- private DataSourceDefinitionDescriptor desc;
+ private DataSourceDefinitionDescriptor dataSourceDefinitionDescriptor;
private String name;
public MyJdbcConnectionPool(DataSourceDefinitionDescriptor desc, String name) {
- this.desc = desc;
+ this.dataSourceDefinitionDescriptor = desc;
this.name = name;
}
+ @Override
public String getDatasourceClassname() {
- if(!getResType().equals(ConnectorConstants.JAVA_SQL_DRIVER)){
- return desc.getClassName();
+ if (!getResType().equals(JAVA_SQL_DRIVER)) {
+ return dataSourceDefinitionDescriptor.getClassName();
}
+
return null;
}
+ @Override
public void setDatasourceClassname(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getResType() {
- String type = ConnectorConstants.JAVAX_SQL_DATASOURCE;
+ String type = JAVAX_SQL_DATASOURCE;
try {
- Class clz = Thread.currentThread().getContextClassLoader().loadClass(desc.getClassName());
- if (javax.sql.XADataSource.class.isAssignableFrom(clz)) {
- type = ConnectorConstants.JAVAX_SQL_XA_DATASOURCE;
- } else if (javax.sql.ConnectionPoolDataSource.class.isAssignableFrom(clz)) {
- type = ConnectorConstants.JAVAX_SQL_CONNECTION_POOL_DATASOURCE;
- } else if (javax.sql.DataSource.class.isAssignableFrom(clz)){
- type = ConnectorConstants.JAVAX_SQL_DATASOURCE;
- } else if(java.sql.Driver.class.isAssignableFrom(clz)){
- type = ConnectorConstants.JAVA_SQL_DRIVER;
- }
- } catch (ClassNotFoundException e) {
- if(_logger.isLoggable(Level.FINEST)) {
- _logger.log(Level.FINEST, "Unable to load class [ " + desc.getClassName() + " ] to " +
- "determine its res-type, defaulting to ["+ConnectorConstants.JAVAX_SQL_DATASOURCE+"]");
+ Class<?> dataSoureClass =
+ Thread.currentThread().getContextClassLoader().loadClass(dataSourceDefinitionDescriptor.getClassName());
+
+ if (XADataSource.class.isAssignableFrom(dataSoureClass)) {
+ type = JAVAX_SQL_XA_DATASOURCE;
+ } else if (ConnectionPoolDataSource.class.isAssignableFrom(dataSoureClass)) {
+ type = JAVAX_SQL_CONNECTION_POOL_DATASOURCE;
+ } else if (DataSource.class.isAssignableFrom(dataSoureClass)) {
+ type = JAVAX_SQL_DATASOURCE;
+ } else if (Driver.class.isAssignableFrom(dataSoureClass)) {
+ type = JAVA_SQL_DRIVER;
}
- // ignore and default to "javax.sql.DataSource"
+ } catch (ClassNotFoundException e) {
+ _logger.log(FINEST, () ->
+ "Unable to load class [ " + dataSourceDefinitionDescriptor.getClassName() + " ] to " +
+ "determine its res-type, defaulting to [" + JAVAX_SQL_DATASOURCE + "]");
+
+ // ignore and default to "javax.sql.DataSource"
}
+
return type;
}
+ @Override
public void setResType(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
@Override
public String getObjectType() {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ return null; // To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void setObjectType(String value) throws PropertyVetoException {
- //To change body of implemented methods use File | Settings | File Templates.
+ // To change body of implemented methods use File | Settings | File Templates.
}
+ @Override
public String getIdentity() {
return name;
}
+ @Override
public String getSteadyPoolSize() {
- int minPoolSize = desc.getMinPoolSize();
+ int minPoolSize = dataSourceDefinitionDescriptor.getMinPoolSize();
if (minPoolSize == -1) {
minPoolSize = 8;
}
+
return String.valueOf(minPoolSize);
}
+ @Override
public void setSteadyPoolSize(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getMaxPoolSize() {
- int maxPoolSize = desc.getMaxPoolSize();
+ int maxPoolSize = dataSourceDefinitionDescriptor.getMaxPoolSize();
if (maxPoolSize == -1) {
maxPoolSize = 32;
}
+
return String.valueOf(maxPoolSize);
}
+ @Override
public void setMaxPoolSize(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getMaxWaitTimeInMillis() {
return String.valueOf(60000);
}
+ @Override
public void setMaxWaitTimeInMillis(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getPoolResizeQuantity() {
return String.valueOf(2);
}
+ @Override
public void setPoolResizeQuantity(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getIdleTimeoutInSeconds() {
- long maxIdleTime = desc.getMaxIdleTime();
+ long maxIdleTime = dataSourceDefinitionDescriptor.getMaxIdleTime();
if (maxIdleTime == -1) {
maxIdleTime = 300;
}
+
return String.valueOf(maxIdleTime);
}
+ @Override
public void setIdleTimeoutInSeconds(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getTransactionIsolationLevel() {
- if (desc.getIsolationLevel() == -1) {
+ if (dataSourceDefinitionDescriptor.getIsolationLevel() == -1) {
return null;
- } else {
- return ConnectorsUtil.getTransactionIsolationInt(desc.getIsolationLevel());
}
+
+ return getTransactionIsolationInt(dataSourceDefinitionDescriptor.getIsolationLevel());
+
}
+ @Override
public void setTransactionIsolationLevel(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getIsIsolationLevelGuaranteed() {
return String.valueOf("true");
}
+ @Override
public void setIsIsolationLevelGuaranteed(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getIsConnectionValidationRequired() {
return String.valueOf("false");
}
+ @Override
public void setIsConnectionValidationRequired(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getConnectionValidationMethod() {
return null;
}
+ @Override
public void setConnectionValidationMethod(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getValidationTableName() {
return null;
}
+ @Override
public void setValidationTableName(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getValidationClassname() {
return null;
}
+ @Override
public void setValidationClassname(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getFailAllConnections() {
return String.valueOf("false");
}
+ @Override
public void setFailAllConnections(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getNonTransactionalConnections() {
- return String.valueOf(!desc.isTransactional());
+ return String.valueOf(!dataSourceDefinitionDescriptor.isTransactional());
}
+ @Override
public void setNonTransactionalConnections(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getAllowNonComponentCallers() {
return String.valueOf("false");
}
+ @Override
public void setAllowNonComponentCallers(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getValidateAtmostOncePeriodInSeconds() {
return String.valueOf(0);
}
+ @Override
public void setValidateAtmostOncePeriodInSeconds(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getConnectionLeakTimeoutInSeconds() {
return String.valueOf(0);
}
+ @Override
public void setConnectionLeakTimeoutInSeconds(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getConnectionLeakReclaim() {
return String.valueOf(false);
}
+ @Override
public void setConnectionLeakReclaim(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getConnectionCreationRetryAttempts() {
return String.valueOf(0);
}
+ @Override
public void setConnectionCreationRetryAttempts(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getConnectionCreationRetryIntervalInSeconds() {
return String.valueOf(10);
}
+ @Override
public void setConnectionCreationRetryIntervalInSeconds(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getStatementTimeoutInSeconds() {
return String.valueOf(-1);
}
+ @Override
public void setStatementTimeoutInSeconds(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getLazyConnectionEnlistment() {
return String.valueOf(false);
}
+ @Override
public void setLazyConnectionEnlistment(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getLazyConnectionAssociation() {
return String.valueOf(false);
}
+ @Override
public void setLazyConnectionAssociation(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getAssociateWithThread() {
return String.valueOf(false);
}
+ @Override
public void setAssociateWithThread(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getPooling() {
return String.valueOf(true);
}
+ @Override
public void setPooling(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getStatementCacheSize() {
return String.valueOf(0);
}
+ @Override
public void setStatementCacheSize(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getMatchConnections() {
return String.valueOf(true);
}
+ @Override
public void setMatchConnections(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getMaxConnectionUsageCount() {
return String.valueOf(0);
}
+ @Override
public void setMaxConnectionUsageCount(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getWrapJdbcObjects() {
return String.valueOf(true);
}
+ @Override
public void setWrapJdbcObjects(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getDescription() {
- return desc.getDescription();
+ return dataSourceDefinitionDescriptor.getDescription();
}
+ @Override
public void setDescription(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public List<Property> getProperty() {
- Properties p = desc.getProperties();
+ Properties descriptorProperties = dataSourceDefinitionDescriptor.getProperties();
List<Property> dataSourceProperties = new ArrayList<Property>();
- for (Map.Entry entry : p.entrySet()) {
+
+ for (Map.Entry<Object, Object> entry : descriptorProperties.entrySet()) {
String key = (String) entry.getKey();
String value = (String) entry.getValue();
- DataSourceProperty dp = convertProperty(key, value);
- dataSourceProperties.add(dp);
+ dataSourceProperties.add(convertProperty(key, value));
}
- if (desc.getUser() != null) {
- DataSourceProperty property = convertProperty(("user"),
- String.valueOf(desc.getUser()));
+ if (dataSourceDefinitionDescriptor.getUser() != null) {
+ DataSourceProperty property = convertProperty("user", dataSourceDefinitionDescriptor.getUser());
dataSourceProperties.add(property);
}
- if (desc.getPassword() != null) {
- DataSourceProperty property = convertProperty(("password"),
- String.valueOf(desc.getPassword()));
+ if (dataSourceDefinitionDescriptor.getPassword() != null) {
+ DataSourceProperty property = convertProperty("password", dataSourceDefinitionDescriptor.getPassword());
dataSourceProperties.add(property);
}
- if (desc.getDatabaseName() != null) {
- DataSourceProperty property = convertProperty(("databaseName"),
- String.valueOf(desc.getDatabaseName()));
+ if (dataSourceDefinitionDescriptor.getDatabaseName() != null) {
+ DataSourceProperty property = convertProperty("databaseName", dataSourceDefinitionDescriptor.getDatabaseName());
dataSourceProperties.add(property);
}
- if (desc.getServerName() != null) {
- DataSourceProperty property = convertProperty(("serverName"),
- String.valueOf(desc.getServerName()));
+ if (dataSourceDefinitionDescriptor.getServerName() != null) {
+ DataSourceProperty property = convertProperty("serverName", dataSourceDefinitionDescriptor.getServerName());
dataSourceProperties.add(property);
}
- if (desc.getPortNumber() != -1) {
- DataSourceProperty property = convertProperty(("portNumber"),
- String.valueOf(desc.getPortNumber()));
+ if (dataSourceDefinitionDescriptor.getPortNumber() != -1) {
+ DataSourceProperty property = convertProperty("portNumber", String.valueOf(dataSourceDefinitionDescriptor.getPortNumber()));
dataSourceProperties.add(property);
}
- //process URL only when standard properties are not set
- if (desc.getUrl() != null && !isStandardPropertiesSet(desc)) {
- DataSourceProperty property = convertProperty(("url"),
- String.valueOf(desc.getUrl()));
+ // Process URL only when standard properties are not set
+ if (dataSourceDefinitionDescriptor.getUrl() != null && !isStandardPropertiesSet(dataSourceDefinitionDescriptor)) {
+ DataSourceProperty property = convertProperty("url", dataSourceDefinitionDescriptor.getUrl());
dataSourceProperties.add(property);
}
- if (desc.getLoginTimeout() != 0) {
- DataSourceProperty property = convertProperty(("loginTimeout"),
- String.valueOf(desc.getLoginTimeout()));
+ if (dataSourceDefinitionDescriptor.getLoginTimeout() != 0) {
+ DataSourceProperty property = convertProperty("loginTimeout", String.valueOf(dataSourceDefinitionDescriptor.getLoginTimeout()));
dataSourceProperties.add(property);
}
- if (desc.getMaxStatements() != -1) {
- DataSourceProperty property = convertProperty(("maxStatements"),
- String.valueOf(desc.getMaxStatements()));
+ if (dataSourceDefinitionDescriptor.getMaxStatements() != -1) {
+ DataSourceProperty property = convertProperty("maxStatements", String.valueOf(dataSourceDefinitionDescriptor.getMaxStatements()));
dataSourceProperties.add(property);
}
return dataSourceProperties;
}
- private boolean isStandardPropertiesSet(DataSourceDefinitionDescriptor desc){
- boolean result = false;
- if(desc.getServerName() != null && desc.getDatabaseName() != null && desc.getPortNumber() != -1 ){
- result = true;
- }
- return result;
+ private boolean isStandardPropertiesSet(DataSourceDefinitionDescriptor dataSourceDefinitionDescriptor) {
+ return
+ dataSourceDefinitionDescriptor.getServerName() != null &&
+ dataSourceDefinitionDescriptor.getDatabaseName() != null &&
+ dataSourceDefinitionDescriptor.getPortNumber() != -1;
}
+ @Override
public Property getProperty(String name) {
- String value = (String) desc.getProperties().get(name);
+ String value = (String) dataSourceDefinitionDescriptor.getProperties().get(name);
return new DataSourceProperty(name, value);
}
+ @Override
public String getPropertyValue(String name) {
- return (String) desc.getProperties().get(name);
+ return (String) dataSourceDefinitionDescriptor.getProperties().get(name);
}
+ @Override
public String getPropertyValue(String name, String defaultValue) {
- String value = null;
- value = (String) desc.getProperties().get(name);
+ String value = (String) dataSourceDefinitionDescriptor.getProperties().get(name);
if (value != null) {
return value;
- } else {
- return defaultValue;
}
+
+ return defaultValue;
}
public void injectedInto(Object o) {
- //do nothing
+ // do nothing
}
+ @Override
public String getName() {
return name;
}
+ @Override
public void setName(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getSqlTraceListeners() {
return null;
}
+ @Override
public void setSqlTraceListeners(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getPing() {
return String.valueOf(false);
}
+ @Override
public void setPing(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getInitSql() {
return null;
}
+ @Override
public void setInitSql(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getDriverClassname() {
- if(getResType().equals(ConnectorConstants.JAVA_SQL_DRIVER)){
- return desc.getClassName();
+ if (getResType().equals(JAVA_SQL_DRIVER)) {
+ return dataSourceDefinitionDescriptor.getClassName();
}
+
return null;
}
+ @Override
public void setDriverClassname(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getStatementLeakTimeoutInSeconds() {
return String.valueOf(0);
}
+ @Override
public void setStatementLeakTimeoutInSeconds(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getStatementLeakReclaim() {
return String.valueOf(false);
}
+ @Override
public void setStatementLeakReclaim(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getStatementCacheType() {
- return null;
+ return null;
}
+ @Override
public void setStatementCacheType(String value) throws PropertyVetoException {
- //do nothing
+ // do nothing
}
+ @Override
public String getDeploymentOrder() {
return null;
}
+ @Override
public void setDeploymentOrder(String value) {
- //do nothing
+ // do nothing
}
@Override
diff --git a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/deployer/JdbcConnectionPoolDeployer.java b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/deployer/JdbcConnectionPoolDeployer.java
index 4d1f2dc..b747346 100644
--- a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/deployer/JdbcConnectionPoolDeployer.java
+++ b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/deployer/JdbcConnectionPoolDeployer.java
@@ -17,10 +17,56 @@
package org.glassfish.jdbc.deployer;
-import com.sun.appserv.connectors.internal.api.ConnectorConstants;
+import static com.sun.appserv.connectors.internal.api.ConnectorConstants.DYNAMIC_RECONFIGURATION_FLAG;
+import static com.sun.appserv.connectors.internal.api.ConnectorConstants.JAVA_SQL_DRIVER;
+import static com.sun.appserv.connectors.internal.api.ConnectorConstants.JDBCXA_RA_NAME;
+import static com.sun.appserv.connectors.internal.api.ConnectorConstants.LOCAL_TRANSACTION_TX_SUPPORT_STRING;
+import static com.sun.appserv.connectors.internal.api.ConnectorConstants.XA_TRANSACTION_TX_SUPPORT_STRING;
+import static com.sun.appserv.connectors.internal.api.ConnectorsUtil.getResourceInfo;
+import static com.sun.enterprise.connectors.util.ConnectionPoolObjectsUtils.setLazyEnlistAndLazyAssocProperties;
+import static java.util.Arrays.asList;
+import static java.util.concurrent.Executors.callable;
+import static java.util.logging.Level.FINE;
+import static java.util.logging.Level.FINEST;
+import static java.util.logging.Level.SEVERE;
+import static java.util.logging.Level.WARNING;
+import static org.glassfish.jdbc.util.JdbcResourcesUtil.getResourcesOfPool;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Locale;
+import java.util.Map;
+import java.util.MissingResourceException;
+import java.util.Set;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.logging.Logger;
+
+import org.glassfish.jdbc.config.JdbcConnectionPool;
+import org.glassfish.jdbc.util.JdbcResourcesUtil;
+import org.glassfish.resourcebase.resources.api.PoolInfo;
+import org.glassfish.resourcebase.resources.api.ResourceConflictException;
+import org.glassfish.resourcebase.resources.api.ResourceDeployer;
+import org.glassfish.resourcebase.resources.api.ResourceDeployerInfo;
+import org.glassfish.resourcebase.resources.api.ResourceInfo;
+import org.jvnet.hk2.annotations.Optional;
+import org.jvnet.hk2.annotations.Service;
+import org.jvnet.hk2.config.types.Property;
+
import com.sun.appserv.connectors.internal.api.ConnectorRuntimeException;
import com.sun.appserv.connectors.internal.api.ConnectorsUtil;
-import com.sun.enterprise.config.serverbeans.*;
+import com.sun.appserv.jdbc.DataSource;
+import com.sun.enterprise.config.serverbeans.Application;
+import com.sun.enterprise.config.serverbeans.BindableResource;
+import com.sun.enterprise.config.serverbeans.Domain;
+import com.sun.enterprise.config.serverbeans.Resource;
+import com.sun.enterprise.config.serverbeans.Resources;
import com.sun.enterprise.connectors.ConnectorConnectionPool;
import com.sun.enterprise.connectors.ConnectorDescriptorInfo;
import com.sun.enterprise.connectors.ConnectorRegistry;
@@ -30,27 +76,15 @@
import com.sun.enterprise.deployment.ConnectionDefDescriptor;
import com.sun.enterprise.deployment.ConnectorConfigProperty;
import com.sun.enterprise.deployment.ConnectorDescriptor;
-import com.sun.enterprise.resource.DynamicallyReconfigurableResource;
import com.sun.enterprise.resource.pool.ResourcePool;
import com.sun.enterprise.resource.pool.waitqueue.PoolWaitQueue;
import com.sun.enterprise.util.i18n.StringManager;
import com.sun.logging.LogDomains;
-import org.glassfish.jdbc.config.JdbcConnectionPool;
-import org.glassfish.jdbc.util.JdbcResourcesUtil;
-import org.glassfish.resourcebase.resources.api.*;
-import org.jvnet.hk2.annotations.Optional;
-import org.jvnet.hk2.annotations.Service;
-import org.jvnet.hk2.config.types.Property;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
-import java.util.*;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ThreadFactory;
-import java.util.logging.Level;
-import java.util.logging.Logger;
+
+//This class was created to fix the bug # 4650787
/**
* Handles Jdbc connection pool events in the server instance. When user adds a
@@ -62,77 +96,65 @@
*
* @author Tamil Vengan
*/
-
-// This class was created to fix the bug # 4650787
-
@Service
@ResourceDeployerInfo(JdbcConnectionPool.class)
@Singleton
public class JdbcConnectionPoolDeployer implements ResourceDeployer {
+ private static Logger _logger = LogDomains.getLogger(JdbcConnectionPoolDeployer.class, LogDomains.RSR_LOGGER);
+ private static StringManager sm = StringManager.getManager(JdbcConnectionPoolDeployer.class);
+ private static String msg = sm.getString("resource.restart_needed");
+ private static final Locale locale = Locale.getDefault();
+
@Inject
private ConnectorRuntime runtime;
@Inject
- @Optional //we need it only in server mode
+ @Optional // we need it only in server mode
private Domain domain;
- static private StringManager sm = StringManager.getManager(
- JdbcConnectionPoolDeployer.class);
- static private String msg = sm.getString("resource.restart_needed");
-
- static private Logger _logger = LogDomains.getLogger(JdbcConnectionPoolDeployer.class,LogDomains.RSR_LOGGER);
-
- private static final Locale locale = Locale.getDefault();
-
- private ExecutorService execService =
- Executors.newSingleThreadExecutor(new ThreadFactory() {
- public Thread newThread(Runnable r) {
- return new Thread(r);
- }
+ private ExecutorService execService = Executors.newSingleThreadExecutor(new ThreadFactory() {
+ @Override
+ public Thread newThread(Runnable r) {
+ return new Thread(r);
+ }
});
- /**
- * {@inheritDoc}
- */
+ @Override
public void deployResource(Object resource, String applicationName, String moduleName) throws Exception {
- //deployResource is not synchronized as there is only one caller
- //ResourceProxy which is synchronized
+ // deployResource is not synchronized as there is only one caller
+ // ResourceProxy which is synchronized
- //intentional no-op
- //From 8.1 PE/SE/EE, JDBC connection pools are no more resources and
- //they would be available only to server instances that have a resoruce-ref
- //that maps to a pool. So deploy resource would not be called during
- //JDBC connection pool creation. The actualDeployResource method
- //below is invoked by JdbcResourceDeployer when a resource-ref for a
- //resource that is pointed to this pool is added to a server instance
- JdbcConnectionPool jcp = (JdbcConnectionPool)resource;
- PoolInfo poolInfo = new PoolInfo(jcp.getName(), applicationName, moduleName);
- if(_logger.isLoggable(Level.FINE)){
- _logger.fine(" JdbcConnectionPoolDeployer - deployResource : " + poolInfo + " calling actualDeploy");
- }
+ // intentional no-op
+ // From 8.1 PE/SE/EE, JDBC connection pools are no more resources and
+ // they would be available only to server instances that have a resource-ref
+ // that maps to a pool. So deploy resource would not be called during
+ // JDBC connection pool creation. The actualDeployResource method
+ // below is invoked by JdbcResourceDeployer when a resource-ref for a
+ // resource that is pointed to this pool is added to a server instance
+
+ JdbcConnectionPool jdbcConnectionPool = (JdbcConnectionPool) resource;
+ PoolInfo poolInfo = new PoolInfo(jdbcConnectionPool.getName(), applicationName, moduleName);
+ _logger.fine(() -> " JdbcConnectionPoolDeployer - deployResource : " + poolInfo + " calling actualDeploy");
+
actualDeployResource(resource, poolInfo);
}
- /**
- * {@inheritDoc}
- */
+ @Override
public void deployResource(Object resource) throws Exception {
-
- JdbcConnectionPool jcp = (JdbcConnectionPool)resource;
- PoolInfo poolInfo = ConnectorsUtil.getPoolInfo(jcp);
+ JdbcConnectionPool jdbcConnectionPool = (JdbcConnectionPool) resource;
+ PoolInfo poolInfo = ConnectorsUtil.getPoolInfo(jdbcConnectionPool);
actualDeployResource(resource, poolInfo);
}
- /**
- * {@inheritDoc}
- */
- public boolean canDeploy(boolean postApplicationDeployment, Collection<Resource> allResources, Resource resource){
- if(handles(resource)){
- if(!postApplicationDeployment){
+ @Override
+ public boolean canDeploy(boolean postApplicationDeployment, Collection<Resource> allResources, Resource resource) {
+ if (handles(resource)) {
+ if (!postApplicationDeployment) {
return true;
}
}
+
return false;
}
@@ -143,390 +165,320 @@
* @throws Exception thrown if fail
*/
public void actualDeployResource(Object resource, PoolInfo poolInfo) {
- if(_logger.isLoggable(Level.FINE)){
+ if (_logger.isLoggable(FINE)) {
_logger.fine(" JdbcConnectionPoolDeployer - actualDeployResource : " + poolInfo);
}
+
JdbcConnectionPool adminPool = (JdbcConnectionPool) resource;
try {
ConnectorConnectionPool connConnPool = createConnectorConnectionPool(adminPool, poolInfo);
registerTransparentDynamicReconfigPool(poolInfo, adminPool);
- //now do internal book keeping
+
+ // Now do internal book keeping
runtime.createConnectorConnectionPool(connConnPool);
} catch (Exception e) {
- Object params[] = new Object[]{poolInfo, e};
- _logger.log(Level.WARNING, "error.creating.jdbc.pool", params);
+ _logger.log(WARNING, "error.creating.jdbc.pool", new Object[] { poolInfo, e });
}
}
- //performance issue related fix : IT 15784
+ // performance issue related fix : IT 15784
private void registerTransparentDynamicReconfigPool(PoolInfo poolInfo, JdbcConnectionPool resourcePool) {
ConnectorRegistry registry = ConnectorRegistry.getInstance();
- if(ConnectorsUtil.isDynamicReconfigurationEnabled(resourcePool)){
+ if (ConnectorsUtil.isDynamicReconfigurationEnabled(resourcePool)) {
registry.addTransparentDynamicReconfigPool(poolInfo);
- }else{
+ } else {
registry.removeTransparentDynamicReconfigPool(poolInfo);
}
}
- /**
- * {@inheritDoc}
- */
- public void undeployResource(Object resource, String applicationName, String moduleName) throws Exception{
+ @Override
+ public void undeployResource(Object resource, String applicationName, String moduleName) throws Exception {
JdbcConnectionPool jdbcConnPool = (JdbcConnectionPool) resource;
PoolInfo poolInfo = new PoolInfo(jdbcConnPool.getName(), applicationName, moduleName);
- if(_logger.isLoggable(Level.FINE)) {
- _logger.fine(" JdbcConnectionPoolDeployer - unDeployResource : " +
- "calling actualUndeploy of " + poolInfo);
- }
+
+ _logger.fine(() -> " JdbcConnectionPoolDeployer - unDeployResource : " + "calling actualUndeploy of " + poolInfo);
actualUndeployResource(poolInfo);
}
- /**
- * {@inheritDoc}
- */
+ @Override
public synchronized void undeployResource(Object resource) throws Exception {
JdbcConnectionPool jdbcConnPool = (JdbcConnectionPool) resource;
PoolInfo poolInfo = ConnectorsUtil.getPoolInfo(jdbcConnPool);
- if(_logger.isLoggable(Level.FINE)) {
- _logger.fine(" JdbcConnectionPoolDeployer - unDeployResource : " +
- "calling actualUndeploy of " + poolInfo);
- }
+
+ _logger.fine(() -> " JdbcConnectionPoolDeployer - unDeployResource : " + "calling actualUndeploy of " + poolInfo);
actualUndeployResource(poolInfo);
}
- /**
- * {@inheritDoc}
- */
- public boolean handles(Object resource){
+ @Override
+ public boolean handles(Object resource) {
return resource instanceof JdbcConnectionPool;
}
- /**
- * @inheritDoc
- */
+ @Override
public boolean supportsDynamicReconfiguration() {
return true;
}
- /**
- * @inheritDoc
- */
+ @Override
public Class[] getProxyClassesForDynamicReconfiguration() {
- return new Class[]{com.sun.appserv.jdbc.DataSource.class};
+ return new Class[] { DataSource.class };
}
-
/**
* Undeploy the resource from the server's runtime naming context
*
* @param poolInfo a resource object
- * @throws UnsupportedOperationException Currently we are not supporting this method.
+ * @throws UnsupportedOperationException Currently we are not supporting this
+ * method.
*/
-
private synchronized void actualUndeployResource(PoolInfo poolInfo) throws Exception {
runtime.deleteConnectorConnectionPool(poolInfo);
- //performance issue related fix : IT 15784
+
+ // Performance issue related fix : IT 15784
ConnectorRegistry.getInstance().removeTransparentDynamicReconfigPool(poolInfo);
- if (_logger.isLoggable(Level.FINEST)) {
- _logger.finest("Pool Undeployed");
- }
+ _logger.finest("Pool Undeployed");
}
/**
- * Pull out the MCF configuration properties and return them as an array
- * of ConnectorConfigProperty
+ * Pull out the MCF configuration properties and return them as an array of
+ * ConnectorConfigProperty
*
- * @param adminPool - The JdbcConnectionPool to pull out properties from
- * @param conConnPool - ConnectorConnectionPool which will be used by Resource Pool
- * @param connDesc - The ConnectorDescriptor for this JDBC RA
+ * @param adminPool - The JdbcConnectionPool to pull out properties from
+ * @param connectorConnectionPool - ConnectorConnectionPool which will be used by Resource
+ * Pool
+ * @param connectorDescriptor - The ConnectorDescriptor for this JDBC RA
* @return ConnectorConfigProperty [] array of MCF Config properties specified
- * in this JDBC RA
+ * in this JDBC RA
*/
- private ConnectorConfigProperty [] getMCFConfigProperties(
- JdbcConnectionPool adminPool,
- ConnectorConnectionPool conConnPool, ConnectorDescriptor connDesc) {
-
- ArrayList propList = new ArrayList();
+ private ConnectorConfigProperty[] getMCFConfigProperties(JdbcConnectionPool adminPool, ConnectorConnectionPool connectorConnectionPool, ConnectorDescriptor connectorDescriptor) {
+ List<ConnectorConfigProperty> configProperties = new ArrayList<>();
if (adminPool.getResType() != null) {
- if (ConnectorConstants.JAVA_SQL_DRIVER.equals(adminPool.getResType())) {
- propList.add(new ConnectorConfigProperty("ClassName",
+ if (JAVA_SQL_DRIVER.equals(adminPool.getResType())) {
+ configProperties.add(new ConnectorConfigProperty("ClassName",
adminPool.getDriverClassname() == null ? "" : adminPool.getDriverClassname(),
- "The driver class name", "java.lang.String"));
+ "The driver class name",
+ "java.lang.String"));
} else {
- propList.add(new ConnectorConfigProperty("ClassName",
+ configProperties.add(new ConnectorConfigProperty("ClassName",
adminPool.getDatasourceClassname() == null ? "" : adminPool.getDatasourceClassname(),
- "The datasource class name", "java.lang.String"));
+ "The datasource class name",
+ "java.lang.String"));
}
} else {
- //When resType is null, one of these classnames would be specified
+ // When resType is null, one of these classnames would be specified
if (adminPool.getDriverClassname() != null) {
- propList.add(new ConnectorConfigProperty("ClassName",
+ configProperties.add(new ConnectorConfigProperty("ClassName",
adminPool.getDriverClassname() == null ? "" : adminPool.getDriverClassname(),
- "The driver class name", "java.lang.String"));
+ "The driver class name",
+ "java.lang.String"));
} else if (adminPool.getDatasourceClassname() != null) {
- propList.add(new ConnectorConfigProperty("ClassName",
+ configProperties.add(new ConnectorConfigProperty("ClassName",
adminPool.getDatasourceClassname() == null ? "" : adminPool.getDatasourceClassname(),
- "The datasource class name", "java.lang.String"));
+ "The datasource class name",
+ "java.lang.String"));
}
}
- propList.add(new ConnectorConfigProperty("ConnectionValidationRequired",
- adminPool.getIsConnectionValidationRequired() + "",
- "Is connection validation required",
+ configProperties.add(new ConnectorConfigProperty("ConnectionValidationRequired", adminPool.getIsConnectionValidationRequired() + "",
+ "Is connection validation required", "java.lang.String"));
+
+ configProperties.add(new ConnectorConfigProperty("ValidationMethod",
+ adminPool.getConnectionValidationMethod() == null ? "" : adminPool.getConnectionValidationMethod(),
+ "How the connection is validated", "java.lang.String"));
+
+ configProperties.add(new ConnectorConfigProperty("ValidationTableName",
+ adminPool.getValidationTableName() == null ? "" : adminPool.getValidationTableName(), "Validation Table name",
"java.lang.String"));
- propList.add(new ConnectorConfigProperty("ValidationMethod",
- adminPool.getConnectionValidationMethod() == null ? ""
- : adminPool.getConnectionValidationMethod(),
- "How the connection is validated",
+ configProperties.add(new ConnectorConfigProperty("ValidationClassName",
+ adminPool.getValidationClassname() == null ? "" : adminPool.getValidationClassname(), "Validation Class name",
"java.lang.String"));
- propList.add(new ConnectorConfigProperty("ValidationTableName",
- adminPool.getValidationTableName() == null
- ? "" : adminPool.getValidationTableName(),
- "Validation Table name",
+ configProperties.add(new ConnectorConfigProperty("TransactionIsolation",
+ adminPool.getTransactionIsolationLevel() == null ? "" : adminPool.getTransactionIsolationLevel(),
+ "Transaction Isolatin Level", "java.lang.String"));
+
+ configProperties.add(new ConnectorConfigProperty("GuaranteeIsolationLevel", adminPool.getIsIsolationLevelGuaranteed() + "",
+ "Transaction Isolation Guarantee", "java.lang.String"));
+
+ configProperties.add(new ConnectorConfigProperty("StatementWrapping", adminPool.getWrapJdbcObjects() + "", "Statement Wrapping",
"java.lang.String"));
- propList.add(new ConnectorConfigProperty("ValidationClassName",
- adminPool.getValidationClassname() == null
- ? "" : adminPool.getValidationClassname(),
- "Validation Class name",
+ configProperties.add(new ConnectorConfigProperty("StatementTimeout", adminPool.getStatementTimeoutInSeconds() + "", "Statement Timeout",
"java.lang.String"));
- propList.add(new ConnectorConfigProperty("TransactionIsolation",
- adminPool.getTransactionIsolationLevel() == null ? ""
- : adminPool.getTransactionIsolationLevel(),
- "Transaction Isolatin Level",
- "java.lang.String"));
+ PoolInfo poolInfo = connectorConnectionPool.getPoolInfo();
- propList.add(new ConnectorConfigProperty("GuaranteeIsolationLevel",
- adminPool.getIsIsolationLevelGuaranteed() + "",
- "Transaction Isolation Guarantee",
- "java.lang.String"));
+ configProperties.add(new ConnectorConfigProperty("PoolMonitoringSubTreeRoot",
+ ConnectorsUtil.getPoolMonitoringSubTreeRoot(poolInfo, true) + "", "Pool Monitoring Sub Tree Root", "java.lang.String"));
- propList.add(new ConnectorConfigProperty("StatementWrapping",
- adminPool.getWrapJdbcObjects() + "",
- "Statement Wrapping",
- "java.lang.String"));
-
-
- propList.add(new ConnectorConfigProperty("StatementTimeout",
- adminPool.getStatementTimeoutInSeconds() + "",
- "Statement Timeout",
- "java.lang.String"));
-
- PoolInfo poolInfo = conConnPool.getPoolInfo();
-
- propList.add(new ConnectorConfigProperty("PoolMonitoringSubTreeRoot",
- ConnectorsUtil.getPoolMonitoringSubTreeRoot(poolInfo, true) + "",
- "Pool Monitoring Sub Tree Root",
- "java.lang.String"));
-
- propList.add(new ConnectorConfigProperty("PoolName",
- poolInfo.getName() + "",
- "Pool Name",
- "java.lang.String"));
+ configProperties.add(new ConnectorConfigProperty("PoolName", poolInfo.getName() + "", "Pool Name", "java.lang.String"));
if (poolInfo.getApplicationName() != null) {
- propList.add(new ConnectorConfigProperty("ApplicationName",
- poolInfo.getApplicationName() + "",
- "Application Name",
+ configProperties.add(new ConnectorConfigProperty("ApplicationName", poolInfo.getApplicationName() + "", "Application Name",
"java.lang.String"));
}
if (poolInfo.getModuleName() != null) {
- propList.add(new ConnectorConfigProperty("ModuleName",
- poolInfo.getModuleName() + "",
- "Module name",
- "java.lang.String"));
+ configProperties.add(new ConnectorConfigProperty("ModuleName", poolInfo.getModuleName() + "", "Module name", "java.lang.String"));
}
- propList.add(new ConnectorConfigProperty("StatementCacheSize",
- adminPool.getStatementCacheSize() + "",
- "Statement Cache Size",
+ configProperties.add(new ConnectorConfigProperty("StatementCacheSize", adminPool.getStatementCacheSize() + "", "Statement Cache Size",
"java.lang.String"));
- propList.add(new ConnectorConfigProperty("StatementCacheType",
- adminPool.getStatementCacheType() + "",
- "Statement Cache Type",
+ configProperties.add(new ConnectorConfigProperty("StatementCacheType", adminPool.getStatementCacheType() + "", "Statement Cache Type",
"java.lang.String"));
- propList.add(new ConnectorConfigProperty("InitSql",
- adminPool.getInitSql() + "",
- "InitSql",
+ configProperties.add(new ConnectorConfigProperty("InitSql", adminPool.getInitSql() + "", "InitSql", "java.lang.String"));
+
+ configProperties.add(new ConnectorConfigProperty("SqlTraceListeners", adminPool.getSqlTraceListeners() + "", "Sql Trace Listeners",
"java.lang.String"));
- propList.add(new ConnectorConfigProperty("SqlTraceListeners",
- adminPool.getSqlTraceListeners() + "",
- "Sql Trace Listeners",
+ configProperties.add(new ConnectorConfigProperty("StatementLeakTimeoutInSeconds", adminPool.getStatementLeakTimeoutInSeconds() + "",
+ "Statement Leak Timeout in seconds", "java.lang.String"));
+
+ configProperties.add(new ConnectorConfigProperty("StatementLeakReclaim", adminPool.getStatementLeakReclaim() + "", "Statement Leak Reclaim",
"java.lang.String"));
- propList.add(new ConnectorConfigProperty("StatementLeakTimeoutInSeconds",
- adminPool.getStatementLeakTimeoutInSeconds() + "",
- "Statement Leak Timeout in seconds",
- "java.lang.String"));
+ // Dump user defined poperties into the list
+ Set<ConnectionDefDescriptor> connectionDefs = connectorDescriptor.getOutboundResourceAdapter().getConnectionDefs();
- propList.add(new ConnectorConfigProperty("StatementLeakReclaim",
- adminPool.getStatementLeakReclaim() + "",
- "Statement Leak Reclaim",
- "java.lang.String"));
-
- //dump user defined poperties into the list
- Set connDefDescSet = connDesc.getOutboundResourceAdapter().
- getConnectionDefs();
- //since this a 1.0 RAR, we will have only 1 connDefDesc
- if (connDefDescSet.size() != 1) {
- throw new MissingResourceException("Only one connDefDesc present",
- null, null);
+ // since this a 1.0 RAR, we will have only 1 connDefDesc
+ if (connectionDefs.size() != 1) {
+ throw new MissingResourceException("Only one connDefDesc present", null, null);
}
- Iterator iter = connDefDescSet.iterator();
+ Iterator<ConnectionDefDescriptor> iter = connectionDefs.iterator();
- //Now get the set of MCF config properties associated with each
- //connection-definition . Each element here is an EnviromnentProperty
- Set mcfConfigProps = null;
+ // Now get the set of MCF config properties associated with each
+ // connection-definition. Each element here is an EnviromnentProperty
+ Set<ConnectorConfigProperty> mcfConfigProps = null;
while (iter.hasNext()) {
- mcfConfigProps = ((ConnectionDefDescriptor) iter.next()).getConfigProperties();
+ mcfConfigProps = iter.next().getConfigProperties();
}
+
if (mcfConfigProps != null) {
- Map mcfConPropKeys = new HashMap();
- Iterator mcfConfigPropsIter = mcfConfigProps.iterator();
+ Map<String, String> mcfConPropKeys = new HashMap<>();
+ Iterator<ConnectorConfigProperty> mcfConfigPropsIter = mcfConfigProps.iterator();
while (mcfConfigPropsIter.hasNext()) {
- String key = ((ConnectorConfigProperty) mcfConfigPropsIter.next()).getName();
+ String key = mcfConfigPropsIter.next().getName();
mcfConPropKeys.put(key.toUpperCase(locale), key);
}
String driverProperties = "";
- for (Property rp : adminPool.getProperty()) {
- if (rp == null) {
+ for (Property adminPoolProperty : adminPool.getProperty()) {
+ if (adminPoolProperty == null) {
continue;
}
- String name = rp.getName();
- //The idea here is to convert the Environment Properties coming from
- //the admin connection pool to standard pool properties thereby
- //making it easy to compare in the event of a reconfig
+ String name = adminPoolProperty.getName();
+
+ // The idea here is to convert the Environment Properties coming from
+ // the admin connection pool to standard pool properties thereby
+ // making it easy to compare in the event of a reconfig
+
if ("MATCHCONNECTIONS".equals(name.toUpperCase(locale))) {
- //JDBC - matchConnections if not set is decided by the ConnectionManager
- //so default is false
- conConnPool.setMatchConnections(toBoolean(rp.getValue(), false));
+ // JDBC - matchConnections if not set is decided by the ConnectionManager
+ // so default is false
+ connectorConnectionPool.setMatchConnections(toBoolean(adminPoolProperty.getValue(), false));
logFine("MATCHCONNECTIONS");
} else if ("ASSOCIATEWITHTHREAD".equals(name.toUpperCase(locale))) {
- conConnPool.setAssociateWithThread(toBoolean(rp.getValue(), false));
+ connectorConnectionPool.setAssociateWithThread(toBoolean(adminPoolProperty.getValue(), false));
logFine("ASSOCIATEWITHTHREAD");
} else if ("LAZYCONNECTIONASSOCIATION".equals(name.toUpperCase(locale))) {
- ConnectionPoolObjectsUtils.setLazyEnlistAndLazyAssocProperties(rp.getValue(),
- adminPool.getProperty(), conConnPool);
+ setLazyEnlistAndLazyAssocProperties(adminPoolProperty.getValue(), adminPool.getProperty(), connectorConnectionPool);
logFine("LAZYCONNECTIONASSOCIATION");
} else if ("LAZYCONNECTIONENLISTMENT".equals(name.toUpperCase(Locale.getDefault()))) {
- conConnPool.setLazyConnectionEnlist(toBoolean(rp.getValue(), false));
+ connectorConnectionPool.setLazyConnectionEnlist(toBoolean(adminPoolProperty.getValue(), false));
logFine("LAZYCONNECTIONENLISTMENT");
} else if ("POOLDATASTRUCTURE".equals(name.toUpperCase(Locale.getDefault()))) {
- conConnPool.setPoolDataStructureType(rp.getValue());
+ connectorConnectionPool.setPoolDataStructureType(adminPoolProperty.getValue());
logFine("POOLDATASTRUCTURE");
- } else if (ConnectorConstants.DYNAMIC_RECONFIGURATION_FLAG.equals(name.toLowerCase(locale))) {
- String value = rp.getValue();
+ } else if (DYNAMIC_RECONFIGURATION_FLAG.equals(name.toLowerCase(locale))) {
+ String value = adminPoolProperty.getValue();
try {
- conConnPool.setDynamicReconfigWaitTimeout(Long.parseLong(rp.getValue()) * 1000L);
- logFine(ConnectorConstants.DYNAMIC_RECONFIGURATION_FLAG);
+ connectorConnectionPool.setDynamicReconfigWaitTimeout(Long.parseLong(adminPoolProperty.getValue()) * 1000L);
+ logFine(DYNAMIC_RECONFIGURATION_FLAG);
} catch (NumberFormatException nfe) {
- _logger.log(Level.WARNING, "Invalid value for "
- + "'" + ConnectorConstants.DYNAMIC_RECONFIGURATION_FLAG + "' : " + value);
+ _logger.log(WARNING,
+ "Invalid value for " + "'" + DYNAMIC_RECONFIGURATION_FLAG + "' : " + value);
}
} else if ("POOLWAITQUEUE".equals(name.toUpperCase(locale))) {
- conConnPool.setPoolWaitQueue(rp.getValue());
+ connectorConnectionPool.setPoolWaitQueue(adminPoolProperty.getValue());
logFine("POOLWAITQUEUE");
} else if ("DATASTRUCTUREPARAMETERS".equals(name.toUpperCase(locale))) {
- conConnPool.setDataStructureParameters(rp.getValue());
+ connectorConnectionPool.setDataStructureParameters(adminPoolProperty.getValue());
logFine("DATASTRUCTUREPARAMETERS");
- } else if ("USERNAME".equals(name.toUpperCase(Locale.getDefault()))
- || "USER".equals(name.toUpperCase(locale))) {
-
- propList.add(new ConnectorConfigProperty("User",
- rp.getValue(), "user name", "java.lang.String"));
+ } else if ("USERNAME".equals(name.toUpperCase(Locale.getDefault())) || "USER".equals(name.toUpperCase(locale))) {
+ configProperties.add(new ConnectorConfigProperty("User", adminPoolProperty.getValue(), "user name", "java.lang.String"));
} else if ("PASSWORD".equals(name.toUpperCase(locale))) {
-
- propList.add(new ConnectorConfigProperty("Password",
- rp.getValue(), "Password", "java.lang.String"));
+ configProperties.add(new ConnectorConfigProperty("Password", adminPoolProperty.getValue(), "Password", "java.lang.String"));
} else if ("JDBC30DATASOURCE".equals(name.toUpperCase(locale))) {
-
- propList.add(new ConnectorConfigProperty("JDBC30DataSource",
- rp.getValue(), "JDBC30DataSource", "java.lang.String"));
+ configProperties.add(new ConnectorConfigProperty("JDBC30DataSource", adminPoolProperty.getValue(), "JDBC30DataSource", "java.lang.String"));
} else if ("PREFER-VALIDATE-OVER-RECREATE".equals(name.toUpperCase(Locale.getDefault()))) {
- String value = rp.getValue();
- conConnPool.setPreferValidateOverRecreate(toBoolean(value, false));
+ String value = adminPoolProperty.getValue();
+ connectorConnectionPool.setPreferValidateOverRecreate(toBoolean(value, false));
logFine("PREFER-VALIDATE-OVER-RECREATE : " + value);
} else if ("STATEMENT-CACHE-TYPE".equals(name.toUpperCase(Locale.getDefault()))) {
-
if (adminPool.getStatementCacheType() != null) {
- propList.add(new ConnectorConfigProperty("StatementCacheType", rp.getValue(),
- "StatementCacheType", "java.lang.String"));
+ configProperties.add(
+ new ConnectorConfigProperty("StatementCacheType", adminPoolProperty.getValue(), "StatementCacheType", "java.lang.String"));
}
} else if ("NUMBER-OF-TOP-QUERIES-TO-REPORT".equals(name.toUpperCase(Locale.getDefault()))) {
-
- propList.add(new ConnectorConfigProperty("NumberOfTopQueriesToReport",
- rp.getValue(), "NumberOfTopQueriesToReport", "java.lang.String"));
+ configProperties.add(new ConnectorConfigProperty("NumberOfTopQueriesToReport", adminPoolProperty.getValue(), "NumberOfTopQueriesToReport",
+ "java.lang.String"));
} else if ("TIME-TO-KEEP-QUERIES-IN-MINUTES".equals(name.toUpperCase(Locale.getDefault()))) {
-
- propList.add(new ConnectorConfigProperty("TimeToKeepQueriesInMinutes",
- rp.getValue(), "TimeToKeepQueriesInMinutes", "java.lang.String"));
+ configProperties.add(new ConnectorConfigProperty("TimeToKeepQueriesInMinutes", adminPoolProperty.getValue(), "TimeToKeepQueriesInMinutes",
+ "java.lang.String"));
} else if (mcfConPropKeys.containsKey(name.toUpperCase(Locale.getDefault()))) {
-
- propList.add(new ConnectorConfigProperty(
- (String) mcfConPropKeys.get(name.toUpperCase(Locale.getDefault())),
- rp.getValue() == null ? "" : rp.getValue(),
- "Some property",
- "java.lang.String"));
+ configProperties.add(new ConnectorConfigProperty(mcfConPropKeys.get(name.toUpperCase(Locale.getDefault())),
+ adminPoolProperty.getValue() == null ? "" : adminPoolProperty.getValue(), "Some property", "java.lang.String"));
} else {
- driverProperties = driverProperties + "set" + escape(name)
- + "#" + escape(rp.getValue()) + "##";
+ driverProperties = driverProperties + "set" + escape(name) + "#" + escape(adminPoolProperty.getValue()) + "##";
}
}
if (!driverProperties.equals("")) {
- propList.add(new ConnectorConfigProperty("DriverProperties",
- driverProperties,
+ configProperties.add(
+ new ConnectorConfigProperty(
+ "DriverProperties", driverProperties,
"some proprietarty properties",
"java.lang.String"));
}
}
+ configProperties.add(new ConnectorConfigProperty("Delimiter", "#", "delim", "java.lang.String"));
+ configProperties.add(new ConnectorConfigProperty("EscapeCharacter", "\\", "escapeCharacter", "java.lang.String"));
- propList.add(new ConnectorConfigProperty("Delimiter",
- "#", "delim", "java.lang.String"));
-
- propList.add(new ConnectorConfigProperty("EscapeCharacter",
- "\\", "escapeCharacter", "java.lang.String"));
-
- //create an array of EnvironmentProperties from above list
- ConnectorConfigProperty[] eProps = new ConnectorConfigProperty[propList.size()];
- ListIterator propListIter = propList.listIterator();
+ // Create an array of EnvironmentProperties from above list
+ ConnectorConfigProperty[] environmentProperties = new ConnectorConfigProperty[configProperties.size()];
+ ListIterator<ConnectorConfigProperty> propListIter = configProperties.listIterator();
for (int i = 0; propListIter.hasNext(); i++) {
- eProps[i] = (ConnectorConfigProperty) propListIter.next();
+ environmentProperties[i] = propListIter.next();
}
- return eProps;
-
+ return environmentProperties;
}
/**
- * To escape the "delimiter" characters that are internally used by Connector & JDBCRA.
+ * To escape the "delimiter" characters that are internally used by Connector &
+ * JDBCRA.
*
* @param value String that need to be escaped
* @return Escaped value
@@ -542,222 +494,182 @@
return value;
}
-
- private boolean toBoolean(Object prop, boolean defaultVal) {
- if (prop == null) {
- return defaultVal;
+ private boolean toBoolean(Object property, boolean defaultValue) {
+ if (property == null) {
+ return defaultValue;
}
- return Boolean.valueOf(((String) prop).toLowerCase(locale));
+ return Boolean.valueOf(((String) property).toLowerCase(locale));
}
/**
* Use this method if the string being passed does not <br>
* involve multiple concatenations<br>
- * Avoid using this method in exception-catch blocks as they
- * are not frequently executed <br>
+ * Avoid using this method in exception-catch blocks as they are not frequently
+ * executed <br>
*
* @param msg
*/
private void logFine(String msg) {
- if (_logger.isLoggable(Level.FINE) && msg != null) {
+ if (_logger.isLoggable(FINE) && msg != null) {
_logger.fine(msg);
}
}
- public ConnectorConnectionPool createConnectorConnectionPool(JdbcConnectionPool adminPool, PoolInfo poolInfo)
- throws ConnectorRuntimeException {
-
+ public ConnectorConnectionPool createConnectorConnectionPool(JdbcConnectionPool adminPool, PoolInfo poolInfo) throws ConnectorRuntimeException {
String moduleName = JdbcResourcesUtil.createInstance().getRANameofJdbcConnectionPool(adminPool);
int txSupport = getTxSupport(moduleName);
- ConnectorDescriptor connDesc = runtime.getConnectorDescriptor(moduleName);
+ ConnectorDescriptor connectorDescriptor = runtime.getConnectorDescriptor(moduleName);
- //Create the connector Connection Pool object from the configbean object
- ConnectorConnectionPool conConnPool = new ConnectorConnectionPool(poolInfo);
+ // Create the connector Connection Pool object from the configbean object
+ ConnectorConnectionPool connectorConnectionPool = new ConnectorConnectionPool(poolInfo);
- conConnPool.setTransactionSupport(txSupport);
- setConnectorConnectionPoolAttributes(conConnPool, adminPool);
+ connectorConnectionPool.setTransactionSupport(txSupport);
+ setConnectorConnectionPoolAttributes(connectorConnectionPool, adminPool);
- //Initially create the ConnectorDescriptor
- ConnectorDescriptorInfo connDescInfo =
- createConnectorDescriptorInfo(connDesc, moduleName);
+ // Initially create the ConnectorDescriptor
+ ConnectorDescriptorInfo connectorDescriptorInfo = createConnectorDescriptorInfo(connectorDescriptor, moduleName);
+ connectorDescriptorInfo.setMCFConfigProperties(getMCFConfigProperties(adminPool, connectorConnectionPool, connectorDescriptor));
- connDescInfo.setMCFConfigProperties(
- getMCFConfigProperties(adminPool, conConnPool, connDesc));
+ // Since we are deploying a 1.0 RAR, this is null
+ connectorDescriptorInfo.setResourceAdapterConfigProperties((Set) null);
- //since we are deploying a 1.0 RAR, this is null
- connDescInfo.setResourceAdapterConfigProperties((Set) null);
+ connectorConnectionPool.setConnectorDescriptorInfo(connectorDescriptorInfo);
- conConnPool.setConnectorDescriptorInfo(connDescInfo);
-
- return conConnPool;
+ return connectorConnectionPool;
}
-
private int getTxSupport(String moduleName) {
- if (ConnectorConstants.JDBCXA_RA_NAME.equals(moduleName)) {
- return ConnectionPoolObjectsUtils.parseTransactionSupportString(
- ConnectorConstants.XA_TRANSACTION_TX_SUPPORT_STRING );
+ if (JDBCXA_RA_NAME.equals(moduleName)) {
+ return ConnectionPoolObjectsUtils.parseTransactionSupportString(XA_TRANSACTION_TX_SUPPORT_STRING);
}
- return ConnectionPoolObjectsUtils.parseTransactionSupportString(
- ConnectorConstants.LOCAL_TRANSACTION_TX_SUPPORT_STRING);
+
+ return ConnectionPoolObjectsUtils.parseTransactionSupportString(LOCAL_TRANSACTION_TX_SUPPORT_STRING);
}
- private ConnectorDescriptorInfo createConnectorDescriptorInfo(
- ConnectorDescriptor connDesc, String moduleName) {
- ConnectorDescriptorInfo connDescInfo = new ConnectorDescriptorInfo();
+ private ConnectorDescriptorInfo createConnectorDescriptorInfo(ConnectorDescriptor connectorDescriptor, String moduleName) {
+ ConnectorDescriptorInfo connectorDescriptorInfo = new ConnectorDescriptorInfo();
- connDescInfo.setManagedConnectionFactoryClass(
- connDesc.getOutboundResourceAdapter().
- getManagedConnectionFactoryImpl());
+ connectorDescriptorInfo.setManagedConnectionFactoryClass(connectorDescriptor.getOutboundResourceAdapter().getManagedConnectionFactoryImpl());
+ connectorDescriptorInfo.setRarName(moduleName);
+ connectorDescriptorInfo.setResourceAdapterClassName(connectorDescriptor.getResourceAdapterClass());
+ connectorDescriptorInfo.setConnectionDefinitionName(connectorDescriptor.getOutboundResourceAdapter().getConnectionFactoryIntf());
+ connectorDescriptorInfo.setConnectionFactoryClass(connectorDescriptor.getOutboundResourceAdapter().getConnectionFactoryImpl());
+ connectorDescriptorInfo.setConnectionFactoryInterface(connectorDescriptor.getOutboundResourceAdapter().getConnectionFactoryIntf());
+ connectorDescriptorInfo.setConnectionClass(connectorDescriptor.getOutboundResourceAdapter().getConnectionImpl());
+ connectorDescriptorInfo.setConnectionInterface(connectorDescriptor.getOutboundResourceAdapter().getConnectionIntf());
- connDescInfo.setRarName(moduleName);
-
- connDescInfo.setResourceAdapterClassName(connDesc.
- getResourceAdapterClass());
-
- connDescInfo.setConnectionDefinitionName(
- connDesc.getOutboundResourceAdapter().getConnectionFactoryIntf());
-
- connDescInfo.setConnectionFactoryClass(
- connDesc.getOutboundResourceAdapter().getConnectionFactoryImpl());
-
- connDescInfo.setConnectionFactoryInterface(
- connDesc.getOutboundResourceAdapter().getConnectionFactoryIntf());
-
- connDescInfo.setConnectionClass(
- connDesc.getOutboundResourceAdapter().getConnectionImpl());
-
- connDescInfo.setConnectionInterface(
- connDesc.getOutboundResourceAdapter().getConnectionIntf());
-
- return connDescInfo;
+ return connectorDescriptorInfo;
}
- private void setConnectorConnectionPoolAttributes(ConnectorConnectionPool ccp, JdbcConnectionPool adminPool) {
- String poolName = ccp.getName();
- ccp.setMaxPoolSize(adminPool.getMaxPoolSize());
- ccp.setSteadyPoolSize(adminPool.getSteadyPoolSize());
- ccp.setMaxWaitTimeInMillis(adminPool.getMaxWaitTimeInMillis());
+ private void setConnectorConnectionPoolAttributes(ConnectorConnectionPool connectorConnectionPool, JdbcConnectionPool adminPool) {
+ String poolName = connectorConnectionPool.getName();
- ccp.setPoolResizeQuantity(adminPool.getPoolResizeQuantity());
+ connectorConnectionPool.setMaxPoolSize(adminPool.getMaxPoolSize());
+ connectorConnectionPool.setSteadyPoolSize(adminPool.getSteadyPoolSize());
+ connectorConnectionPool.setMaxWaitTimeInMillis(adminPool.getMaxWaitTimeInMillis());
+ connectorConnectionPool.setPoolResizeQuantity(adminPool.getPoolResizeQuantity());
+ connectorConnectionPool.setIdleTimeoutInSeconds(adminPool.getIdleTimeoutInSeconds());
+ connectorConnectionPool.setFailAllConnections(Boolean.valueOf(adminPool.getFailAllConnections()));
+ connectorConnectionPool.setConnectionValidationRequired(Boolean.valueOf(adminPool.getIsConnectionValidationRequired()));
+ connectorConnectionPool.setNonTransactional(Boolean.valueOf(adminPool.getNonTransactionalConnections()));
+ connectorConnectionPool.setNonComponent(Boolean.valueOf(adminPool.getAllowNonComponentCallers()));
+ connectorConnectionPool.setPingDuringPoolCreation(Boolean.valueOf(adminPool.getPing()));
- ccp.setIdleTimeoutInSeconds(adminPool.getIdleTimeoutInSeconds());
-
- ccp.setFailAllConnections(Boolean.valueOf(adminPool.getFailAllConnections()));
-
- ccp.setConnectionValidationRequired(Boolean.valueOf(adminPool.getIsConnectionValidationRequired()));
-
- ccp.setNonTransactional(Boolean.valueOf(adminPool.getNonTransactionalConnections()));
- ccp.setNonComponent(Boolean.valueOf(adminPool.getAllowNonComponentCallers()));
-
- ccp.setPingDuringPoolCreation(Boolean.valueOf(adminPool.getPing()));
- //These are default properties of all Jdbc pools
- //So set them here first and then figure out from the parsing routine
- //if they need to be reset
- ccp.setMatchConnections(Boolean.valueOf(adminPool.getMatchConnections()));
- ccp.setAssociateWithThread(Boolean.valueOf(adminPool.getAssociateWithThread()));
- ccp.setConnectionLeakTracingTimeout(adminPool.getConnectionLeakTimeoutInSeconds());
- ccp.setConnectionReclaim(Boolean.valueOf(adminPool.getConnectionLeakReclaim()));
+ // These are default properties of all Jdbc pools
+ // So set them here first and then figure out from the parsing routine
+ // if they need to be reset
+ connectorConnectionPool.setMatchConnections(Boolean.valueOf(adminPool.getMatchConnections()));
+ connectorConnectionPool.setAssociateWithThread(Boolean.valueOf(adminPool.getAssociateWithThread()));
+ connectorConnectionPool.setConnectionLeakTracingTimeout(adminPool.getConnectionLeakTimeoutInSeconds());
+ connectorConnectionPool.setConnectionReclaim(Boolean.valueOf(adminPool.getConnectionLeakReclaim()));
boolean lazyConnectionEnlistment = Boolean.valueOf(adminPool.getLazyConnectionEnlistment());
boolean lazyConnectionAssociation = Boolean.valueOf(adminPool.getLazyConnectionAssociation());
- //lazy-connection-enlistment need to be ON for lazy-connection-association to work.
+ // lazy-connection-enlistment need to be ON for lazy-connection-association to
+ // work.
if (lazyConnectionAssociation) {
if (lazyConnectionEnlistment) {
- ccp.setLazyConnectionAssoc(true);
- ccp.setLazyConnectionEnlist(true);
+ connectorConnectionPool.setLazyConnectionAssoc(true);
+ connectorConnectionPool.setLazyConnectionEnlist(true);
} else {
- _logger.log(Level.SEVERE, "conn_pool_obj_utils.lazy_enlist-lazy_assoc-invalid-combination",
- poolName);
- String i18nMsg = sm.getString(
- "cpou.lazy_enlist-lazy_assoc-invalid-combination", poolName);
- throw new RuntimeException(i18nMsg);
+ _logger.log(SEVERE, "conn_pool_obj_utils.lazy_enlist-lazy_assoc-invalid-combination", poolName);
+ throw new RuntimeException(sm.getString("cpou.lazy_enlist-lazy_assoc-invalid-combination", poolName));
}
} else {
- ccp.setLazyConnectionAssoc(lazyConnectionAssociation);
- ccp.setLazyConnectionEnlist(lazyConnectionEnlistment);
+ connectorConnectionPool.setLazyConnectionAssoc(lazyConnectionAssociation);
+ connectorConnectionPool.setLazyConnectionEnlist(lazyConnectionEnlistment);
}
boolean pooling = Boolean.valueOf(adminPool.getPooling());
- if(!pooling) {
- //Throw exception if assoc with thread is set to true.
- if(Boolean.valueOf(adminPool.getAssociateWithThread())) {
- _logger.log(Level.SEVERE, "conn_pool_obj_utils.pooling_disabled_assocwiththread_invalid_combination",
- poolName);
- String i18nMsg = sm.getString(
- "cpou.pooling_disabled_assocwiththread_invalid_combination", poolName);
- throw new RuntimeException(i18nMsg);
+ if (!pooling) {
+ // Throw exception if assoc with thread is set to true.
+ if (Boolean.valueOf(adminPool.getAssociateWithThread())) {
+ _logger.log(SEVERE, "conn_pool_obj_utils.pooling_disabled_assocwiththread_invalid_combination", poolName);
+ throw new RuntimeException(sm.getString("cpou.pooling_disabled_assocwiththread_invalid_combination", poolName));
}
- //Below are useful in pooled environment only.
- //Throw warning for connection validation/validate-atmost-once/
- //match-connections/max-connection-usage-count/idele-timeout
- if(Boolean.valueOf(adminPool.getIsConnectionValidationRequired())) {
- _logger.log(Level.WARNING, "conn_pool_obj_utils.pooling_disabled_conn_validation_invalid_combination",
- poolName);
+ // Below are useful in pooled environment only.
+ // Throw warning for connection validation/validate-atmost-once/
+ // match-connections/max-connection-usage-count/idele-timeout
+ if (Boolean.valueOf(adminPool.getIsConnectionValidationRequired())) {
+ _logger.log(WARNING, "conn_pool_obj_utils.pooling_disabled_conn_validation_invalid_combination", poolName);
}
- if(Integer.parseInt(adminPool.getValidateAtmostOncePeriodInSeconds()) > 0) {
- _logger.log(Level.WARNING, "conn_pool_obj_utils.pooling_disabled_validate_atmost_once_invalid_combination",
- poolName);
+ if (Integer.parseInt(adminPool.getValidateAtmostOncePeriodInSeconds()) > 0) {
+ _logger.log(WARNING, "conn_pool_obj_utils.pooling_disabled_validate_atmost_once_invalid_combination", poolName);
}
- if(Boolean.valueOf(adminPool.getMatchConnections())) {
- _logger.log(Level.WARNING, "conn_pool_obj_utils.pooling_disabled_match_connections_invalid_combination",
- poolName);
+ if (Boolean.valueOf(adminPool.getMatchConnections())) {
+ _logger.log(WARNING, "conn_pool_obj_utils.pooling_disabled_match_connections_invalid_combination", poolName);
}
- if(Integer.parseInt(adminPool.getMaxConnectionUsageCount()) > 0) {
- _logger.log(Level.WARNING, "conn_pool_obj_utils.pooling_disabled_max_conn_usage_invalid_combination",
- poolName);
+ if (Integer.parseInt(adminPool.getMaxConnectionUsageCount()) > 0) {
+ _logger.log(WARNING, "conn_pool_obj_utils.pooling_disabled_max_conn_usage_invalid_combination", poolName);
}
- if(Integer.parseInt(adminPool.getIdleTimeoutInSeconds()) > 0) {
- _logger.log(Level.WARNING, "conn_pool_obj_utils.pooling_disabled_idle_timeout_invalid_combination",
- poolName);
+ if (Integer.parseInt(adminPool.getIdleTimeoutInSeconds()) > 0) {
+ _logger.log(WARNING, "conn_pool_obj_utils.pooling_disabled_idle_timeout_invalid_combination", poolName);
}
}
- ccp.setPooling(pooling);
- ccp.setMaxConnectionUsage(adminPool.getMaxConnectionUsageCount());
- ccp.setConCreationRetryAttempts(adminPool.getConnectionCreationRetryAttempts());
- ccp.setConCreationRetryInterval(
- adminPool.getConnectionCreationRetryIntervalInSeconds());
+ connectorConnectionPool.setPooling(pooling);
+ connectorConnectionPool.setMaxConnectionUsage(adminPool.getMaxConnectionUsageCount());
- ccp.setValidateAtmostOncePeriod(adminPool.getValidateAtmostOncePeriodInSeconds());
+ connectorConnectionPool.setConCreationRetryAttempts(adminPool.getConnectionCreationRetryAttempts());
+ connectorConnectionPool.setConCreationRetryInterval(adminPool.getConnectionCreationRetryIntervalInSeconds());
+
+ connectorConnectionPool.setValidateAtmostOncePeriod(adminPool.getValidateAtmostOncePeriodInSeconds());
}
/**
* {@inheritDoc}
*/
+ @Override
public synchronized void redeployResource(Object resource) throws Exception {
-
final JdbcConnectionPool adminPool = (JdbcConnectionPool) resource;
PoolInfo poolInfo = ConnectorsUtil.getPoolInfo(adminPool);
- //Only if pool has already been deployed in this server-instance
- //reconfig this pool
+ // Only if pool has already been deployed in this server-instance
+ // reconfig this pool
if (!runtime.isConnectorConnectionPoolDeployed(poolInfo)) {
- if(_logger.isLoggable(Level.FINE)) {
- _logger.fine("The JDBC connection pool " + poolInfo
- + " is not referred or not yet created in this server "
- + "instance and hence pool redeployment is ignored");
- }
+ _logger.fine(() ->
+ "The JDBC connection pool " + poolInfo + " is not referred or not yet created in this server " +
+ "instance and hence pool redeployment is ignored");
return;
}
- final ConnectorConnectionPool connConnPool = createConnectorConnectionPool(adminPool, poolInfo);
-
- if (connConnPool == null) {
- throw new ConnectorRuntimeException("Unable to create ConnectorConnectionPool " +
- "from JDBC connection pool");
+ final ConnectorConnectionPool connectorConnectionPool = createConnectorConnectionPool(adminPool, poolInfo);
+ if (connectorConnectionPool == null) {
+ throw new ConnectorRuntimeException("Unable to create ConnectorConnectionPool " + "from JDBC connection pool");
}
- //now do internal book keeping
- HashSet excludes = new HashSet();
- //add MCF config props to the set that need to be excluded
- //in checking for the equality of the props with old pool
+ // Now do internal book keeping
+
+ Set<String> excludes = new HashSet<>();
+
+ // Add MCF config props to the set that need to be excluded
+ // in checking for the equality of the props with old pool
excludes.add("TransactionIsolation");
excludes.add("GuaranteeIsolationLevel");
excludes.add("ValidationTableName");
@@ -771,22 +683,18 @@
excludes.add("StatementLeakTimeoutInSeconds");
excludes.add("StatementLeakReclaim");
-
try {
- if(_logger.isLoggable(Level.FINEST)) {
- _logger.finest("Calling reconfigure pool");
- }
- boolean requirePoolRecreation = runtime.reconfigureConnectorConnectionPool(connConnPool, excludes);
+ _logger.finest("Calling reconfigure pool");
+ boolean requirePoolRecreation = runtime.reconfigureConnectorConnectionPool(connectorConnectionPool, excludes);
if (requirePoolRecreation) {
if (runtime.isServer() || runtime.isEmbedded()) {
- handlePoolRecreation(connConnPool);
- }else{
- recreatePool(connConnPool);
+ handlePoolRecreation(connectorConnectionPool);
+ } else {
+ recreatePool(connectorConnectionPool);
}
}
} catch (ConnectorRuntimeException cre) {
- Object params[] = new Object[]{poolInfo, cre};
- _logger.log(Level.WARNING, "error.redeploying.jdbc.pool", params);
+ _logger.log(WARNING, "error.redeploying.jdbc.pool", new Object[] { poolInfo, cre });
throw cre;
}
}
@@ -795,29 +703,27 @@
debug("[DRC] Pool recreation required");
final long reconfigWaitTimeout = connConnPool.getDynamicReconfigWaitTimeout();
- PoolInfo poolInfo = new PoolInfo(connConnPool.getName(), connConnPool.getApplicationName(),
- connConnPool.getModuleName());
+ PoolInfo poolInfo = new PoolInfo(connConnPool.getName(), connConnPool.getApplicationName(), connConnPool.getModuleName());
final ResourcePool oldPool = runtime.getPoolManager().getPool(poolInfo);
if (reconfigWaitTimeout > 0) {
-
oldPool.blockRequests(reconfigWaitTimeout);
if (oldPool.getPoolWaitQueue().getQueueLength() > 0 || oldPool.getPoolStatus().getNumConnUsed() > 0) {
Runnable thread = new Runnable() {
+ @Override
public void run() {
try {
- long numSeconds = 5000L ; //poll every 5 seconds
- long steps = reconfigWaitTimeout/numSeconds;
- if(steps == 0){
+ long numSeconds = 5000L; // poll every 5 seconds
+ long steps = reconfigWaitTimeout / numSeconds;
+ if (steps == 0) {
waitForCompletion(steps, oldPool, reconfigWaitTimeout);
- }else{
+ } else {
for (long i = 0; i < steps; i++) {
waitForCompletion(steps, oldPool, reconfigWaitTimeout);
- if (oldPool.getPoolWaitQueue().getQueueLength() == 0 &&
- oldPool.getPoolStatus().getNumConnUsed() == 0) {
+ if (oldPool.getPoolWaitQueue().getQueueLength() == 0 && oldPool.getPoolStatus().getNumConnUsed() == 0) {
debug("wait-queue is empty and num-con-used is 0");
break;
}
@@ -837,81 +743,76 @@
}
}
} catch (InterruptedException ie) {
- if(_logger.isLoggable(Level.FINEST)) {
- _logger.log(Level.FINEST,
+ _logger.log(FINEST,
"Interrupted while waiting for all existing clients to return connections to pool", ie);
- }
}
- if(_logger.isLoggable(Level.FINEST)){
- _logger.finest("woke-up after giving time for in-use connections to return, " +
- "WaitQueue-Length : ["+oldPool.getPoolWaitQueue().getQueueContents()+"], " +
- "Num-Conn-Used : ["+oldPool.getPoolStatus().getNumConnUsed()+"]");
- }
- }
+ _logger.finest(() ->
+ "woke-up after giving time for in-use connections to return, " +
+ "WaitQueue-Length : [" + oldPool.getPoolWaitQueue().getQueueContents() + "], " +
+ "Num-Conn-Used : [" + oldPool.getPoolStatus().getNumConnUsed() + "]");
+ }
};
- Callable c = Executors.callable(thread);
- ArrayList list = new ArrayList();
- list.add(c);
- try{
- execService.invokeAll(list);
- }catch(Exception e){
- Object[] params = new Object[]{connConnPool.getName(), e};
- _logger.log(Level.WARNING,"exception.redeploying.pool.transparently", params);
+ try {
+ execService.invokeAll(asList(callable(thread)));
+ } catch (Exception e) {
+ _logger.log(WARNING, "exception.redeploying.pool.transparently", new Object[] { connConnPool.getName(), e });
}
- }else{
+ } else {
handlePoolRecreationForExistingProxies(connConnPool);
}
- } else if(oldPool.getReconfigWaitTime() > 0){
- //reconfig is being switched off, invalidate proxies
- Collection<BindableResource> resources =
- JdbcResourcesUtil.getResourcesOfPool(runtime.getResources(oldPool.getPoolInfo()), oldPool.getPoolInfo().getName());
+ } else if (oldPool.getReconfigWaitTime() > 0) {
+ // Reconfig is being switched off, invalidate proxies
+ Collection<BindableResource> resources = getResourcesOfPool(
+ runtime.getResources(oldPool.getPoolInfo()),
+ oldPool.getPoolInfo().getName());
+
ConnectorRegistry registry = ConnectorRegistry.getInstance();
- for(BindableResource resource : resources){
- ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(resource);
- registry.removeResourceFactories(resourceInfo);
+ for (BindableResource resource : resources) {
+ registry.removeResourceFactories(getResourceInfo(resource));
}
- //recreate the pool now.
+
+ // Recreate the pool now.
recreatePool(connConnPool);
- }else {
+ } else {
recreatePool(connConnPool);
}
}
private void waitForCompletion(long steps, ResourcePool oldPool, long totalWaitTime) throws InterruptedException {
debug("waiting for in-use connections to return to pool or waiting requests to complete");
- try{
+
+ try {
Object poolWaitQueue = oldPool.getPoolWaitQueue();
- synchronized(poolWaitQueue){
- long waitTime = totalWaitTime/steps;
- if(waitTime > 0) {
+ synchronized (poolWaitQueue) {
+ long waitTime = totalWaitTime / steps;
+ if (waitTime > 0) {
poolWaitQueue.wait(waitTime);
}
}
- }catch(InterruptedException ie){
- //ignore
+ } catch (InterruptedException ie) {
+ // ignore
}
+
debug("woke-up to verify in-use / waiting requests list");
}
+ private void handlePoolRecreationForExistingProxies(ConnectorConnectionPool connectorConnectionPool) {
+ recreatePool(connectorConnectionPool);
- private void handlePoolRecreationForExistingProxies(ConnectorConnectionPool connConnPool) {
-
- recreatePool(connConnPool);
-
- Collection<BindableResource> resourcesList ;
- if(!connConnPool.isApplicationScopedResource()){
- resourcesList = JdbcResourcesUtil.getResourcesOfPool(domain.getResources(), connConnPool.getName());
- }else{
- PoolInfo poolInfo = connConnPool.getPoolInfo();
+ Collection<BindableResource> resourcesList;
+ if (!connectorConnectionPool.isApplicationScopedResource()) {
+ resourcesList = getResourcesOfPool(domain.getResources(), connectorConnectionPool.getName());
+ } else {
+ PoolInfo poolInfo = connectorConnectionPool.getPoolInfo();
Resources resources = ResourcesUtil.createInstance().getResources(poolInfo);
- resourcesList = JdbcResourcesUtil.getResourcesOfPool(resources, connConnPool.getName());
+ resourcesList = getResourcesOfPool(resources, connectorConnectionPool.getName());
}
- for (BindableResource bindableResource : resourcesList) {
- ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(bindableResource);
+ for (BindableResource bindableResource : resourcesList) {
+ ResourceInfo resourceInfo = getResourceInfo(bindableResource);
ConnectorRegistry.getInstance().updateResourceInfoVersion(resourceInfo);
}
}
@@ -919,10 +820,9 @@
private void recreatePool(ConnectorConnectionPool connConnPool) {
try {
runtime.recreateConnectorConnectionPool(connConnPool);
- debug("Pool ["+connConnPool.getName()+"] recreation done");
+ debug("Pool [" + connConnPool.getName() + "] recreation done");
} catch (ConnectorRuntimeException cre) {
- Object params[] = new Object[]{connConnPool.getName(), cre};
- _logger.log(Level.WARNING, "error.redeploying.jdbc.pool", params);
+ _logger.log(WARNING, "error.redeploying.jdbc.pool", new Object[] { connConnPool.getName(), cre });
}
}
@@ -930,9 +830,11 @@
* Enable the resource in the server's runtime naming context
*
* @param resource a resource object
- * @exception UnsupportedOperationException Currently we are not supporting this method.
+ * @exception UnsupportedOperationException Currently we are not supporting this
+ * method.
*
*/
+ @Override
public synchronized void enableResource(Object resource) throws Exception {
throw new UnsupportedOperationException(msg);
}
@@ -941,9 +843,11 @@
* Disable the resource in the server's runtime naming context
*
* @param resource a resource object
- * @exception UnsupportedOperationException Currently we are not supporting this method.
+ * @exception UnsupportedOperationException Currently we are not supporting this
+ * method.
*
*/
+ @Override
public synchronized void disableResource(Object resource) throws Exception {
throw new UnsupportedOperationException(msg);
}
@@ -951,15 +855,14 @@
/**
* {@inheritDoc}
*/
- public void validatePreservedResource(Application oldApp, Application newApp, Resource resource,
- Resources allResources)
- throws ResourceConflictException {
- //do nothing.
+ @Override
+ public void validatePreservedResource(Application oldApp, Application newApp, Resource resource, Resources allResources) throws ResourceConflictException {
+ // do nothing.
}
- private void debug(String message){
- if(_logger.isLoggable(Level.FINEST)) {
- _logger.finest("[DRC] : "+ message);
+ private void debug(String message) {
+ if (_logger.isLoggable(FINEST)) {
+ _logger.finest("[DRC] : " + message);
}
}
}
diff --git a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/deployer/JdbcResourceDeployer.java b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/deployer/JdbcResourceDeployer.java
index 7d428b9..211288a 100644
--- a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/deployer/JdbcResourceDeployer.java
+++ b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/deployer/JdbcResourceDeployer.java
@@ -16,31 +16,39 @@
package org.glassfish.jdbc.deployer;
+import static com.sun.appserv.connectors.internal.api.ConnectorsUtil.getPMJndiName;
+import static com.sun.appserv.connectors.internal.api.ConnectorsUtil.getResourceByName;
+import static com.sun.appserv.connectors.internal.api.ConnectorsUtil.getResourceInfo;
+import static com.sun.appserv.connectors.internal.api.ConnectorsUtil.getValidSuffix;
+
+import java.util.Collection;
+import java.util.logging.Logger;
+
+import org.glassfish.jdbc.config.JdbcConnectionPool;
+import org.glassfish.jdbc.config.JdbcResource;
+import org.glassfish.jdbc.util.JdbcResourcesUtil;
+import org.glassfish.resourcebase.resources.api.PoolInfo;
+import org.glassfish.resourcebase.resources.api.ResourceConflictException;
+import org.glassfish.resourcebase.resources.api.ResourceDeployer;
+import org.glassfish.resourcebase.resources.api.ResourceDeployerInfo;
+import org.glassfish.resourcebase.resources.api.ResourceInfo;
+import org.jvnet.hk2.annotations.Service;
+
import com.sun.appserv.connectors.internal.api.ConnectorsUtil;
import com.sun.enterprise.config.serverbeans.Application;
import com.sun.enterprise.config.serverbeans.Resource;
import com.sun.enterprise.config.serverbeans.Resources;
import com.sun.enterprise.connectors.ConnectorRegistry;
import com.sun.enterprise.connectors.ConnectorRuntime;
-import com.sun.enterprise.util.i18n.StringManager;
import com.sun.logging.LogDomains;
-import org.glassfish.jdbc.config.JdbcConnectionPool;
-import org.glassfish.jdbc.config.JdbcResource;
-import org.glassfish.jdbc.util.JdbcResourcesUtil;
-import org.glassfish.resourcebase.resources.api.*;
-import org.jvnet.hk2.annotations.Service;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
-import java.util.Collection;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
/**
- * Handles Jdbc resource events in the server instance. When user adds a
- * jdbc resource, the admin instance emits resource event. The jdbc
- * resource events are propagated to this object.
+ * Handles Jdbc resource events in the server instance. When user adds a jdbc
+ * resource, the admin instance emits resource event. The jdbc resource events
+ * are propagated to this object.
* <p/>
* The methods can potentially be called concurrently, therefore implementation
* need to be synchronized.
@@ -53,22 +61,16 @@
@Singleton
public class JdbcResourceDeployer implements ResourceDeployer {
+ private static Logger _logger = LogDomains.getLogger(JdbcResourceDeployer.class, LogDomains.RSR_LOGGER);
+
@Inject
private ConnectorRuntime runtime;
- private static final StringManager localStrings =
- StringManager.getManager(JdbcResourceDeployer.class);
- // logger for this deployer
- private static Logger _logger = LogDomains.getLogger(JdbcResourceDeployer.class, LogDomains.RSR_LOGGER);
+ @Override
+ public synchronized void deployResource(Object resource, String applicationName, String moduleName) throws Exception {
- /**
- * {@inheritDoc}
- */
- public synchronized void deployResource(Object resource, String applicationName, String moduleName)
- throws Exception {
-
- //deployResource is not synchronized as there is only one caller
- //ResourceProxy which is synchronized
+ // deployResource is not synchronized as there is only one caller
+ // ResourceProxy which is synchronized
JdbcResource jdbcRes = (JdbcResource) resource;
String jndiName = jdbcRes.getJndiName();
@@ -77,90 +79,82 @@
ResourceInfo resourceInfo = new ResourceInfo(jndiName, applicationName, moduleName);
runtime.createConnectorResource(resourceInfo, poolInfo, null);
- //In-case the resource is explicitly created with a suffix (__nontx or __PM), no need to create one
- if (ConnectorsUtil.getValidSuffix(jndiName) == null) {
- ResourceInfo pmResourceInfo = new ResourceInfo(ConnectorsUtil.getPMJndiName(jndiName),
- resourceInfo.getApplicationName(), resourceInfo.getModuleName());
+
+ // In-case the resource is explicitly created with a suffix (__nontx or __PM),
+ // no need to create one
+ if (getValidSuffix(jndiName) == null) {
+ ResourceInfo pmResourceInfo =
+ new ResourceInfo(
+ getPMJndiName(jndiName),
+ resourceInfo.getApplicationName(),
+ resourceInfo.getModuleName());
+
runtime.createConnectorResource(pmResourceInfo, poolInfo, null);
}
- if (_logger.isLoggable(Level.FINEST)) {
- _logger.finest("deployed resource " + jndiName);
- }
+
+ _logger.finest(() -> "deployed resource " + jndiName);
}
- /**
- * {@inheritDoc}
- */
+ @Override
public void deployResource(Object resource) throws Exception {
JdbcResource jdbcRes = (JdbcResource) resource;
ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(jdbcRes);
+
deployResource(jdbcRes, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
}
- /**
- * {@inheritDoc}
- */
+ @Override
public boolean canDeploy(boolean postApplicationDeployment, Collection<Resource> allResources, Resource resource) {
if (handles(resource)) {
if (!postApplicationDeployment) {
return true;
}
}
+
return false;
}
- /**
- * {@inheritDoc}
- */
+ @Override
public void undeployResource(Object resource, String applicationName, String moduleName) throws Exception {
JdbcResource jdbcRes = (JdbcResource) resource;
ResourceInfo resourceInfo = new ResourceInfo(jdbcRes.getJndiName(), applicationName, moduleName);
+
deleteResource(jdbcRes, resourceInfo);
}
- /**
- * {@inheritDoc}
- */
- public synchronized void undeployResource(Object resource)
- throws Exception {
+ @Override
+ public synchronized void undeployResource(Object resource) throws Exception {
JdbcResource jdbcRes = (JdbcResource) resource;
- ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(jdbcRes);
- deleteResource(jdbcRes, resourceInfo);
+
+ deleteResource(jdbcRes, getResourceInfo(jdbcRes));
}
private void deleteResource(JdbcResource jdbcResource, ResourceInfo resourceInfo) throws Exception {
-
runtime.deleteConnectorResource(resourceInfo);
ConnectorRegistry.getInstance().removeResourceFactories(resourceInfo);
- //In-case the resource is explicitly created with a suffix (__nontx or __PM), no need to delete one
- if (ConnectorsUtil.getValidSuffix(resourceInfo.getName()) == null) {
- String pmJndiName = ConnectorsUtil.getPMJndiName(resourceInfo.getName());
- ResourceInfo pmResourceInfo = new ResourceInfo(pmJndiName, resourceInfo.getApplicationName(),
- resourceInfo.getModuleName());
+
+ // In-case the resource is explicitly created with a suffix (__nontx or __PM),
+ // no need to delete one
+ if (getValidSuffix(resourceInfo.getName()) == null) {
+ String pmJndiName = getPMJndiName(resourceInfo.getName());
+ ResourceInfo pmResourceInfo = new ResourceInfo(pmJndiName, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
runtime.deleteConnectorResource(pmResourceInfo);
ConnectorRegistry.getInstance().removeResourceFactories(pmResourceInfo);
}
- //Since 8.1 PE/SE/EE - if no more resource-ref to the pool
- //of this resource in this server instance, remove pool from connector
- //runtime
+ // Since 8.1 PE/SE/EE - if no more resource-ref to the pool
+ // of this resource in this server instance, remove pool from connector
+ // runtime
checkAndDeletePool(jdbcResource);
-
}
- /**
- * {@inheritDoc}
- */
- public synchronized void redeployResource(Object resource)
- throws Exception {
-
+ @Override
+ public synchronized void redeployResource(Object resource) throws Exception {
undeployResource(resource);
deployResource(resource);
}
- /**
- * {@inheritDoc}
- */
+ @Override
public boolean handles(Object resource) {
return resource instanceof JdbcResource;
}
@@ -168,6 +162,7 @@
/**
* @inheritDoc
*/
+ @Override
public Class[] getProxyClassesForDynamicReconfiguration() {
return new Class[0];
}
@@ -175,14 +170,15 @@
/**
* @inheritDoc
*/
+ @Override
public boolean supportsDynamicReconfiguration() {
return false;
}
-
/**
* {@inheritDoc}
*/
+ @Override
public synchronized void enableResource(Object resource) throws Exception {
deployResource(resource);
}
@@ -190,55 +186,51 @@
/**
* {@inheritDoc}
*/
+ @Override
public synchronized void disableResource(Object resource) throws Exception {
undeployResource(resource);
}
/**
- * Checks if no more resource-refs to resources exists for the
- * JDBC connection pool and then deletes the pool
+ * Checks if no more resource-refs to resources exists for the JDBC connection
+ * pool and then deletes the pool
*
- * @param cr Jdbc Resource Config bean
+ * @param jdbcResource Jdbc Resource Config bean
* @throws Exception if unable to access configuration/undeploy resource.
* @since 8.1 pe/se/ee
*/
- private void checkAndDeletePool(JdbcResource cr) throws Exception {
- String poolName = cr.getPoolName();
- ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(cr);
+ private void checkAndDeletePool(JdbcResource jdbcResource) throws Exception {
+ String poolName = jdbcResource.getPoolName();
+ ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(jdbcResource);
PoolInfo poolInfo = new PoolInfo(poolName, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
- Resources resources = (Resources) cr.getParent();
- //Its possible that the JdbcResource here is a DataSourceDefinition. Ignore optimization.
+ Resources resources = (Resources) jdbcResource.getParent();
+
+ // Its possible that the JdbcResource here is a DataSourceDefinition. Ignore
+ // optimization.
if (resources != null) {
try {
- boolean poolReferred =
- JdbcResourcesUtil.createInstance().isJdbcPoolReferredInServerInstance(poolInfo);
+ boolean poolReferred = JdbcResourcesUtil.createInstance().isJdbcPoolReferredInServerInstance(poolInfo);
if (!poolReferred) {
- if (_logger.isLoggable(Level.FINE)) {
- _logger.fine("Deleting JDBC pool [" + poolName + " ] as there are no more " +
- "resource-refs to the pool in this server instance");
- }
+ _logger.fine(() ->
+ "Deleting JDBC pool [" + poolName + " ] as there are no more " +
+ "resource-refs to the pool in this server instance");
JdbcConnectionPool jcp = (JdbcConnectionPool)
- ConnectorsUtil.getResourceByName(resources, JdbcConnectionPool.class, poolName);
- //Delete/Undeploy Pool
+ getResourceByName(resources, JdbcConnectionPool.class, poolName);
+
+ // Delete/Undeploy Pool
runtime.getResourceDeployer(jcp).undeployResource(jcp);
}
} catch (Exception ce) {
_logger.warning(ce.getMessage());
- if (_logger.isLoggable(Level.FINE)) {
- _logger.fine("Exception while deleting pool [ " + poolName + " ] : " + ce);
- }
+ _logger.fine(() -> "Exception while deleting pool [ " + poolName + " ] : " + ce);
throw ce;
}
}
}
- /**
- * {@inheritDoc}
- */
- public void validatePreservedResource(Application oldApp, Application newApp, Resource resource,
- Resources allResources)
- throws ResourceConflictException {
- //do nothing.
+ @Override
+ public void validatePreservedResource(Application oldApp, Application newApp, Resource resource, Resources allResources) throws ResourceConflictException {
+ // do nothing.
}
}
diff --git a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/pool/monitor/JdbcConnPoolAppProbeProvider.java b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/pool/monitor/JdbcConnPoolAppProbeProvider.java
index edaa779..61a210b 100644
--- a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/pool/monitor/JdbcConnPoolAppProbeProvider.java
+++ b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/pool/monitor/JdbcConnPoolAppProbeProvider.java
@@ -19,42 +19,44 @@
import org.glassfish.external.probe.provider.annotations.Probe;
import org.glassfish.external.probe.provider.annotations.ProbeParam;
import org.glassfish.external.probe.provider.annotations.ProbeProvider;
-import com.sun.enterprise.resource.pool.monitor.*;
+
+import com.sun.enterprise.resource.pool.monitor.ConnectionPoolAppProbeProvider;
+
/**
* Probe provider interface for JDBC connection pool related events to provide
- * information related to the various objects on jdbc pool monitoring grouped
- * by applications.
+ * information related to the various objects on jdbc pool monitoring grouped by
+ * applications.
*
* @author Shalini M
*/
-@ProbeProvider(moduleProviderName="glassfish", moduleName="jdbc-pool", probeProviderName="applications")
+@ProbeProvider(moduleProviderName = "glassfish", moduleName = "jdbc-pool", probeProviderName = "applications")
public class JdbcConnPoolAppProbeProvider extends ConnectionPoolAppProbeProvider {
/**
* Emits probe event/notification that the given jdbc connection pool
- * <code>poolName</code> for the <code>appName</code> has got a
- * decrement connections used event.
+ * <code>poolName</code> for the <code>appName</code> has got a decrement
+ * connections used event.
*
* @param poolName for which decrement numConnUsed is got
* @param appName for which decrement numConnUsed is got
*/
- @Probe(name="decrementConnectionUsedEvent")
- public void decrementConnectionUsedEvent(
- @ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName) { }
+ @Override
+ @Probe(name = "decrementConnectionUsedEvent")
+ public void decrementConnectionUsedEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName) {
+ }
/**
* Emits probe event/notification that the given jdbc connection pool
- * <code>poolName</code> for the <code>appName</code> has got an
- * increment connections used event.
+ * <code>poolName</code> for the <code>appName</code> has got an increment
+ * connections used event.
*
* @param poolName for which increment numConnUsed is got
* @param appName for which increment numConnUsed is got
*/
- @Probe(name="connectionUsedEvent")
- public void connectionUsedEvent(
- @ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName) { }
+ @Override
+ @Probe(name = "connectionUsedEvent")
+ public void connectionUsedEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName) {
+ }
/**
* Emits probe event/notification that a connection is acquired by application
@@ -64,22 +66,21 @@
* @param poolName
* @param appName
*/
- @Probe(name="connectionAcquiredEvent")
- public void connectionAcquiredEvent(
- @ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName) { }
+ @Override
+ @Probe(name = "connectionAcquiredEvent")
+ public void connectionAcquiredEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName) {
+ }
/**
* Emits probe event/notification that a connection is released for the given
- * jdbc connection pool <code>poolName</code> by the
- * <code>appName</code>
+ * jdbc connection pool <code>poolName</code> by the <code>appName</code>
*
* @param poolName
* @param appName
*/
- @Probe(name="connectionReleasedEvent")
- public void connectionReleasedEvent(@ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName) { }
-
+ @Override
+ @Probe(name = "connectionReleasedEvent")
+ public void connectionReleasedEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName) {
+ }
}
diff --git a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/pool/monitor/JdbcConnPoolAppStatsProvider.java b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/pool/monitor/JdbcConnPoolAppStatsProvider.java
index 0bdf5d2..9c1e89f 100644
--- a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/pool/monitor/JdbcConnPoolAppStatsProvider.java
+++ b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/pool/monitor/JdbcConnPoolAppStatsProvider.java
@@ -16,13 +16,14 @@
package org.glassfish.jdbc.pool.monitor;
+import static org.glassfish.external.statistics.impl.StatisticImpl.UNIT_COUNT;
+
import org.glassfish.external.probe.provider.annotations.ProbeListener;
import org.glassfish.external.probe.provider.annotations.ProbeParam;
import org.glassfish.external.statistics.CountStatistic;
import org.glassfish.external.statistics.RangeStatistic;
import org.glassfish.external.statistics.impl.CountStatisticImpl;
import org.glassfish.external.statistics.impl.RangeStatisticImpl;
-import org.glassfish.external.statistics.impl.StatisticImpl;
import org.glassfish.gmbal.AMXMetadata;
import org.glassfish.gmbal.Description;
import org.glassfish.gmbal.ManagedAttribute;
@@ -37,25 +38,34 @@
*
* @author Shalini M
*/
-@AMXMetadata(type="jdbc-connection-pool-app-mon", group="monitoring")
+@AMXMetadata(type = "jdbc-connection-pool-app-mon", group = "monitoring")
@ManagedObject
@Description("JDBC Connection pool Application based Statistics")
public class JdbcConnPoolAppStatsProvider {
- private RangeStatisticImpl numConnUsed = new RangeStatisticImpl(
- 0, 0, 0,
- "NumConnUsed", StatisticImpl.UNIT_COUNT, "Provides connection usage " +
+ private static final String JDBC_APP_PROBE_LISTENER = "glassfish:jdbc-pool:applications:";
+
+ private RangeStatisticImpl numConnUsed =
+ new RangeStatisticImpl(
+ 0, 0, 0, "NumConnUsed", UNIT_COUNT,
+ "Provides connection usage " +
"statistics. The total number of connections that are currently being " +
"used, as well as information about the maximum number of connections " +
"that were used (the high water mark).",
- System.currentTimeMillis(), System.currentTimeMillis());
- private CountStatisticImpl numConnAcquired = new CountStatisticImpl(
- "NumConnAcquired", StatisticImpl.UNIT_COUNT, "Number of logical " +
+ System.currentTimeMillis(),
+ System.currentTimeMillis());
+
+ private CountStatisticImpl numConnAcquired =
+ new CountStatisticImpl("NumConnAcquired", UNIT_COUNT,
+ "Number of logical " +
"connections acquired from the pool.");
- private CountStatisticImpl numConnReleased = new CountStatisticImpl(
- "NumConnReleased", StatisticImpl.UNIT_COUNT, "Number of logical " +
+
+ private CountStatisticImpl numConnReleased =
+ new CountStatisticImpl("NumConnReleased", UNIT_COUNT,
+ "Number of logical " +
"connections released to the pool.");
- private static final String JDBC_APP_PROBE_LISTENER = "glassfish:jdbc-pool:applications:";
+
+
private String appName;
private String poolName;
@@ -73,13 +83,11 @@
}
@ProbeListener(JDBC_APP_PROBE_LISTENER + "decrementConnectionUsedEvent")
- public void decrementConnectionUsedEvent(
- @ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName) {
+ public void decrementConnectionUsedEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName) {
// handle the num conn used decrement event
- if((poolName != null) && (poolName.equals(this.poolName))) {
+ if ((poolName != null) && (poolName.equals(this.poolName))) {
if (appName != null && appName.equals(this.appName)) {
- //Decrement numConnUsed counter
+ // Decrement numConnUsed counter
synchronized (numConnUsed) {
numConnUsed.setCurrent(numConnUsed.getCurrent() - 1);
}
@@ -89,17 +97,16 @@
/**
* Connection used event
+ *
* @param poolName
* @param appName
*/
@ProbeListener(JDBC_APP_PROBE_LISTENER + "connectionUsedEvent")
- public void connectionUsedEvent(
- @ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName) {
+ public void connectionUsedEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName) {
// handle the connection used event
- if((poolName != null) && (poolName.equals(this.poolName))) {
+ if ((poolName != null) && (poolName.equals(this.poolName))) {
if (appName != null && appName.equals(this.appName)) {
- //increment numConnUsed
+ // increment numConnUsed
synchronized (numConnUsed) {
numConnUsed.setCurrent(numConnUsed.getCurrent() + 1);
}
@@ -111,10 +118,8 @@
* When a connection is acquired increment counter
*/
@ProbeListener(JDBC_APP_PROBE_LISTENER + "connectionAcquiredEvent")
- public void connectionAcquiredEvent(
- @ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName) {
- if((poolName != null) && (poolName.equals(this.poolName))) {
+ public void connectionAcquiredEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName) {
+ if ((poolName != null) && (poolName.equals(this.poolName))) {
if (appName != null && appName.equals(this.appName)) {
numConnAcquired.increment();
}
@@ -125,27 +130,25 @@
* When a connection is released increment counter
*/
@ProbeListener(JDBC_APP_PROBE_LISTENER + "connectionReleasedEvent")
- public void connectionReleasedEvent(
- @ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName) {
- if((poolName != null) && (poolName.equals(this.poolName))) {
+ public void connectionReleasedEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName) {
+ if ((poolName != null) && (poolName.equals(this.poolName))) {
if (appName != null && appName.equals(this.appName)) {
numConnReleased.increment();
}
}
}
- @ManagedAttribute(id="numconnused")
+ @ManagedAttribute(id = "numconnused")
public RangeStatistic getNumConnUsed() {
return numConnUsed;
}
- @ManagedAttribute(id="numconnacquired")
+ @ManagedAttribute(id = "numconnacquired")
public CountStatistic getNumConnAcquired() {
return numConnAcquired;
}
- @ManagedAttribute(id="numconnreleased")
+ @ManagedAttribute(id = "numconnreleased")
public CountStatistic getNumConnReleased() {
return numConnReleased;
}
diff --git a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/pool/monitor/JdbcConnPoolProbeProvider.java b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/pool/monitor/JdbcConnPoolProbeProvider.java
index 42b59df..5dac526 100644
--- a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/pool/monitor/JdbcConnPoolProbeProvider.java
+++ b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/pool/monitor/JdbcConnPoolProbeProvider.java
@@ -16,17 +16,19 @@
package org.glassfish.jdbc.pool.monitor;
-import org.glassfish.external.probe.provider.annotations.ProbeParam;
import org.glassfish.external.probe.provider.annotations.Probe;
+import org.glassfish.external.probe.provider.annotations.ProbeParam;
import org.glassfish.external.probe.provider.annotations.ProbeProvider;
-import com.sun.enterprise.resource.pool.monitor.*;
+
+import com.sun.enterprise.resource.pool.monitor.ConnectionPoolProbeProvider;
+
/**
* Probe provider interface for JDBC connection pool related events to provide
* information related to the various objects on jdbc pool monitoring.
*
* @author Shalini M
*/
-@ProbeProvider(moduleProviderName="glassfish", moduleName="jdbc", probeProviderName="connection-pool")
+@ProbeProvider(moduleProviderName = "glassfish", moduleName = "jdbc", probeProviderName = "connection-pool")
public class JdbcConnPoolProbeProvider extends ConnectionPoolProbeProvider {
/**
@@ -36,13 +38,14 @@
* @param poolName for which connection validation has failed
* @param increment number of times the validation failed
*/
- @Probe(name="connectionValidationFailedEvent")
+ @Probe(name = "connectionValidationFailedEvent")
@Override
public void connectionValidationFailedEvent(
- @ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName,
- @ProbeParam("moduleName") String moduleName,
- @ProbeParam("increment") int increment){ }
+ @ProbeParam("poolName") String poolName,
+ @ProbeParam("appName") String appName,
+ @ProbeParam("moduleName") String moduleName,
+ @ProbeParam("increment") int increment) {
+ }
/**
* Emits probe event/notification that a jdbc connection pool with the given
@@ -50,12 +53,13 @@
*
* @param poolName that has got a connection timed-out event
*/
- @Probe(name="connectionTimedOutEvent")
+ @Probe(name = "connectionTimedOutEvent")
@Override
- public void connectionTimedOutEvent(@ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName,
- @ProbeParam("moduleName") String moduleName
- ) { }
+ public void connectionTimedOutEvent(
+ @ProbeParam("poolName") String poolName,
+ @ProbeParam("appName") String appName,
+ @ProbeParam("moduleName") String moduleName) {
+ }
/**
* Emits probe event/notification that the pool with the given name
@@ -63,12 +67,13 @@
*
* @param poolName
*/
- @Probe(name="potentialConnLeakEvent")
+ @Probe(name = "potentialConnLeakEvent")
@Override
- public void potentialConnLeakEvent(@ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName,
- @ProbeParam("moduleName") String moduleName
- ) { }
+ public void potentialConnLeakEvent(
+ @ProbeParam("poolName") String poolName,
+ @ProbeParam("appName") String appName,
+ @ProbeParam("moduleName") String moduleName) {
+ }
/**
* Emits probe event/notification that the given jdbc connection pool
@@ -77,13 +82,11 @@
* @param poolName for which decrement numConnFree is got
* @param steadyPoolSize
*/
- @Probe(name="decrementNumConnFreeEvent")
+ @Probe(name = "decrementNumConnFreeEvent")
@Override
- public void decrementNumConnFreeEvent(
- @ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName,
- @ProbeParam("moduleName") String moduleName
- ) { }
+ public void decrementNumConnFreeEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName,
+ @ProbeParam("moduleName") String moduleName) {
+ }
/**
* Emits probe event/notification that the given jdbc connection pool
@@ -93,14 +96,12 @@
* @param beingDestroyed if connection is destroyed due to error
* @param steadyPoolSize
*/
- @Probe(name="incrementNumConnFreeEvent")
+ @Probe(name = "incrementNumConnFreeEvent")
@Override
- public void incrementNumConnFreeEvent(
- @ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName,
- @ProbeParam("moduleName") String moduleName,
- @ProbeParam("beingDestroyed") boolean beingDestroyed,
- @ProbeParam("steadyPoolSize") int steadyPoolSize) { }
+ public void incrementNumConnFreeEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName,
+ @ProbeParam("moduleName") String moduleName, @ProbeParam("beingDestroyed") boolean beingDestroyed,
+ @ProbeParam("steadyPoolSize") int steadyPoolSize) {
+ }
/**
* Emits probe event/notification that the given jdbc connection pool
@@ -108,13 +109,11 @@
*
* @param poolName for which decrement numConnUsed is got
*/
- @Probe(name="decrementConnectionUsedEvent")
+ @Probe(name = "decrementConnectionUsedEvent")
@Override
- public void decrementConnectionUsedEvent(
- @ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName,
- @ProbeParam("moduleName") String moduleName
- ) { }
+ public void decrementConnectionUsedEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName,
+ @ProbeParam("moduleName") String moduleName) {
+ }
/**
* Emits probe event/notification that the given jdbc connection pool
@@ -122,13 +121,11 @@
*
* @param poolName for which increment numConnUsed is got
*/
- @Probe(name="connectionUsedEvent")
+ @Probe(name = "connectionUsedEvent")
@Override
- public void connectionUsedEvent(
- @ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName,
- @ProbeParam("moduleName") String moduleName
- ) { }
+ public void connectionUsedEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName,
+ @ProbeParam("moduleName") String moduleName) {
+ }
/**
* Emits probe event/notification that the given jdbc connection pool
@@ -137,13 +134,11 @@
* @param poolName for which increment numConnFree is got
* @param count number of connections freed to pool
*/
- @Probe(name="connectionsFreedEvent")
+ @Probe(name = "connectionsFreedEvent")
@Override
- public void connectionsFreedEvent(
- @ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName,
- @ProbeParam("moduleName") String moduleName,
- @ProbeParam("count") int count) { }
+ public void connectionsFreedEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName,
+ @ProbeParam("moduleName") String moduleName, @ProbeParam("count") int count) {
+ }
/**
* Emits probe event/notification that a connection request is served in the
@@ -153,27 +148,23 @@
* @param poolName
* @param timeTakenInMillis time taken to serve a connection
*/
- @Probe(name="connectionRequestServedEvent")
+ @Probe(name = "connectionRequestServedEvent")
@Override
- public void connectionRequestServedEvent(
- @ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName,
- @ProbeParam("moduleName") String moduleName,
- @ProbeParam("timeTakenInMillis") long timeTakenInMillis) { }
+ public void connectionRequestServedEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName,
+ @ProbeParam("moduleName") String moduleName, @ProbeParam("timeTakenInMillis") long timeTakenInMillis) {
+ }
/**
- * Emits probe event/notification that a connection is destroyed for the
- * given jdbc connection pool <code>poolName</code>
+ * Emits probe event/notification that a connection is destroyed for the given
+ * jdbc connection pool <code>poolName</code>
*
* @param poolName
*/
- @Probe(name="connectionDestroyedEvent")
+ @Probe(name = "connectionDestroyedEvent")
@Override
- public void connectionDestroyedEvent(
- @ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName,
- @ProbeParam("moduleName") String moduleName
- ) { }
+ public void connectionDestroyedEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName,
+ @ProbeParam("moduleName") String moduleName) {
+ }
/**
* Emits probe event/notification that a connection is acquired by application
@@ -181,13 +172,11 @@
*
* @param poolName
*/
- @Probe(name="connectionAcquiredEvent")
+ @Probe(name = "connectionAcquiredEvent")
@Override
- public void connectionAcquiredEvent(
- @ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName,
- @ProbeParam("moduleName") String moduleName
- ) { }
+ public void connectionAcquiredEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName,
+ @ProbeParam("moduleName") String moduleName) {
+ }
/**
* Emits probe event/notification that a connection is released for the given
@@ -195,32 +184,29 @@
*
* @param poolName
*/
- @Probe(name="connectionReleasedEvent")
+ @Probe(name = "connectionReleasedEvent")
@Override
- public void connectionReleasedEvent(@ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName,
- @ProbeParam("moduleName") String moduleName
- ) { }
+ public void connectionReleasedEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName,
+ @ProbeParam("moduleName") String moduleName) {
+ }
/**
- * Emits probe event/notification that a new connection is created for the
- * given jdbc connection pool <code>poolName</code>
+ * Emits probe event/notification that a new connection is created for the given
+ * jdbc connection pool <code>poolName</code>
*
* @param poolName
*/
- @Probe(name="connectionCreatedEvent")
+ @Probe(name = "connectionCreatedEvent")
@Override
- public void connectionCreatedEvent(@ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName,
- @ProbeParam("moduleName") String moduleName
- ) { }
+ public void connectionCreatedEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName,
+ @ProbeParam("moduleName") String moduleName) {
+ }
- @Probe(name="toString", hidden=true)
+ @Probe(name = "toString", hidden = true)
@Override
- public void toString(@ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName,
- @ProbeParam("moduleName") String moduleName,
- @ProbeParam("stackTrace") StringBuffer stackTrace) { }
+ public void toString(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName,
+ @ProbeParam("moduleName") String moduleName, @ProbeParam("stackTrace") StringBuffer stackTrace) {
+ }
/**
* Emits probe event/notification that a connection under test matches the
@@ -228,50 +214,45 @@
*
* @param poolName
*/
- @Probe(name="connectionMatchedEvent")
+ @Probe(name = "connectionMatchedEvent")
@Override
- public void connectionMatchedEvent(@ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName,
- @ProbeParam("moduleName") String moduleName
- ) { }
+ public void connectionMatchedEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName,
+ @ProbeParam("moduleName") String moduleName) {
+ }
/**
- * Emits probe event/notification that a connection under test does not
- * match the current request for the given jdbc connection pool
- * <code>poolName</code>
+ * Emits probe event/notification that a connection under test does not match
+ * the current request for the given jdbc connection pool <code>poolName</code>
*
* @param poolName
*/
- @Probe(name="connectionNotMatchedEvent")
+ @Probe(name = "connectionNotMatchedEvent")
@Override
- public void connectionNotMatchedEvent(@ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName,
- @ProbeParam("moduleName") String moduleName
- ) { }
+ public void connectionNotMatchedEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName,
+ @ProbeParam("moduleName") String moduleName) {
+ }
/**
- * Emits probe event/notification that the wait queue length has increased
- * for the given jdbc connection pool <code>poolName</code>
+ * Emits probe event/notification that the wait queue length has increased for
+ * the given jdbc connection pool <code>poolName</code>
*
* @param poolName
*/
- @Probe(name="connectionRequestQueuedEvent")
+ @Probe(name = "connectionRequestQueuedEvent")
@Override
- public void connectionRequestQueuedEvent(@ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName,
- @ProbeParam("moduleName") String moduleName
- ) { }
+ public void connectionRequestQueuedEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName,
+ @ProbeParam("moduleName") String moduleName) {
+ }
/**
- * Emits probe event/notification that the wait queue length has decreased
- * for the given jdbc connection pool <code>poolName</code>
+ * Emits probe event/notification that the wait queue length has decreased for
+ * the given jdbc connection pool <code>poolName</code>
*
* @param poolName
*/
- @Probe(name="connectionRequestDequeuedEvent")
+ @Probe(name = "connectionRequestDequeuedEvent")
@Override
- public void connectionRequestDequeuedEvent(@ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName,
- @ProbeParam("moduleName") String moduleName
- ) { }
+ public void connectionRequestDequeuedEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName,
+ @ProbeParam("moduleName") String moduleName) {
+ }
}
diff --git a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/pool/monitor/JdbcConnPoolStatsProvider.java b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/pool/monitor/JdbcConnPoolStatsProvider.java
index 7785304..7bccdf3 100644
--- a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/pool/monitor/JdbcConnPoolStatsProvider.java
+++ b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/pool/monitor/JdbcConnPoolStatsProvider.java
@@ -16,9 +16,9 @@
package org.glassfish.jdbc.pool.monitor;
-import com.sun.enterprise.connectors.ConnectorRuntime;
-import com.sun.enterprise.resource.pool.PoolLifeCycleListenerRegistry;
-import com.sun.enterprise.resource.pool.PoolStatus;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
import org.glassfish.external.probe.provider.annotations.ProbeListener;
import org.glassfish.external.probe.provider.annotations.ProbeParam;
import org.glassfish.external.statistics.CountStatistic;
@@ -33,8 +33,9 @@
import org.glassfish.gmbal.ManagedObject;
import org.glassfish.resourcebase.resources.api.PoolInfo;
-import java.util.logging.Level;
-import java.util.logging.Logger;
+import com.sun.enterprise.connectors.ConnectorRuntime;
+import com.sun.enterprise.resource.pool.PoolLifeCycleListenerRegistry;
+import com.sun.enterprise.resource.pool.PoolStatus;
/**
* StatsProvider object for Jdbc pool monitoring.
@@ -61,14 +62,17 @@
"NumConnFailedValidation", StatisticImpl.UNIT_COUNT,
"The total number of connections in the connection pool that failed " +
"validation from the start time until the last sample time.");
+
private CountStatisticImpl numConnTimedOut = new CountStatisticImpl(
"NumConnTimedOut", StatisticImpl.UNIT_COUNT, "The total number of " +
"connections in the pool that timed out between the start time and the last sample time.");
+
private RangeStatisticImpl numConnFree = new RangeStatisticImpl(
0, 0, 0,
"NumConnFree", StatisticImpl.UNIT_COUNT, "The total number of free " +
"connections in the pool as of the last sampling.",
System.currentTimeMillis(), System.currentTimeMillis());
+
private RangeStatisticImpl numConnUsed = new RangeStatisticImpl(
0, 0, 0,
"NumConnUsed", StatisticImpl.UNIT_COUNT, "Provides connection usage " +
@@ -76,6 +80,7 @@
"used, as well as information about the maximum number of connections " +
"that were used (the high water mark).",
System.currentTimeMillis(), System.currentTimeMillis());
+
private RangeStatisticImpl connRequestWaitTime = new RangeStatisticImpl(
0, 0, 0,
"ConnRequestWaitTime", StatisticImpl.UNIT_MILLISECOND,
@@ -83,12 +88,15 @@
"current value indicates the wait time of the last request that was " +
"serviced by the pool.",
System.currentTimeMillis(), System.currentTimeMillis());
+
private CountStatisticImpl numConnDestroyed = new CountStatisticImpl(
"NumConnDestroyed", StatisticImpl.UNIT_COUNT,
"Number of physical connections that were destroyed since the last reset.");
+
private CountStatisticImpl numConnAcquired = new CountStatisticImpl(
"NumConnAcquired", StatisticImpl.UNIT_COUNT, "Number of logical " +
"connections acquired from the pool.");
+
private CountStatisticImpl numConnReleased = new CountStatisticImpl(
"NumConnReleased", StatisticImpl.UNIT_COUNT, "Number of logical " +
"connections released to the pool.");
@@ -203,22 +211,21 @@
@ProbeParam("steadyPoolSize") int steadyPoolSize) {
// handle the num conn free increment event
PoolInfo poolInfo = new PoolInfo(poolName, appName, moduleName);
- if(this.poolInfo.equals(poolInfo)) {
- if(logger.isLoggable(Level.FINEST)) {
- logger.finest("Increment Num Connections Free event received - poolName = " +
- poolName);
+ if (this.poolInfo.equals(poolInfo)) {
+ if (logger.isLoggable(Level.FINEST)) {
+ logger.finest("Increment Num Connections Free event received - poolName = " + poolName);
}
- if(beingDestroyed) {
- //if pruned by resizer thread
- synchronized(numConnFree) {
- synchronized(numConnUsed) {
- if(numConnFree.getCurrent() + numConnUsed.getCurrent() < steadyPoolSize) {
+ if (beingDestroyed) {
+ // if pruned by resizer thread
+ synchronized (numConnFree) {
+ synchronized (numConnUsed) {
+ if (numConnFree.getCurrent() + numConnUsed.getCurrent() < steadyPoolSize) {
numConnFree.setCurrent(numConnFree.getCurrent() + 1);
}
}
}
} else {
- synchronized(numConnFree) {
+ synchronized (numConnFree) {
numConnFree.setCurrent(numConnFree.getCurrent() + 1);
}
}
@@ -232,20 +239,17 @@
* @param steadyPoolSize
*/
@ProbeListener(JDBC_PROBE_LISTENER + "decrementConnectionUsedEvent")
- public void decrementConnectionUsedEvent(
- @ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName,
- @ProbeParam("moduleName") String moduleName
- ) {
+ public void decrementConnectionUsedEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName,
+ @ProbeParam("moduleName") String moduleName) {
+
// handle the num conn used decrement event
PoolInfo poolInfo = new PoolInfo(poolName, appName, moduleName);
- if(this.poolInfo.equals(poolInfo)) {
- if(logger.isLoggable(Level.FINEST)) {
- logger.finest("Decrement Num Connections Used event received - poolName = " +
- poolName);
+ if (this.poolInfo.equals(poolInfo)) {
+ if (logger.isLoggable(Level.FINEST)) {
+ logger.finest("Decrement Num Connections Used event received - poolName = " + poolName);
}
- //Decrement numConnUsed counter
- synchronized(numConnUsed) {
+ // Decrement numConnUsed counter
+ synchronized (numConnUsed) {
numConnUsed.setCurrent(numConnUsed.getCurrent() - 1);
}
}
@@ -264,16 +268,14 @@
@ProbeParam("count") int count) {
// handle the connections freed event
PoolInfo poolInfo = new PoolInfo(poolName, appName, moduleName);
- if(this.poolInfo.equals(poolInfo)) {
- if(logger.isLoggable(Level.FINEST)) {
- logger.finest("Connections Freed event received - poolName = " +
- poolName);
- logger.finest("numConnUsed =" + numConnUsed.getCurrent() +
- " numConnFree=" + numConnFree.getCurrent() +
- " Number of connections freed =" + count);
+ if (this.poolInfo.equals(poolInfo)) {
+ if (logger.isLoggable(Level.FINEST)) {
+ logger.finest("Connections Freed event received - poolName = " + poolName);
+ logger.finest("numConnUsed =" + numConnUsed.getCurrent() + " numConnFree=" + numConnFree.getCurrent()
+ + " Number of connections freed =" + count);
}
- //set numConnFree to the count value
- synchronized(numConnFree) {
+ // set numConnFree to the count value
+ synchronized (numConnFree) {
numConnFree.setCurrent(count);
}
}
@@ -284,20 +286,17 @@
* @param poolName
*/
@ProbeListener(JDBC_PROBE_LISTENER + "connectionUsedEvent")
- public void connectionUsedEvent(
- @ProbeParam("poolName") String poolName,
- @ProbeParam("appName") String appName,
- @ProbeParam("moduleName") String moduleName
- ) {
+ public void connectionUsedEvent(@ProbeParam("poolName") String poolName, @ProbeParam("appName") String appName,
+ @ProbeParam("moduleName") String moduleName) {
+
// handle the connection used event
PoolInfo poolInfo = new PoolInfo(poolName, appName, moduleName);
- if(this.poolInfo.equals(poolInfo)) {
- if(logger.isLoggable(Level.FINEST)) {
- logger.finest("Connection Used event received - poolName = " +
- poolName);
+ if (this.poolInfo.equals(poolInfo)) {
+ if (logger.isLoggable(Level.FINEST)) {
+ logger.finest("Connection Used event received - poolName = " + poolName);
}
- //increment numConnUsed
- synchronized(numConnUsed) {
+ // increment numConnUsed
+ synchronized (numConnUsed) {
numConnUsed.setCurrent(numConnUsed.getCurrent() + 1);
}
}
@@ -315,12 +314,12 @@
@ProbeParam("increment") int increment) {
PoolInfo poolInfo = new PoolInfo(poolName, appName, moduleName);
- if(this.poolInfo.equals(poolInfo)) {
- if(logger.isLoggable(Level.FINEST)) {
- logger.finest("Connection Validation Failed event received - " +
- "poolName = " + poolName);
+ if (this.poolInfo.equals(poolInfo)) {
+ if (logger.isLoggable(Level.FINEST)) {
+ logger.finest("Connection Validation Failed event received - " + "poolName = " + poolName);
}
- //TODO V3 : add support in CounterImpl for addAndGet(increment)
+
+ // TODO V3 : add support in CounterImpl for addAndGet(increment)
numConnFailedValidation.increment(increment);
}
@@ -553,58 +552,6 @@
return poolRegistry;
}
- /**
- * When a connection leak is observed, the monitoring statistics are displayed
- * to the server.log. This method helps in segregating the statistics based
- * on LOW/HIGH monitoring levels and displaying them.
- *
- * @param poolName
- * @param stackTrace
- */
- //TODO V3 need this?
- /*@ProbeListener("glassfish:connector:jdbc-connection-pool:toString")
- public void toString(@ProbeParam("poolName") String poolName,
- @ProbeParam("stackTrace") StringBuffer stackTrace) {
- logger.finest("toString(poolName) event received. " +
- "poolName = " + poolName);
- if((poolName != null) && (poolName.equals(this.jdbcPoolName))) {
- //If level is not OFF then print the stack trace.
- if(jdbcPoolStatsProviderBootstrap.getEnabledValue(monitoringLevel)) {
- if("LOW".equals(monitoringLevel)) {
- lowLevelLog(stackTrace);
- } else if("HIGH".equals(monitoringLevel)) {
- highLevelLog(stackTrace);
- }
- }
- }
- }*/
-
-/* private void lowLevelLog(StringBuffer stackTrace) {
- stackTrace.append("\n curNumConnUsed = " + numConnUsed.getCurrent());
- stackTrace.append("\n curNumConnFree = " + numConnFree.getCurrent());
- stackTrace.append("\n numConnCreated = " + numConnCreated.getCount());
- stackTrace.append("\n numConnDestroyed = " + numConnDestroyed.getCount());
- }
-
- private void highLevelLog(StringBuffer stackTrace) {
- lowLevelLog(stackTrace);
- stackTrace.append("\n numConnFailedValidation = " + numConnFailedValidation.getCount());
- stackTrace.append("\n numConnTimedOut = " + numConnTimedOut.getCount());
-
- stackTrace.append("\n numConnAcquired = " + numConnAcquired.getCount());
- stackTrace.append("\n numConnReleased = " + numConnReleased.getCount());
-
- //TODO V3 : enabling other counters.
- stackTrace.append("\n currConnectionRequestWait = " + currConnectionRequestWait);
- stackTrace.append("\n minConnectionRequestWait = " + minConnectionRequestWait);
- stackTrace.append("\n maxConnectionRequestWait = " + maxConnectionRequestWait);
- stackTrace.append("\n totalConnectionRequestWait = " + totalConnectionRequestWait);
-
- stackTrace.append("\n numConnSuccessfullyMatched = " + this.numConnSuccessfullyMatched);
- stackTrace.append("\n numConnNotSuccessfullyMatched = " + numConnNotSuccessfullyMatched);
- stackTrace.append("\n numPotentialConnLeak = " + numPotentialConnLeak.getCount());
- }
-*/
@ManagedAttribute(id="numpotentialconnleak")
public CountStatistic getNumPotentialConnLeakCount() {
return numPotentialConnLeak;
@@ -667,8 +614,8 @@
@ManagedAttribute(id="averageconnwaittime")
public CountStatistic getAverageConnWaitTime() {
- //Time taken by all connection requests divided by total number of
- //connections acquired in the sampling period.
+ // Time taken by all connection requests divided by total number of
+ // connections acquired in the sampling period.
long averageWaitTime = 0;
if (numConnAcquired.getCount() != 0) {
averageWaitTime = totalConnRequestWaitTime.getCount()/
diff --git a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/recovery/JdbcRecoveryResourceHandler.java b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/recovery/JdbcRecoveryResourceHandler.java
index c3b7e9a..ae348ce 100644
--- a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/recovery/JdbcRecoveryResourceHandler.java
+++ b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/recovery/JdbcRecoveryResourceHandler.java
@@ -16,15 +16,20 @@
package org.glassfish.jdbc.recovery;
-import com.sun.appserv.connectors.internal.api.ConnectorRuntime;
-import com.sun.appserv.connectors.internal.api.ConnectorsUtil;
-import com.sun.enterprise.config.serverbeans.*;
-import com.sun.enterprise.connectors.util.ResourcesUtil;
-import com.sun.enterprise.deployment.ResourcePrincipal;
-import com.sun.enterprise.transaction.api.XAResourceWrapper;
-import com.sun.enterprise.transaction.config.TransactionService;
-import com.sun.enterprise.transaction.spi.RecoveryResourceHandler;
-import com.sun.logging.LogDomains;
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.security.auth.Subject;
+import javax.transaction.xa.XAResource;
+
import org.glassfish.api.admin.ServerEnvironment;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.jdbc.config.JdbcConnectionPool;
@@ -34,22 +39,29 @@
import org.glassfish.resourcebase.resources.api.ResourceInfo;
import org.jvnet.hk2.annotations.Service;
import org.jvnet.hk2.config.types.Property;
+
+import com.sun.appserv.connectors.internal.api.ConnectorRuntime;
+import com.sun.appserv.connectors.internal.api.ConnectorsUtil;
+import com.sun.enterprise.config.serverbeans.Application;
+import com.sun.enterprise.config.serverbeans.Applications;
+import com.sun.enterprise.config.serverbeans.Config;
+import com.sun.enterprise.config.serverbeans.Domain;
import com.sun.enterprise.config.serverbeans.Module;
+import com.sun.enterprise.config.serverbeans.Resource;
+import com.sun.enterprise.config.serverbeans.Resources;
+import com.sun.enterprise.connectors.util.ResourcesUtil;
+import com.sun.enterprise.deployment.ResourcePrincipal;
+import com.sun.enterprise.transaction.api.XAResourceWrapper;
+import com.sun.enterprise.transaction.config.TransactionService;
+import com.sun.enterprise.transaction.spi.RecoveryResourceHandler;
+import com.sun.logging.LogDomains;
import jakarta.inject.Inject;
import jakarta.inject.Provider;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
import jakarta.resource.ResourceException;
import jakarta.resource.spi.ManagedConnection;
import jakarta.resource.spi.ManagedConnectionFactory;
import jakarta.resource.spi.security.PasswordCredential;
-import javax.security.auth.Subject;
-import javax.transaction.xa.XAResource;
-import java.security.Principal;
-import java.util.*;
-import java.util.logging.Level;
-import java.util.logging.Logger;
/**
* Recovery Handler for Jdbc Resources
@@ -79,7 +91,7 @@
private void loadAllJdbcResources() {
- if(_logger.isLoggable(Level.FINEST)) {
+ if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, "loadAllJdbcResources start");
}
try {
@@ -87,12 +99,11 @@
InitialContext ic = new InitialContext();
for (Resource resource : jdbcResources) {
JdbcResource jdbcResource = (JdbcResource) resource;
- if(getResourcesUtil().isEnabled(jdbcResource)) {
+ if (getResourcesUtil().isEnabled(jdbcResource)) {
try {
ic.lookup(jdbcResource.getJndiName());
} catch (Exception ex) {
- _logger.log(Level.SEVERE, "error.loading.jdbc.resources.during.recovery",
- jdbcResource.getJndiName());
+ _logger.log(Level.SEVERE, "error.loading.jdbc.resources.during.recovery", jdbcResource.getJndiName());
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, ex.toString(), ex);
}
@@ -105,7 +116,7 @@
_logger.log(Level.FINE, ne.toString(), ne);
}
}
- if(_logger.isLoggable(Level.FINEST)) {
+ if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, "loadAllJdbcResources end");
}
}
@@ -114,28 +125,28 @@
Collection<JdbcResource> allResources = new ArrayList<JdbcResource>();
Collection<JdbcResource> jdbcResources = domain.getResources().getResources(JdbcResource.class);
allResources.addAll(jdbcResources);
- for(Application app : applications.getApplications()){
- if(ResourcesUtil.createInstance().isEnabled(app)){
- Resources appScopedResources = app.getResources();
- if(appScopedResources != null && appScopedResources.getResources() != null){
- allResources.addAll(appScopedResources.getResources(JdbcResource.class));
- }
- List<Module> modules = app.getModule();
- if(modules != null){
- for(Module module : modules){
- Resources msr = module.getResources();
- if(msr != null && msr.getResources() != null){
- allResources.addAll(msr.getResources(JdbcResource.class));
- }
- }
- }
- }
- }
+ for (Application app : applications.getApplications()) {
+ if (ResourcesUtil.createInstance().isEnabled(app)) {
+ Resources appScopedResources = app.getResources();
+ if (appScopedResources != null && appScopedResources.getResources() != null) {
+ allResources.addAll(appScopedResources.getResources(JdbcResource.class));
+ }
+ List<Module> modules = app.getModule();
+ if (modules != null) {
+ for (Module module : modules) {
+ Resources msr = module.getResources();
+ if (msr != null && msr.getResources() != null) {
+ allResources.addAll(msr.getResources(JdbcResource.class));
+ }
+ }
+ }
+ }
+ }
return allResources;
}
- private ResourcesUtil getResourcesUtil(){
- if(resourcesUtil == null){
+ private ResourcesUtil getResourcesUtil() {
+ if (resourcesUtil == null) {
resourcesUtil = ResourcesUtil.createInstance();
}
return resourcesUtil;
@@ -144,16 +155,18 @@
/**
* {@inheritDoc}
*/
+ @Override
public void loadXAResourcesAndItsConnections(List xaresList, List connList) {
- //Done so as to initialize connectors-runtime before loading jdbc-resources. need a better way ?
+ // Done so as to initialize connectors-runtime before loading jdbc-resources.
+ // need a better way ?
ConnectorRuntime crt = connectorRuntimeProvider.get();
Collection<JdbcResource> jdbcResources = getAllJdbcResources();
if (jdbcResources == null || jdbcResources.size() == 0) {
if (_logger.isLoggable(Level.FINEST)) {
- _logger.finest("loadXAResourcesAndItsConnections : no resources" );
+ _logger.finest("loadXAResourcesAndItsConnections : no resources");
}
return;
}
@@ -162,15 +175,15 @@
for (Resource resource : jdbcResources) {
JdbcResource jdbcResource = (JdbcResource) resource;
- if(getResourcesUtil().isEnabled(jdbcResource)) {
+ if (getResourcesUtil().isEnabled(jdbcResource)) {
ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(jdbcResource);
JdbcConnectionPool pool = JdbcResourcesUtil.createInstance().getJdbcConnectionPoolOfResource(resourceInfo);
if (pool != null && "javax.sql.XADataSource".equals(pool.getResType())) {
jdbcPools.add(pool);
}
if (_logger.isLoggable(Level.FINE)) {
- _logger.fine("JdbcRecoveryResourceHandler:: loadXAResourcesAndItsConnections :: "
- + "adding : " + (jdbcResource.getPoolName()));
+ _logger.fine("JdbcRecoveryResourceHandler:: loadXAResourcesAndItsConnections :: " + "adding : "
+ + (jdbcResource.getPoolName()));
}
}
}
@@ -181,12 +194,10 @@
// If yes, put the mapping in the xaresourcewrappers properties.
Properties XAResourceWrappers = new Properties();
- XAResourceWrappers.put(
- "oracle.jdbc.xa.client.OracleXADataSource",
- "com.sun.enterprise.transaction.jts.recovery.OracleXAResource");
+ XAResourceWrappers.put("oracle.jdbc.xa.client.OracleXADataSource", "com.sun.enterprise.transaction.jts.recovery.OracleXAResource");
Config c = habitat.getService(Config.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
- txService = c.getExtensionByType(TransactionService.class);
+ txService = c.getExtensionByType(TransactionService.class);
List<Property> properties = txService.getProperty();
@@ -196,24 +207,20 @@
String value = property.getValue();
if (name.equals("oracle-xa-recovery-workaround")) {
if ("false".equals(value)) {
- XAResourceWrappers.remove(
- "oracle.jdbc.xa.client.OracleXADataSource");
+ XAResourceWrappers.remove("oracle.jdbc.xa.client.OracleXADataSource");
}
} else if (name.equals("sybase-xa-recovery-workaround")) {
if (value.equals("true")) {
- XAResourceWrappers.put(
- "com.sybase.jdbc2.jdbc.SybXADataSource",
+ XAResourceWrappers.put("com.sybase.jdbc2.jdbc.SybXADataSource",
"com.sun.enterprise.transaction.jts.recovery.SybaseXAResource");
}
}
}
}
- for(JdbcConnectionPool jdbcConnectionPool : jdbcPools){
- if (jdbcConnectionPool.getResType() == null
- || jdbcConnectionPool.getName() == null
- || !jdbcConnectionPool.getResType().equals(
- "javax.sql.XADataSource")) {
+ for (JdbcConnectionPool jdbcConnectionPool : jdbcPools) {
+ if (jdbcConnectionPool.getResType() == null || jdbcConnectionPool.getName() == null
+ || !jdbcConnectionPool.getResType().equals("javax.sql.XADataSource")) {
if (_logger.isLoggable(Level.FINEST)) {
_logger.finest("skipping pool : " + jdbcConnectionPool.getName());
}
@@ -232,23 +239,19 @@
if (dbPassword == null) {
dbPassword = "";
if (_logger.isLoggable(Level.FINEST)) {
- _logger.log(Level.FINEST,
- "datasource.xadatasource_nullpassword_error", poolInfo);
+ _logger.log(Level.FINEST, "datasource.xadatasource_nullpassword_error", poolInfo);
}
}
if (dbUser == null) {
dbUser = "";
if (_logger.isLoggable(Level.FINEST)) {
- _logger.log(Level.FINEST,
- "datasource.xadatasource_nulluser_error", poolInfo);
+ _logger.log(Level.FINEST, "datasource.xadatasource_nulluser_error", poolInfo);
}
}
- ManagedConnectionFactory fac =
- crt.obtainManagedConnectionFactory(poolInfo);
+ ManagedConnectionFactory fac = crt.obtainManagedConnectionFactory(poolInfo);
Subject subject = new Subject();
- PasswordCredential pc = new PasswordCredential(
- dbUser, dbPassword.toCharArray());
+ PasswordCredential pc = new PasswordCredential(dbUser, dbPassword.toCharArray());
pc.setManagedConnectionFactory(fac);
Principal prin = new ResourcePrincipal(dbUser, dbPassword);
subject.getPrincipals().add(prin);
@@ -263,19 +266,16 @@
// specified if yes, replace the XAResouce class of database
// vendor with our own version
- String datasourceClassname =
- jdbcConnectionPool.getDatasourceClassname();
- String wrapperclass = (String) XAResourceWrappers.get(
- datasourceClassname);
+ String datasourceClassname = jdbcConnectionPool.getDatasourceClassname();
+ String wrapperclass = (String) XAResourceWrappers.get(datasourceClassname);
if (wrapperclass != null) {
- //need to load wrapper class provided by "transactions" module.
- //Using connector-class-loader so as to get access to "transaction" module.
+ // need to load wrapper class provided by "transactions" module.
+ // Using connector-class-loader so as to get access to "transaction" module.
XAResourceWrapper xaresWrapper = null;
- xaresWrapper = (XAResourceWrapper) crt.getConnectorClassLoader().loadClass(wrapperclass).
- newInstance();
+ xaresWrapper = (XAResourceWrapper) crt.getConnectorClassLoader().loadClass(wrapperclass).newInstance();
xaresWrapper.init(mc, subject);
if (_logger.isLoggable(Level.FINEST)) {
- _logger.finest("adding resource " + poolInfo + " -- "+xaresWrapper);
+ _logger.finest("adding resource " + poolInfo + " -- " + xaresWrapper);
}
xaresList.add(xaresWrapper);
} else {
@@ -287,28 +287,28 @@
}
} catch (ResourceException ex) {
_logger.log(Level.WARNING, "datasource.xadatasource_error", poolInfo);
- if(_logger.isLoggable(Level.FINE)) {
+ if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "datasource.xadatasource_error_excp", ex);
}
// ignored. Not at XA_TRANSACTION level
}
} catch (Exception ex) {
_logger.log(Level.WARNING, "datasource.xadatasource_error", poolInfo);
- if(_logger.isLoggable(Level.FINE)) {
+ if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "datasource.xadatasource_error_excp", ex);
}
}
}
}
-
/**
* {@inheritDoc}
*/
+ @Override
public void closeConnections(List connList) {
for (Object obj : connList) {
try {
- ManagedConnection con = (ManagedConnection)obj;
+ ManagedConnection con = (ManagedConnection) obj;
con.destroy();
} catch (Exception ex) {
_logger.log(Level.WARNING, "recovery.jdbc-resource.destroy-error", ex);
@@ -318,11 +318,11 @@
/**
* gets the user-name & password for the jdbc-connection-pool
+ *
* @param jdbcConnectionPool connection pool
* @return user, password
*/
- public String[] getdbUserPasswordOfJdbcConnectionPool(
- JdbcConnectionPool jdbcConnectionPool) {
+ public String[] getdbUserPasswordOfJdbcConnectionPool(JdbcConnectionPool jdbcConnectionPool) {
String[] userPassword = new String[2];
userPassword[0] = null;
diff --git a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/util/JdbcResourcesUtil.java b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/util/JdbcResourcesUtil.java
index bfe3e26..447b137 100644
--- a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/util/JdbcResourcesUtil.java
+++ b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbc/util/JdbcResourcesUtil.java
@@ -16,6 +16,17 @@
package org.glassfish.jdbc.util;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.glassfish.jdbc.config.JdbcConnectionPool;
+import org.glassfish.jdbc.config.JdbcResource;
+import org.glassfish.resourcebase.resources.api.PoolInfo;
+import org.glassfish.resourcebase.resources.api.ResourceInfo;
+
import com.sun.appserv.connectors.internal.api.ConnectorConstants;
import com.sun.appserv.connectors.internal.api.ConnectorsUtil;
import com.sun.enterprise.config.serverbeans.BindableResource;
@@ -26,16 +37,6 @@
import com.sun.enterprise.connectors.util.ClassLoadingUtility;
import com.sun.enterprise.connectors.util.ResourcesUtil;
import com.sun.logging.LogDomains;
-import org.glassfish.jdbc.config.JdbcConnectionPool;
-import org.glassfish.jdbc.config.JdbcResource;
-import org.glassfish.resourcebase.resources.api.PoolInfo;
-import org.glassfish.resourcebase.resources.api.ResourceInfo;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
/**
* Utility class for JDBC related classes
@@ -43,18 +44,17 @@
public class JdbcResourcesUtil {
private volatile static JdbcResourcesUtil jdbcResourcesUtil;
- static Logger _logger = LogDomains.getLogger(JdbcResourcesUtil.class,
- LogDomains.RSR_LOGGER);
+ static Logger _logger = LogDomains.getLogger(JdbcResourcesUtil.class, LogDomains.RSR_LOGGER);
private ConnectorRuntime runtime;
- private JdbcResourcesUtil(){
+ private JdbcResourcesUtil() {
}
public static JdbcResourcesUtil createInstance() {
- //stateless, no synchronization needed
- if(jdbcResourcesUtil == null){
- synchronized(JdbcResourcesUtil.class) {
- if(jdbcResourcesUtil == null) {
+ // stateless, no synchronization needed
+ if (jdbcResourcesUtil == null) {
+ synchronized (JdbcResourcesUtil.class) {
+ if (jdbcResourcesUtil == null) {
jdbcResourcesUtil = new JdbcResourcesUtil();
}
}
@@ -62,14 +62,13 @@
return jdbcResourcesUtil;
}
- private ConnectorRuntime getRuntime(){
- if(runtime == null){
+ private ConnectorRuntime getRuntime() {
+ if (runtime == null) {
runtime = ConnectorRuntime.getRuntime();
}
return runtime;
}
-
public static <T> Resource getResourceByName(Resources resources, Class<T> type, String name) {
return resources.getResourceByName(type, name);
}
@@ -91,8 +90,8 @@
}
/**
- * This method takes in an admin JdbcConnectionPool and returns the RA
- * that it belongs to.
+ * This method takes in an admin JdbcConnectionPool and returns the RA that it
+ * belongs to.
*
* @param pool - The pool to check
* @return The name of the JDBC RA that provides this pool's data-source
@@ -103,57 +102,56 @@
Class clz = null;
- if(pool.getDatasourceClassname() != null && !pool.getDatasourceClassname().isEmpty()) {
+ if (pool.getDatasourceClassname() != null && !pool.getDatasourceClassname().isEmpty()) {
try {
clz = ClassLoadingUtility.loadClass(pool.getDatasourceClassname());
} catch (ClassNotFoundException cnfe) {
- Object params[] = new Object[]{dsRAName, pool.getName()};
+ Object params[] = new Object[] { dsRAName, pool.getName() };
_logger.log(Level.WARNING, "using.default.ds", params);
return dsRAName;
}
- } else if(pool.getDriverClassname() != null && !pool.getDriverClassname().isEmpty()) {
+ } else if (pool.getDriverClassname() != null && !pool.getDriverClassname().isEmpty()) {
try {
clz = ClassLoadingUtility.loadClass(pool.getDriverClassname());
} catch (ClassNotFoundException cnfe) {
- Object params[] = new Object[]{dsRAName, pool.getName()};
+ Object params[] = new Object[] { dsRAName, pool.getName() };
_logger.log(Level.WARNING, "using.default.ds", params);
return dsRAName;
}
}
- if(clz != null){
- //check if its XA
+ if (clz != null) {
+ // check if its XA
if (ConnectorConstants.JAVAX_SQL_XA_DATASOURCE.equals(pool.getResType())) {
if (javax.sql.XADataSource.class.isAssignableFrom(clz)) {
return ConnectorConstants.JDBCXA_RA_NAME;
}
}
- //check if its CP
+ // check if its CP
if (ConnectorConstants.JAVAX_SQL_CONNECTION_POOL_DATASOURCE.equals(pool.getResType())) {
- if (javax.sql.ConnectionPoolDataSource.class.isAssignableFrom(
- clz)) {
+ if (javax.sql.ConnectionPoolDataSource.class.isAssignableFrom(clz)) {
return ConnectorConstants.JDBCCONNECTIONPOOLDATASOURCE_RA_NAME;
}
}
- //check if its DM
- if(ConnectorConstants.JAVA_SQL_DRIVER.equals(pool.getResType())) {
- if(java.sql.Driver.class.isAssignableFrom(clz)) {
+ // check if its DM
+ if (ConnectorConstants.JAVA_SQL_DRIVER.equals(pool.getResType())) {
+ if (java.sql.Driver.class.isAssignableFrom(clz)) {
return ConnectorConstants.JDBCDRIVER_RA_NAME;
}
}
- //check if its DS
+ // check if its DS
if ("javax.sql.DataSource".equals(pool.getResType())) {
if (javax.sql.DataSource.class.isAssignableFrom(clz)) {
return dsRAName;
}
}
}
- Object params[] = new Object[]{dsRAName, pool.getName()};
+ Object params[] = new Object[] { dsRAName, pool.getName() };
_logger.log(Level.WARNING, "using.default.ds", params);
- //default to __ds
+ // default to __ds
return dsRAName;
}
@@ -161,10 +159,10 @@
JdbcResource resource = null;
JdbcConnectionPool pool = null;
Resources resources = getResources(resourceInfo);
- if(resources != null){
+ if (resources != null) {
resource = (JdbcResource) ConnectorsUtil.getResourceByName(resources, JdbcResource.class, resourceInfo.getName());
- if(resource != null){
- pool = (JdbcConnectionPool)ConnectorsUtil.getResourceByName(resources, JdbcConnectionPool.class, resource.getPoolName());
+ if (resource != null) {
+ pool = (JdbcConnectionPool) ConnectorsUtil.getResourceByName(resources, JdbcConnectionPool.class, resource.getPoolName());
}
}
return pool;
@@ -175,11 +173,12 @@
}
/**
- * Determines if a JDBC connection pool is referred in a
- * server-instance via resource-refs
+ * Determines if a JDBC connection pool is referred in a server-instance via
+ * resource-refs
+ *
* @param poolInfo pool-name
- * @return boolean true if pool is referred in this server instance as well enabled, false
- * otherwise
+ * @return boolean true if pool is referred in this server instance as well
+ * enabled, false otherwise
*/
public boolean isJdbcPoolReferredInServerInstance(PoolInfo poolInfo) {
@@ -187,21 +186,20 @@
for (JdbcResource resource : jdbcResources) {
ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(resource);
- //Have to check isReferenced here!
- if ((resource.getPoolName().equalsIgnoreCase(poolInfo.getName())) &&
- ResourcesUtil.createInstance().isReferenced(resourceInfo)
- && ResourcesUtil.createInstance().isEnabled(resource)){
+ // Have to check isReferenced here!
+ if ((resource.getPoolName().equalsIgnoreCase(poolInfo.getName())) && ResourcesUtil.createInstance().isReferenced(resourceInfo)
+ && ResourcesUtil.createInstance().isEnabled(resource)) {
if (_logger.isLoggable(Level.FINE)) {
- _logger.fine("pool " + poolInfo + "resource " + resourceInfo
- + " referred " + ResourcesUtil.createInstance().isReferenced(resourceInfo));
+ _logger.fine("pool " + poolInfo + "resource " + resourceInfo + " referred "
+ + ResourcesUtil.createInstance().isReferenced(resourceInfo));
- _logger.fine("JDBC resource " + resource.getJndiName() + "refers " + poolInfo
- + "in this server instance and is enabled");
+ _logger.fine(
+ "JDBC resource " + resource.getJndiName() + "refers " + poolInfo + "in this server instance and is enabled");
}
return true;
}
}
- if(_logger.isLoggable(Level.FINE)) {
+ if (_logger.isLoggable(Level.FINE)) {
_logger.fine("No JDBC resource refers [ " + poolInfo + " ] in this server instance");
}
return false;
diff --git a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/DefaultDataSource.java b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/DefaultDataSource.java
index 15cc607..dc86001 100644
--- a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/DefaultDataSource.java
+++ b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/DefaultDataSource.java
@@ -16,35 +16,38 @@
package org.glassfish.jdbcruntime;
+import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
+
import org.glassfish.api.naming.DefaultResourceProxy;
import org.glassfish.api.naming.NamedNamingObjectProxy;
import org.glassfish.api.naming.NamespacePrefixes;
import org.jvnet.hk2.annotations.Service;
/**
- * Naming Object Proxy to handle the Default Data Source.
- * Maps to a pre-configured data source, when binding for
- * a datasource reference is absent in the @Resource annotation.
+ * Naming Object Proxy to handle the Default Data Source. Maps to a
+ * pre-configured data source, when binding for a datasource reference is absent
+ * in the @Resource annotation.
*
* @author Shalini M
*/
@Service
-@NamespacePrefixes({DefaultDataSource.DEFAULT_DATASOURCE})
+@NamespacePrefixes(DefaultDataSource.DEFAULT_DATASOURCE)
public class DefaultDataSource implements NamedNamingObjectProxy, DefaultResourceProxy {
static final String DEFAULT_DATASOURCE = "java:comp/DefaultDataSource";
static final String DEFAULT_DATASOURCE_PHYS = "jdbc/__default";
+
private DataSource dataSource;
@Override
public Object handle(String name) throws NamingException {
- if(dataSource == null) {
- javax.naming.Context ctx = new javax.naming.InitialContext();
+ if (dataSource == null) {
// cache the datasource to avoid JNDI lookup overheads
- dataSource = (DataSource)ctx.lookup(DEFAULT_DATASOURCE_PHYS);
+ dataSource = (DataSource) new InitialContext().lookup(DEFAULT_DATASOURCE_PHYS);
}
+
return dataSource;
}
diff --git a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/JdbcPoolMonitoringExtension.java b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/JdbcPoolMonitoringExtension.java
index 0b284f9..9858bba 100644
--- a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/JdbcPoolMonitoringExtension.java
+++ b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/JdbcPoolMonitoringExtension.java
@@ -16,16 +16,11 @@
package org.glassfish.jdbcruntime;
-import com.sun.appserv.connectors.internal.api.ConnectorsUtil;
-import com.sun.enterprise.config.serverbeans.ResourcePool;
-import com.sun.enterprise.connectors.ConnectionPoolMonitoringExtension;
-import com.sun.enterprise.connectors.ConnectorRuntime;
-import com.sun.enterprise.resource.pool.PoolLifeCycleListenerRegistry;
-import com.sun.enterprise.resource.pool.PoolManager;
-import com.sun.enterprise.resource.pool.monitor.ConnectionPoolAppProbeProvider;
-import com.sun.enterprise.resource.pool.monitor.ConnectionPoolProbeProviderUtil;
-import com.sun.enterprise.resource.pool.monitor.ConnectionPoolStatsProviderBootstrap;
-import com.sun.logging.LogDomains;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.logging.Logger;
+
import org.glassfish.external.probe.provider.PluginPoint;
import org.glassfish.external.probe.provider.StatsProviderManager;
import org.glassfish.jdbc.config.JdbcConnectionPool;
@@ -36,12 +31,19 @@
import org.glassfish.resourcebase.resources.api.PoolInfo;
import org.jvnet.hk2.annotations.Service;
+import com.sun.appserv.connectors.internal.api.ConnectorsUtil;
+import com.sun.enterprise.config.serverbeans.ResourcePool;
+import com.sun.enterprise.connectors.ConnectionPoolMonitoringExtension;
+import com.sun.enterprise.connectors.ConnectorRuntime;
+import com.sun.enterprise.resource.pool.PoolLifeCycleListenerRegistry;
+import com.sun.enterprise.resource.pool.PoolManager;
+import com.sun.enterprise.resource.pool.monitor.ConnectionPoolAppProbeProvider;
+import com.sun.enterprise.resource.pool.monitor.ConnectionPoolProbeProviderUtil;
+import com.sun.enterprise.resource.pool.monitor.ConnectionPoolStatsProviderBootstrap;
+import com.sun.logging.LogDomains;
+
import jakarta.inject.Inject;
import jakarta.inject.Provider;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.logging.Logger;
/**
* @author Shalini M
@@ -49,7 +51,6 @@
@Service
public class JdbcPoolMonitoringExtension implements ConnectionPoolMonitoringExtension {
-
@Inject
private Provider<ConnectionPoolProbeProviderUtil> connectionPoolProbeProviderUtilProvider;
@@ -61,10 +62,9 @@
private ConnectorRuntime runtime;
- private final static Logger logger =
- LogDomains.getLogger(JdbcPoolMonitoringExtension.class, LogDomains.RSR_LOGGER);
+ private final static Logger logger = LogDomains.getLogger(JdbcPoolMonitoringExtension.class, LogDomains.RSR_LOGGER);
- //List of all jdbc pool stats providers that are created and stored.
+ // List of all jdbc pool stats providers that are created and stored.
private List<JdbcConnPoolStatsProvider> jdbcStatsProviders = null;
private List<JdbcConnPoolAppStatsProvider> jdbcPoolAppStatsProviders = null;
@@ -74,49 +74,48 @@
runtime = ConnectorRuntime.getRuntime();
}
- public ConnectionPoolProbeProviderUtil getProbeProviderUtil(){
+ public ConnectionPoolProbeProviderUtil getProbeProviderUtil() {
return connectionPoolProbeProviderUtilProvider.get();
}
/**
- * Register jdbc connection pool to the StatsProviderManager.
- * Add the pool lifecycle listeners for the pool to receive events on
- * change of any of the monitoring attribute values.
- * Finally, add this provider to the list of jdbc providers maintained.
+ * Register jdbc connection pool to the StatsProviderManager. Add the pool
+ * lifecycle listeners for the pool to receive events on change of any of the
+ * monitoring attribute values. Finally, add this provider to the list of jdbc
+ * providers maintained.
+ *
* @param poolInfo
*/
+ @Override
public void registerPool(PoolInfo poolInfo) {
- if(poolManager.getPool(poolInfo) != null) {
+ if (poolManager.getPool(poolInfo) != null) {
getProbeProviderUtil().createJdbcProbeProvider();
- //Found in the pool table (pool has been initialized/created)
- JdbcConnPoolStatsProvider jdbcPoolStatsProvider =
- new JdbcConnPoolStatsProvider(poolInfo, logger);
- StatsProviderManager.register(
- "jdbc-connection-pool",
- PluginPoint.SERVER,
+ // Found in the pool table (pool has been initialized/created)
+ JdbcConnPoolStatsProvider jdbcPoolStatsProvider = new JdbcConnPoolStatsProvider(poolInfo, logger);
+ StatsProviderManager.register("jdbc-connection-pool", PluginPoint.SERVER,
ConnectorsUtil.getPoolMonitoringSubTreeRoot(poolInfo, true), jdbcPoolStatsProvider);
- //String jdbcPoolName = jdbcPoolStatsProvider.getJdbcPoolName();
- PoolLifeCycleListenerRegistry registry =
- connectionPoolStatsProviderBootstrapProvider.get().registerPool(
- poolInfo,
- getProbeProviderUtil().getJdbcProbeProvider());
+ // String jdbcPoolName = jdbcPoolStatsProvider.getJdbcPoolName();
+ PoolLifeCycleListenerRegistry registry = connectionPoolStatsProviderBootstrapProvider.get().registerPool(poolInfo,
+ getProbeProviderUtil().getJdbcProbeProvider());
jdbcPoolStatsProvider.setPoolRegistry(registry);
jdbcStatsProviders.add(jdbcPoolStatsProvider);
}
}
/**
- * Unregister Jdbc Connection pool from the StatsProviderManager.
- * Remove the pool lifecycle listeners associated with this pool.
+ * Unregister Jdbc Connection pool from the StatsProviderManager. Remove the
+ * pool lifecycle listeners associated with this pool.
+ *
* @param poolInfo
*/
+ @Override
public void unregisterPool(PoolInfo poolInfo) {
- if(jdbcStatsProviders != null) {
+ if (jdbcStatsProviders != null) {
Iterator i = jdbcStatsProviders.iterator();
while (i.hasNext()) {
JdbcConnPoolStatsProvider jdbcPoolStatsProvider = (JdbcConnPoolStatsProvider) i.next();
if (poolInfo.equals(jdbcPoolStatsProvider.getPoolInfo())) {
- //Get registry and unregister this pool from the registry
+ // Get registry and unregister this pool from the registry
PoolLifeCycleListenerRegistry poolRegistry = jdbcPoolStatsProvider.getPoolRegistry();
poolRegistry.unRegisterPoolLifeCycleListener(poolInfo);
StatsProviderManager.unregister(jdbcPoolStatsProvider);
@@ -129,26 +128,21 @@
}
/**
- * Register the jdbc connection pool Stats Provider object to the
- * monitoring framework under the specific application name monitoring
- * sub tree.
+ * Register the jdbc connection pool Stats Provider object to the monitoring
+ * framework under the specific application name monitoring sub tree.
*
* @param appName
* @return
*/
- public ConnectionPoolAppProbeProvider registerConnectionPool(
- PoolInfo poolInfo, String appName) {
+ @Override
+ public ConnectionPoolAppProbeProvider registerConnectionPool(PoolInfo poolInfo, String appName) {
ConnectionPoolAppProbeProvider probeAppProvider = null;
ResourcePool pool = runtime.getConnectionPoolConfig(poolInfo);
if (pool instanceof JdbcConnectionPool) {
probeAppProvider = new JdbcConnPoolAppProbeProvider();
- JdbcConnPoolAppStatsProvider jdbcPoolAppStatsProvider =
- new JdbcConnPoolAppStatsProvider(poolInfo, appName);
- StatsProviderManager.register(
- "jdbc-connection-pool",
- PluginPoint.SERVER,
- "resources/" + ConnectorsUtil.escapeResourceNameForMonitoring(
- poolInfo.getName()) + "/" + appName,
+ JdbcConnPoolAppStatsProvider jdbcPoolAppStatsProvider = new JdbcConnPoolAppStatsProvider(poolInfo, appName);
+ StatsProviderManager.register("jdbc-connection-pool", PluginPoint.SERVER,
+ "resources/" + ConnectorsUtil.escapeResourceNameForMonitoring(poolInfo.getName()) + "/" + appName,
jdbcPoolAppStatsProvider);
jdbcPoolAppStatsProviders.add(jdbcPoolAppStatsProvider);
}
@@ -158,20 +152,19 @@
/**
* Unregister the AppStatsProviders registered for this connection pool.
*/
+ @Override
public void unRegisterConnectionPool() {
Iterator jdbcProviders = jdbcPoolAppStatsProviders.iterator();
while (jdbcProviders.hasNext()) {
- JdbcConnPoolAppStatsProvider jdbcPoolAppStatsProvider =
- (JdbcConnPoolAppStatsProvider) jdbcProviders.next();
+ JdbcConnPoolAppStatsProvider jdbcPoolAppStatsProvider = (JdbcConnPoolAppStatsProvider) jdbcProviders.next();
StatsProviderManager.unregister(jdbcPoolAppStatsProvider);
}
jdbcPoolAppStatsProviders.clear();
}
+ @Override
public JdbcConnPoolProbeProvider createProbeProvider() {
return new JdbcConnPoolProbeProvider();
}
-
-
}
diff --git a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/JdbcRuntimeExtension.java b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/JdbcRuntimeExtension.java
index b16537d..f67506d 100644
--- a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/JdbcRuntimeExtension.java
+++ b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/JdbcRuntimeExtension.java
@@ -16,6 +16,21 @@
package org.glassfish.jdbcruntime;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.glassfish.jdbc.config.JdbcConnectionPool;
+import org.glassfish.jdbc.config.JdbcResource;
+import org.glassfish.jdbc.deployer.DataSourceDefinitionDeployer;
+import org.glassfish.jdbcruntime.service.JdbcDataSource;
+import org.glassfish.resourcebase.resources.api.PoolInfo;
+import org.glassfish.resourcebase.resources.api.ResourceInfo;
+import org.jvnet.hk2.annotations.Service;
+import org.jvnet.hk2.config.ConfigBeanProxy;
+
import com.sun.appserv.connectors.internal.api.ConnectorConstants;
import com.sun.appserv.connectors.internal.api.ConnectorRuntimeException;
import com.sun.appserv.connectors.internal.api.ConnectorsUtil;
@@ -29,22 +44,9 @@
import com.sun.enterprise.connectors.util.ResourcesUtil;
import com.sun.enterprise.deployment.Application;
import com.sun.logging.LogDomains;
-import org.glassfish.jdbc.config.JdbcConnectionPool;
-import org.glassfish.jdbc.config.JdbcResource;
-import org.glassfish.jdbc.deployer.DataSourceDefinitionDeployer;
-import org.glassfish.jdbcruntime.service.JdbcDataSource;
-import org.glassfish.resourcebase.resources.api.PoolInfo;
-import org.glassfish.resourcebase.resources.api.ResourceInfo;
-import org.jvnet.hk2.annotations.Service;
-import org.jvnet.hk2.config.ConfigBeanProxy;
import jakarta.inject.Inject;
import jakarta.inject.Provider;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
/**
* @author Shalini M
@@ -58,8 +60,7 @@
@Inject
private Provider<DataSourceDefinitionDeployer> dataSourceDefinitionDeployerProvider;
- protected final static Logger logger =
- LogDomains.getLogger(JdbcRuntimeExtension.class, LogDomains.RSR_LOGGER);
+ protected final static Logger logger = LogDomains.getLogger(JdbcRuntimeExtension.class, LogDomains.RSR_LOGGER);
protected ConnectorRuntime runtime;
@@ -67,16 +68,17 @@
runtime = ConnectorRuntime.getRuntime();
}
+ @Override
public Collection<Resource> getAllSystemRAResourcesAndPools() {
List<Resource> resources = new ArrayList<Resource>();
Domain domain = domainProvider.get();
- if(domain !=null) {
+ if (domain != null) {
Resources allResources = domain.getResources();
- for(Resource resource : allResources.getResources()){
- if(resource instanceof JdbcConnectionPool){
+ for (Resource resource : allResources.getResources()) {
+ if (resource instanceof JdbcConnectionPool) {
resources.add(resource);
- } else if(resource instanceof JdbcResource){
+ } else if (resource instanceof JdbcResource) {
resources.add(resource);
}
}
@@ -86,27 +88,30 @@
return resources;
}
+ @Override
public void registerDataSourceDefinitions(Application application) {
dataSourceDefinitionDeployerProvider.get().registerDataSourceDefinitions(application);
}
+ @Override
public void unRegisterDataSourceDefinitions(Application application) {
dataSourceDefinitionDeployerProvider.get().unRegisterDataSourceDefinitions(application);
}
/**
- * Get a wrapper datasource specified by the jdbcjndi name
- * This API is intended to be used in the DAS. The motivation for having this
- * API is to provide the CMP backend/ JPA-Java2DB a means of acquiring a connection during
- * the codegen phase. If a user is trying to deploy an JPA-Java2DB app on a remote server,
- * without this API, a resource reference has to be present both in the DAS
- * and the server instance. This makes the deployment more complex for the
- * user since a resource needs to be forcibly created in the DAS Too.
- * This API will mitigate this need.
+ * Get a wrapper datasource specified by the jdbcjndi name This API is intended
+ * to be used in the DAS. The motivation for having this API is to provide the
+ * CMP backend/ JPA-Java2DB a means of acquiring a connection during the codegen
+ * phase. If a user is trying to deploy an JPA-Java2DB app on a remote server,
+ * without this API, a resource reference has to be present both in the DAS and
+ * the server instance. This makes the deployment more complex for the user
+ * since a resource needs to be forcibly created in the DAS Too. This API will
+ * mitigate this need.
*
* @param resourceInfo the jndi name of the resource
* @return DataSource representing the resource.
*/
+ @Override
public Object lookupDataSourceInDAS(ResourceInfo resourceInfo) throws ConnectorRuntimeException {
JdbcDataSource myDS = new JdbcDataSource();
myDS.setResourceInfo(resourceInfo);
@@ -114,34 +119,33 @@
}
/**
- * Gets the Pool name that this JDBC resource points to. In case of a PMF resource
- * gets the pool name of the pool pointed to by jdbc resource being pointed to by
- * the PMF resource
+ * Gets the Pool name that this JDBC resource points to. In case of a PMF
+ * resource gets the pool name of the pool pointed to by jdbc resource being
+ * pointed to by the PMF resource
*
- * @param resourceInfo the jndi name of the resource being used to get Connection from
- * This resource can either be a pmf resource or a jdbc resource
+ * @param resourceInfo the jndi name of the resource being used to get
+ * Connection from This resource can either be a pmf resource or a jdbc resource
* @return poolName of the pool that this resource directly/indirectly points to
*/
+ @Override
public PoolInfo getPoolNameFromResourceJndiName(ResourceInfo resourceInfo) {
- PoolInfo poolInfo= null;
+ PoolInfo poolInfo = null;
JdbcResource jdbcResource = null;
String jndiName = resourceInfo.getName();
- ResourceInfo actualResourceInfo =
- new ResourceInfo(jndiName, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
+ ResourceInfo actualResourceInfo = new ResourceInfo(jndiName, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
ConnectorRuntime runtime = ConnectorRuntime.getRuntime();
- jdbcResource = (JdbcResource) ConnectorsUtil.getResourceByName(runtime.getResources(actualResourceInfo),
- JdbcResource.class, actualResourceInfo.getName());
- if(jdbcResource == null){
+ jdbcResource = (JdbcResource) ConnectorsUtil.getResourceByName(runtime.getResources(actualResourceInfo), JdbcResource.class,
+ actualResourceInfo.getName());
+ if (jdbcResource == null) {
String suffix = ConnectorsUtil.getValidSuffix(jndiName);
- if(suffix != null){
+ if (suffix != null) {
jndiName = jndiName.substring(0, jndiName.lastIndexOf(suffix));
- actualResourceInfo =
- new ResourceInfo(jndiName, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
+ actualResourceInfo = new ResourceInfo(jndiName, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
}
}
- jdbcResource = (JdbcResource) ConnectorsUtil.getResourceByName(runtime.getResources(actualResourceInfo),
- JdbcResource.class, actualResourceInfo.getName());
+ jdbcResource = (JdbcResource) ConnectorsUtil.getResourceByName(runtime.getResources(actualResourceInfo), JdbcResource.class,
+ actualResourceInfo.getName());
if (jdbcResource != null) {
if (logger.isLoggable(Level.FINE)) {
@@ -149,7 +153,7 @@
logger.fine("poolName is ---: " + jdbcResource.getPoolName());
}
}
- if(jdbcResource != null){
+ if (jdbcResource != null) {
poolInfo = new PoolInfo(jdbcResource.getPoolName(), actualResourceInfo.getApplicationName(),
actualResourceInfo.getModuleName());
}
@@ -157,39 +161,39 @@
}
/**
- * Determines if a JDBC connection pool is referred in a
- * server-instance via resource-refs
+ * Determines if a JDBC connection pool is referred in a server-instance via
+ * resource-refs
+ *
* @param poolInfo pool-name
- * @return boolean true if pool is referred in this server instance as well enabled, false
- * otherwise
+ * @return boolean true if pool is referred in this server instance as well
+ * enabled, false otherwise
*/
+ @Override
public boolean isConnectionPoolReferredInServerInstance(PoolInfo poolInfo) {
- Collection<JdbcResource> jdbcResources = ConnectorRuntime.getRuntime().
- getResources(poolInfo).getResources(JdbcResource.class);
+ Collection<JdbcResource> jdbcResources = ConnectorRuntime.getRuntime().getResources(poolInfo).getResources(JdbcResource.class);
for (JdbcResource resource : jdbcResources) {
ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(resource);
- //Have to check isReferenced here!
- if ((resource.getPoolName().equalsIgnoreCase(poolInfo.getName())) &&
- ResourcesUtil.createInstance().isReferenced(resourceInfo) &&
- ResourcesUtil.createInstance().isEnabled(resource)) {
+ // Have to check isReferenced here!
+ if ((resource.getPoolName().equalsIgnoreCase(poolInfo.getName())) && ResourcesUtil.createInstance().isReferenced(resourceInfo)
+ && ResourcesUtil.createInstance().isEnabled(resource)) {
if (logger.isLoggable(Level.FINE)) {
- logger.fine("pool " + poolInfo + "resource " + resourceInfo
- + " referred is referenced by this server");
+ logger.fine("pool " + poolInfo + "resource " + resourceInfo + " referred is referenced by this server");
- logger.fine("JDBC resource " + resource.getJndiName() + "refers " + poolInfo
- + "in this server instance and is enabled");
+ logger.fine(
+ "JDBC resource " + resource.getJndiName() + "refers " + poolInfo + "in this server instance and is enabled");
}
return true;
}
}
- if(logger.isLoggable(Level.FINE)) {
+ if (logger.isLoggable(Level.FINE)) {
logger.fine("No JDBC resource refers [ " + poolInfo + " ] in this server instance");
}
return false;
}
+ @Override
public String getResourceType(ConfigBeanProxy cb) {
if (cb instanceof JdbcConnectionPool) {
return ConnectorConstants.RES_TYPE_JCP;
@@ -199,13 +203,14 @@
return null;
}
- public DeferredResourceConfig getDeferredResourceConfig(Object resource,
- Object pool, String resType, String raName)
+ @Override
+ public DeferredResourceConfig getDeferredResourceConfig(Object resource, Object pool, String resType, String raName)
throws ConnectorRuntimeException {
String resourceAdapterName;
DeferredResourceConfig resConfig = null;
- //TODO V3 there should not be res-type related check, refactor deferred-ra-config
- //TODO V3 (not to hold specific resource types)
+ // TODO V3 there should not be res-type related check, refactor
+ // deferred-ra-config
+ // TODO V3 (not to hold specific resource types)
if (resource instanceof JdbcResource || pool instanceof JdbcConnectionPool) {
JdbcConnectionPool jdbcPool = (JdbcConnectionPool) pool;
@@ -215,7 +220,7 @@
resConfig = new DeferredResourceConfig(resourceAdapterName, null, jdbcPool, jdbcResource, null);
- Resource[] resourcesToload = new Resource[]{jdbcPool, jdbcResource};
+ Resource[] resourcesToload = new Resource[] { jdbcPool, jdbcResource };
resConfig.setResourcesToLoad(resourcesToload);
} else {
@@ -225,8 +230,8 @@
}
/**
- * This method takes in an admin JdbcConnectionPool and returns the RA
- * that it belongs to.
+ * This method takes in an admin JdbcConnectionPool and returns the RA that it
+ * belongs to.
*
* @param pool - The pool to check
* @return The name of the JDBC RA that provides this pool's data-source
@@ -237,59 +242,57 @@
Class clz = null;
- if(pool.getDatasourceClassname() != null && !pool.getDatasourceClassname().isEmpty()) {
+ if (pool.getDatasourceClassname() != null && !pool.getDatasourceClassname().isEmpty()) {
try {
clz = ClassLoadingUtility.loadClass(pool.getDatasourceClassname());
} catch (ClassNotFoundException cnfe) {
- Object params[] = new Object[]{dsRAName, pool.getName()};
+ Object params[] = new Object[] { dsRAName, pool.getName() };
logger.log(Level.WARNING, "using.default.ds", params);
return dsRAName;
}
- } else if(pool.getDriverClassname() != null && !pool.getDriverClassname().isEmpty()) {
+ } else if (pool.getDriverClassname() != null && !pool.getDriverClassname().isEmpty()) {
try {
clz = ClassLoadingUtility.loadClass(pool.getDriverClassname());
} catch (ClassNotFoundException cnfe) {
- Object params[] = new Object[]{dsRAName, pool.getName()};
+ Object params[] = new Object[] { dsRAName, pool.getName() };
logger.log(Level.WARNING, "using.default.ds", params);
return dsRAName;
}
}
- if(clz != null){
- //check if its XA
+ if (clz != null) {
+ // check if its XA
if (ConnectorConstants.JAVAX_SQL_XA_DATASOURCE.equals(pool.getResType())) {
if (javax.sql.XADataSource.class.isAssignableFrom(clz)) {
return ConnectorConstants.JDBCXA_RA_NAME;
}
}
- //check if its CP
+ // check if its CP
if (ConnectorConstants.JAVAX_SQL_CONNECTION_POOL_DATASOURCE.equals(pool.getResType())) {
- if (javax.sql.ConnectionPoolDataSource.class.isAssignableFrom(
- clz)) {
+ if (javax.sql.ConnectionPoolDataSource.class.isAssignableFrom(clz)) {
return ConnectorConstants.JDBCCONNECTIONPOOLDATASOURCE_RA_NAME;
}
}
- //check if its DM
- if(ConnectorConstants.JAVA_SQL_DRIVER.equals(pool.getResType())) {
- if(java.sql.Driver.class.isAssignableFrom(clz)) {
+ // check if its DM
+ if (ConnectorConstants.JAVA_SQL_DRIVER.equals(pool.getResType())) {
+ if (java.sql.Driver.class.isAssignableFrom(clz)) {
return ConnectorConstants.JDBCDRIVER_RA_NAME;
}
}
- //check if its DS
+ // check if its DS
if ("javax.sql.DataSource".equals(pool.getResType())) {
if (javax.sql.DataSource.class.isAssignableFrom(clz)) {
return dsRAName;
}
}
}
- Object params[] = new Object[]{dsRAName, pool.getName()};
+ Object params[] = new Object[] { dsRAName, pool.getName() };
logger.log(Level.WARNING, "using.default.ds", params);
- //default to __ds
+ // default to __ds
return dsRAName;
}
}
-
diff --git a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/deployment/annotation/handlers/DataSourceDefinitionHandler.java b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/deployment/annotation/handlers/DataSourceDefinitionHandler.java
index ccbb37f..ab1702f 100644
--- a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/deployment/annotation/handlers/DataSourceDefinitionHandler.java
+++ b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/deployment/annotation/handlers/DataSourceDefinitionHandler.java
@@ -17,9 +17,15 @@
package org.glassfish.jdbcruntime.deployment.annotation.handlers;
-import com.sun.enterprise.deployment.*;
-import com.sun.enterprise.deployment.annotation.context.*;
-import com.sun.enterprise.deployment.annotation.handlers.AbstractResourceHandler;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+import java.util.logging.Level;
+
import org.glassfish.apf.AnnotationHandlerFor;
import org.glassfish.apf.AnnotationInfo;
import org.glassfish.apf.AnnotationProcessorException;
@@ -28,15 +34,26 @@
import org.glassfish.deployment.common.RootDeploymentDescriptor;
import org.jvnet.hk2.annotations.Service;
+import com.sun.enterprise.deployment.DataSourceDefinitionDescriptor;
+import com.sun.enterprise.deployment.EjbBundleDescriptor;
+import com.sun.enterprise.deployment.EjbDescriptor;
+import com.sun.enterprise.deployment.MetadataSource;
+import com.sun.enterprise.deployment.ResourceDescriptor;
+import com.sun.enterprise.deployment.WebBundleDescriptor;
+import com.sun.enterprise.deployment.annotation.context.EjbBundleContext;
+import com.sun.enterprise.deployment.annotation.context.EjbContext;
+import com.sun.enterprise.deployment.annotation.context.EjbInterceptorContext;
+import com.sun.enterprise.deployment.annotation.context.ResourceContainerContext;
+import com.sun.enterprise.deployment.annotation.context.WebBundleContext;
+import com.sun.enterprise.deployment.annotation.context.WebComponentContext;
+import com.sun.enterprise.deployment.annotation.context.WebComponentsContext;
+import com.sun.enterprise.deployment.annotation.handlers.AbstractResourceHandler;
+
import jakarta.annotation.sql.DataSourceDefinition;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.AroundTimeout;
import jakarta.interceptor.Interceptor;
import jakarta.interceptor.Interceptors;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.util.*;
-import java.util.logging.Level;
/**
* @author Jagadish Ramu
@@ -48,31 +65,30 @@
public DataSourceDefinitionHandler() {
}
+ @Override
protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, ResourceContainerContext[] rcContexts)
throws AnnotationProcessorException {
- DataSourceDefinition dataSourceDefnAn =
- (DataSourceDefinition)ainfo.getAnnotation();
+ DataSourceDefinition dataSourceDefnAn = (DataSourceDefinition) ainfo.getAnnotation();
return processAnnotation(dataSourceDefnAn, ainfo, rcContexts);
}
protected HandlerProcessingResult processAnnotation(DataSourceDefinition dataSourceDefnAn, AnnotationInfo aiInfo,
- ResourceContainerContext[] rcContexts)
- throws AnnotationProcessorException {
- Class annotatedClass = (Class)aiInfo.getAnnotatedElement();
+ ResourceContainerContext[] rcContexts) throws AnnotationProcessorException {
+ Class annotatedClass = (Class) aiInfo.getAnnotatedElement();
Annotation[] annotations = annotatedClass.getAnnotations();
boolean warClass = isAWebComponentClass(annotations);
boolean ejbClass = isAEjbComponentClass(annotations);
- for(ResourceContainerContext context : rcContexts){
- if (!canProcessAnnotation(annotatedClass, ejbClass, warClass, context)){
- return getDefaultProcessedResult();
- }
+ for (ResourceContainerContext context : rcContexts) {
+ if (!canProcessAnnotation(annotatedClass, ejbClass, warClass, context)) {
+ return getDefaultProcessedResult();
+ }
Set<ResourceDescriptor> dsdDescs = context.getResourceDescriptors(JavaEEResourceType.DSD);
DataSourceDefinitionDescriptor desc = createDescriptor(dataSourceDefnAn);
- if(isDefinitionAlreadyPresent(dsdDescs, desc)){
+ if (isDefinitionAlreadyPresent(dsdDescs, desc)) {
merge(dsdDescs, dataSourceDefnAn);
- }else{
+ } else {
dsdDescs.add(desc);
}
}
@@ -80,11 +96,12 @@
}
/**
- * To take care of the case where an ejb is provided in a .war and
- * annotation processor will process this class twice (once for ejb and
- * once for web-bundle-context, which is a bug).<br>
+ * To take care of the case where an ejb is provided in a .war and annotation
+ * processor will process this class twice (once for ejb and once for
+ * web-bundle-context, which is a bug).<br>
* This method helps to overcome the issue, partially.<br>
- * Checks whether both the annotated class and the context are either ejb or web.
+ * Checks whether both the annotated class and the context are either ejb or
+ * web.
*
* @param annotatedClass annotated-class
* @param ejbClass indicates whether the class is an ejb-class
@@ -92,16 +109,12 @@
* @param context resource-container-context
* @return boolean indicates whether the annotation can be processed.
*/
- private boolean canProcessAnnotation(Class annotatedClass, boolean ejbClass, boolean warClass,
- ResourceContainerContext context) {
+ private boolean canProcessAnnotation(Class annotatedClass, boolean ejbClass, boolean warClass, ResourceContainerContext context) {
if (ejbClass) {
- if (!(context instanceof EjbBundleContext ||
- context instanceof EjbContext ||
- context instanceof EjbInterceptorContext
- )) {
+ if (!(context instanceof EjbBundleContext || context instanceof EjbContext || context instanceof EjbInterceptorContext)) {
if (logger.isLoggable(Level.FINEST)) {
- logger.log(Level.FINEST, "Ignoring @DataSourceDefinition annotation processing as the class is " +
- "an EJB class and context is not one of EJBContext");
+ logger.log(Level.FINEST, "Ignoring @DataSourceDefinition annotation processing as the class is "
+ + "an EJB class and context is not one of EJBContext");
}
return false;
}
@@ -111,18 +124,17 @@
EjbDescriptor[] ejbDescriptor = ejbBundleDescriptor.getEjbByClassName(annotatedClass.getName());
if (ejbDescriptor == null || ejbDescriptor.length == 0) {
if (logger.isLoggable(Level.FINEST)) {
- logger.log(Level.FINEST, "Ignoring @DataSourceDefinition annotation processing as the class " +
- "[ " + annotatedClass + " ] is " +
- "not an EJB class and the context is EJBContext");
+ logger.log(Level.FINEST, "Ignoring @DataSourceDefinition annotation processing as the class " + "[ " + annotatedClass
+ + " ] is " + "not an EJB class and the context is EJBContext");
}
return false;
}
} else if (warClass) {
if (!(context instanceof WebBundleContext || context instanceof WebComponentsContext
- || context instanceof WebComponentContext )) {
+ || context instanceof WebComponentContext)) {
if (logger.isLoggable(Level.FINEST)) {
- logger.log(Level.FINEST, "Ignoring @DataSourceDefinition annotation processing as the class is " +
- "an Web class and context is not one of WebContext");
+ logger.log(Level.FINEST, "Ignoring @DataSourceDefinition annotation processing as the class is "
+ + "an Web class and context is not one of WebContext");
}
return false;
}
@@ -130,38 +142,35 @@
WebBundleContext webBundleContext = (WebBundleContext) context;
WebBundleDescriptor webBundleDescriptor = webBundleContext.getDescriptor();
Collection<RootDeploymentDescriptor> extDesc = webBundleDescriptor.getExtensionsDescriptors();
- for(RootDeploymentDescriptor desc : extDesc){
- if(desc instanceof EjbBundleDescriptor){
- EjbBundleDescriptor ejbBundleDesc = (EjbBundleDescriptor)desc;
+ for (RootDeploymentDescriptor desc : extDesc) {
+ if (desc instanceof EjbBundleDescriptor) {
+ EjbBundleDescriptor ejbBundleDesc = (EjbBundleDescriptor) desc;
EjbDescriptor[] ejbDescs = ejbBundleDesc.getEjbByClassName(annotatedClass.getName());
- if(ejbDescs != null && ejbDescs.length > 0){
+ if (ejbDescs != null && ejbDescs.length > 0) {
if (logger.isLoggable(Level.FINEST)) {
- logger.log(Level.FINEST, "Ignoring @DataSourceDefinition annotation processing as the class " +
- "[ " + annotatedClass + " ] is " +
- "not an Web class and the context is WebContext");
+ logger.log(Level.FINEST, "Ignoring @DataSourceDefinition annotation processing as the class " + "[ "
+ + annotatedClass + " ] is " + "not an Web class and the context is WebContext");
}
return false;
- }else if(ejbBundleDesc.getInterceptorByClassName(annotatedClass.getName()) != null){
- if (logger.isLoggable(Level.FINEST)) {
- logger.log(Level.FINEST, "Ignoring @DataSourceDefinition annotation processing " +
- "as the class " +
- "[ " + annotatedClass + " ] is " +
- "not an Web class and the context is WebContext");
- }
- return false;
- }else{
+ } else if (ejbBundleDesc.getInterceptorByClassName(annotatedClass.getName()) != null) {
+ if (logger.isLoggable(Level.FINEST)) {
+ logger.log(Level.FINEST, "Ignoring @DataSourceDefinition annotation processing " + "as the class " + "[ "
+ + annotatedClass + " ] is " + "not an Web class and the context is WebContext");
+ }
+ return false;
+ } else {
Method[] methods = annotatedClass.getDeclaredMethods();
- for(Method method : methods){
+ for (Method method : methods) {
Annotation annotations[] = method.getAnnotations();
- for(Annotation annotation : annotations){
- if(annotation.annotationType().equals(AroundInvoke.class) ||
- annotation.annotationType().equals(AroundTimeout.class) ||
- annotation.annotationType().equals(Interceptors.class)) {
+ for (Annotation annotation : annotations) {
+ if (annotation.annotationType().equals(AroundInvoke.class)
+ || annotation.annotationType().equals(AroundTimeout.class)
+ || annotation.annotationType().equals(Interceptors.class)) {
if (logger.isLoggable(Level.FINEST)) {
- logger.log(Level.FINEST, "Ignoring @DataSourceDefinition annotation processing " +
- "as the class " +
- "[ " + annotatedClass + " ] is " +
- "not an Web class, an interceptor and the context is WebContext");
+ logger.log(Level.FINEST,
+ "Ignoring @DataSourceDefinition annotation processing " + "as the class " + "[ "
+ + annotatedClass + " ] is "
+ + "not an Web class, an interceptor and the context is WebContext");
}
return false;
}
@@ -174,11 +183,10 @@
return true;
}
- private boolean isDefinitionAlreadyPresent(Set<ResourceDescriptor> dsdDescs,
- DataSourceDefinitionDescriptor desc) {
- boolean result = false ;
- for(ResourceDescriptor descriptor : dsdDescs){
- if(descriptor.equals(desc)){
+ private boolean isDefinitionAlreadyPresent(Set<ResourceDescriptor> dsdDescs, DataSourceDefinitionDescriptor desc) {
+ boolean result = false;
+ for (ResourceDescriptor descriptor : dsdDescs) {
+ if (descriptor.equals(desc)) {
result = true;
break;
}
@@ -186,11 +194,11 @@
return result;
}
-
+ @Override
public Class<? extends Annotation>[] getTypeDependencies() {
- Class<? extends Annotation> [] annotations = getEjbAndWebAnnotationTypes();
- List<Class <? extends Annotation>> annotationsList = new ArrayList<Class <? extends Annotation>>();
- for(Class<? extends Annotation> annotation : annotations){
+ Class<? extends Annotation>[] annotations = getEjbAndWebAnnotationTypes();
+ List<Class<? extends Annotation>> annotationsList = new ArrayList<Class<? extends Annotation>>();
+ for (Class<? extends Annotation> annotation : annotations) {
annotationsList.add(annotation);
}
annotationsList.add(Interceptors.class);
@@ -202,11 +210,10 @@
return annotationsList.toArray(result);
}
-
private void merge(Set<ResourceDescriptor> dsdDescs, DataSourceDefinition defn) {
for (ResourceDescriptor orgdesc : dsdDescs) {
- DataSourceDefinitionDescriptor desc = (DataSourceDefinitionDescriptor)orgdesc;
+ DataSourceDefinitionDescriptor desc = (DataSourceDefinitionDescriptor) orgdesc;
if (desc.getName().equals(defn.name())) {
if (desc.getClassName() == null) {
@@ -221,36 +228,37 @@
// When either URL or Standard properties are specified in DD, annotation values
// (of URL or standard properties) are ignored.
- // DD values will win as either of URL or standard properties will be present most of the times.
- // Only when neither URL nor standard properties are not present, annotation values are considered.
+ // DD values will win as either of URL or standard properties will be present
+ // most of the times.
+ // Only when neither URL nor standard properties are not present, annotation
+ // values are considered.
// In such case, standard properties take precedence over URL.
- //try only when URL is not set
+ // try only when URL is not set
if (!desc.isServerNameSet() && desc.getUrl() == null) {
- //localhost is the default value (even in the descriptor)
+ // localhost is the default value (even in the descriptor)
if (defn.serverName() != null && !defn.serverName().equals("localhost")) {
desc.setServerName(defn.serverName());
}
}
- //try only when URL is not set
+ // try only when URL is not set
if (desc.getPortNumber() == -1 && desc.getUrl() == null) {
if (defn.portNumber() != -1) {
desc.setPortNumber(defn.portNumber());
}
}
- //try only when URL is not set
+ // try only when URL is not set
if (desc.getDatabaseName() == null && desc.getUrl() == null) {
if (defn.databaseName() != null && !defn.databaseName().equals("")) {
desc.setDatabaseName(defn.databaseName());
}
}
- //try only when URL or standard properties are not set
- if (desc.getUrl() == null &&
- !(desc.getPortNumber() != -1 && desc.getServerName() != null &&
- (desc.getDatabaseName() != null))) {
+ // try only when URL or standard properties are not set
+ if (desc.getUrl() == null
+ && !(desc.getPortNumber() != -1 && desc.getServerName() != null && (desc.getDatabaseName() != null))) {
if (defn.url() != null && !defn.url().equals("")) {
desc.setUrl(defn.url());
}
@@ -264,7 +272,7 @@
}
if (desc.getPassword() == null) {
- if (defn.password() != null /*ALLOW EMPTY PASSWORDS && !defn.password().equals("")*/) {
+ if (defn.password() != null /* ALLOW EMPTY PASSWORDS && !defn.password().equals("") */) {
desc.setPassword(defn.password());
}
}
@@ -329,7 +337,7 @@
if (index > -1 && index != 0 && index < property.length() - 1) {
String name = property.substring(0, index);
String value = property.substring(index + 1);
- //add to properties only when not already present
+ // add to properties only when not already present
if (properties.get(name) == null) {
properties.put(name, value);
}
@@ -342,7 +350,6 @@
}
-
private DataSourceDefinitionDescriptor createDescriptor(DataSourceDefinition defn) {
DataSourceDefinitionDescriptor desc = new DataSourceDefinitionDescriptor();
@@ -363,13 +370,12 @@
desc.setPortNumber(defn.portNumber());
}
-
if (defn.databaseName() != null && !defn.databaseName().equals("")) {
desc.setDatabaseName(defn.databaseName());
}
if ((desc.getPortNumber() != -1 && desc.getDatabaseName() != null && desc.getServerName() != null)) {
- //standard properties are set, ignore URL
+ // standard properties are set, ignore URL
} else {
if (defn.url() != null && !defn.url().equals("")) {
desc.setUrl(defn.url());
@@ -380,7 +386,7 @@
desc.setUser(defn.user());
}
- if (defn.password() != null /*ALLOW EMPTY PASSWORDS && !defn.password().equals("")*/) {
+ if (defn.password() != null /* ALLOW EMPTY PASSWORDS && !defn.password().equals("") */) {
desc.setPassword(defn.password());
}
@@ -416,7 +422,6 @@
desc.setLoginTimeout(String.valueOf(defn.loginTimeout()));
}
-
if (defn.properties() != null) {
Properties properties = desc.getProperties();
diff --git a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/deployment/annotation/handlers/DataSourceDefinitionsHandler.java b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/deployment/annotation/handlers/DataSourceDefinitionsHandler.java
index ebecd03..5a6d9c4 100644
--- a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/deployment/annotation/handlers/DataSourceDefinitionsHandler.java
+++ b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/deployment/annotation/handlers/DataSourceDefinitionsHandler.java
@@ -16,23 +16,24 @@
package org.glassfish.jdbcruntime.deployment.annotation.handlers;
-
-import com.sun.enterprise.deployment.annotation.handlers.*;
-import org.glassfish.apf.*;
-import org.jvnet.hk2.annotations.Service;
-import org.glassfish.apf.impl.HandlerProcessingResultImpl;
-
-import jakarta.annotation.sql.DataSourceDefinitions;
-import jakarta.annotation.sql.DataSourceDefinition;
import java.lang.annotation.Annotation;
-import java.util.Set;
import java.util.HashSet;
-import java.util.logging.Level;
+import java.util.Set;
-import com.sun.enterprise.deployment.annotation.context.ResourceContainerContext;
+import org.glassfish.apf.AnnotationHandlerFor;
+import org.glassfish.apf.AnnotationInfo;
+import org.glassfish.apf.AnnotationProcessorException;
+import org.glassfish.apf.HandlerProcessingResult;
+import org.jvnet.hk2.annotations.Service;
+
import com.sun.enterprise.deployment.DataSourceDefinitionDescriptor;
+import com.sun.enterprise.deployment.annotation.context.ResourceContainerContext;
+import com.sun.enterprise.deployment.annotation.handlers.AbstractResourceHandler;
import com.sun.enterprise.util.LocalStringManagerImpl;
+import jakarta.annotation.sql.DataSourceDefinition;
+import jakarta.annotation.sql.DataSourceDefinitions;
+
/**
* @author Jagadish Ramu
*/
@@ -40,34 +41,33 @@
@AnnotationHandlerFor(DataSourceDefinitions.class)
public class DataSourceDefinitionsHandler extends AbstractResourceHandler {
- protected final static LocalStringManagerImpl localStrings =
- new LocalStringManagerImpl(DataSourceDefinitionsHandler.class);
+ protected final static LocalStringManagerImpl localStrings = new LocalStringManagerImpl(DataSourceDefinitionsHandler.class);
public DataSourceDefinitionsHandler() {
}
+ @Override
protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, ResourceContainerContext[] rcContexts)
throws AnnotationProcessorException {
DataSourceDefinitions defns = (DataSourceDefinitions) ainfo.getAnnotation();
DataSourceDefinition values[] = defns.value();
Set duplicates = new HashSet();
- if(values != null && values.length >0){
- for(DataSourceDefinition defn : values){
+ if (values != null && values.length > 0) {
+ for (DataSourceDefinition defn : values) {
String defnName = DataSourceDefinitionDescriptor.getJavaName(defn.name());
- if(duplicates.contains(defnName)){
- String localString = localStrings.getLocalString(
- "enterprise.deployment.annotation.handlers.datasourcedefinitionsduplicates",
- "@DataSourceDefinitions cannot have multiple definitions with same name : ''{0}''",
- defnName);
+ if (duplicates.contains(defnName)) {
+ String localString = localStrings.getLocalString(
+ "enterprise.deployment.annotation.handlers.datasourcedefinitionsduplicates",
+ "@DataSourceDefinitions cannot have multiple definitions with same name : ''{0}''", defnName);
throw new IllegalStateException(localString);
/*
- //TODO V3 should we throw exception or return failure result ?
- return getFailureResult(ainfo, "@DataSourceDefinitions cannot have multiple" +
- " definitions with same name [ "+defnName+" ]", true );
- */
- }else{
+ * //TODO V3 should we throw exception or return failure result ? return
+ * getFailureResult(ainfo, "@DataSourceDefinitions cannot have multiple" +
+ * " definitions with same name [ "+defnName+" ]", true );
+ */
+ } else {
duplicates.add(defnName);
}
DataSourceDefinitionHandler handler = new DataSourceDefinitionHandler();
@@ -78,21 +78,19 @@
return getDefaultProcessedResult();
}
-/* private HandlerProcessingResultImpl getFailureResult(AnnotationInfo element, String message, boolean doLog) {
- HandlerProcessingResultImpl result = new HandlerProcessingResultImpl();
- result.addResult(getAnnotationType(), ResultType.FAILED);
- if (doLog) {
- Class c = (Class) element.getAnnotatedElement();
- String className = c.getName();
- String localString = localStrings.getLocalString(
- "enterprise.deployment.annotation.handlers.datasourcedefinitionsfailure",
- "failed to handle annotation [ {0} ] on class [ {1} ] due to the following exception : ",
- element.getAnnotation(), className);
- logger.log(Level.WARNING, localString, message);
- }
- return result;
- }
-*/
+ /*
+ * private HandlerProcessingResultImpl getFailureResult(AnnotationInfo element,
+ * String message, boolean doLog) { HandlerProcessingResultImpl result = new
+ * HandlerProcessingResultImpl(); result.addResult(getAnnotationType(),
+ * ResultType.FAILED); if (doLog) { Class c = (Class)
+ * element.getAnnotatedElement(); String className = c.getName(); String
+ * localString = localStrings.getLocalString(
+ * "enterprise.deployment.annotation.handlers.datasourcedefinitionsfailure",
+ * "failed to handle annotation [ {0} ] on class [ {1} ] due to the following exception : "
+ * , element.getAnnotation(), className); logger.log(Level.WARNING, localString,
+ * message); } return result; }
+ */
+ @Override
public Class<? extends Annotation>[] getTypeDependencies() {
return getEjbAndWebAnnotationTypes();
}
diff --git a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/service/JdbcAdminServiceImpl.java b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/service/JdbcAdminServiceImpl.java
index 0a0fa21..717f639 100644
--- a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/service/JdbcAdminServiceImpl.java
+++ b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/service/JdbcAdminServiceImpl.java
@@ -16,6 +16,27 @@
package org.glassfish.jdbcruntime.service;
+import static com.sun.enterprise.connectors.util.ConnectionPoolObjectsUtils.getValueFromMCF;
+import static java.util.logging.Level.FINEST;
+import static java.util.logging.Level.WARNING;
+
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.util.Enumeration;
+import java.util.Properties;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.logging.Level;
+
+import javax.naming.NamingException;
+
+import org.glassfish.resourcebase.resources.api.PoolInfo;
+import org.jvnet.hk2.annotations.Service;
+
import com.sun.appserv.connectors.internal.api.ConnectorConstants;
import com.sun.enterprise.connectors.ConnectorConnectionPool;
import com.sun.enterprise.connectors.ConnectorRuntime;
@@ -23,22 +44,12 @@
import com.sun.enterprise.connectors.service.ConnectorAdminServicesFactory;
import com.sun.enterprise.connectors.service.ConnectorConnectionPoolAdminServiceImpl;
import com.sun.enterprise.connectors.service.ConnectorService;
-import com.sun.enterprise.connectors.util.ConnectionPoolObjectsUtils;
import com.sun.enterprise.connectors.util.DriverLoader;
-import org.glassfish.resourcebase.resources.api.PoolInfo;
-import org.jvnet.hk2.annotations.Service;
import jakarta.inject.Singleton;
-import javax.naming.NamingException;
import jakarta.resource.ResourceException;
import jakarta.resource.spi.ManagedConnection;
import jakarta.resource.spi.ManagedConnectionFactory;
-import java.io.File;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.sql.DatabaseMetaData;
-import java.util.*;
-import java.util.logging.Level;
/**
* Jdbc admin service performs Jdbc related operations for administration.
@@ -51,11 +62,13 @@
private ConnectorConnectionPoolAdminServiceImpl ccPoolAdmService;
private static final String DBVENDOR_MAPPINGS_ROOT =
- System.getProperty(ConnectorConstants.INSTALL_ROOT) + File.separator +
- "lib" + File.separator + "install" + File.separator + "databases" +
- File.separator + "dbvendormapping" + File.separator;
- private final static String JDBC40_CONNECTION_VALIDATION =
- "org.glassfish.api.jdbc.validation.JDBC40ConnectionValidation";
+ System.getProperty(ConnectorConstants.INSTALL_ROOT) + File.separator +
+ "lib" + File.separator +
+ "install" + File.separator +
+ "databases" + File.separator +
+ "dbvendormapping" + File.separator;
+
+ private final static String JDBC40_CONNECTION_VALIDATION = "org.glassfish.api.jdbc.validation.JDBC40ConnectionValidation";
private final static String DS_PROPERTIES = "ds.properties";
private final static String CPDS_PROPERTIES = "cpds.properties";
private final static String XADS_PROPERTIES = "xads.properties";
@@ -69,35 +82,36 @@
*/
public JdbcAdminServiceImpl() {
super();
- //jdbcAdminService = this;
- ccPoolAdmService = (ConnectorConnectionPoolAdminServiceImpl)
- ConnectorAdminServicesFactory.getService(ConnectorConstants.CCP);
+ ccPoolAdmService = (ConnectorConnectionPoolAdminServiceImpl) ConnectorAdminServicesFactory.getService(ConnectorConstants.CCP);
}
public static JdbcAdminServiceImpl getJdbcAdminService() {
if (jdbcAdminService == null) {
throw new RuntimeException("JDBC admin service not initialized");
}
+
return jdbcAdminService;
}
/**
- * Get Validation class names list for the classname that the jdbc
- * connection pool refers to. This is used for custom connection validation.
+ * Get Validation class names list for the classname that the jdbc connection
+ * pool refers to. This is used for custom connection validation.
+ *
* @param className
* @return all validation class names.
*/
public Set<String> getValidationClassNames(String className) {
SortedSet classNames = new TreeSet();
- if(className == null) {
- _logger.log(Level.WARNING, "jdbc.admin.service.ds_class_name_null");
+ if (className == null) {
+ _logger.log(WARNING, "jdbc.admin.service.ds_class_name_null");
return classNames;
}
File validationClassMappingFile;
String dbVendor = getDatabaseVendorName(className);
- //Retrieve validation classnames from the properties file based on the retrieved
- //dbvendor name
+ // Retrieve validation classnames from the properties file based on the
+ // retrieved
+ // dbvendor name
if (dbVendor != null) {
validationClassMappingFile = new File(DBVENDOR_MAPPINGS_ROOT + CONVAL_PROPERTIES);
Properties validationClassMappings = DriverLoader.loadFile(validationClassMappingFile);
@@ -105,7 +119,7 @@
if (validationClassName != null) {
classNames.add(validationClassName);
}
- //If JDBC40 runtime, add the jdbc40 validation classname
+ // If JDBC40 runtime, add the jdbc40 validation classname
if (detectJDBC40(className)) {
classNames.add(JDBC40_CONNECTION_VALIDATION);
}
@@ -114,19 +128,15 @@
}
private String getDatabaseVendorName(String className) {
- String dbVendor = getDatabaseVendorName(DriverLoader.loadFile(
- new File(DBVENDOR_MAPPINGS_ROOT + DS_PROPERTIES)), className);
- if(dbVendor == null) {
- dbVendor = getDatabaseVendorName(DriverLoader.loadFile(
- new File(DBVENDOR_MAPPINGS_ROOT + CPDS_PROPERTIES)), className);
+ String dbVendor = getDatabaseVendorName(DriverLoader.loadFile(new File(DBVENDOR_MAPPINGS_ROOT + DS_PROPERTIES)), className);
+ if (dbVendor == null) {
+ dbVendor = getDatabaseVendorName(DriverLoader.loadFile(new File(DBVENDOR_MAPPINGS_ROOT + CPDS_PROPERTIES)), className);
}
- if(dbVendor == null) {
- dbVendor = getDatabaseVendorName(DriverLoader.loadFile(
- new File(DBVENDOR_MAPPINGS_ROOT + XADS_PROPERTIES)), className);
+ if (dbVendor == null) {
+ dbVendor = getDatabaseVendorName(DriverLoader.loadFile(new File(DBVENDOR_MAPPINGS_ROOT + XADS_PROPERTIES)), className);
}
- if(dbVendor == null) {
- dbVendor = getDatabaseVendorName(DriverLoader.loadFile(
- new File(DBVENDOR_MAPPINGS_ROOT + DRIVER_PROPERTIES)), className);
+ if (dbVendor == null) {
+ dbVendor = getDatabaseVendorName(DriverLoader.loadFile(new File(DBVENDOR_MAPPINGS_ROOT + DRIVER_PROPERTIES)), className);
}
return dbVendor;
}
@@ -134,11 +144,11 @@
private String getDatabaseVendorName(Properties classNameProperties, String className) {
String dbVendor = null;
Enumeration e = classNameProperties.propertyNames();
- while(e.hasMoreElements()) {
+ while (e.hasMoreElements()) {
String key = (String) e.nextElement();
String value = classNameProperties.getProperty(key);
- if(className.equalsIgnoreCase(value)){
- //There could be multiple keys for a particular value.
+ if (className.equalsIgnoreCase(value)) {
+ // There could be multiple keys for a particular value.
dbVendor = key;
break;
}
@@ -148,14 +158,13 @@
private boolean detectJDBC40(String className) {
boolean jdbc40 = true;
- ClassLoader commonClassLoader =
- ConnectorRuntime.getRuntime().getClassLoaderHierarchy().getCommonClassLoader();
+ ClassLoader commonClassLoader = ConnectorRuntime.getRuntime().getClassLoaderHierarchy().getCommonClassLoader();
Class cls = null;
try {
cls = commonClassLoader.loadClass(className);
} catch (ClassNotFoundException e) {
- if(_logger.isLoggable(Level.FINEST)) {
- _logger.log(Level.FINEST, "jdbc.admin.service.ex_detect_jdbc40");
+ if (_logger.isLoggable(FINEST)) {
+ _logger.log(FINEST, "jdbc.admin.service.ex_detect_jdbc40");
}
return false;
}
@@ -165,21 +174,21 @@
method.invoke(cls.newInstance(), javax.sql.DataSource.class);
} catch (NoSuchMethodException e) {
jdbc40 = false;
- if(_logger.isLoggable(Level.FINEST)) {
- _logger.log(Level.FINEST, "jdbc.admin.service.ex_detect_jdbc40");
+ if (_logger.isLoggable(FINEST)) {
+ _logger.log(FINEST, "jdbc.admin.service.ex_detect_jdbc40");
}
} catch (InvocationTargetException e) {
- if(e.getCause() instanceof AbstractMethodError) {
+ if (e.getCause() instanceof AbstractMethodError) {
jdbc40 = false;
}
} catch (InstantiationException e) {
- if(_logger.isLoggable(Level.FINEST)) {
- _logger.log(Level.FINEST, "jdbc.admin.service.ex_detect_jdbc40");
+ if (_logger.isLoggable(FINEST)) {
+ _logger.log(FINEST, "jdbc.admin.service.ex_detect_jdbc40");
}
jdbc40 = false;
} catch (IllegalAccessException e) {
- if(_logger.isLoggable(Level.FINEST)) {
- _logger.log(Level.FINEST, "jdbc.admin.service.ex_detect_jdbc40");
+ if (_logger.isLoggable(FINEST)) {
+ _logger.log(FINEST, "jdbc.admin.service.ex_detect_jdbc40");
}
jdbc40 = false;
}
@@ -187,60 +196,55 @@
}
/**
- * Get Validation table names list for the database that the jdbc
- * connection pool refers to. This is used for connection validation.
+ * Get Validation table names list for the database that the jdbc connection
+ * pool refers to. This is used for connection validation.
+ *
* @param poolInfo
* @return all validation table names.
* @throws jakarta.resource.ResourceException
* @throws javax.naming.NamingException
*/
- public Set<String> getValidationTableNames(PoolInfo poolInfo)
- throws ResourceException {
- ManagedConnectionFactory mcf = null;
- ManagedConnection mc = null;
- java.sql.Connection con = null;
+ public Set<String> getValidationTableNames(PoolInfo poolInfo) throws ResourceException {
+ ManagedConnectionFactory managedConnectionFactory = null;
+ ManagedConnection managedConnection = null;
+ Connection connection = null;
try {
- mc = (ManagedConnection) ccPoolAdmService.getUnpooledConnection(poolInfo, null, false);
- mcf = ccPoolAdmService.obtainManagedConnectionFactory(poolInfo);
+ managedConnection = (ManagedConnection) ccPoolAdmService.getUnpooledConnection(poolInfo, null, false);
+ managedConnectionFactory = ccPoolAdmService.obtainManagedConnectionFactory(poolInfo);
- if (mc != null) {
- con = (java.sql.Connection) mc.getConnection(null, null);
+ if (managedConnection != null) {
+ connection = (Connection) managedConnection.getConnection(null, null);
}
- return getValidationTableNames(con,
- getDefaultDatabaseName(poolInfo, mcf));
- } catch(Exception re) {
- _logger.log(Level.WARNING, "pool.get_validation_table_names_failure", re.getMessage());
+ return getValidationTableNames(connection, getDefaultDatabaseName(poolInfo, managedConnectionFactory));
+ } catch (Exception re) {
+ _logger.log(WARNING, "pool.get_validation_table_names_failure", re.getMessage());
throw new ResourceException(re);
} finally {
try {
- if(mc != null) {
- mc.destroy();
+ if (managedConnection != null) {
+ managedConnection.destroy();
}
- } catch(Exception ex) {
- if(_logger.isLoggable(Level.FINEST)) {
- _logger.log(Level.FINEST, "pool.get_validation_table_names_mc_destroy", poolInfo);
- }
+ } catch (Exception ex) {
+ _logger.log(FINEST, "pool.get_validation_table_names_mc_destroy", poolInfo);
}
}
}
/**
* Returns a databaseName that is populated in pool's default DATABASENAME
+ *
* @param poolInfo
- * @param mcf
+ * @param managedConnectionFactory
* @return
* @throws javax.naming.NamingException if poolName lookup fails
*/
- private String getDefaultDatabaseName(PoolInfo poolInfo, ManagedConnectionFactory mcf)
- throws NamingException {
+ private String getDefaultDatabaseName(PoolInfo poolInfo, ManagedConnectionFactory managedConnectionFactory) throws NamingException {
// All this to get the default user name and principal
String databaseName = null;
ConnectorConnectionPool connectorConnectionPool = null;
try {
String jndiNameForPool = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForPool(poolInfo);
- connectorConnectionPool = (ConnectorConnectionPool)
- _runtime.getResourceNamingService().
- lookup(poolInfo, jndiNameForPool, null);
+ connectorConnectionPool = (ConnectorConnectionPool) _runtime.getResourceNamingService().lookup(poolInfo, jndiNameForPool, null);
} catch (NamingException ne) {
throw ne;
}
@@ -250,25 +254,25 @@
// To avoid using "" as the default databasename, try to get
// the databasename from MCF.
if (databaseName == null || databaseName.trim().equals("")) {
- databaseName = ConnectionPoolObjectsUtils.getValueFromMCF("DatabaseName", poolInfo, mcf);
+ databaseName = getValueFromMCF("DatabaseName", poolInfo, managedConnectionFactory);
}
+
return databaseName;
}
/**
- * Get Validation table names list for the catalog that the jdbc
- * connection pool refers to. This is used for connection validation.
+ * Get Validation table names list for the catalog that the jdbc connection pool
+ * refers to. This is used for connection validation.
+ *
* @param con
* @param catalog database name used.
* @return
* @throws jakarta.resource.ResourceException
*/
- public static Set<String> getValidationTableNames(java.sql.Connection con, String catalog)
- throws ResourceException {
-
+ public static Set<String> getValidationTableNames(java.sql.Connection con, String catalog) throws ResourceException {
SortedSet<String> tableNames = new TreeSet();
- if(catalog.trim().equals("")) {
+ if (catalog.trim().equals("")) {
catalog = null;
}
@@ -277,11 +281,11 @@
try {
DatabaseMetaData dmd = con.getMetaData();
rs = dmd.getTables(catalog, null, null, null);
- while(rs.next()) {
+ while (rs.next()) {
String schemaName = rs.getString(2);
String tableName = rs.getString(3);
String actualTableName = tableName;
- if(schemaName != null && !schemaName.equals("")){
+ if (schemaName != null && !schemaName.equals("")) {
actualTableName = schemaName + "." + tableName;
}
tableNames.add(actualTableName);
@@ -294,48 +298,12 @@
if (rs != null) {
rs.close();
}
- } catch (Exception e1) {}
+ } catch (Exception e1) {
+ }
}
} else {
- throw new ResourceException("The connection is not valid as "
- + "the connection is null");
+ throw new ResourceException("The connection is not valid as " + "the connection is null");
}
return tableNames;
}
-
- /**
- * Utility method to check if the retrieved table is accessible, since this
- * will be used for connection validation method "table".
- * @param tableName
- * @param con
- * @return accessibility status of the table.
- */
- /*private static boolean isPingable(String tableName, java.sql.Connection con) {
- java.sql.PreparedStatement stmt = null;
- java.sql.ResultSet rs = null;
- final String sql = "SELECT COUNT(*) FROM " + tableName;
- try {
- stmt = con.prepareStatement(sql);
- rs = stmt.executeQuery();
- } catch (Exception sqle) {
- _logger.log(Level.INFO, "pool.exc_is_pingable", tableName);
- return false;
-
- } finally {
- try {
- if (rs != null) {
- rs.close();
- }
- } catch (Exception e1) {
- }
-
- try {
- if (stmt != null) {
- stmt.close();
- }
- } catch (Exception e2) {
- }
- }
- return true;
- } */
}
diff --git a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/service/JdbcDataSource.java b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/service/JdbcDataSource.java
index 07333bc..3e974fc 100644
--- a/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/service/JdbcDataSource.java
+++ b/appserver/jdbc/jdbc-runtime/src/main/java/org/glassfish/jdbcruntime/service/JdbcDataSource.java
@@ -16,20 +16,23 @@
package org.glassfish.jdbcruntime.service;
-import com.sun.appserv.connectors.internal.api.ConnectorRuntimeException;
-import com.sun.appserv.connectors.internal.api.ConnectorsUtil;
-import com.sun.enterprise.connectors.ConnectorRuntime;
-import com.sun.enterprise.connectors.util.ResourcesUtil;
-import org.glassfish.jdbc.config.JdbcResource;
-import org.glassfish.resourcebase.resources.api.ResourceInfo;
+import static com.sun.appserv.connectors.internal.api.ConnectorsUtil.getValidSuffix;
-import javax.sql.DataSource;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;
+import javax.sql.DataSource;
+
+import org.glassfish.jdbc.config.JdbcResource;
+import org.glassfish.resourcebase.resources.api.ResourceInfo;
+
+import com.sun.appserv.connectors.internal.api.ConnectorRuntimeException;
+import com.sun.enterprise.connectors.ConnectorRuntime;
+import com.sun.enterprise.connectors.util.ResourcesUtil;
+
public class JdbcDataSource implements DataSource {
private ResourceInfo resourceInfo;
private PrintWriter logWriter;
@@ -43,52 +46,62 @@
private void validateResource(ResourceInfo resourceInfo) throws ConnectorRuntimeException {
ResourcesUtil resourcesUtil = ResourcesUtil.createInstance();
String jndiName = resourceInfo.getName();
- String suffix = ConnectorsUtil.getValidSuffix(jndiName);
+ String suffix = getValidSuffix(jndiName);
- if(suffix != null){
- //Typically, resource is created without suffix. Try without suffix.
+ if (suffix != null) {
+ // Typically, resource is created without suffix. Try without suffix.
String tmpJndiName = jndiName.substring(0, jndiName.lastIndexOf(suffix));
- if(resourcesUtil.getResource(tmpJndiName, resourceInfo.getApplicationName(),
- resourceInfo.getModuleName(), JdbcResource.class) != null){
+ if (resourcesUtil.getResource(tmpJndiName, resourceInfo.getApplicationName(), resourceInfo.getModuleName(), JdbcResource.class) != null) {
return;
}
}
- if(resourcesUtil.getResource(resourceInfo, JdbcResource.class) == null){
+ if (resourcesUtil.getResource(resourceInfo, JdbcResource.class) == null) {
throw new ConnectorRuntimeException("Invalid resource : " + resourceInfo);
}
}
+ @Override
public Connection getConnection() throws SQLException {
return ConnectorRuntime.getRuntime().getConnection(resourceInfo);
}
+ @Override
public Connection getConnection(String username, String password) throws SQLException {
return ConnectorRuntime.getRuntime().getConnection(resourceInfo, username, password);
}
+ @Override
public PrintWriter getLogWriter() throws SQLException {
return logWriter;
}
+ @Override
public void setLogWriter(PrintWriter out) throws SQLException {
- this.logWriter = out;
+ this.logWriter = out;
}
+ @Override
public void setLoginTimeout(int seconds) throws SQLException {
- loginTimeout = seconds;
+ loginTimeout = seconds;
}
+ @Override
public int getLoginTimeout() throws SQLException {
return loginTimeout;
}
- public boolean isWrapperFor(Class<?> iface) throws SQLException{
- throw new SQLException("Not supported operation");
- }
- public <T> T unwrap(Class<T> iface) throws SQLException{
- throw new SQLException("Not supported operation");
+
+ @Override
+ public boolean isWrapperFor(Class<?> iface) throws SQLException {
+ throw new SQLException("Not supported operation");
}
+ @Override
+ public <T> T unwrap(Class<T> iface) throws SQLException {
+ throw new SQLException("Not supported operation");
+ }
+
+ @Override
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
throw new SQLFeatureNotSupportedException("Not supported operation");
}