From 707986e6f6917ed1b025472d46c9866b0bc39084 Mon Sep 17 00:00:00 2001 From: Rakhi Agrawal Date: Thu, 16 Jan 2025 00:05:11 -0800 Subject: [PATCH] feat(SMO relationship onboarding: Hack week): Add a getter method for 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 --- .../dao/EbeanLocalRelationshipQueryDAO.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/dao-impl/ebean-dao/src/main/java/com/linkedin/metadata/dao/EbeanLocalRelationshipQueryDAO.java b/dao-impl/ebean-dao/src/main/java/com/linkedin/metadata/dao/EbeanLocalRelationshipQueryDAO.java index 2f88d8449..0a0e5e1a8 100644 --- a/dao-impl/ebean-dao/src/main/java/com/linkedin/metadata/dao/EbeanLocalRelationshipQueryDAO.java +++ b/dao-impl/ebean-dao/src/main/java/com/linkedin/metadata/dao/EbeanLocalRelationshipQueryDAO.java @@ -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)); } @@ -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 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; } }