Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use property name where possible for commands #1796

Merged
merged 9 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ private static Collection<PropertyName> availableCommands() {
supportedCommands.add(
new PropertyName(
"<query_name>",
"Shows results of query <query_name>, "
"Show results of query <query_name>, "
+ "as specified in the configuration properties file"));
supportedCommands.add(
new PropertyName(
"<query>",
String.join(
"\n",
"Shows results of SQL <query>",
"Show results of SQL <query>",
"The query itself can contain the variables ${table}, ${columns} "
+ "and ${tabletype}, or system properties referenced as ${<system-property-name>}",
"Queries without any variables are executed exactly once",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SchemaCrawler 16.23.1
SchemaCrawler 16.24.1
Database schema discovery and comprehension tool
https://www.schemacrawler.com/
Copyright (c) 2000-2025, Sualeh Fatehi <sualeh@hotmail.com>.
Expand Down Expand Up @@ -222,7 +222,7 @@ Options:
Optional, default is 0


Loader for catalog attributes, such as remarks or tags
** Loader for catalog attributes, such as remarks or tags
Command:
loader:attributesloader

Expand All @@ -233,7 +233,7 @@ Options:
Add loader options to the `load` command in the SchemaCrawler Shell


Loader for table row counts
** Loader for table row counts
Command:
loader:countsloader

Expand All @@ -247,7 +247,7 @@ Options:
Add loader options to the `load` command in the SchemaCrawler Shell


Loader for testing
** Loader for testing
Command:
loader:testloader

Expand All @@ -257,7 +257,7 @@ Options:
Add loader options to the `load` command in the SchemaCrawler Shell


Loader for weak associations
** Loader for weak associations
Command:
loader:weakassociationsloader

Expand Down Expand Up @@ -291,7 +291,8 @@ run SchemaCrawler with: `-h loaders`
or from the SchemaCrawler interactive shell: `help loaders`


** Generate text output to show details of a schema
** Show the commonly needed detail of the schema, including details of tables,
views and routines, columns, primary keys, indexes, foreign keys, and triggers
Command:
command:schema
Applies to all commands that show schema information
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@

Available SchemaCrawler Commands:
brief Shows basic schema information, for tables, views and routines,
brief Show basic schema information, for tables, views and routines,
columns, primary keys, and foreign keys
count Shows counts of rows in the tables
details Shows maximum possible detail of the schema, including
count Show counts of rows in the tables
details Show maximum possible detail of the schema, including
privileges, and details of privileges, triggers, and check
constraints
dump Shows data from all rows in the tables
list Shows a list of schema objects
quickdump Shows data from all rows in the tables, but row order is not
dump Show data from all rows in the tables
list Show a list of schema objects
quickdump Show data from all rows in the tables, but row order is not
guaranteed - this can be used with a minimum info-level for
speed
schema Shows the commonly needed detail of the schema, including
schema Show the commonly needed detail of the schema, including
details of tables, views and routines, columns, primary keys,
indexes, foreign keys, and triggers
test-command Test command which is not deployed with the release
<query_name> Shows results of query <query_name>, as specified in the
<query_name> Show results of query <query_name>, as specified in the
configuration properties file
<query> Shows results of SQL <query>
<query> Show results of SQL <query>
The query itself can contain the variables ${table}, ${columns}
and ${tabletype}, or system properties referenced as
${<system-property-name>}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import schemacrawler.tools.executable.BaseCommandProvider;
import schemacrawler.tools.options.Config;
import schemacrawler.tools.options.OutputOptions;
import us.fatehi.utility.property.PropertyName;

public final class DiagramCommandProvider extends BaseCommandProvider {

Expand All @@ -44,9 +45,13 @@ public DiagramCommandProvider() {

@Override
public DiagramRenderer newSchemaCrawlerCommand(final String command, final Config config) {
final PropertyName commandName = lookupSupportedCommand(command);
if (commandName == null) {
throw new IllegalArgumentException("Cannot support command, " + command);
}
final DiagramOptions diagramOptions =
DiagramOptionsBuilder.builder().fromConfig(config).toOptions();
final DiagramRenderer scCommand = new DiagramRenderer(command, new GraphExecutorFactory());
final DiagramRenderer scCommand = new DiagramRenderer(commandName, new GraphExecutorFactory());
scCommand.configure(diagramOptions);
return scCommand;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@

package schemacrawler.tools.command.text.diagram;

import static java.util.Objects.requireNonNull;
import static schemacrawler.tools.command.text.diagram.options.DiagramOutputFormat.scdot;
import static us.fatehi.utility.IOUtility.createTempFilePath;
import static us.fatehi.utility.IOUtility.readResourceFully;
import java.io.IOException;
import java.nio.file.Path;
import static java.util.Objects.requireNonNull;
import schemacrawler.schemacrawler.exceptions.ExecutionRuntimeException;
import schemacrawler.schemacrawler.exceptions.IORuntimeException;
import schemacrawler.schemacrawler.exceptions.SchemaCrawlerException;
Expand All @@ -47,13 +47,15 @@
import schemacrawler.tools.traversal.SchemaTraversalHandler;
import schemacrawler.tools.traversal.SchemaTraverser;
import schemacrawler.utility.NamedObjectSort;
import us.fatehi.utility.property.PropertyName;

public final class DiagramRenderer extends BaseSchemaCrawlerCommand<DiagramOptions> {

private DiagramOutputFormat diagramOutputFormat;
private final GraphExecutorFactory graphExecutorFactory;

public DiagramRenderer(final String command, final GraphExecutorFactory graphExecutorFactory) {
public DiagramRenderer(
final PropertyName command, final GraphExecutorFactory graphExecutorFactory) {
super(command);
this.graphExecutorFactory =
requireNonNull(graphExecutorFactory, "No graph executor factory provided");
Expand Down Expand Up @@ -152,7 +154,7 @@ private String extractErrorMessage(final Exception e) {
private SchemaTextDetailType getSchemaTextDetailType() {
SchemaTextDetailType schemaTextDetailType;
try {
schemaTextDetailType = SchemaTextDetailType.valueOf(command);
schemaTextDetailType = SchemaTextDetailType.valueOf(command.getName());
} catch (final IllegalArgumentException e) {
schemaTextDetailType = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import schemacrawler.tools.executable.BaseCommandProvider;
import schemacrawler.tools.options.Config;
import schemacrawler.tools.options.OutputOptions;
import us.fatehi.utility.property.PropertyName;

public final class EmbeddedDiagramCommandProvider extends BaseCommandProvider {

Expand All @@ -46,10 +47,15 @@ public EmbeddedDiagramCommandProvider() {
@Override
public EmbeddedDiagramRenderer newSchemaCrawlerCommand(
final String command, final Config config) {
final PropertyName commandName = lookupSupportedCommand(command);
if (commandName == null) {
throw new IllegalArgumentException("Cannot support command, " + command);
}

final DiagramOptions diagramOptions =
DiagramOptionsBuilder.builder().fromConfig(config).toOptions();
final EmbeddedDiagramRenderer scCommand =
new EmbeddedDiagramRenderer(command, new GraphExecutorFactory());
new EmbeddedDiagramRenderer(commandName, new GraphExecutorFactory());
scCommand.configure(diagramOptions);
return scCommand;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import schemacrawler.tools.options.OutputFormat;
import schemacrawler.tools.options.OutputOptions;
import schemacrawler.tools.options.OutputOptionsBuilder;
import us.fatehi.utility.property.PropertyName;

public class EmbeddedDiagramRenderer extends BaseSchemaCrawlerCommand<DiagramOptions> {

Expand Down Expand Up @@ -90,7 +91,7 @@ private static void insertSvg(
private final GraphExecutorFactory graphExecutorFactory;

public EmbeddedDiagramRenderer(
final String command, final GraphExecutorFactory graphExecutorFactory) {
final PropertyName command, final GraphExecutorFactory graphExecutorFactory) {
super(command);
this.graphExecutorFactory =
requireNonNull(graphExecutorFactory, "No graph executor factory provided");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ public void diagramRenderer_graphviz(
final Catalog catalog = getCatalog(dataSource);

commandDiagram(
new DiagramRenderer(SchemaTextDetailType.details.name(), new GraphExecutorFactory()),
new DiagramRenderer(
SchemaTextDetailType.details.toPropertyName(), new GraphExecutorFactory()),
dataSource,
catalog,
diagramOptions,
Expand All @@ -233,7 +234,8 @@ public void diagramRenderer_graphviz_java(
final Catalog catalog = getCatalog(dataSource);

commandDiagram(
new DiagramRenderer(SchemaTextDetailType.details.name(), new GraphvizJavaExecutorFactory()),
new DiagramRenderer(
SchemaTextDetailType.details.toPropertyName(), new GraphvizJavaExecutorFactory()),
dataSource,
catalog,
diagramOptions,
Expand All @@ -254,7 +256,7 @@ public void embeddedDiagramRenderer_graphviz(

commandDiagram(
new EmbeddedDiagramRenderer(
SchemaTextDetailType.details.name(), new GraphExecutorFactory()),
SchemaTextDetailType.details.toPropertyName(), new GraphExecutorFactory()),
dataSource,
catalog,
diagramOptions,
Expand All @@ -274,7 +276,7 @@ public void embeddedDiagramRenderer_graphviz_java(

commandDiagram(
new EmbeddedDiagramRenderer(
SchemaTextDetailType.details.name(), new GraphvizJavaExecutorFactory()),
SchemaTextDetailType.details.toPropertyName(), new GraphvizJavaExecutorFactory()),
dataSource,
catalog,
diagramOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,18 @@
import schemacrawler.tools.lint.formatter.LintReportTextFormatter;
import schemacrawler.tools.lint.formatter.LintReportTextGenerator;
import schemacrawler.tools.lint.formatter.LintReportYamlGenerator;
import us.fatehi.utility.property.PropertyName;
import us.fatehi.utility.string.ObjectToStringFormat;

public class LintCommand extends BaseSchemaCrawlerCommand<LintOptions> {

private static final Logger LOGGER = Logger.getLogger(LintCommand.class.getName());

public static final String COMMAND = "lint";
static final PropertyName COMMAND =
new PropertyName(
"lint",
"Find lints (non-adherence to coding standards and conventions) "
+ "in the database schema");

public LintCommand() {
super(COMMAND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

package schemacrawler.tools.command.lint;

import static schemacrawler.tools.command.lint.LintCommand.COMMAND;
import static schemacrawler.tools.executable.commandline.PluginCommand.newPluginCommand;
import java.nio.file.Path;
import schemacrawler.tools.command.lint.options.LintOptions;
Expand All @@ -39,23 +40,18 @@
import schemacrawler.tools.lint.LinterHelp;
import schemacrawler.tools.options.Config;
import schemacrawler.tools.options.OutputOptions;
import us.fatehi.utility.property.PropertyName;

public class LintCommandProvider extends BaseCommandProvider {

public static final String DESCRIPTION_HEADER =
"Find lints (non-adherence to coding standards and conventions) " + "in the database schema";

public LintCommandProvider() {
super(new PropertyName(LintCommand.COMMAND, DESCRIPTION_HEADER));
super(COMMAND);
}

@Override
public PluginCommand getCommandLineCommand() {
final PluginCommand pluginCommand =
newPluginCommand(
"lint",
"** " + DESCRIPTION_HEADER,
COMMAND,
() ->
new String[] {
"For more information, see https://www.schemacrawler.com/lint.html %n"
Expand Down Expand Up @@ -94,6 +90,10 @@ public PluginCommand getHelpCommand() {

@Override
public LintCommand newSchemaCrawlerCommand(final String command, final Config config) {
if (!supportsCommand(command)) {
throw new IllegalArgumentException("Cannot support command, " + command);
}

final LintOptions lintOptions = LintOptionsBuilder.builder().fromConfig(config).toOptions();
final LintCommand scCommand = new LintCommand();
scCommand.configure(lintOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import static java.util.Objects.requireNonNull;
import schemacrawler.schema.AttributedObject;
import schemacrawler.schema.NamedObject;
import schemacrawler.tools.executable.BaseCommand;
import schemacrawler.tools.lint.config.LinterConfig;
import schemacrawler.tools.options.Config;
import us.fatehi.utility.property.PropertyName;
Expand All @@ -44,19 +45,18 @@
* Evaluates a catalog and creates lints. This base class has core functionality for maintaining
* state, but not for visiting a catalog. Includes code for dispatching a linter.
*/
public abstract class AbstractLinter implements Linter {
public abstract class AbstractLinter extends BaseCommand<LinterConfig, Void> implements Linter {

private static final Logger LOGGER = Logger.getLogger(AbstractLinter.class.getName());

private final PropertyName linterName;
private final UUID linterInstanceId;
private final LintCollector lintCollector;
private LintSeverity severity;
private int threshold;
private int lintCount;

protected AbstractLinter(final PropertyName linterName, final LintCollector lintCollector) {
this.linterName = requireNonNull(linterName, "Linter name cannot be null");
super(requireNonNull(linterName, "Linter name not provided"));
linterInstanceId = UUID.randomUUID();
this.lintCollector = requireNonNull(lintCollector, "Lint collector cannot be null");

Expand All @@ -66,11 +66,10 @@ protected AbstractLinter(final PropertyName linterName, final LintCollector lint

@Override
public void configure(final LinterConfig linterConfig) {
if (linterConfig != null) {
setSeverity(linterConfig.getSeverity());
threshold = linterConfig.getThreshold();
configure(linterConfig.getConfig());
}
super.configure(linterConfig);
setSeverity(linterConfig.getSeverity());
threshold = linterConfig.getThreshold();
configure(linterConfig.getConfig());
}

/**
Expand All @@ -86,7 +85,7 @@ public final boolean exceedsThreshold() {
*/
@Override
public String getDescription() {
return linterName.getDescription();
return command.getDescription();
}

/**
Expand All @@ -102,7 +101,7 @@ public final int getLintCount() {
*/
@Override
public String getLinterId() {
return linterName.getName();
return command.getName();
}

/**
Expand All @@ -113,11 +112,6 @@ public final String getLinterInstanceId() {
return linterInstanceId.toString();
}

@Override
public final String getName() {
return getLinterId();
}

/**
* @{@inheritDoc}
*/
Expand Down
Loading
Loading