Skip to content

Commit

Permalink
feat(SMO relationship onboarding: Hack week): Add a getter method for…
Browse files Browse the repository at this point in the history
… mgEntityTypeNameSet (#495)

* getter method

* Merged the init and get method to expose one public method

* Merged the init and get method to expose one public method

---------

Co-authored-by: Rakhi Agrawal <[email protected]>
  • Loading branch information
rakhiagr and Rakhi Agrawal authored Jan 16, 2025
1 parent 88f1da9 commit 707986e
Showing 1 changed file with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,8 @@ protected boolean isMgEntityType(@Nonnull String entityType) {
// there's no concept of MG entity or non-entity in old schema mode. always return false.
return false;
}
// there is some race condition, the local relationship db might not be ready when EbeanLocalRelationshipQueryDAO inits.
// so we can't init the _mgEntityTypeNameSet in constructor.
if (_mgEntityTypeNameSet == null) {
initMgEntityTypeNameSet();
}

initMgEntityTypeNameSet();

return _mgEntityTypeNameSet.contains(StringUtils.lowerCase(entityType));
}
Expand Down Expand Up @@ -480,13 +477,20 @@ private String buildFindRelationshipSQL(
}

/**
* Creates a set of MG entity type names by querying the database.
* Creates and return a set of MG entity type names by querying the database.
*/
public void initMgEntityTypeNameSet() {
final String sql = "SELECT table_name FROM information_schema.tables"
+ " WHERE table_type = 'BASE TABLE' AND TABLE_SCHEMA=DATABASE() AND table_name LIKE 'metadata_entity_%'";
_mgEntityTypeNameSet = _server.createSqlQuery(sql).findList().stream()
.map(row -> row.getString("table_name").replace("metadata_entity_", ""))
.collect(Collectors.toSet());
public Set<String> initMgEntityTypeNameSet() {
// there is some race condition, the local relationship db might not be ready when EbeanLocalRelationshipQueryDAO inits.
// so we can't init the _mgEntityTypeNameSet in constructor.
if (_mgEntityTypeNameSet == null) {
final String sql = "SELECT table_name FROM information_schema.tables"
+ " WHERE table_type = 'BASE TABLE' AND TABLE_SCHEMA=DATABASE() AND table_name LIKE 'metadata_entity_%'";
_mgEntityTypeNameSet = _server.createSqlQuery(sql)
.findList()
.stream()
.map(row -> row.getString("table_name").replace("metadata_entity_", ""))
.collect(Collectors.toSet());
}
return _mgEntityTypeNameSet;
}
}

0 comments on commit 707986e

Please sign in to comment.