Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JBJCA-1402] add new validation-query-timeout attribute to datasources #786

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -224,6 +224,9 @@ public abstract class BaseWrapperManagedConnectionFactory
/** Query timeout */
protected Integer queryTimeout = Integer.valueOf(0);

/** Validation query timeout */
protected Integer validationQueryTimeout = Integer.valueOf(0);

/**
* The variable <code>urlDelimiter</code> holds the url delimiter
* information to be used for HA DS configuration .
Expand Down Expand Up @@ -694,6 +697,25 @@ public void setQueryTimeout(Integer timeout)
queryTimeout = timeout;
}

/**
* Get the validation query timeout
* @return The value
*/
public Integer getValidationQueryTimeout()
{
return validationQueryTimeout;
}

/**
* Set the validation query timeout
* @param timeout The value
*/
public void setValidationQueryTimeout(Integer timeout)
{
if (timeout != null)
validationQueryTimeout = timeout;
}

/**
* Get the use try lock value
* @return The value
Expand Down Expand Up @@ -1378,7 +1400,6 @@ SQLException isValidConnection(Connection c)
if (o != null && o instanceof ValidConnectionChecker)
{
connectionChecker = (ValidConnectionChecker)o;
return connectionChecker.isValidConnection(c);
}
else
{
Expand All @@ -1397,6 +1418,11 @@ SQLException isValidConnection(Connection c)
if (checkValidConnectionSQL != null)
{
connectionChecker = new CheckValidConnectionSQL(checkValidConnectionSQL);
}

if (connectionChecker != null)
{
connectionChecker.setQueryTimeout(validationQueryTimeout);
return connectionChecker.isValidConnection(c);
}

Expand Down
Expand Up @@ -104,6 +104,8 @@ public SQLException isValidConnection(Connection c)
return e;
}
}

@Override
public void setQueryTimeout(int queryTimeout)
{
this.queryTimeout = queryTimeout;
Expand Down
Expand Up @@ -40,4 +40,9 @@ public interface ValidConnectionChecker
* @return Exception when not valid, null when valid
*/
SQLException isValidConnection(Connection c);

default void setQueryTimeout(int timeout)
{
// nothing to do here
}
}
13 changes: 12 additions & 1 deletion as/src/main/java/org/jboss/jca/as/converters/DataSource.java
Expand Up @@ -154,6 +154,13 @@ public interface DataSource extends ConnectionFactory
*/
public Long getUseTryLock();

/**
* Get the validationQueryTimeout.
*
* @return the validationQueryTimeout.
*/
public Long getValidationQueryTimeout();

/**
*
* A Tag.
Expand Down Expand Up @@ -283,7 +290,11 @@ public enum Tag
/**
* useTryLock tag
*/
USE_TRY_LOCK("use-try-lock");
USE_TRY_LOCK("use-try-lock"),
/**
* validationQueryTimeout tag
*/
VALIDATION_QUERY_TIMEOUT("validation-query-timeout");

private final String name;

Expand Down
Expand Up @@ -236,6 +236,7 @@ private XaDataSource parseXADataSource(XMLStreamReader reader) throws Exception
Long allocationRetryWaitMillis = null;
Long useTryLock = null;
Integer xaResourceTimeout = null;
Long validationQueryTimeout = null;

Long preparedStatementsCacheSize = null;
Boolean sharePreparedStatements = Defaults.SHARE_PREPARED_STATEMENTS;
Expand Down Expand Up @@ -277,7 +278,8 @@ private XaDataSource parseXADataSource(XMLStreamReader reader) throws Exception
LegacyXaDataSourceImp xaDsImpl = new LegacyXaDataSourceImp(xaDataSourceClass,
driver, transactionIsolation, xaDataSourceProperty);
xaDsImpl.buildTimeOut(blockingTimeoutMillis, idleTimeoutMinutes, allocationRetry,
allocationRetryWaitMillis, xaResourceTimeout, setTxQueryTimeout, queryTimeout, useTryLock);
allocationRetryWaitMillis, xaResourceTimeout, setTxQueryTimeout, queryTimeout, useTryLock,
validationQueryTimeout);
xaDsImpl.buildDsSecurity(userName, password, securityDomain, null);
xaDsImpl.buildStatement(sharePreparedStatements, preparedStatementsCacheSize, trackStatements);
xaDsImpl.buildValidation(backgroundValidation, backgroundValidationMillis, useFastFail,
Expand Down Expand Up @@ -428,6 +430,10 @@ private XaDataSource parseXADataSource(XMLStreamReader reader) throws Exception
queryTimeout = elementAsLong(reader);
break;
}
case VALIDATION_QUERY_TIMEOUT : {
validationQueryTimeout = elementAsLong(reader);
break;
}
case SET_TX_QUERY_TIMEOUT : {
setTxQueryTimeout = elementAsBoolean(reader);
break;
Expand Down Expand Up @@ -532,6 +538,7 @@ private LocalTxDataSource parseLocalTxDataSource(XMLStreamReader reader) throws
Long allocationRetryWaitMillis = null;
Long useTryLock = null;
Integer xaResourceTimeout = 0;
Long validationQueryTimeout = null;

Long preparedStatementsCacheSize = null;
Boolean sharePreparedStatements = Defaults.SHARE_PREPARED_STATEMENTS;
Expand Down Expand Up @@ -564,7 +571,8 @@ private LocalTxDataSource parseLocalTxDataSource(XMLStreamReader reader) throws
LegacyTxDataSourceImpl txDsImpl = new LegacyTxDataSourceImpl(connectionUrl,
driverClass, dataSourceClass, driver, transactionIsolation, connectionProperties);
txDsImpl.buildTimeOut(blockingTimeoutMillis, idleTimeoutMinutes, allocationRetry,
allocationRetryWaitMillis, xaResourceTimeout, setTxQueryTimeout, queryTimeout, useTryLock);
allocationRetryWaitMillis, xaResourceTimeout, setTxQueryTimeout, queryTimeout, useTryLock,
validationQueryTimeout);
txDsImpl.buildDsSecurity(userName, password, securityDomain, null);
txDsImpl.buildStatement(sharePreparedStatements, preparedStatementsCacheSize, trackStatements);
txDsImpl.buildValidation(backgroundValidation, backgroundValidationMillis, useFastFail,
Expand Down Expand Up @@ -691,6 +699,10 @@ private LocalTxDataSource parseLocalTxDataSource(XMLStreamReader reader) throws
queryTimeout = elementAsLong(reader);
break;
}
case VALIDATION_QUERY_TIMEOUT : {
validationQueryTimeout = elementAsLong(reader);
break;
}
case SET_TX_QUERY_TIMEOUT : {
setTxQueryTimeout = elementAsBoolean(reader);
break;
Expand Down
Expand Up @@ -159,11 +159,11 @@ public String toString()
*/
public LegacyTxDataSourceImpl buildTimeOut(Long blockingTimeoutMillis, Long idleTimeoutMinutes,
Integer allocationRetry, Long allocationRetryWaitMillis, Integer xaResourceTimeout,
Boolean setTxQueryTimeout, Long queryTimeout, Long useTryLock) throws Exception
Boolean setTxQueryTimeout, Long queryTimeout, Long useTryLock, Long validationQueryTimeout) throws Exception
{
timeOut = new TimeOutImpl(blockingTimeoutMillis, idleTimeoutMinutes, allocationRetry,
allocationRetryWaitMillis, xaResourceTimeout, setTxQueryTimeout,
queryTimeout, useTryLock);
queryTimeout, useTryLock, validationQueryTimeout);
return this;
}

Expand Down Expand Up @@ -484,4 +484,10 @@ public boolean isNoTxSeparatePools()
return false;
}

@Override
public Long getValidationQueryTimeout()
{
return this.timeOut.getValidationQueryTimeout();
}

}
Expand Up @@ -167,11 +167,11 @@ public String toString()
public LegacyXaDataSourceImp buildTimeOut(Long blockingTimeoutMillis, Long idleTimeoutMinutes,
Integer allocationRetry, Long allocationRetryWaitMillis, Integer xaResourceTimeout,
Boolean setTxQueryTimeout, Long queryTimeout,
Long useTryLock) throws Exception
Long useTryLock, Long validationQueryTimeout) throws Exception
{
timeOut = new TimeOutImpl(blockingTimeoutMillis, idleTimeoutMinutes, allocationRetry,
allocationRetryWaitMillis, xaResourceTimeout, setTxQueryTimeout,
queryTimeout, useTryLock);
queryTimeout, useTryLock, validationQueryTimeout);
return this;
}

Expand Down Expand Up @@ -511,6 +511,12 @@ public Integer getXaResourceTimeout()
return this.timeOut.getXaResourceTimeout();
}

@Override
public Long getValidationQueryTimeout()
{
return this.timeOut.getValidationQueryTimeout();
}

@Override
public String getXaDataSourceClass()
{
Expand Down
Expand Up @@ -199,7 +199,11 @@ public enum Tag
/**
* useTryLock tag
*/
USE_TRY_LOCK("use-try-lock");
USE_TRY_LOCK("use-try-lock"),
/**
* validationQueryTimeout tag
*/
VALIDATION_QUERY_TIMEOUT("validation-query-timeout");

private final String name;

Expand Down
Expand Up @@ -197,7 +197,11 @@ public enum Tag
/**
* useTryLock tag
*/
USE_TRY_LOCK("use-try-lock");
USE_TRY_LOCK("use-try-lock"),
/**
* validationQueryTimeout tag
*/
VALIDATION_QUERY_TIMEOUT("validation-query-timeout");

private final String name;

Expand Down
Expand Up @@ -260,7 +260,11 @@ public enum Tag
/**
* noRecovery tag
*/
NO_RECOVER("no_recover");
NO_RECOVER("no_recover"),
/**
* validationQueryTimeout tag
*/
VALIDATION_QUERY_TIMEOUT("validation-query-timeout");

private final String name;

Expand Down
Expand Up @@ -56,6 +56,13 @@ public interface TimeOut extends org.jboss.jca.common.api.metadata.common.TimeOu
*/
public Long getUseTryLock();

/**
* Get the validationQueryTimeout.
*
* @return the validationQueryTimeout.
*/
public Long getValidationQueryTimeout();


/**
*
Expand Down Expand Up @@ -102,7 +109,11 @@ public enum Tag
/**
* allocationRetryWaitMillis tag
*/
ALLOCATION_RETRY_WAIT_MILLIS("allocation-retry-wait-millis");
ALLOCATION_RETRY_WAIT_MILLIS("allocation-retry-wait-millis"),
/**
* validationQueryTimeout tag
*/
VALIDATION_QUERY_TIMEOUT("validation-query-timeout");

private String name;

Expand Down
Expand Up @@ -472,6 +472,7 @@ protected TimeOut parseTimeOutSettings(XMLStreamReader reader) throws XMLStreamE
Long allocationRetryWaitMillis = null;
Long useTryLock = null;
Integer xaResourceTimeout = null;
Long validationQueryTimeout = null;

while (reader.hasNext())
{
Expand All @@ -484,7 +485,7 @@ protected TimeOut parseTimeOutSettings(XMLStreamReader reader) throws XMLStreamE

return new TimeOutImpl(blockingTimeoutMillis, idleTimeoutMinutes, allocationRetry,
allocationRetryWaitMillis, xaResourceTimeout, setTxQuertTimeout,
queryTimeout, useTryLock);
queryTimeout, useTryLock, validationQueryTimeout);
}
else
{
Expand Down Expand Up @@ -530,6 +531,10 @@ protected TimeOut parseTimeOutSettings(XMLStreamReader reader) throws XMLStreamE
xaResourceTimeout = elementAsInteger(reader);
break;
}
case VALIDATION_QUERY_TIMEOUT: {
validationQueryTimeout = elementAsLong(reader);
break;
}
default :
throw new ParserException(bundle.unexpectedElement(reader.getLocalName()));
}
Expand Down
Expand Up @@ -48,6 +48,8 @@ public class TimeOutImpl extends org.jboss.jca.common.metadata.common.TimeOutImp

private final Long useTryLock;

private final Long validationQueryTimeout;

/**
* Create a new TimeOutImpl.
*
Expand All @@ -63,13 +65,14 @@ public class TimeOutImpl extends org.jboss.jca.common.metadata.common.TimeOutImp
*/
public TimeOutImpl(Long blockingTimeoutMillis, Long idleTimeoutMinutes, Integer allocationRetry,
Long allocationRetryWaitMillis, Integer xaResourceTimeout, Boolean setTxQueryTimeout, Long queryTimeout,
Long useTryLock) throws ValidateException
Long useTryLock, Long validationQueryTimeout) throws ValidateException
{
super(blockingTimeoutMillis, idleTimeoutMinutes, allocationRetry, allocationRetryWaitMillis,
xaResourceTimeout);
this.setTxQueryTimeout = setTxQueryTimeout;
this.queryTimeout = queryTimeout;
this.useTryLock = useTryLock;
this.validationQueryTimeout = validationQueryTimeout;
this.validate();
}

Expand Down Expand Up @@ -106,6 +109,11 @@ public final Long getUseTryLock()
return useTryLock;
}

@Override
public Long getValidationQueryTimeout() {
return validationQueryTimeout;
}

@Override
public int hashCode()
{
Expand All @@ -114,6 +122,7 @@ public int hashCode()
result = prime * result + ((queryTimeout == null) ? 0 : queryTimeout.hashCode());
result = prime * result + ((setTxQueryTimeout == null) ? 0 : setTxQueryTimeout.hashCode());
result = prime * result + ((useTryLock == null) ? 0 : useTryLock.hashCode());
result = prime * result + ((validationQueryTimeout == null) ? 0 : validationQueryTimeout.hashCode());
return result;
}

Expand Down Expand Up @@ -148,6 +157,13 @@ else if (!setTxQueryTimeout.equals(other.setTxQueryTimeout))
}
else if (!useTryLock.equals(other.useTryLock))
return false;
if (validationQueryTimeout == null)
{
if (other.validationQueryTimeout != null)
return false;
}
else if (!validationQueryTimeout.equals(other.validationQueryTimeout))
return false;
return true;
}

Expand Down Expand Up @@ -212,6 +228,13 @@ public String toString()
sb.append("</").append(TimeOut.Tag.XA_RESOURCE_TIMEOUT).append(">");
}

if (validationQueryTimeout != null)
{
sb.append("<").append(TimeOut.Tag.VALIDATION_QUERY_TIMEOUT).append(">");
sb.append(validationQueryTimeout);
sb.append("</").append(TimeOut.Tag.VALIDATION_QUERY_TIMEOUT).append(">");
}

sb.append("</timeout>");

return sb.toString();
Expand All @@ -222,5 +245,7 @@ public void validate() throws ValidateException
{
if (this.queryTimeout != null && this.queryTimeout < 0)
throw new ValidateException(bundle.invalidNegative(TimeOut.Tag.QUERY_TIMEOUT.getLocalName()));
if (this.validationQueryTimeout != null && this.validationQueryTimeout < 0)
throw new ValidateException(bundle.invalidNegative(TimeOut.Tag.VALIDATION_QUERY_TIMEOUT.getLocalName()));
}
}
3 changes: 3 additions & 0 deletions common/impl/src/test/resources/ds/unit/complex-ds.xml
Expand Up @@ -118,6 +118,9 @@
<allocation-retry-wait-millis>
3000
</allocation-retry-wait-millis>
<validation-query-timeout>
110
</validation-query-timeout>
</timeout>
<statement>
<prepared-statement-cache-size>
Expand Down