Top Description Inners Fields Constructors Methods
liquibase.command

public Class CommandScope

extends Object
Class Inheritance
Imports
liquibase.GlobalConfiguration, .Scope, liquibase.configuration.*, liquibase.database.Database, liquibase.exception.CommandExecutionException, .CommandValidationException, .DatabaseException, .LiquibaseException, liquibase.integration.commandline.LiquibaseCommandLineConfiguration, liquibase.listener.LiquibaseListener, liquibase.logging.mdc.MdcKey, .MdcManager, .MdcObject, liquibase.logging.mdc.customobjects.ExceptionDetails, liquibase.util.LiquibaseUtil, .StringUtil, java.io.*, java.time.Instant, java.util.*, java.util.regex.Pattern

The primary facade used for executing commands. This object gets configured with the command to run and the input arguments associated with it, then is populated with the result output after execute() is called.

Named similarly to Scope because they both define a self-contained unit of values, but this scope is specific to a command rather than being a global scope.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
CommandScope.CommandScopeValueProvider

Adapts the command-scoped arguments into the overall ValueProvider system

private static class
CommandScope.UnclosableOutputStream

This class is a wrapper around OutputStreams, and makes them impossible for callers to close.

Field Summary

Modifier and TypeField and Description
private final SortedMap<String, Object>
private final CommandDefinition
private final String
completeConfigPrefix

Config key including the command name.

private final Map<Class<?>, Object>
public static final Pattern
private static final String
private OutputStream
private final String
shortConfigPrefix

Config key without the command name.

Constructor Summary

AccessConstructor and Description
public
CommandScope(String... commandName)

Creates a new scope for the given command.

Method Summary

Modifier and TypeMethod and Description
public CommandScope
addArgumentValue(String argument, Object value)

Adds the given key/value pair to the stored argument data.

public <T> CommandScope
addArgumentValue(CommandArgumentDefinition<T> argument, T value)

Adds the given key/value pair to the stored argument data.

private void
private <T> ConfigurationDefinition<T>
createConfigurationDefinition(CommandArgumentDefinition<T> argument, boolean includeCommandName)

public CommandResults
execute()

Executes the command in this scope, and returns the results.

public <T> T
public CommandDefinition
getCommand()

Returns the CommandDefinition for the command in this scope.

private String

Returns:

the full command step name definition delimited by spaces or an empty string if there are no defined command names
getCommandStepName
(CommandStep
the command step to get the name of
commandStep
)

Returns a string of the entire defined command names, joined together with spaces

public String

Returns:

the complete configuration prefix for the command in this scope
getCompleteConfigPrefix
()

Returns the complete configuration prefix (without a trailing period) for the command in this scope.

public <T> ConfiguredValue<T>
getConfiguredValue(CommandArgumentDefinition<T> argument)

Returns the detailed information about how an argument is set.

private static String
public <T> Object
getDependency(Class<T> clazz)

Retrieves the registered dependency object provided by this class identifier

private void
public CommandScope
provideDependency(Class<?> clazz, Object value)

Assign a value to a given provided dependency.

public CommandScope
setOutput(OutputStream outputStream)

Sets the output stream for this command.

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

argumentValuesback to summary
private final SortedMap<String, Object> argumentValues
commandDefinitionback to summary
private final CommandDefinition commandDefinition
completeConfigPrefixback to summary
private final String completeConfigPrefix

Config key including the command name. Example `liquibase.command.update`

dependenciesback to summary
private final Map<Class<?>, Object> dependencies
NO_PREFIX_PATTERNback to summary
public static final Pattern NO_PREFIX_PATTERN
NO_PREFIX_REGEXback to summary
private static final String NO_PREFIX_REGEX
outputStreamback to summary
private OutputStream outputStream
shortConfigPrefixback to summary
private final String shortConfigPrefix

Config key without the command name. Example `liquibase.command`

Constructor Detail

CommandScopeback to summary
public CommandScope(String... commandName) throws CommandExecutionException

Creates a new scope for the given command.

Method Detail

addArgumentValueback to summary
public CommandScope addArgumentValue(String argument, Object value)

Adds the given key/value pair to the stored argument data.

See Also
for a type-safe version
addArgumentValueback to summary
public <T> CommandScope addArgumentValue(CommandArgumentDefinition<T> argument, T value)

Adds the given key/value pair to the stored argument data.

addOutputFileToMdcback to summary
private void addOutputFileToMdc() throws Exception
createConfigurationDefinitionback to summary
private <T> ConfigurationDefinition<T> createConfigurationDefinition(CommandArgumentDefinition<T> argument, boolean includeCommandName)
executeback to summary
public CommandResults execute() throws CommandExecutionException

Executes the command in this scope, and returns the results.

getArgumentValueback to summary
public <T> T getArgumentValue(CommandArgumentDefinition<T> argument)

Convenience method for getConfiguredValue(CommandArgumentDefinition), returning ConfiguredValue#getValue() along with any CommandArgumentDefinition#getValueConverter() applied

getCommandback to summary
public CommandDefinition getCommand()

Returns the CommandDefinition for the command in this scope.

getCommandStepNameback to summary
private String getCommandStepName(CommandStep commandStep)

Returns a string of the entire defined command names, joined together with spaces

Parameters
commandStep:CommandStep

the command step to get the name of

Returns:String

the full command step name definition delimited by spaces or an empty string if there are no defined command names

getCompleteConfigPrefixback to summary
public String getCompleteConfigPrefix()

Returns the complete configuration prefix (without a trailing period) for the command in this scope.

Returns:String

the complete configuration prefix for the command in this scope

getConfiguredValueback to summary
public <T> ConfiguredValue<T> getConfiguredValue(CommandArgumentDefinition<T> argument)

Returns the detailed information about how an argument is set.

Prefers values set with addArgumentValue(String, Object), but will also check liquibase.configuration.LiquibaseConfiguration for settings of liquibase.command.${commandName(s)}.${argumentName} or liquibase.command.${argumentName}

getDatabaseInfoback to summary
private static String getDatabaseInfo(Database database)
getDependencyback to summary
public <T> Object getDependency(Class<T> clazz)

Retrieves the registered dependency object provided by this class identifier

logPrimaryExceptionToMdcback to summary
private void logPrimaryExceptionToMdc(Throwable exception, String source)
provideDependencyback to summary
public CommandScope provideDependency(Class<?> clazz, Object value)

Assign a value to a given provided dependency. So if a CommandStep provides class X, at CommandStep#run(CommandResultsBuilder) method it needs to provide the value for X using this method. commandScope.provideDependency(LockService.class, lockService);

Means that this class will LockService.class using object lock

setOutputback to summary
public CommandScope setOutput(OutputStream outputStream)

Sets the output stream for this command. The command output sent to this stream should not include status/progress type output, only the actual output itself. Think "what would be piped out", not "what the user is told about what is happening".

validateback to summary
public void validate() throws CommandValidationException
liquibase.command back to summary

private Class CommandScope.CommandScopeValueProvider

extends AbstractMapConfigurationValueProvider
Class Inheritance

Adapts the command-scoped arguments into the overall ValueProvider system

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
protected Map<?, ?>
public int
getPrecedence()

Implements liquibase.configuration.ConfigurationValueProvider.getPrecedence.

Returns the precedence of values returned by this provider.

protected String
protected boolean
keyMatches(String
the configuration key requested
wantedKey
,
String
the key stored in the map
storedKey
)

Overrides liquibase.configuration.AbstractMapConfigurationValueProvider.keyMatches.

Used by ConfigurationValueProvider#getProvidedValue(String[]) to determine of a given map entry matches the wanted key.

Inherited from liquibase.configuration.AbstractMapConfigurationValueProvider:
getMapHashgetProvidedValueisValueSetlookupProvidedValue

Constructor Detail

CommandScopeValueProviderback to summary
private CommandScopeValueProvider()

Method Detail

getMapback to summary
protected Map<?, ?> getMap()

Implements abstract liquibase.configuration.AbstractMapConfigurationValueProvider.getMap.

Annotations
@Override
getPrecedenceback to summary
public int getPrecedence()

Implements liquibase.configuration.ConfigurationValueProvider.getPrecedence.

Doc from liquibase.configuration.ConfigurationValueProvider.getPrecedence.

Returns the precedence of values returned by this provider. Higher a provider with higher precedence overrides values from lower precedence providers.

Standard provider precedence:

Annotations
@Override
getSourceDescriptionback to summary
protected String getSourceDescription()

Implements abstract liquibase.configuration.AbstractMapConfigurationValueProvider.getSourceDescription.

Annotations
@Override
keyMatchesback to summary
protected boolean keyMatches(String wantedKey, String storedKey)

Overrides liquibase.configuration.AbstractMapConfigurationValueProvider.keyMatches.

Doc from liquibase.configuration.AbstractMapConfigurationValueProvider.keyMatches.

Used by ConfigurationValueProvider#getProvidedValue(String[]) to determine of a given map entry matches the wanted key. This implementation compares the values case-insensitively, and will replace camelCase words with kabob-case

Parameters
wantedKey:String

the configuration key requested

storedKey:String

the key stored in the map

Annotations
@Override
liquibase.command back to summary

private Class CommandScope.UnclosableOutputStream

extends FilterOutputStream
Class Inheritance

This class is a wrapper around OutputStreams, and makes them impossible for callers to close.

Field Summary

Inherited from java.io.FilterOutputStream:
out

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.FilterOutputStream.close.

Implements java.io.Closeable.close.

This method does not actually close the underlying stream, but rather only flushes it.

public void
write(byte[]
the data.
b
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Overrides java.io.FilterOutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.

Inherited from java.io.FilterOutputStream:
flushwritewrite

Constructor Detail

UnclosableOutputStreamback to summary
public UnclosableOutputStream(OutputStream out)

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.FilterOutputStream.close.

Implements java.io.Closeable.close.

This method does not actually close the underlying stream, but rather only flushes it. Callers should not be closing the stream they are given.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.FilterOutputStream.close.

if an I/O error occurs.

writeback to summary
public void write(byte[] b, int off, int len) throws IOException

Overrides java.io.FilterOutputStream.write.

Doc from java.io.FilterOutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.

Parameters
b:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.