Enum ClassLoaderStrategy

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<ClassLoaderStrategy>

    public enum ClassLoaderStrategy
    extends java.lang.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 Summary

      Enum Constants 
      Enum Constant Description
      CONTEXT_FIRST
      Try the thread context classloader first, then fall back to the driver's classloader.
      DRIVER
      Use the driver's classloader only.
      DRIVER_FIRST
      Try the driver's classloader first, then fall back to the thread context classloader.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      java.lang.String value  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.List<java.lang.ClassLoader> classLoaders​(java.lang.ClassLoader driverClassLoader, java.lang.ClassLoader contextClassLoader)
      Returns the non-null classloaders to try, in priority order.
      static ClassLoaderStrategy of​(java.util.Properties info)
      Resolves the strategy from the PGProperty.CLASS_LOADER_STRATEGY connection property.
      static ClassLoaderStrategy valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static ClassLoaderStrategy[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • 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 Detail

      • value

        public final java.lang.String value
    • Method Detail

      • values

        public static ClassLoaderStrategy[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (ClassLoaderStrategy c : ClassLoaderStrategy.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static ClassLoaderStrategy valueOf​(java.lang.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:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • classLoaders

        public java.util.List<java.lang.ClassLoader> classLoaders​(java.lang.ClassLoader driverClassLoader,
                                                                  java.lang.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