Package org.pjdbc.sql
Class JdbcUrlParser
java.lang.Object
org.pjdbc.sql.JdbcUrlParser
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 Summary
Modifier and TypeMethodDescriptionbooleangetBoolean(String key, boolean defaultValue) Get a parameter value as a boolean.doubleGet a parameter value as a double.intGet a parameter value as an integer.longGet a parameter value as a long.getParameter(String key) Get a parameter value by key.getParameter(String key, String defaultValue) Get a parameter value by key with a default value.Get all parameters as an unmodifiable map.Get the protocol (always "jdbc").Get the subname (everything after the subprotocol and parameters).Get the subprotocol (e.g., "filter", "pool", "log").static JdbcUrlParserParse a JDBC URL into its components.toString()
-
Method Details
-
parse
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
Get the protocol (always "jdbc"). -
getSubprotocol
Get the subprotocol (e.g., "filter", "pool", "log"). -
getSubname
Get the subname (everything after the subprotocol and parameters). -
getParameters
Get all parameters as an unmodifiable map. -
getParameter
Get a parameter value by key.- Parameters:
key- the parameter key- Returns:
- the parameter value, or null if not found
-
getParameter
Get a parameter value by key with a default value.- Parameters:
key- the parameter keydefaultValue- the default value if the parameter is not found- Returns:
- the parameter value, or the default value if not found
-
getInt
Get a parameter value as an integer.- Parameters:
key- the parameter keydefaultValue- the default value if the parameter is not found or invalid- Returns:
- the parameter value as an integer
-
getLong
Get a parameter value as a long.- Parameters:
key- the parameter keydefaultValue- the default value if the parameter is not found or invalid- Returns:
- the parameter value as a long
-
getDouble
Get a parameter value as a double.- Parameters:
key- the parameter keydefaultValue- the default value if the parameter is not found or invalid- Returns:
- the parameter value as a double
-
getBoolean
Get a parameter value as a boolean. Accepts "true" (case-insensitive) as true, anything else as false.- Parameters:
key- the parameter keydefaultValue- the default value if the parameter is not found- Returns:
- the parameter value as a boolean
-
toString
-