Class JdbcUrls

java.lang.Object
io.bloviate.util.JdbcUrls

public final class JdbcUrls extends Object
Small helpers for inspecting and extending JDBC connection URLs.

Bloviate fills through a Connection/DataSource it does not own, so it cannot change the URL after the fact. These helpers let a caller who does build the URL (or DataSource) add the driver's batch-rewrite parameter programmatically — the optimization that is often the single biggest fill speedup. The matching parameter name comes from io.bloviate.ext.DatabaseSupport#batchRewriteUrlParameter() (PostgreSQL reWriteBatchedInserts, MySQL rewriteBatchedStatements).

All methods treat the query string in the simple key=value form drivers use and compare parameter names case-insensitively. They do no URL decoding; they are intended for the straightforward JDBC URLs the supported drivers accept.

Since:
2.10.0
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    appendParameter(String url, String name, String value)
    Appends name=value to the URL's query string, choosing ? or & as the separator.
    static boolean
    Returns whether the URL already carries a query parameter with the given name (any value).
    static boolean
    parameterEquals(String url, String name, String value)
    Returns whether the URL carries the given parameter set to the given value (both name and value compared case-insensitively).
    static String
    withBatchRewrite(String url, String parameterName)
    Returns the URL with the driver's batch-rewrite parameter set to true, or the URL unchanged if parameterName is null/blank (the database has no such parameter) or the URL already specifies the parameter (the caller's explicit value is preserved).

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • hasParameter

      public static boolean hasParameter(String url, String name)
      Returns whether the URL already carries a query parameter with the given name (any value).
      Parameters:
      url - the JDBC URL, may be null
      name - the parameter name (case-insensitive)
      Returns:
      true if the parameter is present
    • parameterEquals

      public static boolean parameterEquals(String url, String name, String value)
      Returns whether the URL carries the given parameter set to the given value (both name and value compared case-insensitively).
      Parameters:
      url - the JDBC URL, may be null
      name - the parameter name (case-insensitive)
      value - the expected value (case-insensitive)
      Returns:
      true if present and equal
    • appendParameter

      public static String appendParameter(String url, String name, String value)
      Appends name=value to the URL's query string, choosing ? or & as the separator. Does not check for or replace an existing parameter of the same name — use hasParameter(String, String) first if that matters.
      Parameters:
      url - the JDBC URL
      name - the parameter name
      value - the parameter value
      Returns:
      the URL with the parameter appended
      Throws:
      IllegalArgumentException - if any argument is null/blank
    • withBatchRewrite

      public static String withBatchRewrite(String url, String parameterName)
      Returns the URL with the driver's batch-rewrite parameter set to true, or the URL unchanged if parameterName is null/blank (the database has no such parameter) or the URL already specifies the parameter (the caller's explicit value is preserved).
      String url = JdbcUrls.withBatchRewrite(baseUrl, support.batchRewriteUrlParameter());
      
      Parameters:
      url - the JDBC URL
      parameterName - the batch-rewrite parameter name, or null if not applicable
      Returns:
      the URL, with the parameter appended when applicable and absent