liquibase.resource.PathHandler implementations allow Liquibase to read files from different physical locations.
They differ from ResourceAccessors in that
ResourceAccesors are used for looking up file references within changelogs,
PathHandlers are used to look up files referenced outside changelogs.
PathHandler implementations can construct ResourceAccessors. This allows new the file lookup logic provided by custom PathHandlers to be used
Liquibase ships with liquibase.resource.DirectoryPathHandler
which looks up paths without a protocol as relative or absolute file paths. Other PathHandlers should generally recognize paths they handle through an expected URL-like protocol, such as
or through specific file extensions like
sequenceDiagram Calling Code->>PathHandlerFactory: getResource() PathHandlerFactory->>PathHandler: getResource() PathHandler-->>Calling Code: Returns Resource
PathHandler defines a
getPriority(path) method which returns the priority for handling that particular path.
PathHandlerFactory will use the
PathHandler that returns the highest priority value.
This allows extensions to either define a new way to look up files OR override existing logic.
If the PathHandler can be dynamically discovered, it must have a no-arg constructor and be registered in the
If the PathHandler must be configured by the integration code, it can have constructor(s) that take required arguments and should NOT be registered in
Used in selecting the instance to use
Looks up the given resource and returns it. This method should return a resource even if it does not exist, with callers using the
Resource.exists() method as needed.
Creates a new resource at the given path and returns a stream for writing to it.
If a file already exists at that location, a
java.nio.file.FileAlreadyExistsException exception should be thrown.
Constructs a ResourceAccessor for the given path.
Because ResourceAccessors are used to look up files, the passed path should be a directory or some other "multiple-file" type location such as a zip file.
The complete javadocs for
liquibase.resource.PathHandler is available at https://javadocs.liquibase.com
The following guides provide relevant examples:
Created: February 18, 2023