Enum ClassLoaderStrategy

java.lang.Object
java.lang.Enum<ClassLoaderStrategy>
org.postgresql.util.ClassLoaderStrategy
All Implemented Interfaces:
Serializable, Comparable<ClassLoaderStrategy>, java.lang.constant.Constable

public enum ClassLoaderStrategy extends Enum<ClassLoaderStrategy>
Order in which the driver searches classloaders when loading a class named by a connection property. The driver's own classloader can see only what is on its classpath, so in a non-flat class path (for example an application server or an OSGi container) a user-supplied class may be visible only through the thread context classloader.

The class is NOT public API, so it is subject to change.

  • Enum Constant Details

    • DRIVER

      public static final ClassLoaderStrategy DRIVER
      Use the driver's classloader only. This was the behaviour before the strategy became configurable and is the safest choice when the thread context classloader is undefined.
    • DRIVER_FIRST

      public static final ClassLoaderStrategy DRIVER_FIRST
      Try the driver's classloader first, then fall back to the thread context classloader. The fallback heals environments where the class is reachable only through the context classloader, while keeping the driver's classloader authoritative.
    • CONTEXT_FIRST

      public static final ClassLoaderStrategy CONTEXT_FIRST
      Try the thread context classloader first, then fall back to the driver's classloader. Use this in containers that manage class loading and expect their context classloader to win, even when the driver's classloader could resolve a class of the same name.
  • Field Details

    • value

      public final String value
  • Method Details

    • values

      public static ClassLoaderStrategy[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static ClassLoaderStrategy valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null
    • of

      public static ClassLoaderStrategy of(Properties info) throws PSQLException
      Resolves the strategy from the PGProperty.CLASS_LOADER_STRATEGY connection property.
      Parameters:
      info - connection properties
      Returns:
      the configured strategy, or DRIVER_FIRST when the property is absent
      Throws:
      PSQLException - if the property holds an unknown value
    • classLoaders

      public List<ClassLoader> classLoaders(ClassLoader driverClassLoader, ClassLoader contextClassLoader)
      Returns the non-null classloaders to try, in priority order. A null input (for instance a null context classloader) is dropped, so the list contains only classloaders the caller can use.
      Parameters:
      driverClassLoader - the driver's own classloader
      contextClassLoader - the thread context classloader
      Returns:
      an ordered list of non-null classloaders to try