Class QueryBuilder
java.lang.Object
org.odpi.openmetadata.adapters.repositoryservices.postgres.repositoryconnector.database.QueryBuilder
Translates open metadata query requests into SQL fragments that can be assembled before issuing
then to the database.
-
Constructor Summary
ConstructorDescriptionQueryBuilder
(String principleTableName, String propertyTableName, OMRSRepositoryHelper repositoryHelper, String repositoryName) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionReturn the where clause built up from the query parameters supplied.getDistinctPropertyJoinQuery
(RepositoryTable principleTable, String propertiesTableName) Join the principle table with its associated attributes table.getPrimaryKeysClause
(String instanceGUID, long version, String classificationName) Return the where clause that identified the primary key of an entity, relationship or classification.getPropertyJoinQuery
(String principleTableName, String propertiesTableName, String columnSelection) Join the principle table with its associated attributes table.getSequenceAndPaging
(String principleTableName) The sequencing (order by) and paging (limit/offset) can only be added at the end and may only includevoid
setAsOfTime
(Date asOfTime) Set up the database time to issue the query for - null means the latest versionvoid
setGUIDList
(List<String> guidList) Set up a list of GUIDs as part of a search.void
setLimitResultsByClassification
(List<String> limitResultsByClassification) Set up the list of classifications that must be present on all returned entities.void
setLimitResultsByStatus
(List<InstanceStatus> limitResultsByStatus) Set up the list od current statuses that an instance must have to be returned.void
setMatchProperties
(InstanceProperties matchProperties, MatchCriteria matchCriteria) Set up the properties that should be matched during the query.void
setPaging
(int fromElement, int pageSize) Set up the required paging.void
setRelationshipEndGUID
(String relationshipEndGUID) Set up an entity GUID for searching for an entity's relationships.void
setSearchClassifications
(SearchClassifications matchClassifications) Set up optional list of entity classifications to match.void
setSearchProperties
(SearchProperties searchProperties) Set up the search properties.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).void
setSequencingOrder
(SequencingOrder sequencingOrder, String sequencingProperty) Set up the sequencing order required.void
setTypeGUID
(String typeGUID, String typeGUIDParameterName) Set up the type information for the query.void
setTypeGUID
(String typeGUID, String typeGUIDParameterName, List<String> subTypeGUIDs, String subTypeGUIDsParameterName) Set up the type information for the query.toString()
toString() JSON-style
-
Constructor Details
-
QueryBuilder
public QueryBuilder(String principleTableName, String propertyTableName, OMRSRepositoryHelper repositoryHelper, String repositoryName) Constructor.- Parameters:
principleTableName
- name of entity, relationship, classificationpropertyTableName
- name of entity_attribute_value, classification_attribute_value, relationship_attribute_valuerepositoryName
- name of this repositoryrepositoryHelper
- helper
-
-
Method Details
-
setRelationshipEndGUID
Set up an entity GUID for searching for an entity's relationships.- Parameters:
relationshipEndGUID
- entity GUID
-
setSearchString
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
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
Set up the search properties.- Parameters:
searchProperties
- Optional list of entity property conditions to match.
-
setSearchClassifications
Set up optional list of entity classifications to match.- Parameters:
matchClassifications
- match classifications
-
setLimitResultsByClassification
Set up the list of classifications that must be present on all returned entities.- Parameters:
limitResultsByClassification
- list of classification names
-
setTypeGUID
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 guidsubTypeGUIDs
- list of unique identifiers for the desired typesubTypeGUIDsParameterName
- parameter name use to pass the subtype guid list
-
setLimitResultsByStatus
Set up the list od current statuses that an instance must have to be returned.- Parameters:
limitResultsByStatus
- list of statuses
-
setAsOfTime
Set up the database time to issue the query for - null means the latest version- Parameters:
asOfTime
- date or null
-
setSequencingOrder
Set up the sequencing order required.- Parameters:
sequencingOrder
- order to return resultssequencingProperty
- 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
Set up a list of GUIDs as part of a search.- Parameters:
guidList
- list of GUID to search for
-
getPrimaryKeysClause
Return the where clause that identified the primary key of an entity, relationship or classification.- Parameters:
instanceGUID
- unique identifier of the associated entity or relationshipversion
- the version of the instanceclassificationName
- 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 tablepropertiesTableName
- name of attributes tablecolumnSelection
- 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 tablepropertiesTableName
- name of attributes table- Returns:
- the join part of the SQL query
-
getAsOfTimeWhereClause
Return the where clause built up from the query parameters supplied.- Returns:
- SQL command fragment
- Throws:
RepositoryErrorException
-
getSequenceAndPaging
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
toString() JSON-style
-