java.lang.Object
org.odpi.openmetadata.adapters.repositoryservices.postgres.repositoryconnector.database.DatabaseStore

public class DatabaseStore extends Object
Manages the connection between the repository connector and the database. Note, a single JDBC Connection can only be used from a single thread.
  • Constructor Details

    • DatabaseStore

      public DatabaseStore(org.odpi.openmetadata.adapters.connectors.resource.jdbc.JDBCResourceConnector jdbcResourceConnector, String repositoryName, org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.repositoryconnector.OMRSRepositoryHelper repositoryHelper) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      Create access to the entity store.
      Parameters:
      jdbcResourceConnector - connector to the database
      repositoryName - name of this repository
      repositoryHelper - helper
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
  • Method Details

    • getControlTable

      public ControlMapper getControlTable() throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      Extract the repository control table from the database schema. This is used to validate that the server is using the correct repository.
      Returns:
      contents of the control table (only 1 row expected)
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - problem connecting to the database
    • saveControlTable

      public void saveControlTable(ControlMapper controlMapper) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      Save the control table row to the database.
      Parameters:
      controlMapper - control mapper filled with the desired values.
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - problem connecting to the database
    • getEntityForUpdate

      public EntityMapper getEntityForUpdate(String guid) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      Retrieve details about an entity from the store. The entity mapper is returned to allow the caller to choose what style of entity to return.
      Parameters:
      guid - unique identifier of the entity
      Returns:
      entity mapper containing all that is known about the latest version of the entity
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - either a problem accessing the database or a mapping problem with the contents retrieved
    • getRelationshipForUpdate

      public RelationshipMapper getRelationshipForUpdate(String guid) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      Retrieve a relationship from the database.
      Parameters:
      guid - unique identifier of the relationship
      Returns:
      Relationship mapper
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - problem communicating with the database, or mapping the values returned
    • getClassificationForUpdate

      public ClassificationMapper getClassificationForUpdate(String entityGUID, String classificationName) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      Retrieve details about an entity from the store. The entity mapper is returned to allow the caller to choose what style of entity to return.
      Parameters:
      entityGUID - unique identifier of the entity
      classificationName - name of classification
      Returns:
      classification mapper containing all that is known about the latest version of the classification
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - either a problem accessing the database or a mapping problem with the contents retrieved
    • getHomeClassifications

      public List<ClassificationMapper> getHomeClassifications(String guid, String localMetadataCollectionId, Date asOfTime) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      Return the list of home classifications for an entity.
      Parameters:
      guid - unique identifier of the entity
      localMetadataCollectionId - unique identifier of the local metadata collection
      asOfTime - database time
      Returns:
      list of classifications or null
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - problem communicating with the database
    • getEntityFromStore

      public EntityMapper getEntityFromStore(String guid, Date asOfTime) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      Retrieve the version of an entity from the database that was active at the requested time. Null is returned if there were no active instance.
      Parameters:
      guid - unique identifier of the entity
      asOfTime - requested time for the version
      Returns:
      entity mapper
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - problem communicating with the database, or mapping the values returned
    • getRelationshipFromStore

      public RelationshipMapper getRelationshipFromStore(String guid, Date asOfTime) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      Retrieve the version of a relationship from the database that was active at the requested time. Null is returned if there were no active instance.
      Parameters:
      guid - unique identifier of the relationship
      asOfTime - requested time for the version
      Returns:
      relationship mapper
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - problem communicating with the database, or mapping the values returned
    • retrieveEntitiesByProperties

      public List<EntityMapper> retrieveEntitiesByProperties(QueryBuilder entityQueryBuilder, QueryBuilder classificationQueryBuilder, Date asOfTime) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      This query is issued against the entity table and the entity attribute table.
      Parameters:
      classificationQueryBuilder - filled with conditions for the where clause for the SQL query
      entityQueryBuilder - filled with conditions for the where clause for the SQL query
      asOfTime - database time
      Returns:
      list of matching entity mappers or null if nothing matches
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - problem communicating with the database, or mapping the values returned
    • retrieveRelationships

      public List<RelationshipMapper> retrieveRelationships(QueryBuilder queryBuilder, Date asOfTime) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      This query is issued against the relationship table.
      Parameters:
      queryBuilder - where clause for the SQL query
      asOfTime - database time
      Returns:
      list of matching relationship mappers or null if nothing matches
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - problem communicating with the database, or mapping the values returned
    • retrieveRelationshipsByProperties

      public List<RelationshipMapper> retrieveRelationshipsByProperties(QueryBuilder queryBuilder, Date asOfTime) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      This query is issued against the relationship table and the relationship attribute table.
      Parameters:
      queryBuilder - populated with details of the where clause for the SQL query
      asOfTime - database time
      Returns:
      list of matching relationship mappers or null if nothing matches
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - problem communicating with the database, or mapping the values returned
    • getCompleteEntityFromStore

      public EntityMapper getCompleteEntityFromStore(String guid, Map<String,org.odpi.openmetadata.adapters.connectors.resource.jdbc.properties.JDBCDataValue> entityRow, Date asOfTime) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      Retrieve the related information for an entity. Null is returned if there were no active instance.
      Parameters:
      guid - unique identifier of the entity
      entityRow - appropriate row from table
      asOfTime - database time
      Returns:
      entity mapper
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - problem communicating with the database, or mapping the values returned
    • getCompleteRelationshipFromStore

      public RelationshipMapper getCompleteRelationshipFromStore(String guid, Map<String,org.odpi.openmetadata.adapters.connectors.resource.jdbc.properties.JDBCDataValue> relationshipRow, Date asOfTime) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      Retrieve the related information for a relationship. Null is returned if there was no active instance.
      Parameters:
      guid - unique identifier of the relationship
      relationshipRow - appropriate row from table
      asOfTime - time for the database query
      Returns:
      relationship mapper
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - problem communicating with the database, or mapping the values returned
    • getEntityHistoryFromStore

      public List<EntityMapper> getEntityHistoryFromStore(String guid, Date fromTime, Date toTime, boolean oldestFirst) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      Return the list of versions for an entity.
      Parameters:
      guid - unique identifier of the instance
      fromTime - starting time
      toTime - ending time
      oldestFirst - ordering
      Returns:
      list of instance versions
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - problem communicating with the database
    • getRelationshipHistoryFromStore

      public List<RelationshipMapper> getRelationshipHistoryFromStore(String guid, Date fromTime, Date toTime, boolean oldestFirst) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      Return the list of versions for a relationship.
      Parameters:
      guid - unique identifier of the relationship
      fromTime - starting time
      toTime - ending time
      oldestFirst - ordering
      Returns:
      list of instance versions
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - problem communicating with the database, or mapping the values returned
    • addEntityToStore

      public void addEntityToStore(EntityMapper entityMapper) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      Add an entity to the database. Its header information (and effectivity dates) goes into the entity table. The properties go into the entity attribute values table.
      Parameters:
      entityMapper - details about the entity
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - problem communicating with the database, or mapping the values returned
    • getVersionEndDate

      public Date getVersionEndDate(Date updateTime) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      Determine the end time for the previous version of an entity, relationship or classification.
      Parameters:
      updateTime - update time from next version
      Returns:
      date - 1 millisecond earlier than that the update time
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - no update time in next version
    • addEntityProxyToStore

      public void addEntityProxyToStore(EntityMapper entityMapper) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      Add an entity proxy to the database only if the entity is not known. Its header information (and effectivity dates) goes into the entity table. The properties go into the entity attribute values table.
      Parameters:
      entityMapper - details about the entity
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - problem communicating with the database, or mapping the values returned
    • saveClassification

      public void saveClassification(ClassificationMapper classificationMapper) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      Maintain a classification within the entity.
      Parameters:
      classificationMapper - classification to update
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - problem communicating with the database
    • addRelationshipToStore

      public void addRelationshipToStore(RelationshipMapper relationshipMapper) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      Add a relationship to the database. Its header information (and effectivity dates) goes into the relationship table. The properties go into the relationship attribute values table.
      Parameters:
      relationshipMapper - details about the relationship
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - problem communicating with the database, or mapping the values returned
    • updatePreviousEntityVersionEndTime

      public void updatePreviousEntityVersionEndTime(EntityMapper entityMapper, Date versionEndTime) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      Update the version end date in an entity to the database.
      Parameters:
      entityMapper - details about the entity
      versionEndTime - time that the previous version ended
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - problem communicating with the database, or mapping the values returned
    • updatePreviousClassificationVersionEndTime

      public void updatePreviousClassificationVersionEndTime(ClassificationMapper classificationMapper, Date versionEndTime) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      Update the version end date in an entity's classification to the database.
      Parameters:
      classificationMapper - details about the classification
      versionEndTime - time that the previous version ended
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - problem communicating with the database, or mapping the values returned
    • updatePreviousRelationshipVersionEndTime

      public void updatePreviousRelationshipVersionEndTime(RelationshipMapper relationshipMapper, Date versionEndTime) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      Update the version end date in a relationship to the database.
      Parameters:
      relationshipMapper - details about the relationship
      versionEndTime - time that the previous version ended
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - problem communicating with the database, or mapping the values returned
    • purgeClassification

      public void purgeClassification(String entityGUID, String classificationName) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      Purge a classification from the database
      Parameters:
      entityGUID - unique identifier
      classificationName - name of classification to remove
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - problem communicating with the database
    • purgeEntity

      public void purgeEntity(String guid) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      Remove (purge) an entity from the repository. This method relies on the foreign key relationships to remove all versions of the entity, and its linked relationships and classifications. This request could ripple updates into all tables except the repository control table.
      Parameters:
      guid - unique identifier of the entity
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - problem communicating with the database
    • purgeRelationship

      public void purgeRelationship(String guid) throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      Remove (purge) a relationship from the repository. This method relies on the foreign key relationships to properly remove all of the versions and properties associated with the relationship. It should have no effect on the entities and classification tables.
      Parameters:
      guid - unique identifier of the entity
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - problem communicating with the database
    • disconnect

      public void disconnect() throws org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException
      Free up the connection since the request is over.
      Throws:
      org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException - problem closing connection