|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.trg.search.BaseSearchProcessor
public abstract class BaseSearchProcessor
This class provides two methods for generating query language to fulfill an
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.trg.dao.hibernate.HibernateSearchToQLProcessor). The that
implementation could be used for EQL query language as well with no or minor
modifications.
| Nested Class Summary | |
|---|---|
protected static class |
BaseSearchProcessor.AliasNode
|
protected static class |
BaseSearchProcessor.SearchContext
|
| Field Summary | |
|---|---|
protected java.util.regex.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 java.lang.String |
ROOT_PATH
|
protected java.lang.String |
rootAlias
|
| Constructor Summary | |
|---|---|
protected |
BaseSearchProcessor(int qlType,
MetadataUtil metaDataUtil)
|
| Method Summary | |
|---|---|
protected Filter |
addExplicitNullChecks(Filter filter)
Used by negate(Filter). |
protected void |
applyFetches(BaseSearchProcessor.SearchContext ctx,
java.util.List<java.lang.String> fetches,
java.util.List<Field> fields)
Apply the fetch list to the alias tree in the search context. |
protected java.util.List<java.lang.String> |
checkAndCleanFetches(java.util.List<java.lang.String> fetches)
Check for injection attack in property strings. |
protected java.util.List<Field> |
checkAndCleanFields(java.util.List<Field> fields)
Check for injection attack in property strings. |
protected java.util.List<Filter> |
checkAndCleanFilters(java.util.List<Filter> filters)
Check for injection attack in property strings. |
protected java.util.List<Sort> |
checkAndCleanSorts(java.util.List<Sort> sorts)
Check for injection attack in property strings. |
protected java.lang.String |
filterToQL(BaseSearchProcessor.SearchContext ctx,
Filter filter)
Recursively generate the QL fragment for a given search filter option. |
protected java.lang.String |
generateFromClause(BaseSearchProcessor.SearchContext ctx,
boolean doEagerFetching)
Internal method for generating from clause. |
protected java.lang.String |
generateJoins(BaseSearchProcessor.SearchContext ctx,
boolean doEagerFetching)
Internal method for generating the join portion of the from clause. |
protected java.lang.String |
generateOrderByClause(BaseSearchProcessor.SearchContext ctx,
java.util.List<Sort> sorts)
Internal method for generating order by clause. |
java.lang.String |
generateQL(java.lang.Class<?> entityClass,
ISearch search,
java.util.List<java.lang.Object> paramList)
Generate the QL string for a given search. |
java.lang.String |
generateRowCountQL(java.lang.Class<?> entityClass,
ISearch search,
java.util.List<java.lang.Object> paramList)
Generate the QL string that will query the total number of results from a given search (paging is ignored). |
protected java.lang.String |
generateSelectClause(BaseSearchProcessor.SearchContext ctx,
java.util.List<Field> fields,
boolean distinct)
Internal method for generating the select clause based on the fields of the given search. |
protected java.lang.String |
generateSimpleAllOrSome(BaseSearchProcessor.SearchContext ctx,
java.lang.String property,
Filter filter,
java.lang.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 java.lang.String |
generateSubquery(BaseSearchProcessor.SearchContext ctx,
java.lang.String property,
Filter filter)
Generate a QL string for a subquery on the given property that uses the given filter. |
protected java.lang.String |
generateWhereClause(BaseSearchProcessor.SearchContext ctx,
java.util.List<Filter> filters,
boolean isDisjunction)
Internal method for generating where clause for given search. |
protected BaseSearchProcessor.AliasNode |
getAlias(BaseSearchProcessor.SearchContext ctx,
java.lang.String path,
boolean setFetch)
Given a full path to an entity (ex. department.manager), return the alias to reference that entity (ex. a4_manager). |
Filter |
getFilterFromExample(java.lang.Object example)
|
Filter |
getFilterFromExample(java.lang.Object example,
ExampleOptions options)
|
MetadataUtil |
getMetadataUtil()
The MetadataUtil used by this search processor. |
protected java.lang.String |
getPathRef(BaseSearchProcessor.SearchContext ctx,
java.lang.String path)
Given a full path to a property (ex. department.manager.salary), return the reference to that property that uses the appropriate alias (ex. |
protected Filter |
negate(Filter filter)
Return a filter that negates the given filter. |
protected java.lang.String |
param(BaseSearchProcessor.SearchContext ctx,
java.lang.Object value)
Add value to paramList and return the named parameter string ":pX". |
protected java.lang.Object |
prepareValue(java.lang.Class<?> rootClass,
java.lang.String property,
java.lang.Object value,
boolean isCollection)
Convert a property value to the expected type for that property. |
protected void |
securityCheckProperty(java.lang.String property)
Used by securityCheck() to check a property string for
injection attack. |
void |
setRootAlias(java.lang.String alias)
This is the string used to represent the root entity of the search within the query. |
protected java.lang.String[] |
splitPath(BaseSearchProcessor.SearchContext ctx,
java.lang.String path)
Split a path into two parts. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static int QLTYPE_HQL
protected static int QLTYPE_EQL
protected int qlType
protected MetadataUtil metadataUtil
protected java.lang.String rootAlias
protected static final java.lang.String ROOT_PATH
protected java.util.regex.Pattern INJECTION_CHECK
| Constructor Detail |
|---|
protected BaseSearchProcessor(int qlType,
MetadataUtil metaDataUtil)
| Method Detail |
|---|
public MetadataUtil getMetadataUtil()
public void setRootAlias(java.lang.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 java.lang.String generateQL(java.lang.Class<?> entityClass,
ISearch search,
java.util.List<java.lang.Object> paramList)
public java.lang.String generateRowCountQL(java.lang.Class<?> entityClass,
ISearch search,
java.util.List<java.lang.Object> paramList)
protected java.lang.String generateSelectClause(BaseSearchProcessor.SearchContext ctx,
java.util.List<Field> fields,
boolean distinct)
protected void applyFetches(BaseSearchProcessor.SearchContext ctx,
java.util.List<java.lang.String> fetches,
java.util.List<Field> fields)
protected java.lang.String generateFromClause(BaseSearchProcessor.SearchContext ctx,
boolean doEagerFetching)
fetches if
doEagerFetching is true. NOTE: When
using eager fetching, applyFetches() must be executed first.
protected java.lang.String generateJoins(BaseSearchProcessor.SearchContext ctx,
boolean doEagerFetching)
fetches if doEagerFetching is true
. NOTE: When using eager fetching, applyFetches()
must be executed first.
protected java.lang.String generateOrderByClause(BaseSearchProcessor.SearchContext ctx,
java.util.List<Sort> sorts)
protected java.lang.String generateWhereClause(BaseSearchProcessor.SearchContext ctx,
java.util.List<Filter> filters,
boolean isDisjunction)
protected java.lang.String filterToQL(BaseSearchProcessor.SearchContext ctx,
Filter filter)
protected java.lang.String generateSubquery(BaseSearchProcessor.SearchContext ctx,
java.lang.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-query
protected java.lang.String generateSimpleAllOrSome(BaseSearchProcessor.SearchContext ctx,
java.lang.String property,
Filter filter,
java.lang.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 java.lang.Object prepareValue(java.lang.Class<?> rootClass,
java.lang.String property,
java.lang.Object value,
boolean isCollection)
isCollection - true if the value is a collection of values, for
example with IN and NOT_IN operators.
protected Filter negate(Filter filter)
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 java.lang.String param(BaseSearchProcessor.SearchContext ctx,
java.lang.Object value)
protected java.lang.String getPathRef(BaseSearchProcessor.SearchContext ctx,
java.lang.String path)
protected java.lang.String[] splitPath(BaseSearchProcessor.SearchContext ctx,
java.lang.String path)
protected BaseSearchProcessor.AliasNode getAlias(BaseSearchProcessor.SearchContext ctx,
java.lang.String path,
boolean setFetch)
protected java.util.List<Field> checkAndCleanFields(java.util.List<Field> fields)
protected java.util.List<java.lang.String> checkAndCleanFetches(java.util.List<java.lang.String> fetches)
protected java.util.List<Sort> checkAndCleanSorts(java.util.List<Sort> sorts)
protected java.util.List<Filter> checkAndCleanFilters(java.util.List<Filter> filters)
protected void securityCheckProperty(java.lang.String property)
securityCheck() to check a property string for
injection attack.
public Filter getFilterFromExample(java.lang.Object example)
public Filter getFilterFromExample(java.lang.Object example,
ExampleOptions options)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||