Package org.postgresql.util
Enum ClassLoaderStrategy
- java.lang.Object
-
- java.lang.Enum<ClassLoaderStrategy>
-
- org.postgresql.util.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 thethread context classloader.The class is NOT public API, so it is subject to change.
-
-
Enum Constant Summary
Enum Constants Enum Constant Description CONTEXT_FIRSTTry the thread context classloader first, then fall back to the driver's classloader.DRIVERUse the driver's classloader only.DRIVER_FIRSTTry the driver's classloader first, then fall back to the thread context classloader.
-
Field Summary
Fields Modifier and Type Field Description java.lang.Stringvalue
-
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 ClassLoaderStrategyof(java.util.Properties info)Resolves the strategy from thePGProperty.CLASS_LOADER_STRATEGYconnection property.static ClassLoaderStrategyvalueOf(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.
-
-
-
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.
-
-
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 namejava.lang.NullPointerException- if the argument is null
-
of
public static ClassLoaderStrategy of(java.util.Properties info) throws PSQLException
Resolves the strategy from thePGProperty.CLASS_LOADER_STRATEGYconnection property.- Parameters:
info- connection properties- Returns:
- the configured strategy, or
DRIVER_FIRSTwhen the property is absent - Throws:
PSQLException- if the property holds an unknown value
-
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 classloadercontextClassLoader- the thread context classloader- Returns:
- an ordered list of non-null classloaders to try
-
-