mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2026-01-07 04:56:54 +00:00
Simplify EntityRepository store method (#8690)
This commit is contained in:
parent
9bd0dbb67d
commit
1db6f1c8a0
@ -47,7 +47,7 @@ public class BotRepository extends EntityRepository<Bot> {
|
||||
public void storeEntity(Bot entity, boolean update) throws IOException {
|
||||
EntityReference botUser = entity.getBotUser();
|
||||
entity.withBotUser(null);
|
||||
store(entity.getId(), entity, update);
|
||||
store(entity, update);
|
||||
entity.withBotUser(botUser);
|
||||
}
|
||||
|
||||
|
||||
@ -71,7 +71,7 @@ public class ChartRepository extends EntityRepository<Chart> {
|
||||
// Don't store owner, database, href and tags as JSON. Build it on the fly based on relationships
|
||||
chart.withOwner(null).withService(null).withHref(null).withTags(null);
|
||||
|
||||
store(chart.getId(), chart, update);
|
||||
store(chart, update);
|
||||
|
||||
// Restore the relationships
|
||||
chart.withOwner(owner).withService(service).withTags(tags);
|
||||
|
||||
@ -117,7 +117,7 @@ public class DashboardRepository extends EntityRepository<Dashboard> {
|
||||
// Don't store owner, database, href and tags as JSON. Build it on the fly based on relationships
|
||||
dashboard.withOwner(null).withHref(null).withTags(null).withService(null);
|
||||
|
||||
store(dashboard.getId(), dashboard, update);
|
||||
store(dashboard, update);
|
||||
|
||||
// Restore the relationships
|
||||
dashboard.withOwner(owner).withTags(tags).withService(service);
|
||||
|
||||
@ -101,7 +101,7 @@ public class DataInsightChartRepository extends EntityRepository<DataInsightChar
|
||||
EntityReference owner = entity.getOwner();
|
||||
// Don't store owner, database, href and tags as JSON. Build it on the fly based on relationships
|
||||
entity.withOwner(null).withHref(null);
|
||||
store(entity.getId(), entity, update);
|
||||
store(entity, update);
|
||||
// Restore the relationships
|
||||
entity.withOwner(owner);
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ public class DatabaseRepository extends EntityRepository<Database> {
|
||||
// Don't store owner, database, href and tags as JSON. Build it on the fly based on relationships
|
||||
database.withOwner(null).withService(null).withHref(null);
|
||||
|
||||
store(database.getId(), database, update);
|
||||
store(database, update);
|
||||
|
||||
// Restore the relationships
|
||||
database.withOwner(owner).withService(service);
|
||||
|
||||
@ -30,7 +30,6 @@ import org.openmetadata.service.resources.databases.DatabaseSchemaResource;
|
||||
import org.openmetadata.service.util.EntityUtil;
|
||||
import org.openmetadata.service.util.EntityUtil.Fields;
|
||||
import org.openmetadata.service.util.FullyQualifiedName;
|
||||
import org.openmetadata.service.util.JsonUtils;
|
||||
|
||||
public class DatabaseSchemaRepository extends EntityRepository<DatabaseSchema> {
|
||||
private static final String DATABASE_SCHEMA_UPDATE_FIELDS = "owner";
|
||||
@ -68,12 +67,7 @@ public class DatabaseSchemaRepository extends EntityRepository<DatabaseSchema> {
|
||||
// Don't store owner, database, href and tags as JSON. Build it on the fly based on relationships
|
||||
schema.withOwner(null).withService(null).withHref(null);
|
||||
|
||||
if (update) {
|
||||
daoCollection.databaseSchemaDAO().update(schema.getId(), JsonUtils.pojoToJson(schema));
|
||||
} else {
|
||||
daoCollection.databaseSchemaDAO().insert(schema);
|
||||
}
|
||||
|
||||
store(schema, update);
|
||||
// Restore the relationships
|
||||
schema.withOwner(owner).withService(service);
|
||||
}
|
||||
|
||||
@ -716,9 +716,9 @@ public abstract class EntityRepository<T extends EntityInterface> {
|
||||
return entity;
|
||||
}
|
||||
|
||||
protected void store(UUID id, T entity, boolean update) throws JsonProcessingException {
|
||||
protected void store(T entity, boolean update) throws JsonProcessingException {
|
||||
if (update) {
|
||||
dao.update(id, JsonUtils.pojoToJson(entity));
|
||||
dao.update(entity.getId(), JsonUtils.pojoToJson(entity));
|
||||
} else {
|
||||
dao.insert(entity);
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ public class GlossaryRepository extends EntityRepository<Glossary> {
|
||||
// Don't store owner, href and tags as JSON. Build it on the fly based on relationships
|
||||
glossary.withOwner(null).withHref(null).withTags(null);
|
||||
|
||||
store(glossary.getId(), glossary, update);
|
||||
store(glossary, update);
|
||||
|
||||
// Restore the relationships
|
||||
glossary.withOwner(owner).withTags(tags).withReviewers(reviewers);
|
||||
|
||||
@ -133,7 +133,7 @@ public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
|
||||
.withHref(null)
|
||||
.withTags(null);
|
||||
|
||||
store(entity.getId(), entity, update);
|
||||
store(entity, update);
|
||||
|
||||
// Restore the relationships
|
||||
entity
|
||||
|
||||
@ -91,7 +91,7 @@ public class IngestionPipelineRepository extends EntityRepository<IngestionPipel
|
||||
// Don't store owner. Build it on the fly based on relationships
|
||||
ingestionPipeline.withOwner(null).withService(null).withHref(null);
|
||||
|
||||
store(ingestionPipeline.getId(), ingestionPipeline, update);
|
||||
store(ingestionPipeline, update);
|
||||
|
||||
// Restore the relationships
|
||||
ingestionPipeline.withOwner(owner).withService(service);
|
||||
|
||||
@ -89,7 +89,7 @@ public class KpiRepository extends EntityRepository<Kpi> {
|
||||
|
||||
// Don't store owner, database, href and tags as JSON. Build it on the fly based on relationships
|
||||
kpi.withOwner(null).withHref(null).withDataInsightChart(null);
|
||||
store(kpi.getId(), kpi, update);
|
||||
store(kpi, update);
|
||||
|
||||
// Restore the relationships
|
||||
kpi.withOwner(owner).withDataInsightChart(dataInsightChart);
|
||||
|
||||
@ -175,7 +175,7 @@ public class LocationRepository extends EntityRepository<Location> {
|
||||
// Don't store owner, href and tags as JSON. Build it on the fly based on relationships
|
||||
location.withOwner(null).withService(null).withHref(null).withTags(null);
|
||||
|
||||
store(location.getId(), location, update);
|
||||
store(location, update);
|
||||
|
||||
// Restore the relationships
|
||||
location.withOwner(owner).withService(service).withTags(tags);
|
||||
|
||||
@ -74,7 +74,7 @@ public class MetricsRepository extends EntityRepository<Metrics> {
|
||||
// Don't store owner, database, href and tags as JSON. Build it on the fly based on relationships
|
||||
metrics.withOwner(null).withService(null).withHref(null).withTags(null);
|
||||
|
||||
store(metrics.getId(), metrics, update);
|
||||
store(metrics, update);
|
||||
|
||||
// Restore the relationships
|
||||
metrics.withOwner(owner).withService(service).withTags(tags);
|
||||
|
||||
@ -153,7 +153,7 @@ public class MlModelRepository extends EntityRepository<MlModel> {
|
||||
// Don't store owner, dashboard, href and tags as JSON. Build it on the fly based on relationships
|
||||
mlModel.withService(null).withOwner(null).withDashboard(null).withHref(null).withTags(null);
|
||||
|
||||
store(mlModel.getId(), mlModel, update);
|
||||
store(mlModel, update);
|
||||
|
||||
// Restore the relationships
|
||||
mlModel.withService(service).withOwner(owner).withDashboard(dashboard).withTags(tags);
|
||||
|
||||
@ -190,7 +190,7 @@ public class PipelineRepository extends EntityRepository<Pipeline> {
|
||||
// Don't store owner, database, href and tags as JSON. Build it on the fly based on relationships
|
||||
pipeline.withOwner(null).withService(null).withHref(null).withTags(null);
|
||||
|
||||
store(pipeline.getId(), pipeline, update);
|
||||
store(pipeline, update);
|
||||
|
||||
// Restore the relationships
|
||||
pipeline.withOwner(owner).withService(service).withTags(tags);
|
||||
|
||||
@ -121,7 +121,7 @@ public class PolicyRepository extends EntityRepository<Policy> {
|
||||
// Don't store owner, location and href as JSON. Build it on the fly based on relationships
|
||||
policy.withOwner(null).withLocation(null).withHref(null);
|
||||
|
||||
store(policy.getId(), policy, update);
|
||||
store(policy, update);
|
||||
|
||||
// Restore the relationships
|
||||
policy.withOwner(owner).withLocation(location).withHref(href);
|
||||
|
||||
@ -51,7 +51,7 @@ public class ReportRepository extends EntityRepository<Report> {
|
||||
@Override
|
||||
public void storeEntity(Report report, boolean update) throws IOException {
|
||||
report.setHref(null);
|
||||
store(report.getId(), report, update);
|
||||
store(report, update);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -95,7 +95,7 @@ public class RoleRepository extends EntityRepository<Role> {
|
||||
// Don't store policy and href as JSON. Build it on the fly based on relationships
|
||||
List<EntityReference> policies = role.getPolicies();
|
||||
role.withPolicies(null).withHref(null);
|
||||
store(role.getId(), role, update);
|
||||
store(role, update);
|
||||
role.withPolicies(policies); // Restore policies
|
||||
}
|
||||
|
||||
|
||||
@ -89,7 +89,7 @@ public abstract class ServiceEntityRepository<
|
||||
serviceType,
|
||||
true));
|
||||
|
||||
store(service.getId(), service, update);
|
||||
store(service, update);
|
||||
|
||||
// Restore the relationships
|
||||
service.withOwner(owner);
|
||||
|
||||
@ -55,7 +55,7 @@ public class StorageServiceRepository extends EntityRepository<StorageService> {
|
||||
// Don't store owner, database, href and tags as JSON. Build it on the fly based on relationships
|
||||
service.withOwner(null).withHref(null);
|
||||
|
||||
store(service.getId(), service, update);
|
||||
store(service, update);
|
||||
|
||||
// Restore the relationships
|
||||
service.withOwner(owner);
|
||||
|
||||
@ -571,7 +571,7 @@ public class TableRepository extends EntityRepository<Table> {
|
||||
table.setColumns(cloneWithoutTags(columnWithTags));
|
||||
table.getColumns().forEach(column -> column.setTags(null));
|
||||
|
||||
store(table.getId(), table, update);
|
||||
store(table, update);
|
||||
|
||||
// Restore the relationships
|
||||
table.withOwner(owner).withTags(tags).withColumns(columnWithTags).withService(service);
|
||||
|
||||
@ -95,7 +95,7 @@ public class TagCategoryRepository extends EntityRepository<TagCategory> {
|
||||
public void storeEntity(TagCategory category, boolean update) throws IOException {
|
||||
List<Tag> primaryTags = category.getChildren();
|
||||
category.setChildren(null); // Children are not stored as json and are constructed on the fly
|
||||
store(category.getId(), category, update);
|
||||
store(category, update);
|
||||
category.withChildren(primaryTags);
|
||||
}
|
||||
|
||||
|
||||
@ -54,7 +54,7 @@ public class TagRepository extends EntityRepository<Tag> {
|
||||
String oldFQN = tag.getFullyQualifiedName();
|
||||
String newFQN = oldFQN.replace(prefix, newPrefix);
|
||||
LOG.info("Replacing tag fqn from {} to {}", oldFQN, newFQN);
|
||||
tag.setFullyQualifiedName(oldFQN.replace(prefix, newPrefix));
|
||||
tag.setFullyQualifiedName(newFQN);
|
||||
daoCollection.tagDAO().update(tag.getId(), JsonUtils.pojoToJson(tag));
|
||||
updateChildrenTagNames(oldFQN, newFQN);
|
||||
}
|
||||
@ -89,7 +89,7 @@ public class TagRepository extends EntityRepository<Tag> {
|
||||
public void storeEntity(Tag tag, boolean update) throws IOException {
|
||||
List<Tag> tags = tag.getChildren();
|
||||
tag.setChildren(null); // Children of tag group are not stored as json but constructed on the fly
|
||||
store(tag.getId(), tag, update);
|
||||
store(tag, update);
|
||||
tag.setChildren(tags);
|
||||
LOG.info("Added tag {}", tag.getFullyQualifiedName());
|
||||
|
||||
|
||||
@ -124,7 +124,7 @@ public class TeamRepository extends EntityRepository<Team> {
|
||||
// Don't store users, defaultRoles, href as JSON. Build it on the fly based on relationships
|
||||
team.withUsers(null).withDefaultRoles(null).withHref(null).withOwner(null).withInheritedRoles(null);
|
||||
|
||||
store(team.getId(), team, update);
|
||||
store(team, update);
|
||||
|
||||
// Restore the relationships
|
||||
team.withUsers(users)
|
||||
|
||||
@ -101,7 +101,7 @@ public class TestCaseRepository extends EntityRepository<TestCase> {
|
||||
|
||||
// Don't store owner, database, href and tags as JSON. Build it on the fly based on relationships
|
||||
test.withOwner(null).withHref(null).withTestSuite(null).withTestDefinition(null);
|
||||
store(test.getId(), test, update);
|
||||
store(test, update);
|
||||
|
||||
// Restore the relationships
|
||||
test.withOwner(owner).withTestSuite(testSuite).withTestDefinition(testDefinition);
|
||||
|
||||
@ -45,7 +45,7 @@ public class TestDefinitionRepository extends EntityRepository<TestDefinition> {
|
||||
EntityReference owner = entity.getOwner();
|
||||
// Don't store owner, database, href and tags as JSON. Build it on the fly based on relationships
|
||||
entity.withOwner(null).withHref(null);
|
||||
store(entity.getId(), entity, update);
|
||||
store(entity, update);
|
||||
|
||||
// Restore the relationships
|
||||
entity.withOwner(owner);
|
||||
|
||||
@ -51,7 +51,7 @@ public class TestSuiteRepository extends EntityRepository<TestSuite> {
|
||||
EntityReference owner = entity.getOwner();
|
||||
// Don't store owner, database, href and tags as JSON. Build it on the fly based on relationships
|
||||
entity.withOwner(null).withHref(null);
|
||||
store(entity.getId(), entity, update);
|
||||
store(entity, update);
|
||||
|
||||
// Restore the relationships
|
||||
entity.withOwner(owner);
|
||||
|
||||
@ -74,7 +74,7 @@ public class TopicRepository extends EntityRepository<Topic> {
|
||||
// Don't store owner, database, href and tags as JSON. Build it on the fly based on relationships
|
||||
topic.withOwner(null).withService(null).withHref(null).withTags(null);
|
||||
|
||||
store(topic.getId(), topic, update);
|
||||
store(topic, update);
|
||||
|
||||
// Restore the relationships
|
||||
topic.withOwner(owner).withService(service).withTags(tags);
|
||||
|
||||
@ -69,7 +69,7 @@ public class TypeRepository extends EntityRepository<Type> {
|
||||
URI href = type.getHref();
|
||||
List<CustomProperty> customProperties = type.getCustomProperties();
|
||||
type.withHref(null).withCustomProperties(null);
|
||||
store(type.getId(), type, update);
|
||||
store(type, update);
|
||||
type.withHref(href).withCustomProperties(customProperties);
|
||||
updateTypeMap(type);
|
||||
}
|
||||
|
||||
@ -101,7 +101,7 @@ public class UserRepository extends EntityRepository<User> {
|
||||
// Don't store roles, teams and href as JSON. Build it on the fly based on relationships
|
||||
user.withRoles(null).withTeams(null).withHref(null).withInheritedRoles(null);
|
||||
|
||||
store(user.getId(), user, update);
|
||||
store(user, update);
|
||||
|
||||
// Restore the relationships
|
||||
user.withRoles(roles).withTeams(teams);
|
||||
|
||||
@ -51,7 +51,7 @@ public class WebAnalyticEventRepository extends EntityRepository<WebAnalyticEven
|
||||
EntityReference owner = entity.getOwner();
|
||||
|
||||
entity.withOwner(null).withHref(null);
|
||||
store(entity.getId(), entity, update);
|
||||
store(entity, update);
|
||||
|
||||
entity.withOwner(owner);
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ public class WebhookRepository extends EntityRepository<Webhook> {
|
||||
@Override
|
||||
public void storeEntity(Webhook entity, boolean update) throws IOException {
|
||||
entity.setHref(null);
|
||||
store(entity.getId(), entity, update);
|
||||
store(entity, update);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user