Class PgUrlParser

java.lang.Object
io.github.mfvanek.pg.connection.host.PgUrlParser

public final class PgUrlParser extends Object
Utility class for parsing and manipulating PostgreSQL connection URLs.
  • Field Details

    • URL_HEADER

      public static final String URL_HEADER
      Header prefix for PostgreSQL JDBC URLs.
      See Also:
    • TESTCONTAINERS_PG_URL_PREFIX

      public static final String TESTCONTAINERS_PG_URL_PREFIX
      The URL prefix used in Testcontainers to initialize PostgreSQL containers.

      Testcontainers provides a special JDBC URL format that allows for on-the-fly creation and management of PostgreSQL database containers during tests. This prefix is part of the JDBC URL and signals Testcontainers to handle the lifecycle of the container automatically.

      Since:
      0.14.2
      See Also:
  • Method Details

    • extractNameWithPortAndUrlForEachHost

      @Nonnull public static List<Map.Entry<String,String>> extractNameWithPortAndUrlForEachHost(@Nonnull String pgUrl)
      Extracts host-port pairs and builds replica-compatible connection URLs for each host.
      Parameters:
      pgUrl - the PostgreSQL connection URL; must be valid and non-blank.
      Returns:
      a list of host-port pairs and corresponding replica-compatible URLs.
    • buildCommonUrlToPrimary

      @Nonnull public static String buildCommonUrlToPrimary(@Nonnull String firstPgUrl, @Nonnull String secondPgUrl)
      Constructs a common (joint) PostgreSQL URL for a primary server.
      Parameters:
      firstPgUrl - a first PostgreSQL connection URL.
      secondPgUrl - a second PostgreSQL connection URL.
      Returns:
      the constructed primary connection URL.
    • buildCommonUrlToPrimary

      @Nonnull public static String buildCommonUrlToPrimary(@Nonnull String firstPgUrl, @Nonnull String secondPgUrl, @Nonnull Map<String,String> urlParameters)
      Constructs a common (joint) PostgreSQL URL for a primary server.
      Parameters:
      firstPgUrl - a first PostgreSQL connection URL.
      secondPgUrl - a second PostgreSQL connection URL.
      urlParameters - optional additional parameters to include in the URL.
      Returns:
      the constructed primary connection URL.
    • buildCommonUrlToPrimary

      @Nonnull public static String buildCommonUrlToPrimary(@Nonnull Set<String> pgUrls)
      Constructs a common (joint) PostgreSQL URL for a primary server.
      Parameters:
      pgUrls - a set of PostgreSQL connection URLs.
      Returns:
      the constructed primary connection URL.
    • buildCommonUrlToPrimary

      @Nonnull public static String buildCommonUrlToPrimary(@Nonnull Set<String> pgUrls, @Nonnull Map<String,String> urlParameters)
      Constructs a common (joint) PostgreSQL URL for a primary server.
      Parameters:
      pgUrls - a set of PostgreSQL connection URLs.
      urlParameters - optional additional parameters to include in the URL.
      Returns:
      the constructed primary connection URL.