throws Exception {
if (jndiName == null) {
String msg = localStrings.getLocalString("jdbc.resource.noJndiName",
"No JNDI name defined for JDBC resource.");
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
// ensure we already have this resource
if(resources.getResourceByName(JdbcResource.class, jndiName) == null){
String msg = localStrings.getLocalString("delete.jdbc.resource.notfound",
"A JDBC resource named {0} does not exist.", jndiName);
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
if (environment.isDas()) {
if ("domain".equals(target)) {
if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 0) {
String msg = localStrings.getLocalString("delete.jdbc.resource.resource-ref.exist",
"jdbc-resource [ {0} ] is referenced in an" +
"instance/cluster target, Use delete-resource-ref on appropriate target",
jndiName);
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
} else {
if (!resourceUtil.isResourceRefInTarget(jndiName, target)) {
String msg = localStrings.getLocalString("delete.jdbc.resource.no.resource-ref",
"jdbc-resource [ {0} ] is not referenced in target [ {1} ]",
jndiName, target);
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 1) {
String msg = localStrings.getLocalString("delete.jdbc.resource.multiple.resource-refs",
"jdbc resource [ {0} ] is referenced in multiple " +
"instance/cluster targets, Use delete-resource-ref on appropriate target",
jndiName);
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
}
}
try {
// delete resource-ref
resourceUtil.deleteResourceRef(jndiName, target);
// delete jdbc-resource
if (ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
JdbcResource resource = (JdbcResource) resources.getResourceByName(JdbcResource.class, jndiName);
return param.getResources().remove(resource);
}
}, resources) == null) {
String msg = localStrings.getLocalString("jdbc.resource.deletionFailed",
"JDBC resource {0} delete failed ", jndiName);
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
} catch(TransactionFailure tfe) {
String msg = localStrings.getLocalString("jdbc.resource.deletionFailed",
"JDBC resource {0} delete failed ", jndiName);
ResourceStatus status = new ResourceStatus(ResourceStatus.FAILURE, msg);
status.setException(tfe);
return status;
}
String msg = localStrings.getLocalString("jdbc.resource.deleteSuccess",
"JDBC resource {0} deleted successfully", jndiName);
return new ResourceStatus(ResourceStatus.SUCCESS, msg);
}