Skip to content

Commit 77a3152

Browse files
refactor: add braces
1 parent 3a31296 commit 77a3152

32 files changed

+232
-133
lines changed

src/main/java/org/schemaspy/DbAnalyzer.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ public static List<Table> getTablesWithoutIndexes(Collection<Table> tables) {
115115
List<Table> withoutIndexes = new ArrayList<>();
116116

117117
for (Table table : tables) {
118-
if (table.getIndexes().isEmpty() && !table.isView() && !table.isLogical())
118+
if (table.getIndexes().isEmpty() && !table.isView() && !table.isLogical()) {
119119
withoutIndexes.add(table);
120+
}
120121
}
121122

122123
return sortTablesByName(withoutIndexes);
@@ -175,8 +176,9 @@ public static List<Table> getTablesWithOneColumn(Collection<Table> tables) {
175176
List<Table> singleColumnTables = new ArrayList<>();
176177

177178
for (Table table : tables) {
178-
if (table.getColumns().size() == 1)
179+
if (table.getColumns().size() == 1) {
179180
singleColumnTables.add(table);
181+
}
180182
}
181183

182184
return sortTablesByName(singleColumnTables);
@@ -191,8 +193,9 @@ public static List<Table> sortTablesByName(List<Table> tables) {
191193
public static List<TableColumn> sortColumnsByTable(List<TableColumn> columns) {
192194
columns.sort((column1, column2) -> {
193195
int rc = column1.getTable().compareTo(column2.getTable());
194-
if (rc == 0)
196+
if (rc == 0) {
195197
rc = column1.getName().compareToIgnoreCase(column2.getName());
198+
}
196199
return rc;
197200
});
198201

src/main/java/org/schemaspy/InsertionOrdered.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,12 @@ public int compare(Table table1, Table table2) {
204204
// have to keep track of and use the 'max' versions because
205205
// by the time we get here we'll (probably?) have no parents or children
206206
int rc = table2.getMaxChildren() - table1.getMaxChildren();
207-
if (rc == 0)
207+
if (rc == 0) {
208208
rc = table1.getMaxParents() - table2.getMaxParents();
209-
if (rc == 0)
209+
}
210+
if (rc == 0) {
210211
rc = table1.compareTo(table2);
212+
}
211213
return rc;
212214
}
213215
}
@@ -234,9 +236,10 @@ private void removeAForeignKeyConstraint(List<Table> remainingTables) {
234236
// target the tables with the biggest delta and therefore the most impact
235237
// on reducing the smaller of the two
236238
int rc = Math.abs(t2.getNumChildren() - t2.getNumParents()) - Math.abs(t1.getNumChildren() - t1.getNumParents());
237-
if (rc == 0)
239+
if (rc == 0) {
238240
rc = t1.compareTo(t2);
241+
}
239242
return rc;
240243
}).ifPresent(Table::removeAForeignKeyConstraint); // this one has the largest delta
241244
}
242-
}
245+
}

src/main/java/org/schemaspy/analyzer/ImpliedConstraintsFinder.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ private boolean noParent(TableColumn column) {
7878

7979
private Comparator<TableColumn> byTable = (column1, column2) -> {
8080
int rc = column1.getTable().compareTo(column2.getTable());
81-
if (rc == 0)
81+
if (rc == 0) {
8282
rc = column1.getName().compareToIgnoreCase(column2.getName());
83+
}
8384
return rc;
8485
};
8586

src/main/java/org/schemaspy/cli/SchemasListConverter.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ public class SchemasListConverter implements IStringConverter<Set<String>> {
1111
public Set<String> convert(String value) {
1212
Set<String> schemas = new HashSet<>();
1313
for (String name : value.split(",")) {
14-
if (name.length() > 0)
14+
if (name.length() > 0) {
1515
schemas.add(name);
16+
}
1617
}
1718
return schemas;
1819
}

src/main/java/org/schemaspy/input/dbms/ConnectionURLBuilder.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ private String getParam(List<String> args, DbSpecificOption option) {
8383
if ("hostOptionalPort".equals(option.getName())) {
8484
param = getHostOptionalPort();
8585
}
86-
if (param == null)
86+
if (param == null) {
8787
throw new MissingParameterException(option.getName(), option.getDescription());
88+
}
8889
} else {
8990
args.remove(paramIndex);
9091
param = args.get(paramIndex);

src/main/java/org/schemaspy/input/dbms/service/ColumnService.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ public void gatherColumns(Table table) throws SQLException {
5656
private void initColumns(Table table) throws SQLException {
5757
synchronized (Table.class) {
5858
try (ResultSet rs = sqlService.getDatabaseMetaData().getColumns(table.getCatalog(), table.getSchema(), table.getName(), "%")) {
59-
while (rs.next())
59+
while (rs.next()) {
6060
addColumn(table, rs);
61+
}
6162
} catch (SQLException exc) {
6263
if (!table.isLogical()) {
6364
throw new ColumnInitializationFailure(table, exc);
@@ -73,8 +74,9 @@ private void initColumns(Table table) throws SQLException {
7374
private void addColumn(Table table, ResultSet rs) throws SQLException {
7475
String columnName = rs.getString("COLUMN_NAME");
7576

76-
if (columnName == null)
77+
if (columnName == null) {
7778
return;
79+
}
7880

7981
if (table.getColumn(columnName) == null) {
8082
TableColumn column = initColumn(table, rs);
@@ -95,10 +97,11 @@ private TableColumn initColumn(Table table, ResultSet rs) throws SQLException {
9597

9698
column.setDecimalDigits(rs.getInt("DECIMAL_DIGITS"));
9799
Number bufLength = (Number)rs.getObject("BUFFER_LENGTH");
98-
if (bufLength != null && bufLength.shortValue() > 0)
100+
if (bufLength != null && bufLength.shortValue() > 0) {
99101
column.setLength(bufLength.shortValue());
100-
else
102+
} else {
101103
column.setLength(rs.getInt("COLUMN_SIZE"));
104+
}
102105

103106
StringBuilder buf = new StringBuilder();
104107
buf.append(column.getLength());

src/main/java/org/schemaspy/input/dbms/service/DatabaseService.java

+14-8
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ public void gatherSchemaDetails(Database db, SchemaMeta schemaMeta, ProgressList
114114
DatabaseMetaData meta = sqlService.getDatabaseMetaData();
115115

116116
initTables(db, listener, meta);
117-
if (viewsEnabled)
117+
if (viewsEnabled) {
118118
initViews(db, listener, meta);
119-
119+
}
120+
120121
initCatalogs(db);
121122
initSchemas(db);
122123

@@ -139,7 +140,7 @@ public void gatherSchemaDetails(Database db, SchemaMeta schemaMeta, ProgressList
139140

140141
listener.finishedConnectingTablesViews();
141142
}
142-
143+
143144
private void initCatalogs(Database db) throws SQLException {
144145

145146
String sql = dbProperties.getProperty("selectCatalogsSql");
@@ -250,8 +251,9 @@ private String[] getTypes(String propName, String defaultValue) {
250251
List<String> types = new ArrayList<>();
251252
for (String type : value.split(",")) {
252253
type = type.trim();
253-
if (type.length() > 0)
254+
if (type.length() > 0) {
254255
types.add(type);
256+
}
255257
}
256258

257259
return types.toArray(new String[types.size()]);
@@ -439,8 +441,9 @@ public void join() {
439441

440442
synchronized (threads) {
441443
Iterator<Thread> iter = threads.iterator();
442-
if (!iter.hasNext())
444+
if (!iter.hasNext()) {
443445
break;
446+
}
444447

445448
thread = iter.next();
446449
}
@@ -498,8 +501,9 @@ private static BasicTableMeta basicTableMetaFromResultSetRow(ResultSet rs, boole
498501
String name = rs.getString(clazz + "_name");
499502
String cat = getOptionalString(rs, clazz + "_catalog");
500503
String sch = getOptionalString(rs, clazz + "_schema");
501-
if (cat == null && sch == null)
504+
if (cat == null && sch == null) {
502505
sch = schemaName;
506+
}
503507
String remarks = getOptionalString(rs, clazz + "_comment");
504508
String viewDefinition = forTables ? null : getOptionalString(rs, "view_definition");
505509
String rows = forTables ? getOptionalString(rs, "table_rows") : null;
@@ -521,8 +525,9 @@ private static void getBasicTableMetaFromDatabaseMetaData(List<BasicTableMeta> b
521525
basics.add(new BasicTableMeta(cat, schem, name, type, remarks, null, -1));
522526
}
523527
} catch (SQLException exc) {
524-
if (forTables)
528+
if (forTables) {
525529
throw exc;
530+
}
526531
LOGGER.warn("Ignoring view '{}' due to exception", lastTableName, exc);
527532
}
528533
}
@@ -603,8 +608,9 @@ private void initIndexIds(Database db) throws SQLException {
603608
Table table = db.getLocals().get(tableName);
604609
if (table != null) {
605610
TableIndex index = table.getIndex(rs.getString("index_name"));
606-
if (index != null)
611+
if (index != null) {
607612
index.setId(rs.getObject("index_id"));
613+
}
608614
}
609615
}
610616
} catch (SQLException sqlException) {

src/main/java/org/schemaspy/input/dbms/service/TableService.java

+16-9
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,9 @@ private void connectForeignKeysRemoteTable(Database db, RemoteTable remoteTable,
174174
} catch (SQLException sqlExc) {
175175
if (!remoteTable.isLogical()) {
176176
// if explicitly asking for these details then propagate the exception
177-
if (multiSchemas)
177+
if (multiSchemas) {
178178
throw sqlExc;
179+
}
179180

180181
// otherwise just report the fact that we tried & couldn't
181182
LOGGER.warn("Couldn't resolve foreign keys for remote table '{}'", remoteTable.getFullName(), sqlExc);
@@ -262,8 +263,9 @@ private boolean shouldExclude(String databaseName, ImportForeignKey foreignKey)
262263
* @return int
263264
*/
264265
protected long fetchNumRows(Database db, Table table) {
265-
if (table.isView() || table.isRemote())
266+
if (table.isView() || table.isRemote()) {
266267
return -1;
268+
}
267269

268270
SQLException originalFailure = null;
269271

@@ -289,8 +291,9 @@ protected long fetchNumRows(Database db, Table table) {
289291
return fetchNumRows(db, table, "count(1)", false);
290292
} catch (SQLException try3Exception) {
291293
if (!table.isLogical()) {
292-
if (originalFailure != null)
294+
if (originalFailure != null) {
293295
LOGGER.warn("Failed to fetch number of rows for '{}' using custom query: '{}'", table.getFullName(), sql, originalFailure);
296+
}
294297
LOGGER.warn("Failed to fetch number of rows for '{}' using built-in query with 'count(*)'", table.getFullName(), try2Exception);
295298
LOGGER.warn("Failed to fetch number of rows for '{}' using built-in query with 'count(1)'", table.getFullName(), try3Exception);
296299
}
@@ -330,8 +333,9 @@ protected long fetchNumRows(Database db, Table table, String clause, boolean for
330333
}
331334
return -1;
332335
} catch (SQLException exc) {
333-
if (forceQuotes) // we tried with and w/o quotes...fail this attempt
336+
if (forceQuotes) {// we tried with and w/o quotes...fail this attempt
334337
throw exc;
338+
}
335339

336340
return fetchNumRows(db, table, clause, true);
337341
}
@@ -355,9 +359,9 @@ private Table addRemoteTable(Database db, RemoteTableIdentifier remoteTableIdent
355359
if (remoteTable == null) {
356360
LOGGER.debug("Creating remote table {}", fullName);
357361

358-
if (logical)
362+
if (logical) {
359363
remoteTable = new LogicalRemoteTable(db, remoteTableIdentifier, baseContainer);
360-
else {
364+
} else {
361365
remoteTable = new RemoteTable(db, remoteTableIdentifier, baseContainer);
362366
columnService.gatherColumns(remoteTable);
363367
}
@@ -472,8 +476,9 @@ public void gatherTableIds(Database db) throws SQLException {
472476
while (rs.next()) {
473477
String tableName = rs.getString(TABLE_NAME);
474478
Table table = db.getLocals().get(tableName);
475-
if (table != null)
479+
if (table != null) {
476480
table.setId(rs.getObject("table_id"));
481+
}
477482
}
478483
} catch (SQLException sqlException) {
479484
LOGGER.warn("Failed to fetch table ids using SQL '{}'", sql, sqlException);
@@ -496,8 +501,9 @@ public void gatherTableComments(Database db) {
496501
while (rs.next()) {
497502
String tableName = rs.getString(TABLE_NAME);
498503
Table table = db.getLocals().get(tableName);
499-
if (table != null)
504+
if (table != null) {
500505
table.setComments(rs.getString("comments"));
506+
}
501507
}
502508
} catch (SQLException sqlException) {
503509
// don't die just because this failed
@@ -523,8 +529,9 @@ public void gatherTableColumnComments(Database db) {
523529
Table table = db.getLocals().get(tableName);
524530
if (table != null) {
525531
TableColumn column = table.getColumn(rs.getString(COLUMN_NAME));
526-
if (column != null)
532+
if (column != null) {
527533
column.setComments(rs.getString(COMMENTS));
534+
}
528535
}
529536
}
530537
} catch (SQLException sqlException) {

src/main/java/org/schemaspy/input/dbms/service/ViewService.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,14 @@ public void gatherViewComments(Database db) {
140140

141141
while (rs.next()) {
142142
String viewName = rs.getString(VIEW_NAME);
143-
if (viewName == null)
143+
if (viewName == null) {
144144
viewName = rs.getString(TABLE_NAME);
145+
}
145146
Table view = db.getViewsMap().get(viewName);
146147

147-
if (view != null)
148+
if (view != null) {
148149
view.setComments(rs.getString(COMMENTS));
150+
}
149151
}
150152
} catch (SQLException sqlException) {
151153
// don't die just because this failed
@@ -166,14 +168,16 @@ public void gatherViewColumnComments(Database db) {
166168

167169
while (rs.next()) {
168170
String viewName = rs.getString(VIEW_NAME);
169-
if (viewName == null)
171+
if (viewName == null) {
170172
viewName = rs.getString(TABLE_NAME);
173+
}
171174
Table view = db.getViewsMap().get(viewName);
172175

173176
if (view != null) {
174177
TableColumn column = view.getColumn(rs.getString(COLUMN_NAME));
175-
if (column != null)
178+
if (column != null) {
176179
column.setComments(rs.getString(COMMENTS));
180+
}
177181
}
178182
}
179183
} catch (SQLException sqlException) {

src/main/java/org/schemaspy/input/dbms/xml/ForeignKeyMeta.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ public class ForeignKeyMeta {
4545
public ForeignKeyMeta(Node foreignKeyNode) {
4646
NamedNodeMap attribs = foreignKeyNode.getAttributes();
4747
Node node = attribs.getNamedItem("table");
48-
if (node == null)
48+
if (node == null) {
4949
throw new IllegalStateException("XML foreignKey definition requires 'table' attribute");
50+
}
5051
tableName = node.getNodeValue();
5152
node = attribs.getNamedItem("column");
52-
if (node == null)
53+
if (node == null) {
5354
throw new IllegalStateException("XML foreignKey definition requires 'column' attribute");
55+
}
5456
columnName = node.getNodeValue();
5557
node = attribs.getNamedItem("remoteSchema");
5658
remoteSchema = node == null ? null : node.getNodeValue();
@@ -80,4 +82,4 @@ public String getRemoteSchema() {
8082
public String toString() {
8183
return tableName + '.' + columnName;
8284
}
83-
}
85+
}

src/main/java/org/schemaspy/input/dbms/xml/SchemaMeta.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,11 @@ public SchemaMeta(String xmlMeta, String dbName, String schema, boolean isMultiS
8989
Document doc = parse(metaFile);
9090

9191
NodeList commentsNodes = doc.getElementsByTagName("comments");
92-
if (commentsNodes != null && commentsNodes.getLength() > 0 && commentsNodes.item(0).hasChildNodes())
92+
if (commentsNodes != null && commentsNodes.getLength() > 0 && commentsNodes.item(0).hasChildNodes()) {
9393
comments = commentsNodes.item(0).getTextContent();
94-
else
94+
} else {
9595
comments = null;
96+
}
9697

9798
NodeList tablesNodes = doc.getElementsByTagName("tables");
9899
if (tablesNodes != null) {
@@ -174,4 +175,4 @@ private Document parse(File file) {
174175

175176
return doc;
176177
}
177-
}
178+
}

src/main/java/org/schemaspy/input/dbms/xml/TableColumnMeta.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ public TableColumnMeta(Node colNode) {
7373
}
7474

7575
private boolean evalBoolean(String exp) {
76-
if (exp == null)
76+
if (exp == null) {
7777
return false;
78+
}
7879

7980
String returnExp = exp.trim().toLowerCase();
8081
return "true".equals(returnExp) || "yes".equals(returnExp) || "1".equals(returnExp);

src/main/java/org/schemaspy/logging/StackTraceOmitter.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ public static boolean hasOmittedStackTrace() {
4747

4848
@Override
4949
public String convert(ILoggingEvent event) {
50-
if (SCHEMA_SPY_LOGGER.isDebugEnabled())
50+
if (SCHEMA_SPY_LOGGER.isDebugEnabled()) {
5151
return super.convert(event);
52+
}
5253
if (Objects.nonNull(event.getThrowableProxy())) {
5354
omittedStackTrace.set(true);
5455
return event.getThrowableProxy().getMessage() + CoreConstants.LINE_SEPARATOR;

0 commit comments

Comments
 (0)