Class EntityRepository<T extends EntityInterface>
- Direct Known Subclasses:
AppMarketPlaceRepository,AppRepository,BotRepository,ChartRepository,ClassificationRepository,ContainerRepository,DashboardDataModelRepository,DashboardRepository,DatabaseRepository,DatabaseSchemaRepository,DataInsightChartRepository,DataProductRepository,DocumentRepository,DomainRepository,EventSubscriptionRepository,GlossaryRepository,GlossaryTermRepository,IngestionPipelineRepository,KpiRepository,MetricsRepository,MlModelRepository,PersonaRepository,PipelineRepository,PolicyRepository,QueryRepository,ReportRepository,RoleRepository,SearchIndexRepository,ServiceEntityRepository,StoredProcedureRepository,TableRepository,TagRepository,TeamRepository,TestCaseRepository,TestConnectionDefinitionRepository,TestDefinitionRepository,TestSuiteRepository,TopicRepository,TypeRepository,UserRepository,WebAnalyticEventRepository,WorkflowRepository
An entity has two types of fields - `attributes` and `relationships`.
- The `attributes` are the core properties of the entity, example - entity id, name, fullyQualifiedName, columns for a table, etc.
- The `relationships` are an associated between two entities, example - table belongs to a database, table has a
tag, user owns a table, etc. All relationships are captured using
EntityReference.
CollectionDAO.TableDAO is used as the DAO object to access the table_entity table.
All DAO objects for an entity are available in daoCollection. Relationships between entity is stored in a separate table that captures the edge - fromEntity, toEntity, and the relationship name entity_relationship table and are supported by
CollectionDAO.EntityRelationshipDAO DAO object.
JSON document of an entity stores only required attributes of an entity. Some attributes such as
href are not stored and are created on the fly.
Json document of an entity does not store relationships. As an example, JSON document for table entity does
not store the relationship database which is of type EntityReference. This is always retrieved from the
relationship table when required to ensure, the data stored is efficiently and consistently, and relationship
information does not become stale.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classclassClass that performs PUT and PATCH update operation.static enumstatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.google.common.cache.LoadingCache<org.apache.commons.lang3.tuple.Pair<String,UUID>, EntityInterface> static final com.google.common.cache.LoadingCache<org.apache.commons.lang3.tuple.Pair<String,String>, EntityInterface> protected final CollectionDAOprotected final Stringprotected final EntityUtil.FieldsFields that can be updated during PUT operationprotected booleanprotected booleanprotected final SearchRepositoryprotected final booleanprotected final booleanprotected final booleanprotected final booleanprotected final booleanprotected final booleanprotected final booleanprotected final booleanprotected booleanfinal booleanprotected final booleanprotected final booleanprotected final boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal RestUtil.PutResponse<T>addFollower(String updatedBy, UUID entityId, UUID userId) final voidaddRelationship(UUID fromId, UUID toId, String fromEntity, String toEntity, Relationship relationship) final voidaddRelationship(UUID fromId, UUID toId, String fromEntity, String toEntity, Relationship relationship, boolean bidirectional) final voidaddRelationship(UUID fromId, UUID toId, String fromEntity, String toEntity, Relationship relationship, String json, boolean bidirectional) protected final voidaddServiceRelationship(T entity, EntityReference service) protected voidapplyColumnTags(List<Column> columns) applySuggestion(EntityInterface entity, String childFQN, Suggestion suggestion) final voidApply tagstagLabelsto the entity or field identified bytargetFQNprotected voidfinal voidbulkAddToRelationship(UUID fromId, List<UUID> toId, String fromEntity, String toEntity, Relationship relationship) protected BulkOperationResultbulkAssetsOperation(UUID entityId, String fromEntity, Relationship relationship, BulkAssets request, boolean isAdd) protected voidcheckSystemEntityDeletion(T entity) protected voidprotected abstract voidclearFields(T entity, EntityUtil.Fields fields) Set the requested fields in an entity.final voidclearFieldsInternal(T entity, EntityUtil.Fields fields) final Tcopy(T entity, CreateEntity request, String updatedBy) final Tfinal TcreateInternal(T entity) final RestUtil.PutResponse<T>createOrUpdate(javax.ws.rs.core.UriInfo uriInfo, T updated) final RestUtil.DeleteResponse<T>final RestUtil.DeleteResponse<T>deleteByName(String updatedBy, String name, boolean recursive, boolean hardDelete) final voiddeleteExtensionAtTimestamp(String fqn, String extension, Long timestamp) final voiddeleteExtensionBeforeTimestamp(String fqn, String extension, Long timestamp) final RestUtil.PutResponse<T>deleteFollower(String updatedBy, UUID entityId, UUID userId) final voiddeleteFrom(UUID fromId, String fromEntityType, Relationship relationship, String toEntityType) final voiddeleteFromSearch(T entity, EventType changeType) final RestUtil.DeleteResponse<T>deleteInternal(String updatedBy, UUID id, boolean recursive, boolean hardDelete) final RestUtil.DeleteResponse<T>deleteInternalByName(String updatedBy, String name, boolean recursive, boolean hardDelete) final voiddeleteRelationship(UUID fromId, String fromEntityType, UUID toId, String toEntityType, Relationship relationship) final voiddeleteTo(UUID toId, String toEntityType, Relationship relationship, String fromEntityType) final voidensureSingleRelationship(String entityType, UUID id, List<CollectionDAO.EntityRelationshipRecord> relations, String relationshipName, String toEntityType, boolean mustHaveRelationship) exportToCsv(String name, String user) Override this method to support downloading CSV functionalityfinal TFind method is used for getting an entity only with core fields stored as JSON without any relational fields setfinal List<EntityReference>findBoth(UUID entity1, String entityType1, Relationship relationship, String entity2) final TfindByName(String fqn, Include include) Find method is used for getting an entity only with core fields stored as JSON without any relational fields setfinal TfindByNameOrNull(String fqn, Include include) final List<EntityReference>findFrom(UUID toId, String toEntityType, Relationship relationship, String fromEntityType) findFromRecords(UUID toId, String toEntityType, Relationship relationship, String fromEntityType) final List<EntityReference>findTo(UUID fromId, String fromEntityType, Relationship relationship, String toEntityType) findToRecords(UUID fromId, String fromEntityType, Relationship relationship, String toEntityType) final Tget(javax.ws.rs.core.UriInfo uriInfo, UUID id, EntityUtil.Fields fields) final Tget(javax.ws.rs.core.UriInfo uriInfo, UUID id, EntityUtil.Fields fields, Include include, boolean fromCache) Used for getting an entity with a set of requested fieldsgetAllTags(EntityInterface entity) getByName(javax.ws.rs.core.UriInfo uriInfo, String fqn, EntityUtil.Fields fields) final TgetByName(javax.ws.rs.core.UriInfo uriInfo, String fqn, EntityUtil.Fields fields, Include include, boolean fromCache) protected List<EntityReference>getChildren(T entity) getCommonFields(Set<String> input) final EntityReferencegetContainer(UUID toId) final EntityReferencegetContainer(UUID toId, String fromEntityType) protected StringgetCustomPropertyFQN(String entityType, String propertyName) protected StringgetCustomPropertyFQNPrefix(String entityType) final EntityReferencestatic <U> List<U>getEntitiesFromSeedData(String entityType, String path, Class<U> clazz) protected List<EntityReference>getExperts(T entity) final ObjectgetExtension(T entity) final StringgetExtensionAtTimestamp(String fqn, String extension, Long timestamp) final EntityUtil.Fieldsprotected final EntityUtil.Fieldsprotected List<EntityReference>getFollowers(T entity) final EntityReferencegetFromEntityRef(UUID toId, Relationship relationship, String fromEntityType, boolean mustHaveRelationship) final URIprotected List<EntityReference>getIngestionPipelines(T service) final StringgetLatestExtensionFromTimeSeries(String fqn, String extension) final EntityReferencegetOwner(EntityReference ref) final EntityReferencefinal EntityReferencegetParentEntity(T entity, String fields) final EntityReferencegetReference(UUID id, Include include) getReference is used for getting the entity references from the entity in the cache.final EntityReferencegetReferenceByName(String fqn, Include include) final ResultList<T>getResultList(List<T> entities, String beforeCursor, String afterCursor, int total) final ResultList<T>getResultList(List<T> entities, List<EntityError> errors, String beforeCursor, String afterCursor, int total) getResultsFromAndToTimestamps(String fullyQualifiedName, String extension, Long startTs, Long endTs) getResultsFromAndToTimestamps(String fqn, String extension, Long startTs, Long endTs, EntityTimeSeriesDAO.OrderBy orderBy) protected List<EntityReference>getReviewers(T entity) getSuggestionFields(Suggestion suggestion) Bring in the necessary fields required to have all the information before applying a suggestiongetSuggestionWorkflow(EntityInterface entity) getTagsByPrefix(String prefix, String postfix) getTaskWorkflow(FeedRepository.ThreadContext threadContext) final EntityReferencegetToEntityRef(UUID fromId, Relationship relationship, String toEntityType, boolean mustHaveRelationship) protected EntityRepository<T>.EntityUpdatergetUpdater(T original, T updated, EntityRepository.Operation operation) final TgetVersion(UUID id, String version) protected VotesimportFromCsv(String name, String csv, boolean dryRun, String user) Load CSV provided for bulk uploadfinal voidinheritDomain(T entity, EntityUtil.Fields fields, EntityInterface parent) final voidinheritExperts(T entity, EntityUtil.Fields fields, EntityInterface parent) final voidinheritOwner(T entity, EntityUtil.Fields fields, EntityInterface parent) final voidinheritReviewers(T entity, EntityUtil.Fields fields, EntityInterface parent) final voidinitializeEntity(T entity) Initialize a given entity if it does not exist.final voidInitialize data from json files if seed data does not exist in corresponding tables.listAfter(javax.ws.rs.core.UriInfo uriInfo, EntityUtil.Fields fields, ListFilter filter, int limitParam, String after) final ResultList<T>listAfterWithSkipFailure(javax.ws.rs.core.UriInfo uriInfo, EntityUtil.Fields fields, ListFilter filter, int limitParam, String after) listAll(EntityUtil.Fields fields, ListFilter filter) listBefore(javax.ws.rs.core.UriInfo uriInfo, EntityUtil.Fields fields, ListFilter filter, int limitParam, String before) final EntityHistorylistVersions(UUID id) final RestUtil.PatchResponse<T>protected voidpopulateOwner(EntityReference owner) protected voidpostCreate(T entity) protected voidpostDelete(T entity) protected voidpostUpdate(T original, T updated) protected voidprotected abstract voidThis method is used for validating an entity to be created during POST, PUT, and PATCH operations and prepare the entity with all the required attributes and relationships.final voidprepareInternal(T entity, boolean update) final voidremoveExtension(EntityInterface entity) final RestUtil.PutResponse<T>restoreEntity(String updatedBy, String entityType, UUID id) final voidrestoreFromSearch(T entity) protected voidrestorePatchAttributes(T original, T updated) PATCH operations can't overwrite certain fields, such as entity ID, fullyQualifiedNames etc.protected abstract voidsetFields(T entity, EntityUtil.Fields fields) Set the requested fields in an entity.final TsetFieldsInternal(T entity, EntityUtil.Fields fields) voidsetFullyQualifiedName(T entity) Set fullyQualifiedName of an entityprotected voidsetInheritedFields(T entity, EntityUtil.Fields fields) This method is called to set inherited fields that an entity inherits from its parent.protected voidprotected voidstoreDataProducts(T entity, List<EntityReference> dataProducts) protected voidstoreDomain(T entity, EntityReference domain) protected abstract voidstoreEntity(T entity, boolean update) An entity is stored in the backend database as JSON document.final voidstoreExtension(EntityInterface entity) protected voidstoreOwner(T entity, EntityReference owner) protected abstract voidstoreRelationships(T entity) This method is called to store all the relationships of an entity.final voidstoreRelationshipsInternal(T entity) protected voidstoreTimeSeries(String fqn, String extension, String jsonSchema, String entityJson) final RestUtil.PutResponse<T>final voidupdateOwner(T ownedEntity, EntityReference originalOwner, EntityReference newOwner) final RestUtil.PutResponse<T>updateVote(String updatedBy, UUID entityId, VoteRequest request) protected voidvalidateColumnTags(List<Column> columns) final voidvalidateDataProducts(List<EntityReference> dataProducts) final EntityReferencevalidateDomain(String domainFqn) final voidvalidateDomain(EntityReference domain) final EntityReferencevalidateOwner(EntityReference owner) final voidvalidateRoles(List<EntityReference> roles) protected voidvalidateTags(List<TagLabel> labels) protected voidvalidateTags(T entity) final voidvalidateTaskThread(FeedRepository.ThreadContext threadContext) final voidvalidateUsers(List<EntityReference> entityReferences) final T
-
Field Details
-
CACHE_WITH_NAME
public static final com.google.common.cache.LoadingCache<org.apache.commons.lang3.tuple.Pair<String,String>, CACHE_WITH_NAMEEntityInterface> -
CACHE_WITH_ID
public static final com.google.common.cache.LoadingCache<org.apache.commons.lang3.tuple.Pair<String,UUID>, CACHE_WITH_IDEntityInterface> -
entityType
-
dao
-
daoCollection
-
searchRepository
-
allowedFields
-
supportsSoftDelete
public final boolean supportsSoftDelete -
supportsTags
protected final boolean supportsTags -
supportsOwner
protected final boolean supportsOwner -
supportsStyle
protected final boolean supportsStyle -
supportsLifeCycle
protected final boolean supportsLifeCycle -
supportsFollower
protected final boolean supportsFollower -
supportsExtension
protected final boolean supportsExtension -
supportsVotes
protected final boolean supportsVotes -
supportsDomain
protected final boolean supportsDomain -
supportsDataProducts
protected final boolean supportsDataProducts -
supportsReviewers
protected final boolean supportsReviewers -
supportsExperts
protected final boolean supportsExperts -
quoteFqn
protected boolean quoteFqn -
renameAllowed
protected boolean renameAllowed -
putFields
Fields that can be updated during PUT operation -
supportsSearch
protected boolean supportsSearch
-
-
Constructor Details
-
EntityRepository
-
-
Method Details
-
setFields
Set the requested fields in an entity. This is used for requesting specific fields in the object during GET operations. It is also used during PUT and PATCH operations to set up fields that can be updated. -
clearFields
Set the requested fields in an entity. This is used for requesting specific fields in the object during GET operations. It is also used during PUT and PATCH operations to set up fields that can be updated. -
prepare
This method is used for validating an entity to be created during POST, PUT, and PATCH operations and prepare the entity with all the required attributes and relationships.The implementation of this method must perform the following:
- Prepare the values for attributes that are not required in the request but can be derived on the server side. Example - >FullyQualifiedNames of an entity can be derived from the hierarchy that an entity belongs to .
- Validate all the attributes of an entity.
- Validate all the relationships of an entity. As an example - during table creation, relationships such as Tags, Owner, Databasea table belongs to are validated. During validation additional information that is not required in the create/update request are set up in the corresponding relationship fields.
- See Also:
-
storeEntity
An entity is stored in the backend database as JSON document. The JSON includes some attributes of the entity and does not include attributes such as href. The relationship fields of an entity is never stored in the JSON document. It is always reconstructed based on relationship edges from the backend database.
As an example, when table entity is stored, the attributes such as href and the relationships such as owner, database, and tags are set to null. These attributes are restored back after the JSON document is stored to be sent as response.- See Also:
-
storeRelationships
This method is called to store all the relationships of an entity. It is expected that all relationships are already validated and completely setup before this method is called and no validation of relationships is required.- See Also:
-
setInheritedFields
This method is called to set inherited fields that an entity inherits from its parent.- See Also:
-
addServiceRelationship
-
restorePatchAttributes
PATCH operations can't overwrite certain fields, such as entity ID, fullyQualifiedNames etc. Instead of throwing an error, we take lenient approach of ignoring the user error and restore those attributes based on what is already stored in the original entity. -
setFullyQualifiedName
Set fullyQualifiedName of an entity -
initSeedDataFromResources
Initialize data from json files if seed data does not exist in corresponding tables. Seed data is stored under openmetadata-service/src/main/resources/json/data/{entityType}This method needs to be explicitly called, typically from initialize method. See
RoleResource.initialize(OpenMetadataApplicationConfig)- Throws:
IOException
-
getEntitiesFromSeedData
- Throws:
IOException
-
getEntitiesFromSeedData
- Throws:
IOException
-
getEntitiesFromSeedData
public static <U> List<U> getEntitiesFromSeedData(String entityType, String path, Class<U> clazz) throws IOException - Throws:
IOException
-
initializeEntity
Initialize a given entity if it does not exist. -
copy
-
getUpdater
protected EntityRepository<T>.EntityUpdater getUpdater(T original, T updated, EntityRepository.Operation operation) -
get
-
get
public final T get(javax.ws.rs.core.UriInfo uriInfo, UUID id, EntityUtil.Fields fields, Include include, boolean fromCache) Used for getting an entity with a set of requested fields -
getReference
getReference is used for getting the entity references from the entity in the cache.- Throws:
EntityNotFoundException
-
find
Find method is used for getting an entity only with core fields stored as JSON without any relational fields set- Throws:
EntityNotFoundException
-
getByName
-
getByName
public final T getByName(javax.ws.rs.core.UriInfo uriInfo, String fqn, EntityUtil.Fields fields, Include include, boolean fromCache) -
getReferenceByName
-
findByNameOrNull
-
findByName
Find method is used for getting an entity only with core fields stored as JSON without any relational fields set -
listAll
-
listAfter
public ResultList<T> listAfter(javax.ws.rs.core.UriInfo uriInfo, EntityUtil.Fields fields, ListFilter filter, int limitParam, String after) -
listAfterWithSkipFailure
public final ResultList<T> listAfterWithSkipFailure(javax.ws.rs.core.UriInfo uriInfo, EntityUtil.Fields fields, ListFilter filter, int limitParam, String after) -
listBefore
public ResultList<T> listBefore(javax.ws.rs.core.UriInfo uriInfo, EntityUtil.Fields fields, ListFilter filter, int limitParam, String before) -
getVersion
-
listVersions
-
create
-
createInternal
-
prepareInternal
-
storeRelationshipsInternal
-
setFieldsInternal
-
clearFieldsInternal
-
createOrUpdate
-
postCreate
-
postUpdate
-
update
public final RestUtil.PutResponse<T> update(javax.ws.rs.core.UriInfo uriInfo, T original, T updated) -
patch
public final RestUtil.PatchResponse<T> patch(javax.ws.rs.core.UriInfo uriInfo, UUID id, String user, javax.json.JsonPatch patch) -
addFollower
-
updateVote
public final RestUtil.PutResponse<T> updateVote(String updatedBy, UUID entityId, VoteRequest request) -
delete
public final RestUtil.DeleteResponse<T> delete(String updatedBy, UUID id, boolean recursive, boolean hardDelete) -
deleteByName
public final RestUtil.DeleteResponse<T> deleteByName(String updatedBy, String name, boolean recursive, boolean hardDelete) -
preDelete
-
postDelete
-
deleteFromSearch
-
restoreFromSearch
-
deleteInternalByName
public final RestUtil.DeleteResponse<T> deleteInternalByName(String updatedBy, String name, boolean recursive, boolean hardDelete) -
deleteInternal
public final RestUtil.DeleteResponse<T> deleteInternal(String updatedBy, UUID id, boolean recursive, boolean hardDelete) -
cleanup
-
deleteFollower
-
getResultList
-
getResultList
public final ResultList<T> getResultList(List<T> entities, List<EntityError> errors, String beforeCursor, String afterCursor, int total) -
store
-
storeTimeSeries
-
getExtensionAtTimestamp
-
getLatestExtensionFromTimeSeries
-
getResultsFromAndToTimestamps
-
getResultsFromAndToTimestamps
-
deleteExtensionAtTimestamp
-
deleteExtensionBeforeTimestamp
-
storeExtension
-
removeExtension
-
getExtension
-
applyColumnTags
-
applyTags
-
applyTags
Apply tagstagLabelsto the entity or field identified bytargetFQN -
getTags
-
getTags
-
getTagsByPrefix
-
getFollowers
-
getVotes
-
withHref
-
getHref
-
restoreEntity
-
addRelationship
public final void addRelationship(UUID fromId, UUID toId, String fromEntity, String toEntity, Relationship relationship) -
addRelationship
public final void addRelationship(UUID fromId, UUID toId, String fromEntity, String toEntity, Relationship relationship, boolean bidirectional) -
addRelationship
-
bulkAddToRelationship
-
findBoth
public final List<EntityReference> findBoth(UUID entity1, String entityType1, Relationship relationship, String entity2) -
findFrom
public final List<EntityReference> findFrom(UUID toId, String toEntityType, Relationship relationship, String fromEntityType) -
findFromRecords
public final List<CollectionDAO.EntityRelationshipRecord> findFromRecords(UUID toId, String toEntityType, Relationship relationship, String fromEntityType) -
getContainer
-
getContainer
-
getFromEntityRef
public final EntityReference getFromEntityRef(UUID toId, Relationship relationship, String fromEntityType, boolean mustHaveRelationship) -
getToEntityRef
public final EntityReference getToEntityRef(UUID fromId, Relationship relationship, String toEntityType, boolean mustHaveRelationship) -
ensureSingleRelationship
-
findTo
public final List<EntityReference> findTo(UUID fromId, String fromEntityType, Relationship relationship, String toEntityType) -
findToRecords
public final List<CollectionDAO.EntityRelationshipRecord> findToRecords(UUID fromId, String fromEntityType, Relationship relationship, String toEntityType) -
deleteRelationship
public final void deleteRelationship(UUID fromId, String fromEntityType, UUID toId, String toEntityType, Relationship relationship) -
deleteTo
public final void deleteTo(UUID toId, String toEntityType, Relationship relationship, String fromEntityType) -
deleteFrom
public final void deleteFrom(UUID fromId, String fromEntityType, Relationship relationship, String toEntityType) -
validateUsers
-
validateRoles
-
getOwner
-
getDomain
-
getParentEntity
-
getParent
-
getChildren
-
getReviewers
-
getExperts
-
getOwner
-
inheritDomain
-
inheritOwner
-
inheritExperts
-
inheritReviewers
-
populateOwner
-
storeOwner
-
storeDomain
-
storeDataProducts
-
bulkAssetsOperation
protected BulkOperationResult bulkAssetsOperation(UUID entityId, String fromEntity, Relationship relationship, BulkAssets request, boolean isAdd) -
updateOwner
public final void updateOwner(T ownedEntity, EntityReference originalOwner, EntityReference newOwner) -
getFields
-
getFields
-
getCommonFields
-
getAllowedFieldsCopy
-
getCustomPropertyFQNPrefix
-
getCustomPropertyFQN
-
getIngestionPipelines
-
checkSystemEntityDeletion
-
validateOwner
-
validateTags
-
validateTags
-
validateDomain
-
validateDomain
-
validateDataProducts
-
exportToCsv
Override this method to support downloading CSV functionality- Throws:
IOException
-
importFromCsv
public CsvImportResult importFromCsv(String name, String csv, boolean dryRun, String user) throws IOException Load CSV provided for bulk upload- Throws:
IOException
-
getAllTags
-
getTaskWorkflow
-
getSuggestionWorkflow
-
applySuggestion
public EntityInterface applySuggestion(EntityInterface entity, String childFQN, Suggestion suggestion) -
getSuggestionFields
Bring in the necessary fields required to have all the information before applying a suggestion -
validateTaskThread
-
validateColumnTags
-