use of org.glassfish.jdbc.config.JdbcResource 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;
}
use of org.glassfish.jdbc.config.JdbcResource in project Payara by payara.
the class JdbcRecoveryResourceHandler method getAllJdbcResources.
private Collection<JdbcResource> getAllJdbcResources() {
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));
}
}
}
}
}
return allResources;
}
use of org.glassfish.jdbc.config.JdbcResource in project Payara by payara.
the class JdbcRuntimeExtension method getDeferredResourceConfig.
@Override
public DeferredResourceConfig getDeferredResourceConfig(Object resource, Object pool, String resType, String raName) throws ConnectorRuntimeException {
String resourceAdapterName;
DeferredResourceConfig resConfig = null;
// TODO V3 (not to hold specific resource types)
if (resource instanceof JdbcResource || pool instanceof JdbcConnectionPool) {
JdbcConnectionPool jdbcPool = (JdbcConnectionPool) pool;
JdbcResource jdbcResource = (JdbcResource) resource;
resourceAdapterName = getRANameofJdbcConnectionPool((JdbcConnectionPool) pool);
resConfig = new DeferredResourceConfig(resourceAdapterName, null, jdbcPool, jdbcResource, null);
Resource[] resourcesToload = new Resource[] { jdbcPool, jdbcResource };
resConfig.setResourcesToLoad(resourcesToload);
} else {
throw new ConnectorRuntimeException("unsupported resource type : " + resource);
}
return resConfig;
}
use of org.glassfish.jdbc.config.JdbcResource in project Payara by payara.
the class JdbcRuntimeExtension method getPoolNameFromResourceJndiName.
/**
* 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
* @return poolName of the pool that this resource directly/indirectly points to
*/
@Override
public PoolInfo getPoolNameFromResourceJndiName(ResourceInfo resourceInfo) {
PoolInfo poolInfo = null;
JdbcResource jdbcResource = null;
String jndiName = resourceInfo.getName();
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) {
String suffix = ConnectorsUtil.getValidSuffix(jndiName);
if (suffix != null) {
jndiName = jndiName.substring(0, jndiName.lastIndexOf(suffix));
actualResourceInfo = new ResourceInfo(jndiName, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
}
}
jdbcResource = (JdbcResource) ConnectorsUtil.getResourceByName(runtime.getResources(actualResourceInfo), JdbcResource.class, actualResourceInfo.getName());
if (jdbcResource != null) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("jdbcRes is ---: " + jdbcResource.getJndiName());
logger.fine("poolName is ---: " + jdbcResource.getPoolName());
}
}
if (jdbcResource != null) {
poolInfo = new PoolInfo(jdbcResource.getPoolName(), actualResourceInfo.getApplicationName(), actualResourceInfo.getModuleName());
}
return poolInfo;
}
use of org.glassfish.jdbc.config.JdbcResource in project Payara by payara.
the class ReferenceConstrainTest method doChangeToValidPool.
// @Ignore
@Test
public void doChangeToValidPool() throws TransactionFailure {
Domain domain = habitat.getService(Domain.class);
// Find JdbcResource to chenge its values
Iterator<JdbcResource> iterator = domain.getResources().getResources(JdbcResource.class).iterator();
JdbcResource jdbc = null;
while (iterator.hasNext()) {
JdbcResource res = iterator.next();
if ("__TimerPool".equals(res.getPoolName())) {
jdbc = res;
break;
}
}
assertNotNull(jdbc);
ConfigBean poolConfig = (ConfigBean) ConfigBean.unwrap(jdbc);
Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
Map<String, String> configChanges = new HashMap<String, String>();
configChanges.put("pool-name", "DerbyPool");
changes.put(poolConfig, configChanges);
try {
ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
cs.apply(changes);
} catch (TransactionFailure tf) {
fail();
}
}
Aggregations