Top Description Fields Constructors Methods
liquibase.command

public Class CommandFactory

extends Object
implements SingletonObject
Class Inheritance
All Implemented Interfaces
liquibase.SingletonObject
Imports
liquibase.Scope, .SingletonObject, liquibase.servicelocator.ServiceLocator, liquibase.util.DependencyUtil, .StringUtil, java.lang.reflect.InvocationTargetException, java.util.*, java.util.concurrent.ConcurrentHashMap, java.util.stream.Collectors

Manages the command related implementations.

Field Summary

Modifier and TypeField and Description
private Collection<CommandStep>
private final Map<String, Set<CommandArgumentDefinition<?>>>
private final Map<String[], CommandDefinition>
commandDefinitions

A cache of all found command names and their corresponding command definition.

private Map<Class<? extends CommandStep>, CommandStep>
commandOverrides

A cache of all found CommandStep classes and their corresponding override CommandStep.

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
private void
private void
computePipelineForCommandDefinition(CommandDefinition
the CommandDefinition to compute the pipeline
commandDefinition
)

Compute the pipeline for a given command.

private void
consolidateCommandArgumentsForCommand(CommandDefinition commandDefinition)

Go through all the commandSteps on the pipeline and add their arguments to the commandDefinition arguments list.

public <T extends CommandResult> T
execute(LiquibaseCommand<T> command)
Deprecated Use CommandScope#execute()

private synchronized Collection<CommandStep>
private Map<Class<? extends CommandStep>, CommandStep>

Returns:

a map with key of the CommandStep intended to override and value of the valid overriding command step
findAllOverrides
(Collection<CommandStep>
all commands found during runtime
allCommandSteps
)

Find all commands that override other commands based on CommandOverride#override().

private void
findDependenciesForCommand(DependencyUtil.DependencyGraph<CommandStep> pipelineGraph, Collection<CommandStep> allCommandStepInstances, CommandStep step)

Given a CommandStep step this method adds to the pipelineGraph all the CommandSteps that are providing the dependencies that it requires.

public LiquibaseCommand<T extends CommandResult>
public CommandDefinition
getCommandDefinition(String... commandName)

Returns the complete CommandDefinition for the given commandName.

public SortedSet<CommandDefinition>
getCommands(boolean
if true, also include commands marked as CommandDefinition#getInternal()
includeInternal
)

Returns all known CommandDefinitions.

public static CommandFactory
private Optional<CommandStep>

Returns:

an optional containing the CommandStep override if present
getOverride
(Map<Class<? extends CommandStep>, CommandStep>
the list of overrides
overrides
,
CommandStep
the step to check for overrides
step
)

Get the override for a given CommandStep.

protected void
register(String[] commandName, CommandArgumentDefinition<?> definition)

Called by CommandArgumentDefinition.Building#build() to register that a particular CommandArgumentDefinition is available for a command.

protected void
unregister(String[] commandName)

Unregisters all information about the given CommandStep.

private void
validateOverrides(Map<Class<? extends CommandStep>, List<CommandStep>>
the list of overrides
overrides
)

Validates that for all overrides, there is only a single override per command step.

private CommandStep
whoProvidesClass(Class<?> dependency, Collection<CommandStep> allCommandStepInstances)

Go through all command steps and find the step that provides the desired class.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allInstancesback to summary
private Collection<CommandStep> allInstances
commandArgumentDefinitionsback to summary
private final Map<String, Set<CommandArgumentDefinition<?>>> commandArgumentDefinitions
commandDefinitionsback to summary
private final Map<String[], CommandDefinition> commandDefinitions

A cache of all found command names and their corresponding command definition.

commandOverridesback to summary
private Map<Class<? extends CommandStep>, CommandStep> commandOverrides

A cache of all found CommandStep classes and their corresponding override CommandStep.

Constructor Detail

CommandFactoryback to summary
protected CommandFactory()

Method Detail

adjustCommandDefinitionForStepsback to summary
private void adjustCommandDefinitionForSteps(CommandDefinition commandDefinition)
computePipelineForCommandDefinitionback to summary
private void computePipelineForCommandDefinition(CommandDefinition commandDefinition)

Compute the pipeline for a given command. Takes into consideration all the dependencies required by the command and other commands subscribed to it by getOrder.

Parameters
commandDefinition:CommandDefinition

the CommandDefinition to compute the pipeline

consolidateCommandArgumentsForCommandback to summary
private void consolidateCommandArgumentsForCommand(CommandDefinition commandDefinition)

Go through all the commandSteps on the pipeline and add their arguments to the commandDefinition arguments list.

executeback to summary
public <T extends CommandResult> T execute(LiquibaseCommand<T> command) throws CommandExecutionException

Deprecated

Use CommandScope#execute()

findAllInstancesback to summary
private synchronized Collection<CommandStep> findAllInstances()
findAllOverridesback to summary
private Map<Class<? extends CommandStep>, CommandStep> findAllOverrides(Collection<CommandStep> allCommandSteps) throws RuntimeException

Find all commands that override other commands based on CommandOverride#override(). Validates that only a single command is overriding another.

Parameters
allCommandSteps:Collection<CommandStep>

all commands found during runtime

Returns:Map<Class<? extends CommandStep>, CommandStep>

a map with key of the CommandStep intended to override and value of the valid overriding command step

Exceptions
RuntimeException:
if more than one command step overrides another command step
findDependenciesForCommandback to summary
private void findDependenciesForCommand(DependencyUtil.DependencyGraph<CommandStep> pipelineGraph, Collection<CommandStep> allCommandStepInstances, CommandStep step)

Given a CommandStep step this method adds to the pipelineGraph all the CommandSteps that are providing the dependencies that it requires.

getCommandback to summary
public LiquibaseCommand<T extends CommandResult> getCommand(String commandName)
getCommandDefinitionback to summary
public CommandDefinition getCommandDefinition(String... commandName) throws IllegalArgumentException

Returns the complete CommandDefinition for the given commandName.

Exceptions
IllegalArgumentException:
if the commandName is not known
getCommandsback to summary
public SortedSet<CommandDefinition> getCommands(boolean includeInternal)

Returns all known CommandDefinitions.

Parameters
includeInternal:boolean

if true, also include commands marked as CommandDefinition#getInternal()

getInstanceback to summary
public static CommandFactory getInstance()
getOverrideback to summary
private Optional<CommandStep> getOverride(Map<Class<? extends CommandStep>, CommandStep> overrides, CommandStep step)

Get the override for a given CommandStep.

Parameters
overrides:Map<Class<? extends CommandStep>, CommandStep>

the list of overrides

step:CommandStep

the step to check for overrides

Returns:Optional<CommandStep>

an optional containing the CommandStep override if present

registerback to summary
protected void register(String[] commandName, CommandArgumentDefinition<?> definition)

Called by CommandArgumentDefinition.Building#build() to register that a particular CommandArgumentDefinition is available for a command.

unregisterback to summary
protected void unregister(String[] commandName)

Unregisters all information about the given CommandStep. package-protected method used primarily for testing and may be removed or modified in the future.

validateOverridesback to summary
private void validateOverrides(Map<Class<? extends CommandStep>, List<CommandStep>> overrides) throws RuntimeException

Validates that for all overrides, there is only a single override per command step. Logs all invalid overrides found.

Parameters
overrides:Map<Class<? extends CommandStep>, List<CommandStep>>

the list of overrides

Exceptions
RuntimeException:
if more than one command step overrides a command step
whoProvidesClassback to summary
private CommandStep whoProvidesClass(Class<?> dependency, Collection<CommandStep> allCommandStepInstances)

Go through all command steps and find the step that provides the desired class.