Skip to content

Commit b26809f

Browse files
committed
Refactor QualifiedName. Removed fields that were not thread-safe.
1 parent ee14eb3 commit b26809f

File tree

1 file changed

+47
-61
lines changed

1 file changed

+47
-61
lines changed

Diff for: metacat-common/src/main/java/com/netflix/metacat/common/QualifiedName.java

+47-61
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ public final class QualifiedName implements Serializable {
4545
private final String partitionName;
4646
private final String tableName;
4747
private final String viewName;
48-
private String qualifiedName;
49-
private Map<String, String> qualifiedNameMap;
50-
private Map<String, String> parts;
51-
private Type type;
48+
private final Type type;
5249

5350
private QualifiedName(
5451
@NonNull final String catalogName,
@@ -471,31 +468,27 @@ private static String standardizeRequired(final String name, @Nullable final Str
471468
*/
472469
@JsonValue
473470
public Map<String, String> toJson() {
474-
if (qualifiedNameMap == null) {
475-
final Map<String, String> map = new HashMap<>(5);
476-
map.put("qualifiedName", toString());
477-
map.put("catalogName", catalogName);
471+
final Map<String, String> map = new HashMap<>(5);
472+
map.put("qualifiedName", toString());
473+
map.put("catalogName", catalogName);
478474

479-
if (!databaseName.isEmpty()) {
480-
map.put("databaseName", databaseName);
481-
}
482-
483-
if (!tableName.isEmpty()) {
484-
map.put("tableName", tableName);
485-
}
475+
if (!databaseName.isEmpty()) {
476+
map.put("databaseName", databaseName);
477+
}
486478

487-
if (!partitionName.isEmpty()) {
488-
map.put("partitionName", partitionName);
489-
}
479+
if (!tableName.isEmpty()) {
480+
map.put("tableName", tableName);
481+
}
490482

491-
if (!viewName.isEmpty()) {
492-
map.put("viewName", viewName);
493-
}
483+
if (!partitionName.isEmpty()) {
484+
map.put("partitionName", partitionName);
485+
}
494486

495-
qualifiedNameMap = map;
487+
if (!viewName.isEmpty()) {
488+
map.put("viewName", viewName);
496489
}
497490

498-
return qualifiedNameMap;
491+
return map;
499492
}
500493

501494
/**
@@ -504,30 +497,26 @@ public Map<String, String> toJson() {
504497
* @return parts of the qualified name as a Map
505498
*/
506499
public Map<String, String> parts() {
507-
if (parts == null) {
508-
final Map<String, String> map = new HashMap<>(4);
509-
map.put("catalogName", catalogName);
510-
511-
if (!databaseName.isEmpty()) {
512-
map.put("databaseName", databaseName);
513-
}
500+
final Map<String, String> map = new HashMap<>(5);
501+
map.put("catalogName", catalogName);
514502

515-
if (!tableName.isEmpty()) {
516-
map.put("tableName", tableName);
517-
}
503+
if (!databaseName.isEmpty()) {
504+
map.put("databaseName", databaseName);
505+
}
518506

519-
if (!partitionName.isEmpty()) {
520-
map.put("partitionName", partitionName);
521-
}
507+
if (!tableName.isEmpty()) {
508+
map.put("tableName", tableName);
509+
}
522510

523-
if (!viewName.isEmpty()) {
524-
map.put("viewName", viewName);
525-
}
511+
if (!partitionName.isEmpty()) {
512+
map.put("partitionName", partitionName);
513+
}
526514

527-
parts = map;
515+
if (!viewName.isEmpty()) {
516+
map.put("viewName", viewName);
528517
}
529518

530-
return parts;
519+
return map;
531520
}
532521

533522
public boolean isViewDefinition() {
@@ -568,32 +557,29 @@ public int hashCode() {
568557
*/
569558
@Override
570559
public String toString() {
571-
if (qualifiedName == null) {
572-
final StringBuilder sb = new StringBuilder(catalogName);
560+
final StringBuilder sb = new StringBuilder(catalogName);
573561

574-
if (!databaseName.isEmpty()) {
575-
sb.append('/');
576-
sb.append(databaseName);
577-
}
562+
if (!databaseName.isEmpty()) {
563+
sb.append('/');
564+
sb.append(databaseName);
565+
}
578566

579-
if (!tableName.isEmpty()) {
580-
sb.append('/');
581-
sb.append(tableName);
582-
}
567+
if (!tableName.isEmpty()) {
568+
sb.append('/');
569+
sb.append(tableName);
570+
}
583571

584-
if (!partitionName.isEmpty()) {
585-
sb.append('/');
586-
sb.append(partitionName);
587-
}
572+
if (!partitionName.isEmpty()) {
573+
sb.append('/');
574+
sb.append(partitionName);
575+
}
588576

589-
if (!viewName.isEmpty()) {
590-
sb.append('/');
591-
sb.append(viewName);
592-
}
593-
qualifiedName = sb.toString();
577+
if (!viewName.isEmpty()) {
578+
sb.append('/');
579+
sb.append(viewName);
594580
}
595581

596-
return qualifiedName;
582+
return sb.toString();
597583
}
598584

599585

0 commit comments

Comments
 (0)