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

public class QueryBuilder extends Object
Translates open metadata query requests into SQL fragments that can be assembled before issuing then to the database.
  • Constructor Details

    • QueryBuilder

      public QueryBuilder(String principleTableName, String propertyTableName, OMRSRepositoryHelper repositoryHelper, String repositoryName)
      Constructor.
      Parameters:
      principleTableName - name of entity, relationship, classification
      propertyTableName - name of entity_attribute_value, classification_attribute_value, relationship_attribute_value
      repositoryName - name of this repository
      repositoryHelper - helper
  • Method Details

    • setRelationshipEndGUID

      public void setRelationshipEndGUID(String relationshipEndGUID)
      Set up an entity GUID for searching for an entity's relationships.
      Parameters:
      relationshipEndGUID - entity GUID
    • setSearchString

      public void setSearchString(String searchString)
      Set up the Java regular expression used to match against any of the String property values within instances of the specified type(s).
      Parameters:
      searchString - regex
    • setMatchProperties

      public void setMatchProperties(InstanceProperties matchProperties, MatchCriteria matchCriteria)
      Set up the properties that should be matched during the query.
      Parameters:
      matchProperties - Optional list of entity properties to match (where any String property's value should be defined as a Java regular expression, even if it should be an exact match).
      matchCriteria - Enum defining how the match properties should be matched to the entities in the repository.
    • setSearchProperties

      public void setSearchProperties(SearchProperties searchProperties)
      Set up the search properties.
      Parameters:
      searchProperties - Optional list of entity property conditions to match.
    • setSearchClassifications

      public void setSearchClassifications(SearchClassifications matchClassifications)
      Set up optional list of entity classifications to match.
      Parameters:
      matchClassifications - match classifications
    • setLimitResultsByClassification

      public void setLimitResultsByClassification(List<String> limitResultsByClassification)
      Set up the list of classifications that must be present on all returned entities.
      Parameters:
      limitResultsByClassification - list of classification names
    • setTypeGUID

      public void setTypeGUID(String typeGUID, String typeGUIDParameterName)
      Set up the type information for the query.
      Parameters:
      typeGUID - unique identifier of desired type.
      typeGUIDParameterName - parameter name use to pass the type guid
    • setTypeGUID

      public void setTypeGUID(String typeGUID, String typeGUIDParameterName, List<String> subTypeGUIDs, String subTypeGUIDsParameterName)
      Set up the type information for the query.
      Parameters:
      typeGUID - unique identifier of desired type.
      typeGUIDParameterName - parameter name use to pass the type guid
      subTypeGUIDs - list of unique identifiers for the desired type
      subTypeGUIDsParameterName - parameter name use to pass the subtype guid list
    • setLimitResultsByStatus

      public void setLimitResultsByStatus(List<InstanceStatus> limitResultsByStatus)
      Set up the list od current statuses that an instance must have to be returned.
      Parameters:
      limitResultsByStatus - list of statuses
    • setAsOfTime

      public void setAsOfTime(Date asOfTime)
      Set up the database time to issue the query for - null means the latest version
      Parameters:
      asOfTime - date or null
    • setSequencingOrder

      public void setSequencingOrder(SequencingOrder sequencingOrder, String sequencingProperty)
      Set up the sequencing order required.
      Parameters:
      sequencingOrder - order to return results
      sequencingProperty - optional property if sequencing on specific property results
    • setPaging

      public void setPaging(int fromElement, int pageSize)
      Set up the required paging.
      Parameters:
      fromElement - starting from element (0 for first)
      pageSize - maximum number of elements that can be returned
    • setGUIDList

      public void setGUIDList(List<String> guidList)
      Set up a list of GUIDs as part of a search.
      Parameters:
      guidList - list of GUID to search for
    • getPrimaryKeysClause

      public String getPrimaryKeysClause(String instanceGUID, long version, String classificationName)
      Return the where clause that identified the primary key of an entity, relationship or classification.
      Parameters:
      instanceGUID - unique identifier of the associated entity or relationship
      version - the version of the instance
      classificationName - optional classification name
      Returns:
      where clause
    • getPropertyJoinQuery

      public String getPropertyJoinQuery(String principleTableName, String propertiesTableName, String columnSelection)
      Join the principle table with its associated attributes table.
      Parameters:
      principleTableName - name of main table
      propertiesTableName - name of attributes table
      columnSelection - name of a specific column to select
      Returns:
      the join part of the SQL query
    • getDistinctPropertyJoinQuery

      public String getDistinctPropertyJoinQuery(RepositoryTable principleTable, String propertiesTableName)
      Join the principle table with its associated attributes table.
      Parameters:
      principleTable - main table
      propertiesTableName - name of attributes table
      Returns:
      the join part of the SQL query
    • getAsOfTimeWhereClause

      public String getAsOfTimeWhereClause() throws RepositoryErrorException
      Return the where clause built up from the query parameters supplied.
      Returns:
      SQL command fragment
      Throws:
      RepositoryErrorException
    • getSequenceAndPaging

      public String getSequenceAndPaging(String principleTableName)
      The sequencing (order by) and paging (limit/offset) can only be added at the end and may only include
      Parameters:
      principleTableName - main table that the ordering will occur on
      Returns:
      sql fragment
    • toString

      public String toString()
      toString() JSON-style
      Overrides:
      toString in class Object
      Returns:
      string description