Class PjdbcCapabilities

java.lang.Object
org.pjdbc.capabilities.PjdbcCapabilities

public final class PjdbcCapabilities extends Object
Runtime introspection API for PJDBC driver capabilities.

This class provides access to the capabilities manifest that describes all available PJDBC drivers, their parameters, dependencies, and side effects.

Example usage:


 PjdbcCapabilities caps = PjdbcCapabilities.load();

 // Find all caching drivers
 List<DriverCapability> cachingDrivers = caps.findByCapability("caching");

 // Get a specific driver by prefix
 Optional<DriverCapability> pool = caps.findByPrefix("pool");

 // Check if a driver has optional dependencies
 pool.ifPresent(d -> {
     if (!d.dependencies().isEmpty()) {
         System.out.println("Requires: " + d.dependencies());
     }
 });
 
  • Method Details

    • load

      public static PjdbcCapabilities load()
      Loads capabilities, trying manifest first then falling back to reflection.

      This method first attempts to load from the pjdbc.capabilities.json manifest. If the manifest is not found, it falls back to discovering drivers via runtime reflection on annotated classes.

      Returns:
      The loaded capabilities
      Throws:
      PjdbcCapabilitiesException - if capabilities cannot be loaded from either source
    • loadFromManifest

      public static PjdbcCapabilities loadFromManifest()
      Forces loading from the manifest only.
      Returns:
      The loaded capabilities
      Throws:
      PjdbcCapabilitiesException - if the manifest cannot be loaded or parsed
    • loadFromReflection

      public static PjdbcCapabilities loadFromReflection()
      Forces loading via runtime reflection on annotated driver classes.

      This method scans known driver classes for @DriverCapability annotations and builds the capabilities model from those annotations. Useful during development when the manifest may not be up to date.

      Returns:
      The loaded capabilities
    • reload

      public static PjdbcCapabilities reload()
      Forces a reload of capabilities, trying manifest first then reflection. Useful for testing or when the manifest may have changed.
      Returns:
      The reloaded capabilities
    • getVersion

      public String getVersion()
      Returns the schema version of the capabilities manifest.
    • getSource

      public PjdbcCapabilities.Source getSource()
      Returns the source from which capabilities were loaded.
    • getAllDrivers

      public List<DriverCapability> getAllDrivers()
      Returns all available drivers.
    • findByPrefix

      public Optional<DriverCapability> findByPrefix(String prefix)
      Finds a driver by its URL prefix.
      Parameters:
      prefix - The URL prefix (e.g., "pool", "log")
      Returns:
      The driver if found
    • findByClass

      public Optional<DriverCapability> findByClass(String className)
      Finds a driver by its class name.
      Parameters:
      className - The fully qualified class name
      Returns:
      The driver if found
    • findByCapability

      public List<DriverCapability> findByCapability(String capability)
      Finds all drivers with the specified capability.
      Parameters:
      capability - The capability tag (e.g., "caching", "pooling")
      Returns:
      List of matching drivers
    • findComposable

      public List<DriverCapability> findComposable()
      Finds all drivers that are composable (can be chained).
    • findTerminal

      public List<DriverCapability> findTerminal()
      Finds all terminal drivers (those that don't delegate).
    • findWithDependencies

      public List<DriverCapability> findWithDependencies()
      Finds all drivers with external dependencies.
    • findBySideEffect

      public List<DriverCapability> findBySideEffect(String sideEffect)
      Finds all drivers that produce the specified side effect.
      Parameters:
      sideEffect - One of: "logging", "metrics", "network", "filesystem", "stateful"
      Returns:
      List of matching drivers
    • getAllCapabilityTags

      public List<String> getAllCapabilityTags()
      Returns a list of all available capability tags across all drivers.
    • hasDriver

      public boolean hasDriver(String prefix)
      Checks if a driver with the given prefix is available.
    • getDriverCount

      public int getDriverCount()
      Returns the number of available drivers.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • builder

      public static PjdbcCapabilities.Builder builder()
      Builder for creating PjdbcCapabilities instances programmatically. Primarily useful for testing.