Package org.openbravo.service.json
Class AdvancedQueryBuilder
- java.lang.Object
-
- org.openbravo.service.json.AdvancedQueryBuilder
-
public class AdvancedQueryBuilder extends Object
Translates an advanced criteria/filter object into a HQL query. Also takes into account session and other parameters.- Author:
- mtaal
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AdvancedQueryBuilder.TextMatching
-
Field Summary
Fields Modifier and Type Field Description static String
EXISTS_QUERY_KEY
static String
EXISTS_VALUE_HOLDER
static String
OPERATOR_EXISTS
-
Constructor Summary
Constructors Constructor Description AdvancedQueryBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFilterParameter(String key, String value)
Add a filter parameter, the methodgetWhereClause()
will try to convert the String value to a typed parameter.String
addNamedParameter(Object value)
Adds a named parameter for the query to be builtvoid
addSelectClausePart(String selectClausePart)
void
addSelectFunctionPart(String function, String field)
void
clearCachedValues()
List<String>
getAdditionalProperties()
org.codehaus.jettison.json.JSONObject
getCriteria()
Entity
getEntity()
static String
getHqlOperator(String operator)
String
getJoinClause()
String
getMainAlias()
Map<String,Object>
getNamedParameters()
Gets the named parameters of the query to buildString
getOrderBy()
String
getOrderByClause()
Converts the value of the sortBy member into a valid order by clause in a HQL query.protected String
getOrderByClausePart(String orderByParam)
String
getSelectClause()
String
getWhereClause()
Translates the filter criteria (addFilterParameter(String, String)
) to a valid HQL where clause (without the 'where' keyword).boolean
hasOrganizationParameter()
boolean
isJoinAssociatedEntities()
void
preventCreatingJoinsInWhereClause(boolean preventedCreatingJoinsInWhereClause)
Allows preventing the creation of new join alias when the where clause is built.String
resolveJoins(List<Property> props, String originalPath)
String
resolveJoins(List<Property> props, String originalPath, boolean fromCriteria)
void
setAdditionalProperties(List<String> additionalProperties)
void
setCriteria(org.codehaus.jettison.json.JSONObject criteria)
void
setDistinctProperty(Property distinctProperty)
void
setDoOr(boolean doOr)
void
setEntity(String entityName)
void
setEntity(Entity entity)
void
setJoinAssociatedEntities(boolean joinAssociatedEntities)
void
setMainAlias(String mainAlias)
void
setOrderBy(String orderBy)
void
setSubDataEntityQueryService(DataEntityQueryService dataEntityQueryService)
void
setSubEntityName(String subEntityName)
-
-
-
Field Detail
-
EXISTS_QUERY_KEY
public static final String EXISTS_QUERY_KEY
- See Also:
- Constant Field Values
-
EXISTS_VALUE_HOLDER
public static final String EXISTS_VALUE_HOLDER
- See Also:
- Constant Field Values
-
OPERATOR_EXISTS
public static final String OPERATOR_EXISTS
- See Also:
- Constant Field Values
-
-
Method Detail
-
getEntity
public Entity getEntity()
-
setEntity
public void setEntity(String entityName)
-
setEntity
public void setEntity(Entity entity)
-
getWhereClause
public String getWhereClause()
Translates the filter criteria (addFilterParameter(String, String)
) to a valid HQL where clause (without the 'where' keyword). After calling this method the methodgetNamedParameters()
can be called. Note that currently only filtering on string and boolean properties is supported. Also filtering on the identifier of a referenced business object is supported.- Returns:
- a valid where clause or an empty string if not set.
-
getJoinClause
public String getJoinClause()
- Returns:
- an empty String if there is no join clause, in other cases a String like the following is returned " as e left join e.bank as alias_1"
-
getOrderByClause
public String getOrderByClause()
Converts the value of the sortBy member into a valid order by clause in a HQL query. The method handles special cases as sorting by the identifier properties and descending which is controlled with a minus sign before the property name.- Returns:
- a valid order by clause (or an empty string if no sorting)
-
hasOrganizationParameter
public boolean hasOrganizationParameter()
- Returns:
- true if one of the filter parameters is the
JsonConstants.ORG_PARAMETER
.
-
addFilterParameter
public void addFilterParameter(String key, String value)
Add a filter parameter, the methodgetWhereClause()
will try to convert the String value to a typed parameter.- Parameters:
key
- the filter key, can be direct property or a referenced property.value
- the value as a String
-
getNamedParameters
public Map<String,Object> getNamedParameters()
Gets the named parameters of the query to build- Returns:
- a map whose keys are the parameter names and the values the parameter values
-
addNamedParameter
public String addNamedParameter(Object value)
Adds a named parameter for the query to be built- Parameters:
value
- the value for the query parameter- Returns:
- the parameter name as it is used in the query
-
setDoOr
public void setDoOr(boolean doOr)
-
resolveJoins
public String resolveJoins(List<Property> props, String originalPath, boolean fromCriteria)
-
getMainAlias
public String getMainAlias()
-
setMainAlias
public void setMainAlias(String mainAlias)
-
getOrderBy
public String getOrderBy()
-
setOrderBy
public void setOrderBy(String orderBy)
-
getCriteria
public org.codehaus.jettison.json.JSONObject getCriteria()
-
setCriteria
public void setCriteria(org.codehaus.jettison.json.JSONObject criteria)
-
isJoinAssociatedEntities
public boolean isJoinAssociatedEntities()
-
setJoinAssociatedEntities
public void setJoinAssociatedEntities(boolean joinAssociatedEntities)
-
clearCachedValues
public void clearCachedValues()
-
addSelectClausePart
public void addSelectClausePart(String selectClausePart)
-
getSelectClause
public String getSelectClause()
-
setSubEntityName
public void setSubEntityName(String subEntityName)
-
setSubDataEntityQueryService
public void setSubDataEntityQueryService(DataEntityQueryService dataEntityQueryService)
-
setDistinctProperty
public void setDistinctProperty(Property distinctProperty)
-
preventCreatingJoinsInWhereClause
public void preventCreatingJoinsInWhereClause(boolean preventedCreatingJoinsInWhereClause)
Allows preventing the creation of new join alias when the where clause is built. This is useful when the AdvancedQueryBuilder is used to obtain the WHERE clause, but when the FROM clause built is not used (i.e. en HQLDataSourceService)- Parameters:
preventedCreatingJoinsInWhereClause
- If true, the creation of new join alias is prevented when the where clause is built
-
-