@Override
public TestResult test()
{
if (isConnected())
{
return new DefaultTestResult(TestResult.Status.SUCCESS);
}
Connection con = null;
try
{
con = dataSource.getConnection();
return new DefaultTestResult(TestResult.Status.SUCCESS);
}
catch (Exception e)
{
// this surely doesn't cover all cases for all kinds of jdbc drivers but it is better than nothing
FailureType failureType = FailureType.UNSPECIFIED;
String msg = e.getMessage();
if (msg != null && msg.contains("Communications link failure"))
{
failureType = FailureType.CONNECTION_FAILURE;
}
else if (msg != null && msg.contains("Access denied for user"))
{
failureType = FailureType.INVALID_CREDENTIALS;
}
return new DefaultTestResult(TestResult.Status.FAILURE, e.getMessage(), failureType, e);
}
finally
{
if (con != null)
{