Class JdbcUrls
java.lang.Object
io.bloviate.util.JdbcUrls
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 TypeMethodDescriptionstatic StringappendParameter(String url, String name, String value) Appendsname=valueto the URL's query string, choosing?or&as the separator.static booleanhasParameter(String url, String name) Returns whether the URL already carries a query parameter with the given name (any value).static booleanparameterEquals(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 StringwithBatchRewrite(String url, String parameterName) Returns the URL with the driver's batch-rewrite parameter set totrue, or the URL unchanged ifparameterNameis null/blank (the database has no such parameter) or the URL already specifies the parameter (the caller's explicit value is preserved).
-
Method Details
-
hasParameter
-
parameterEquals
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 nullname- the parameter name (case-insensitive)value- the expected value (case-insensitive)- Returns:
trueif present and equal
-
appendParameter
Appendsname=valueto the URL's query string, choosing?or&as the separator. Does not check for or replace an existing parameter of the same name — usehasParameter(String, String)first if that matters.- Parameters:
url- the JDBC URLname- the parameter namevalue- the parameter value- Returns:
- the URL with the parameter appended
- Throws:
IllegalArgumentException- if any argument is null/blank
-
withBatchRewrite
Returns the URL with the driver's batch-rewrite parameter set totrue, or the URL unchanged ifparameterNameis 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 URLparameterName- the batch-rewrite parameter name, or null if not applicable- Returns:
- the URL, with the parameter appended when applicable and absent
-