Record Class ConnectionString
java.lang.Object
java.lang.Record
io.micronaut.core.util.ConnectionString
- Record Components:
rawValue- The original unparsed connection stringparseMode- The parse mode used when parsingprefix- Optional prefix (e.g.optional)protocol- The protocol componentusername- Optional username from authoritypassword- Optional password from authorityhosts- Parsed list of host/port pairspath- The path componentoptions- Parsed query optionscanonicalForm- Normalized canonical representation
public record ConnectionString(String rawValue, ConnectionString.ParseMode parseMode, @Nullable String prefix, String protocol, @Nullable String username, @Nullable String password, List<ConnectionString.HostPort> hosts, String path, Map<String,String> options, String canonicalForm)
extends Record
Parsed representation of protocol-based connection strings.
Supported syntax:
[optional:]<protocol>://[username[:password]@][host[:port][,host[:port]...]/]<path>[?key=value[&key=value...]]
Examples:
file:///etc/app/config.ymloptional:file://config/extraconsul://user:pass@localhost:8500/app/config?dc=localenv://APP_IMPORT.properties
- Since:
- 5.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordHost and optional port.static enumParse mode that defines which components are required. -
Constructor Summary
ConstructorsConstructorDescriptionConnectionString(String rawValue, ConnectionString.ParseMode parseMode, @Nullable String prefix, String protocol, @Nullable String username, @Nullable String password, List<ConnectionString.HostPort> hosts, String path, Map<String, String> options, String canonicalForm) Creates an instance of aConnectionStringrecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thecanonicalFormrecord component.booleanIndicates whether some other object is "equal to" this one.getHosts()getPath()inthashCode()Returns a hash code value for this object.hosts()Returns the value of thehostsrecord component.booleanoptions()Returns the value of theoptionsrecord component.static ConnectionStringParse a connection string.static ConnectionStringparse(String value, ConnectionString.ParseMode parseMode) Parse a connection string with the provided mode.Returns the value of theparseModerecord component.@Nullable Stringpassword()Returns the value of thepasswordrecord component.path()Returns the value of thepathrecord component.@Nullable Stringprefix()Returns the value of theprefixrecord component.protocol()Returns the value of theprotocolrecord component.rawValue()Returns the value of therawValuerecord component.toString()Returns a string representation of this record class.@Nullable Stringusername()Returns the value of theusernamerecord component.
-
Constructor Details
-
ConnectionString
public ConnectionString(String rawValue, ConnectionString.ParseMode parseMode, @Nullable String prefix, String protocol, @Nullable String username, @Nullable String password, List<ConnectionString.HostPort> hosts, String path, Map<String, String> options, String canonicalForm) Creates an instance of aConnectionStringrecord class.- Parameters:
rawValue- the value for therawValuerecord componentparseMode- the value for theparseModerecord componentprefix- the value for theprefixrecord componentprotocol- the value for theprotocolrecord componentusername- the value for theusernamerecord componentpassword- the value for thepasswordrecord componenthosts- the value for thehostsrecord componentpath- the value for thepathrecord componentoptions- the value for theoptionsrecord componentcanonicalForm- the value for thecanonicalFormrecord component
-
-
Method Details
-
parse
Parse a connection string.- Parameters:
value- The value- Returns:
- The parsed connection string
-
parse
Parse a connection string with the provided mode.- Parameters:
value- The raw valueparseMode- The parse mode that defines required components- Returns:
- The parsed connection string
-
getRawValue
-
getParseMode
- Returns:
- Returns the parse mode used to parse this value
-
getPrefix
-
isOptional
public boolean isOptional()- Returns:
- Returns whether the connection string starts with
optional:
-
getProtocol
- Returns:
- Returns the normalized lower-case protocol
-
getUsername
-
getPassword
-
getHosts
- Returns:
- Returns immutable list of host/port entries from the authority section
-
getPath
- Returns:
- Returns parsed path component (may be empty depending on parse mode)
-
getCanonicalPath
- Returns:
- Returns normalized path with duplicate separators and dot segments removed
-
getResourcePath
- Returns:
- Returns resource path for file/classpath-like use cases
-
getExtension
-
getOptions
-
getCanonicalForm
- Returns:
- Returns canonical representation preserving semantic components
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
hashCode
-
toString
-
rawValue
-
parseMode
-
prefix
-
protocol
-
username
-
password
-
hosts
-
path
-
options
-
canonicalForm
Returns the value of thecanonicalFormrecord component.- Returns:
- the value of the
canonicalFormrecord component
-