Skip to content

Commit

Permalink
Pipe hide options into the formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
sualeh committed Jul 14, 2023
1 parent e33acb9 commit be84cea
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
import static schemacrawler.tools.command.text.schema.options.HideDatabaseObjectNamesType.hideTableConstraintNames;
import static schemacrawler.tools.command.text.schema.options.HideDatabaseObjectNamesType.hideTriggerNames;
import static schemacrawler.tools.command.text.schema.options.HideDatabaseObjectNamesType.hideWeakAssociationNames;
import static schemacrawler.tools.command.text.schema.options.HideDatabaseObjectsType.hideRoutines;
import static schemacrawler.tools.command.text.schema.options.HideDatabaseObjectsType.hideSchemas;
import static schemacrawler.tools.command.text.schema.options.HideDatabaseObjectsType.hideSequences;
import static schemacrawler.tools.command.text.schema.options.HideDatabaseObjectsType.hideSynonyms;
import static schemacrawler.tools.command.text.schema.options.HideDatabaseObjectsType.hideTables;
import static schemacrawler.tools.command.text.schema.options.HideDependantDatabaseObjectsType.hideAlternateKeys;
import static schemacrawler.tools.command.text.schema.options.HideDependantDatabaseObjectsType.hideForeignKeys;
import static schemacrawler.tools.command.text.schema.options.HideDependantDatabaseObjectsType.hideIndexes;
Expand Down Expand Up @@ -74,10 +79,12 @@ public abstract class BaseSchemaTextOptionsBuilder<
protected boolean isShowOrdinalNumbers;
protected boolean isShowStandardColumnTypeNames;
protected boolean isHideTableRowCounts;
protected final Map<HideDatabaseObjectsType, Boolean> hideDatabaseObjects;
protected final Map<HideDependantDatabaseObjectsType, Boolean> hideDependantDatabaseObjects;
protected final Map<HideDatabaseObjectNamesType, Boolean> hideNames;

public BaseSchemaTextOptionsBuilder() {
hideDatabaseObjects = new EnumMap<>(HideDatabaseObjectsType.class);
hideDependantDatabaseObjects = new EnumMap<>(HideDependantDatabaseObjectsType.class);
hideNames = new EnumMap<>(HideDatabaseObjectNamesType.class);
}
Expand All @@ -99,6 +106,10 @@ public B fromConfig(final Config config) {
config.getBooleanValue(SC_SORT_ALPHABETICALLY_TABLE_FOREIGNKEYS);
isAlphabeticalSortForIndexes = config.getBooleanValue(SC_SORT_ALPHABETICALLY_TABLE_INDEXES);

for (final HideDatabaseObjectsType databaseObjectsType : HideDatabaseObjectsType.values()) {
final boolean booleanValue = config.getBooleanValue(databaseObjectsType.getKey());
hideDatabaseObjects.put(databaseObjectsType, booleanValue);
}
for (final HideDependantDatabaseObjectsType databaseObjectsType :
HideDependantDatabaseObjectsType.values()) {
final boolean booleanValue = config.getBooleanValue(databaseObjectsType.getKey());
Expand Down Expand Up @@ -132,6 +143,9 @@ public B fromOptions(final O options) {
isAlphabeticalSortForForeignKeys = options.isAlphabeticalSortForForeignKeys();
isAlphabeticalSortForIndexes = options.isAlphabeticalSortForIndexes();

for (final HideDatabaseObjectsType databaseObjectsType : HideDatabaseObjectsType.values()) {
hideDatabaseObjects.put(databaseObjectsType, options.is(databaseObjectsType));
}
for (final HideDependantDatabaseObjectsType databaseObjectsType :
HideDependantDatabaseObjectsType.values()) {
hideDependantDatabaseObjects.put(databaseObjectsType, options.is(databaseObjectsType));
Expand Down Expand Up @@ -254,6 +268,15 @@ public final B noRoutineParameters(final boolean value) {
return (B) this;
}

public final B noRoutines() {
return noRoutines(true);
}

public final B noRoutines(final boolean value) {
hideDatabaseObjects.put(hideRoutines, value);
return (B) this;
}

public final B noRoutineSpecificNames() {
return noRoutineSpecificNames(true);
}
Expand All @@ -263,6 +286,33 @@ public final B noRoutineSpecificNames(final boolean value) {
return (B) this;
}

public final B noSchemas() {
return noSchemas(true);
}

public final B noSchemas(final boolean value) {
hideDatabaseObjects.put(hideSchemas, value);
return (B) this;
}

public final B noSequences() {
return noSequences(true);
}

public final B noSequences(final boolean value) {
hideDatabaseObjects.put(hideSequences, value);
return (B) this;
}

public final B noSynonyms() {
return noSynonyms(true);
}

public final B noSynonyms(final boolean value) {
hideDatabaseObjects.put(hideSynonyms, value);
return (B) this;
}

public final B noTableColumns() {
return noTableColumns(true);
}
Expand All @@ -281,6 +331,15 @@ public final B noTableConstraints(final boolean value) {
return (B) this;
}

public final B noTables() {
return noTables(true);
}

public final B noTables(final boolean value) {
hideDatabaseObjects.put(hideTables, value);
return (B) this;
}

public final B noTriggerNames() {
return noTriggerNames(true);
}
Expand Down Expand Up @@ -383,6 +442,11 @@ public Config toConfig() {
config.put(SC_SORT_ALPHABETICALLY_TABLE_FOREIGNKEYS, isAlphabeticalSortForForeignKeys);
config.put(SC_SORT_ALPHABETICALLY_TABLE_INDEXES, isAlphabeticalSortForIndexes);

for (final HideDatabaseObjectsType databaseObjectsType : HideDatabaseObjectsType.values()) {
config.put(
databaseObjectsType.getKey(),
hideDatabaseObjects.getOrDefault(databaseObjectsType, false));
}
for (final HideDependantDatabaseObjectsType databaseObjectsType :
HideDependantDatabaseObjectsType.values()) {
config.put(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public class SchemaTextOptions extends BaseTextOptions {
private final boolean isShowOrdinalNumbers;
private final boolean isShowStandardColumnTypeNames;
private final boolean isHideTableRowCounts;
private final Map<HideDependantDatabaseObjectsType, Boolean> hideDatabaseObjects;
private final Map<HideDatabaseObjectsType, Boolean> hideDatabaseObjects;
private final Map<HideDependantDatabaseObjectsType, Boolean> hideDependantDatabaseObjects;
private final Map<HideDatabaseObjectNamesType, Boolean> hideNames;

protected SchemaTextOptions(
Expand All @@ -54,10 +55,16 @@ protected SchemaTextOptions(
isShowStandardColumnTypeNames = builder.isShowStandardColumnTypeNames;
isHideTableRowCounts = builder.isHideTableRowCounts;

hideDatabaseObjects = new EnumMap<>(HideDependantDatabaseObjectsType.class);
hideDatabaseObjects = new EnumMap<>(HideDatabaseObjectsType.class);
for (final HideDatabaseObjectsType databaseObjectsType : HideDatabaseObjectsType.values()) {
hideDatabaseObjects.put(
databaseObjectsType,
builder.hideDatabaseObjects.getOrDefault(databaseObjectsType, false));
}
hideDependantDatabaseObjects = new EnumMap<>(HideDependantDatabaseObjectsType.class);
for (final HideDependantDatabaseObjectsType databaseObjectsType :
HideDependantDatabaseObjectsType.values()) {
hideDatabaseObjects.put(
hideDependantDatabaseObjects.put(
databaseObjectsType,
builder.hideDependantDatabaseObjects.getOrDefault(databaseObjectsType, false));
}
Expand All @@ -73,10 +80,14 @@ public boolean is(final HideDatabaseObjectNamesType key) {
return hideNames.getOrDefault(key, false);
}

public boolean is(final HideDependantDatabaseObjectsType key) {
public boolean is(final HideDatabaseObjectsType key) {
return hideDatabaseObjects.getOrDefault(key, false);
}

public boolean is(final HideDependantDatabaseObjectsType key) {
return hideDependantDatabaseObjects.getOrDefault(key, false);
}

public boolean isAlphabeticalSortForForeignKeys() {
return isAlphabeticalSortForForeignKeys;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@

package schemacrawler.tools.text.formatter.schema;

import static schemacrawler.tools.command.text.schema.options.HideDatabaseObjectsType.hideRoutines;
import static schemacrawler.tools.command.text.schema.options.HideDatabaseObjectsType.hideSequences;
import static schemacrawler.tools.command.text.schema.options.HideDatabaseObjectsType.hideSynonyms;
import static schemacrawler.tools.command.text.schema.options.HideDatabaseObjectsType.hideTables;
import static us.fatehi.utility.Utility.isBlank;

import schemacrawler.schema.ColumnDataType;
import schemacrawler.schema.CrawlInfo;
import schemacrawler.schema.DatabaseInfo;
Expand All @@ -40,6 +43,7 @@
import schemacrawler.schema.Synonym;
import schemacrawler.schema.Table;
import schemacrawler.schemacrawler.Identifiers;
import schemacrawler.tools.command.text.schema.options.HideDatabaseObjectsType;
import schemacrawler.tools.command.text.schema.options.SchemaTextDetailType;
import schemacrawler.tools.command.text.schema.options.SchemaTextOptions;
import schemacrawler.tools.options.OutputOptions;
Expand Down Expand Up @@ -140,6 +144,10 @@ public void handle(final JdbcDriverInfo driverInfo) {
/** {@inheritDoc} */
@Override
public void handle(final Routine routine) {
if (routine == null || options.is(hideRoutines)) {
return;
}

final String routineTypeDetail =
String.format("%s, %s", routine.getRoutineType(), routine.getReturnType());
final String routineName = quoteName(routine);
Expand All @@ -152,6 +160,10 @@ public void handle(final Routine routine) {
/** {@inheritDoc} */
@Override
public void handle(final Sequence sequence) {
if (sequence == null || options.is(hideSequences)) {
return;
}

final String sequenceName = quoteName(sequence);
final String sequenceType = "[sequence]";

Expand All @@ -162,6 +174,10 @@ public void handle(final Sequence sequence) {
/** {@inheritDoc} */
@Override
public void handle(final Synonym synonym) {
if (synonym == null || options.is(hideSynonyms)) {
return;
}

final String synonymName = quoteName(synonym);
final String synonymType = "[synonym]";

Expand All @@ -171,6 +187,10 @@ public void handle(final Synonym synonym) {

@Override
public void handle(final Table table) {
if (options.is(hideTables)) {
return;
}

final String tableName = quoteName(table);
final String tableType = "[" + table.getTableType() + "]";

Expand Down Expand Up @@ -213,12 +233,20 @@ public void handleInfoStart() {
/** {@inheritDoc} */
@Override
public void handleRoutinesEnd() {
if (options.is(hideRoutines)) {
return;
}

formattingHelper.writeObjectEnd();
}

/** {@inheritDoc} */
@Override
public void handleRoutinesStart() {
if (options.is(hideRoutines)) {
return;
}

formattingHelper.writeHeader(DocumentHeaderType.subTitle, "Routines");

formattingHelper.writeObjectStart();
Expand All @@ -227,12 +255,20 @@ public void handleRoutinesStart() {
/** {@inheritDoc} */
@Override
public void handleSequencesEnd() {
if (options.is(hideSequences)) {
return;
}

formattingHelper.writeObjectEnd();
}

/** {@inheritDoc} */
@Override
public void handleSequencesStart() {
if (options.is(hideSequences)) {
return;
}

formattingHelper.writeHeader(DocumentHeaderType.subTitle, "Sequences");

formattingHelper.writeObjectStart();
Expand All @@ -241,12 +277,20 @@ public void handleSequencesStart() {
/** {@inheritDoc} */
@Override
public void handleSynonymsEnd() {
if (options.is(hideSynonyms)) {
return;
}

formattingHelper.writeObjectEnd();
}

/** {@inheritDoc} */
@Override
public void handleSynonymsStart() {
if (options.is(HideDatabaseObjectsType.hideSynonyms)) {
return;
}

formattingHelper.writeHeader(DocumentHeaderType.subTitle, "Synonyms");

formattingHelper.writeObjectStart();
Expand All @@ -255,12 +299,20 @@ public void handleSynonymsStart() {
/** {@inheritDoc} */
@Override
public void handleTablesEnd() {
if (options.is(hideTables)) {
return;
}

formattingHelper.writeObjectEnd();
}

/** {@inheritDoc} */
@Override
public void handleTablesStart() {
if (options.is(hideTables)) {
return;
}

formattingHelper.writeHeader(DocumentHeaderType.subTitle, "Tables");

formattingHelper.writeObjectStart();
Expand Down
Loading

0 comments on commit be84cea

Please sign in to comment.