@Override
public Object executeSProc(final DataSource ds, final String sql, final Object[] args, final int[] types,
final InvocationContext invocationContext, final Class<?> returnType) {
SameConnectionDatasource sameConnDs = null;
try {
sameConnDs = new SameConnectionDatasource(ds.getConnection());
setTimeout(sameConnDs.getConnection());
if (!lockAdvisoryLock(sameConnDs.getConnection())) {
throw new RuntimeException("Could not acquire AdvisoryLock " + lock.name());
}
return executor.executeSProc(sameConnDs, sql, args, types, invocationContext, returnType);
} catch (final SQLException e) {
throw new RuntimeException("SQL Exception in execute sproc: " + sql, e);
} finally {
if (sameConnDs != null) {
try {
if (timeoutInMilliSeconds > 0) {
try {
resetTimeout(sameConnDs.getConnection());
} catch (final SQLException ex) {
LOG.error("Exception in reseting statement timeout!", ex);
}
}
// unlock in all cases, locks not owned by this session cannot be unlocked
if (lock != AdvisoryLock.NO_LOCK) {
try {
unlockAdvisoryLock(sameConnDs.getConnection());
} catch (final SQLException ex) {
LOG.error("Exception in reseting advisory lock!", ex);
}
}
} finally {
try {
sameConnDs.close();
} catch (final SQLException ex) {
LOG.error("Exception in closing underlying connection!", ex);
}
}
}