Package org.pjdbc.sql

Class JdbcUrlParser

java.lang.Object
org.pjdbc.sql.JdbcUrlParser

public class JdbcUrlParser extends Object
Parser for PJDBC URLs with optional parameter support. URL format: jdbc:subprotocol[param1=value1,param2=value2]:subname Examples: - jdbc:filter:jdbc:mock:foo - jdbc:filter[class=com.example.MyFilter]:jdbc:mock:foo - jdbc:pool[min=5,max=20]:jdbc:postgresql://localhost/db
  • Method Details

    • parse

      public static JdbcUrlParser parse(String url)
      Parse a JDBC URL into its components.
      Parameters:
      url - the JDBC URL to parse
      Returns:
      a JdbcUrlParser instance containing the parsed components
      Throws:
      IllegalArgumentException - if the URL is null or invalid
    • getProtocol

      public String getProtocol()
      Get the protocol (always "jdbc").
    • getSubprotocol

      public String getSubprotocol()
      Get the subprotocol (e.g., "filter", "pool", "log").
    • getSubname

      public String getSubname()
      Get the subname (everything after the subprotocol and parameters).
    • getParameters

      public Map<String,String> getParameters()
      Get all parameters as an unmodifiable map.
    • getParameter

      public String getParameter(String key)
      Get a parameter value by key.
      Parameters:
      key - the parameter key
      Returns:
      the parameter value, or null if not found
    • getParameter

      public String getParameter(String key, String defaultValue)
      Get a parameter value by key with a default value.
      Parameters:
      key - the parameter key
      defaultValue - the default value if the parameter is not found
      Returns:
      the parameter value, or the default value if not found
    • getInt

      public int getInt(String key, int defaultValue)
      Get a parameter value as an integer.
      Parameters:
      key - the parameter key
      defaultValue - the default value if the parameter is not found or invalid
      Returns:
      the parameter value as an integer
    • getLong

      public long getLong(String key, long defaultValue)
      Get a parameter value as a long.
      Parameters:
      key - the parameter key
      defaultValue - the default value if the parameter is not found or invalid
      Returns:
      the parameter value as a long
    • getDouble

      public double getDouble(String key, double defaultValue)
      Get a parameter value as a double.
      Parameters:
      key - the parameter key
      defaultValue - the default value if the parameter is not found or invalid
      Returns:
      the parameter value as a double
    • getBoolean

      public boolean getBoolean(String key, boolean defaultValue)
      Get a parameter value as a boolean. Accepts "true" (case-insensitive) as true, anything else as false.
      Parameters:
      key - the parameter key
      defaultValue - the default value if the parameter is not found
      Returns:
      the parameter value as a boolean
    • toString

      public String toString()
      Overrides:
      toString in class Object