use of org.glassfish.resourcebase.resources.api.ResourceInfo in project Payara by payara.
the class DataSourceDefinitionDeployer method registerDSDReferredByApplication.
private void registerDSDReferredByApplication(String appName, DataSourceDefinitionDescriptor dsd) {
// DSD is bound to JNDI only when it is not already deployed.
if (!dsd.isDeployed()) {
CommonResourceProxy proxy = dataSourceDefinitionProxyProvider.get();
ResourceNamingService resourceNamingService = resourceNamingServiceProvider.get();
proxy.setDescriptor(dsd);
String dsdName = dsd.getName();
if (dsdName.startsWith(JAVA_APP_SCOPE_PREFIX)) {
dsd.setResourceId(appName);
}
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);
} catch (NamingException e) {
_logger.log(Level.WARNING, "dsd.registration.failed", new Object[] { appName, dsdName, e });
}
}
}
}
use of org.glassfish.resourcebase.resources.api.ResourceInfo in project Payara by payara.
the class JdbcResourceDeployer method undeployResource.
/**
* {@inheritDoc}
*/
@Override
public synchronized void undeployResource(Object resource) throws Exception {
JdbcResource jdbcRes = (JdbcResource) resource;
ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(jdbcRes);
deleteResource(jdbcRes, resourceInfo);
}
use of org.glassfish.resourcebase.resources.api.ResourceInfo in project Payara by payara.
the class JdbcResourceDeployer method undeployResource.
/**
* {@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);
}
use of org.glassfish.resourcebase.resources.api.ResourceInfo in project Payara by payara.
the class JdbcResourceDeployer method checkAndDeletePool.
/**
* 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
* @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);
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.
if (resources != null) {
try {
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");
}
JdbcConnectionPool jcp = (JdbcConnectionPool) ConnectorsUtil.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);
}
throw ce;
}
}
}
use of org.glassfish.resourcebase.resources.api.ResourceInfo in project Payara by payara.
the class JdbcResourcesUtil method isJdbcPoolReferredInServerInstance.
/**
* 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
*/
public boolean isJdbcPoolReferredInServerInstance(PoolInfo poolInfo) {
Collection<JdbcResource> jdbcResources = 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)) {
if (_logger.isLoggable(Level.FINE)) {
_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");
}
return true;
}
}
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("No JDBC resource refers [ " + poolInfo + " ] in this server instance");
}
return false;
}
Aggregations