public abstract class BaseSearchProcessor extends Object
ISearch.
generateQL() - is used for getting the actual search
results.generateRowCountQL() - is used for getting just the number
of results.select _it from com.example.Cat _it where _it.age > :p1 and _it.name != :p2 parameter list: [3, 'Mittens']This is an abstract class. A subclass must be used to implement individual query languages. Currently only HQL query language is supported (
com.googlecode.genericdao.dao.hibernate.HibernateSearchToQLProcessor). The that
implementation could be used for EQL query language as well with no or minor
modifications.| Modifier and Type | Class and Description |
|---|---|
protected static class |
BaseSearchProcessor.AliasNode |
protected static class |
BaseSearchProcessor.SearchContext |
| Modifier and Type | Field and Description |
|---|---|
protected Pattern |
INJECTION_CHECK
Regex pattern for a valid property name/path.
|
protected MetadataUtil |
metadataUtil |
protected int |
qlType |
protected static int |
QLTYPE_EQL |
protected static int |
QLTYPE_HQL |
protected static String |
ROOT_PATH |
protected String |
rootAlias |
| Modifier | Constructor and Description |
|---|---|
protected |
BaseSearchProcessor(int qlType,
MetadataUtil metadataUtil) |
| Modifier and Type | Method and Description |
|---|---|
protected Filter |
addExplicitNullChecks(Filter filter)
Used by
negate(Filter). |
protected void |
appendCustomExpression(StringBuilder sb,
BaseSearchProcessor.SearchContext ctx,
String expression)
append a custom expression to the string builder, replacing any
property tokens (i.e "{prop}") with a reference to the property.
|
protected void |
appendCustomExpression(StringBuilder sb,
BaseSearchProcessor.SearchContext ctx,
String expression,
List<?> values)
append a custom expression to the string builder, replacing any
property tokens (i.e "{prop}") with a reference to the property and
value tokens (i.e.
|
protected void |
applyFetches(BaseSearchProcessor.SearchContext ctx,
List<String> fetches,
List<Field> fields)
Apply the fetch list to the alias tree in the search context.
|
protected List<String> |
checkAndCleanFetches(List<String> fetches)
Check for injection attack in property strings.
|
protected List<Field> |
checkAndCleanFields(List<Field> fields)
Check for injection attack in property strings.
|
protected List<Filter> |
checkAndCleanFilters(List<Filter> filters)
Check for injection attack in property strings.
|
protected List<Sort> |
checkAndCleanSorts(List<Sort> sorts)
Check for injection attack in property strings.
|
protected String |
filterToQL(BaseSearchProcessor.SearchContext ctx,
Filter filter)
Recursively generate the QL fragment for a given search filter option.
|
protected String |
generateFromClause(BaseSearchProcessor.SearchContext ctx,
boolean doEagerFetching)
Internal method for generating from clause.
|
protected String |
generateJoins(BaseSearchProcessor.SearchContext ctx,
boolean doEagerFetching)
Internal method for generating the join portion of the from clause.
|
protected String |
generateOrderByClause(BaseSearchProcessor.SearchContext ctx,
List<Sort> sorts)
Internal method for generating order by clause.
|
String |
generateQL(Class<?> entityClass,
ISearch search,
List<Object> paramList)
Generate the QL string for a given search.
|
String |
generateRowCountQL(Class<?> entityClass,
ISearch search,
List<Object> paramList)
Generate the QL string that will query the total number of results from a
given search (paging is ignored).
|
protected String |
generateSelectClause(BaseSearchProcessor.SearchContext ctx,
List<Field> fields,
boolean distinct)
Internal method for generating the select clause based on the fields of
the given search.
|
protected String |
generateSimpleAllOrSome(BaseSearchProcessor.SearchContext ctx,
String property,
Filter filter,
String operation)
In the case of simple ALL/SOME/NONE filters, a simpler hql syntax is used
(which is also compatible with collections of values).
|
protected String |
generateSubquery(BaseSearchProcessor.SearchContext ctx,
String property,
Filter filter)
Generate a QL string for a subquery on the given property that uses the
given filter.
|
protected String |
generateWhereClause(BaseSearchProcessor.SearchContext ctx,
List<Filter> filters,
boolean isDisjunction)
Internal method for generating where clause for given search.
|
protected BaseSearchProcessor.AliasNode |
getAliasForPathIfItExists(BaseSearchProcessor.SearchContext ctx,
String path)
Given a full path to an entity (ex.
|
Filter |
getFilterFromExample(Object example) |
Filter |
getFilterFromExample(Object example,
ExampleOptions options) |
MetadataUtil |
getMetadataUtil()
The MetadataUtil used by this search processor.
|
protected BaseSearchProcessor.AliasNode |
getOrCreateAlias(BaseSearchProcessor.SearchContext ctx,
String path,
boolean setFetch)
Given a full path to an entity (ex.
|
protected String |
getPathRef(BaseSearchProcessor.SearchContext ctx,
String path)
Given a full path to a property (ex.
|
protected Filter |
negate(Filter filter)
Return a filter that negates the given filter.
|
protected String |
param(BaseSearchProcessor.SearchContext ctx,
Object value)
Add value to paramList and return the named parameter string ":pX".
|
protected Object |
prepareValue(Class<?> rootClass,
String property,
Object value,
boolean isCollection)
Convert a property value to the expected type for that property.
|
protected void |
securityCheckProperty(String property)
Used by
securityCheck() to check a property string for
injection attack. |
protected void |
setFetchOnAliasNodeAndAllAncestors(BaseSearchProcessor.AliasNode node) |
void |
setRootAlias(String alias)
This is the string used to represent the root entity of the search within
the query.
|
protected String[] |
splitPath(BaseSearchProcessor.SearchContext ctx,
String path)
Split a path into two parts.
|
protected static int QLTYPE_HQL
protected static int QLTYPE_EQL
protected int qlType
protected MetadataUtil metadataUtil
protected String rootAlias
protected static final String ROOT_PATH
protected Pattern INJECTION_CHECK
protected BaseSearchProcessor(int qlType,
MetadataUtil metadataUtil)
public MetadataUtil getMetadataUtil()
public void setRootAlias(String alias)
"_it". It may be necessary
to use a different alias if there are entities in the data model with the
name or property "_it".public String generateQL(Class<?> entityClass, ISearch search, List<Object> paramList)
public String generateRowCountQL(Class<?> entityClass, ISearch search, List<Object> paramList)
protected String generateSelectClause(BaseSearchProcessor.SearchContext ctx, List<Field> fields, boolean distinct)
protected void applyFetches(BaseSearchProcessor.SearchContext ctx, List<String> fetches, List<Field> fields)
protected String generateFromClause(BaseSearchProcessor.SearchContext ctx, boolean doEagerFetching)
fetches if
doEagerFetching is true. NOTE: When
using eager fetching, applyFetches() must be executed first.protected String generateJoins(BaseSearchProcessor.SearchContext ctx, boolean doEagerFetching)
fetches if doEagerFetching is true
. NOTE: When using eager fetching, applyFetches()
must be executed first.protected String generateOrderByClause(BaseSearchProcessor.SearchContext ctx, List<Sort> sorts)
protected String generateWhereClause(BaseSearchProcessor.SearchContext ctx, List<Filter> filters, boolean isDisjunction)
protected String filterToQL(BaseSearchProcessor.SearchContext ctx, Filter filter)
protected String generateSubquery(BaseSearchProcessor.SearchContext ctx, String property, Filter filter)
ctx - - a new context just for this sub-queryproperty - - the property of the main query that points to the collection
on which to queryfilter - - the filter to use for the where clause of the sub-queryprotected String generateSimpleAllOrSome(BaseSearchProcessor.SearchContext ctx, String property, Filter filter, String operation)
In the case of simple ALL/SOME/NONE filters, a simpler hql syntax is used (which is also compatible with collections of values). Simple filters include ALL/SOME/NONE filters with exactly one sub-filter where that filter applies to the elements of the collection directly (as opposed to their properties) and the operator is =, !=, <, <=, >, or >=.
For example:
Filter.some("some_collection_of_strings", Filter.equal("", "Bob")
Filter.all("some_collection_of_numbers", Filter.greaterThan(null, 23)
If the filter meets these criteria as a simple ALL/SOME/NONE filter, the
QL string for the filter will be returned. If not, null is
returned.ctx - - the context of the SOME/ALL/NONE filterproperty - - the property of the SOME/ALL/NONE filterfilter - - the sub-filter that is the value of the SOME/ALL/NONE filteroperation - - a string used to fill in the collection operation. The value
should be either "some" or "all".protected Object prepareValue(Class<?> rootClass, String property, Object value, boolean isCollection)
isCollection - true if the value is a collection of values, for
example with IN and NOT_IN operators.protected Filter addExplicitNullChecks(Filter filter)
negate(Filter). There's a complication with null values
in the database so that !(x == 1) is not the opposite of (x == 1). Rather
!(x == 1 and x != null) is the same as (x == 1). This method applies the
null check explicitly to all filters included in the given filter tree.protected void appendCustomExpression(StringBuilder sb, BaseSearchProcessor.SearchContext ctx, String expression)
protected void appendCustomExpression(StringBuilder sb, BaseSearchProcessor.SearchContext ctx, String expression, List<?> values)
protected String param(BaseSearchProcessor.SearchContext ctx, Object value)
protected String getPathRef(BaseSearchProcessor.SearchContext ctx, String path)
protected String[] splitPath(BaseSearchProcessor.SearchContext ctx, String path)
protected BaseSearchProcessor.AliasNode getOrCreateAlias(BaseSearchProcessor.SearchContext ctx, String path, boolean setFetch)
protected BaseSearchProcessor.AliasNode getAliasForPathIfItExists(BaseSearchProcessor.SearchContext ctx, String path)
null if none.protected void setFetchOnAliasNodeAndAllAncestors(BaseSearchProcessor.AliasNode node)
protected List<Field> checkAndCleanFields(List<Field> fields)
protected List<String> checkAndCleanFetches(List<String> fetches)
protected List<Sort> checkAndCleanSorts(List<Sort> sorts)
protected List<Filter> checkAndCleanFilters(List<Filter> filters)
protected void securityCheckProperty(String property)
securityCheck() to check a property string for
injection attack.public Filter getFilterFromExample(Object example, ExampleOptions options)
Copyright © 2008-2013. All Rights Reserved.