Interface Validator


public interface Validator
Interface to be implemented by custom validator classes.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    validate(Connection connection, int validateAction)
    Validate a connection and return a boolean to indicate if it's valid.
  • Method Details

    • validate

      boolean validate(Connection connection, int validateAction)
      Validate a connection and return a boolean to indicate if it's valid.

      The pool calls this method with the underlying JDBC connection, outside any interceptor chain, and treats any runtime exception thrown by an implementation as a validation failure. Implementations that invoke JDBC APIs must catch SQLException and return false themselves, since this method does not declare a checked exception. A false result (or a thrown runtime exception) causes the pool to discard the connection.

      The pool may skip validation entirely for a given action - it only validates when the corresponding testOnBorrow, testOnReturn, testWhileIdle or testOnConnect flag is set - and it may short-circuit repeated validations, see PoolConfiguration.setValidationInterval(long). This method is therefore not guaranteed to run for every borrow, and it must not be relied on for per-borrow session state. Implementations are invoked concurrently from borrowing and returning application threads and from the pool cleaner thread and must be thread-safe.

      Parameters:
      connection - the underlying (non-proxied) Connection object to test
      validateAction - the action used. One of PooledConnection.VALIDATE_BORROW, PooledConnection.VALIDATE_IDLE, PooledConnection.VALIDATE_INIT or PooledConnection.VALIDATE_RETURN
      Returns:
      true if the connection is valid