Class EntityRepository<T extends EntityInterface>

    • Field Detail

      • CACHE_WITH_NAME

        public static final com.google.common.cache.LoadingCache<org.apache.commons.lang3.tuple.Pair<String,​String>,​EntityInterface> CACHE_WITH_NAME
      • CACHE_WITH_ID

        public static final com.google.common.cache.LoadingCache<org.apache.commons.lang3.tuple.Pair<String,​UUID>,​EntityInterface> CACHE_WITH_ID
      • entityType

        protected final String entityType
      • allowedFields

        protected final Set<String> allowedFields
      • supportsSoftDelete

        public final boolean supportsSoftDelete
      • supportsTags

        protected final boolean supportsTags
      • supportsOwner

        protected final boolean supportsOwner
      • supportsFollower

        protected final boolean supportsFollower
      • supportsExtension

        protected final boolean supportsExtension
      • supportsVotes

        protected final boolean supportsVotes
      • quoteFqn

        protected boolean quoteFqn
      • putFields

        protected final EntityUtil.Fields putFields
        Fields that can be updated during PUT operation
    • Method Detail

      • setFields

        public abstract T setFields​(T entity,
                                    EntityUtil.Fields fields)
        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

        public abstract T clearFields​(T entity,
                                      EntityUtil.Fields fields)
        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

        public abstract void prepare​(T entity)
        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:

        1. 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 .
        2. Validate all the attributes of an entity.
        3. 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.
        At the end of this operation, entity is expected to be valid and fully constructed with all the fields that will be sent as payload in the POST, PUT, and PATCH operations response.
        See Also:
        for an example implementation
      • storeEntity

        public abstract void storeEntity​(T entity,
                                         boolean update)
        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:
        for an example implementation
      • storeRelationships

        public abstract void storeRelationships​(T entity)
        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:
        for an example implementation
      • restorePatchAttributes

        public void restorePatchAttributes​(T original,
                                           T updated)
        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

        public void setFullyQualifiedName​(T entity)
        Set fullyQualifiedName of an entity
      • initSeedDataFromResources

        public void initSeedDataFromResources()
                                       throws IOException
        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
      • initializeEntity

        public void initializeEntity​(T entity)
        Initialize a given entity if it does not exist.
      • 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
      • findByNameOrNull

        public T findByNameOrNull​(String fqn,
                                  Include include)
      • findByName

        public T findByName​(String fqn,
                            Include include)
        Find method is used for getting an entity only with core fields stored as JSON without any relational fields set
      • getVersion

        public T getVersion​(UUID id,
                            String version)
      • create

        public final T create​(javax.ws.rs.core.UriInfo uriInfo,
                              T entity)
      • createInternal

        public final T createInternal​(T entity)
      • prepareInternal

        public void prepareInternal​(T entity)
      • storeRelationshipsInternal

        public void storeRelationshipsInternal​(T entity)
      • createOrUpdate

        public final RestUtil.PutResponse<T> createOrUpdate​(javax.ws.rs.core.UriInfo uriInfo,
                                                            T updated)
      • createOrUpdateInternal

        public final RestUtil.PutResponse<T> createOrUpdateInternal​(javax.ws.rs.core.UriInfo uriInfo,
                                                                    T updated)
      • postCreate

        protected void postCreate​(T entity)
      • postUpdate

        protected void postUpdate​(T entity)
      • preDelete

        protected void preDelete​(T entity)
      • postDelete

        protected void postDelete​(T entity)
      • cleanup

        protected void cleanup​(T entityInterface)
      • store

        protected void store​(T entity,
                             boolean update)
      • storeTimeSeries

        protected void storeTimeSeries​(String fqn,
                                       String extension,
                                       String jsonSchema,
                                       String entityJson,
                                       Long timestamp)
      • storeTimeSeriesWithOperation

        protected void storeTimeSeriesWithOperation​(String fqn,
                                                    String extension,
                                                    String jsonSchema,
                                                    String entityJson,
                                                    Long timestamp,
                                                    String operation,
                                                    boolean update)
      • getExtensionAtTimestamp

        public String getExtensionAtTimestamp​(String fqn,
                                              String extension,
                                              Long timestamp)
      • getExtensionAtTimestampWithOperation

        public String getExtensionAtTimestampWithOperation​(String fqn,
                                                           String extension,
                                                           Long timestamp,
                                                           String operation)
      • getLatestExtensionFromTimeseries

        public String getLatestExtensionFromTimeseries​(String fqn,
                                                       String extension)
      • getResultsFromAndToTimestamps

        public List<String> getResultsFromAndToTimestamps​(String fullyQualifiedName,
                                                          String extension,
                                                          Long startTs,
                                                          Long endTs)
      • deleteExtensionAtTimestamp

        public void deleteExtensionAtTimestamp​(String fqn,
                                               String extension,
                                               Long timestamp)
      • deleteExtensionBeforeTimestamp

        public void deleteExtensionBeforeTimestamp​(String fqn,
                                                   String extension,
                                                   Long timestamp)
      • removeExtension

        public void removeExtension​(EntityInterface entity)
      • getExtension

        public Object getExtension​(T entity)
      • addDerivedTags

        public final List<TagLabel> addDerivedTags​(List<TagLabel> tagLabels)
        Validate given list of tags and add derived tags to it
      • applyTags

        protected void applyTags​(T entity)
      • applyTags

        public void applyTags​(List<TagLabel> tagLabels,
                              String targetFQN)
        Apply tags tagLabels to the entity or field identified by targetFQN
      • getVotes

        protected Votes getVotes​(T entity)
      • withHref

        public T withHref​(javax.ws.rs.core.UriInfo uriInfo,
                          T entity)
      • getHref

        public URI getHref​(javax.ws.rs.core.UriInfo uriInfo,
                           UUID id)
      • addRelationship

        public void addRelationship​(UUID fromId,
                                    UUID toId,
                                    String fromEntity,
                                    String toEntity,
                                    Relationship relationship,
                                    boolean bidirectional)
      • ensureSingleRelationship

        public void ensureSingleRelationship​(String entityType,
                                             UUID id,
                                             List<?> relations,
                                             String relationshipName,
                                             boolean mustHaveRelationship)
      • getAllowedFieldsCopy

        public final Set<String> getAllowedFieldsCopy()
      • getCustomPropertyFQNPrefix

        protected String getCustomPropertyFQNPrefix​(String entityType)
      • getCustomPropertyFQN

        protected String getCustomPropertyFQN​(String entityType,
                                              String propertyName)
      • checkSystemEntityDeletion

        protected void checkSystemEntityDeletion​(T entity)