com.trg.search
Class Search

java.lang.Object
  extended by com.trg.search.Search
All Implemented Interfaces:
IMutableSearch, ISearch, java.io.Serializable

public class Search
extends java.lang.Object
implements IMutableSearch, java.io.Serializable

A convenient fully-featured implementation of ISearch and IMutableSearch for general use in Java code.

Author:
dwolverton
See Also:
Serialized Form

Field Summary
protected  boolean disjunction
           
protected  boolean distinct
           
protected  java.util.List<java.lang.String> fetches
           
protected  java.util.List<Field> fields
           
protected  java.util.List<Filter> filters
           
protected  int firstResult
           
protected  int maxResults
           
protected  int page
           
protected  int resultMode
           
protected  java.lang.Class<?> searchClass
           
protected  java.util.List<Sort> sorts
           
 
Fields inherited from interface com.trg.search.ISearch
RESULT_ARRAY, RESULT_AUTO, RESULT_LIST, RESULT_MAP, RESULT_SINGLE
 
Constructor Summary
Search()
           
Search(java.lang.Class<?> searchClass)
           
 
Method Summary
 Search addFetch(java.lang.String property)
           
 Search addFetches(java.lang.String... properties)
           
 Search addField(Field field)
           
 Search addField(java.lang.String property)
          If this field is used with resultMode == RESULT_MAP, the property will also be used as the key for this value in the map.
 Search addField(java.lang.String property, int operator)
          If this field is used with resultMode == RESULT_MAP, the property will also be used as the key for this value in the map.
 Search addField(java.lang.String property, int operator, java.lang.String key)
          If this field is used with resultMode == RESULT_MAP, the key will be used as the key for this value in the map.
 Search addField(java.lang.String property, java.lang.String key)
          If this field is used with resultMode == RESULT_MAP, the key will be used as the key for this value in the map.
 Search addFields(Field... fields)
           
 Search addFilter(Filter filter)
           
 Search addFilterAll(java.lang.String property, Filter filter)
          Add a filter that uses the ALL operator.
 Search addFilterAnd(Filter... filters)
          Add a filter that uses the AND operator.
 Search addFilterEmpty(java.lang.String property)
          Add a filter that uses the IS EMPTY operator.
 Search addFilterEqual(java.lang.String property, java.lang.Object value)
          Add a filter that uses the == operator.
 Search addFilterGreaterOrEqual(java.lang.String property, java.lang.Object value)
          Add a filter that uses the >= operator.
 Search addFilterGreaterThan(java.lang.String property, java.lang.Object value)
          Add a filter that uses the > operator.
 Search addFilterILike(java.lang.String property, java.lang.String value)
          Add a filter that uses the ILIKE operator.
 Search addFilterIn(java.lang.String property, java.util.Collection<?> value)
          Add a filter that uses the IN operator.
 Search addFilterIn(java.lang.String property, java.lang.Object... value)
          Add a filter that uses the IN operator.
 Search addFilterLessOrEqual(java.lang.String property, java.lang.Object value)
          Add a filter that uses the <= operator.
 Search addFilterLessThan(java.lang.String property, java.lang.Object value)
          Add a filter that uses the < operator.
 Search addFilterLike(java.lang.String property, java.lang.String value)
          Add a filter that uses the LIKE operator.
 Search addFilterNone(java.lang.String property, Filter filter)
          Add a filter that uses the NONE operator.
 Search addFilterNot(Filter filter)
          Add a filter that uses the NOT operator.
 Search addFilterNotEmpty(java.lang.String property)
          Add a filter that uses the IS NOT EMPTY operator.
 Search addFilterNotEqual(java.lang.String property, java.lang.Object value)
          Add a filter that uses the !
 Search addFilterNotIn(java.lang.String property, java.util.Collection<?> value)
          Add a filter that uses the NOT IN operator.
 Search addFilterNotIn(java.lang.String property, java.lang.Object... value)
          Add a filter that uses the NOT IN operator.
 Search addFilterNotNull(java.lang.String property)
          Add a filter that uses the IS NOT NULL operator.
 Search addFilterNull(java.lang.String property)
          Add a filter that uses the IS NULL operator.
 Search addFilterOr(Filter... filters)
          Add a filter that uses the OR operator.
 Search addFilters(Filter... filters)
           
 Search addFilterSome(java.lang.String property, Filter filter)
          Add a filter that uses the SOME operator.
 Search addSort(Sort sort)
           
 Search addSort(java.lang.String property, boolean desc)
          Add sort by property.
 Search addSort(java.lang.String property, boolean desc, boolean ignoreCase)
          Add sort by property.
 Search addSortAsc(java.lang.String property)
          Add ascending sort by property
 Search addSortAsc(java.lang.String property, boolean ignoreCase)
          Add ascending sort by property
 Search addSortDesc(java.lang.String property)
          Add descending sort by property
 Search addSortDesc(java.lang.String property, boolean ignoreCase)
          Add descending sort by property
 Search addSorts(Sort... sorts)
           
 void clear()
           
 void clearFetches()
           
 void clearFields()
           
 void clearFilters()
           
 void clearPaging()
           
 void clearSorts()
           
 Search copy()
          Create a copy of this search.
 boolean equals(java.lang.Object obj)
           
 java.util.List<java.lang.String> getFetches()
           
 java.util.List<Field> getFields()
           
 java.util.List<Filter> getFilters()
           
 int getFirstResult()
          Zero based index of first result record to return.
 int getMaxResults()
          The maximum number of records to return.
 int getPage()
          Zero based index of the page of records to return.
 int getResultMode()
          Result mode tells the search what form to use for the results.
 java.lang.Class<?> getSearchClass()
           
 java.util.List<Sort> getSorts()
           
 int hashCode()
           
 boolean isDisjunction()
           
 boolean isDistinct()
           
 void removeFetch(java.lang.String property)
           
 void removeField(Field field)
           
 void removeField(java.lang.String property)
           
 void removeField(java.lang.String property, java.lang.String key)
           
 void removeFilter(Filter filter)
           
 void removeFiltersOnProperty(java.lang.String property)
          Remove all filters on the given property.
 void removeSort(Sort sort)
           
 void removeSort(java.lang.String property)
           
 Search setDisjunction(boolean disjunction)
          Filters added to a search are "ANDed" together if this is false (default) and "ORed" if it is set to true.
 IMutableSearch setDistinct(boolean distinct)
           
 Search setFetches(java.util.List<java.lang.String> fetches)
           
 Search setFields(java.util.List<Field> fields)
           
 Search setFilters(java.util.List<Filter> filters)
           
 Search setFirstResult(int firstResult)
           
 Search setMaxResults(int maxResults)
           
 Search setPage(int page)
           
 Search setResultMode(int resultMode)
           
 Search setSearchClass(java.lang.Class<?> searchClass)
           
 Search setSorts(java.util.List<Sort> sorts)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

firstResult

protected int firstResult

maxResults

protected int maxResults

page

protected int page

searchClass

protected java.lang.Class<?> searchClass

filters

protected java.util.List<Filter> filters

disjunction

protected boolean disjunction

sorts

protected java.util.List<Sort> sorts

fields

protected java.util.List<Field> fields

distinct

protected boolean distinct

fetches

protected java.util.List<java.lang.String> fetches

resultMode

protected int resultMode
Constructor Detail

Search

public Search()

Search

public Search(java.lang.Class<?> searchClass)
Method Detail

setSearchClass

public Search setSearchClass(java.lang.Class<?> searchClass)
Specified by:
setSearchClass in interface IMutableSearch

getSearchClass

public java.lang.Class<?> getSearchClass()
Specified by:
getSearchClass in interface ISearch

addFilter

public Search addFilter(Filter filter)

addFilters

public Search addFilters(Filter... filters)

addFilterEqual

public Search addFilterEqual(java.lang.String property,
                             java.lang.Object value)
Add a filter that uses the == operator.


addFilterGreaterOrEqual

public Search addFilterGreaterOrEqual(java.lang.String property,
                                      java.lang.Object value)
Add a filter that uses the >= operator.


addFilterGreaterThan

public Search addFilterGreaterThan(java.lang.String property,
                                   java.lang.Object value)
Add a filter that uses the > operator.


addFilterIn

public Search addFilterIn(java.lang.String property,
                          java.util.Collection<?> value)
Add a filter that uses the IN operator.


addFilterIn

public Search addFilterIn(java.lang.String property,
                          java.lang.Object... value)
Add a filter that uses the IN operator.

This takes a variable number of parameters. Any number of values can be specified.


addFilterNotIn

public Search addFilterNotIn(java.lang.String property,
                             java.util.Collection<?> value)
Add a filter that uses the NOT IN operator.


addFilterNotIn

public Search addFilterNotIn(java.lang.String property,
                             java.lang.Object... value)
Add a filter that uses the NOT IN operator.

This takes a variable number of parameters. Any number of values can be specified.


addFilterLessOrEqual

public Search addFilterLessOrEqual(java.lang.String property,
                                   java.lang.Object value)
Add a filter that uses the <= operator.


addFilterLessThan

public Search addFilterLessThan(java.lang.String property,
                                java.lang.Object value)
Add a filter that uses the < operator.


addFilterLike

public Search addFilterLike(java.lang.String property,
                            java.lang.String value)
Add a filter that uses the LIKE operator.


addFilterILike

public Search addFilterILike(java.lang.String property,
                             java.lang.String value)
Add a filter that uses the ILIKE operator.


addFilterNotEqual

public Search addFilterNotEqual(java.lang.String property,
                                java.lang.Object value)
Add a filter that uses the != operator.


addFilterNull

public Search addFilterNull(java.lang.String property)
Add a filter that uses the IS NULL operator.


addFilterNotNull

public Search addFilterNotNull(java.lang.String property)
Add a filter that uses the IS NOT NULL operator.


addFilterEmpty

public Search addFilterEmpty(java.lang.String property)
Add a filter that uses the IS EMPTY operator.


addFilterNotEmpty

public Search addFilterNotEmpty(java.lang.String property)
Add a filter that uses the IS NOT EMPTY operator.


addFilterAnd

public Search addFilterAnd(Filter... filters)
Add a filter that uses the AND operator.

This takes a variable number of parameters. Any number of Filter s can be specified.


addFilterOr

public Search addFilterOr(Filter... filters)
Add a filter that uses the OR operator.

This takes a variable number of parameters. Any number of Filter s can be specified.


addFilterNot

public Search addFilterNot(Filter filter)
Add a filter that uses the NOT operator.


addFilterSome

public Search addFilterSome(java.lang.String property,
                            Filter filter)
Add a filter that uses the SOME operator.


addFilterAll

public Search addFilterAll(java.lang.String property,
                           Filter filter)
Add a filter that uses the ALL operator.


addFilterNone

public Search addFilterNone(java.lang.String property,
                            Filter filter)
Add a filter that uses the NONE operator.


removeFilter

public void removeFilter(Filter filter)

removeFiltersOnProperty

public void removeFiltersOnProperty(java.lang.String property)
Remove all filters on the given property.


clearFilters

public void clearFilters()

isDisjunction

public boolean isDisjunction()
Specified by:
isDisjunction in interface ISearch

setDisjunction

public Search setDisjunction(boolean disjunction)
Filters added to a search are "ANDed" together if this is false (default) and "ORed" if it is set to true.

Specified by:
setDisjunction in interface IMutableSearch

addSort

public Search addSort(Sort sort)

addSorts

public Search addSorts(Sort... sorts)

addSortAsc

public Search addSortAsc(java.lang.String property)
Add ascending sort by property


addSortAsc

public Search addSortAsc(java.lang.String property,
                         boolean ignoreCase)
Add ascending sort by property


addSortDesc

public Search addSortDesc(java.lang.String property)
Add descending sort by property


addSortDesc

public Search addSortDesc(java.lang.String property,
                          boolean ignoreCase)
Add descending sort by property


addSort

public Search addSort(java.lang.String property,
                      boolean desc)
Add sort by property. Ascending if desc == false, descending if desc == true.


addSort

public Search addSort(java.lang.String property,
                      boolean desc,
                      boolean ignoreCase)
Add sort by property. Ascending if desc == false, descending if desc == true.


removeSort

public void removeSort(Sort sort)

removeSort

public void removeSort(java.lang.String property)

clearSorts

public void clearSorts()

addField

public Search addField(Field field)

addFields

public Search addFields(Field... fields)

addField

public Search addField(java.lang.String property)
If this field is used with resultMode == RESULT_MAP, the property will also be used as the key for this value in the map.


addField

public Search addField(java.lang.String property,
                       java.lang.String key)
If this field is used with resultMode == RESULT_MAP, the key will be used as the key for this value in the map.


addField

public Search addField(java.lang.String property,
                       int operator)
If this field is used with resultMode == RESULT_MAP, the property will also be used as the key for this value in the map.


addField

public Search addField(java.lang.String property,
                       int operator,
                       java.lang.String key)
If this field is used with resultMode == RESULT_MAP, the key will be used as the key for this value in the map.


removeField

public void removeField(Field field)

removeField

public void removeField(java.lang.String property)

removeField

public void removeField(java.lang.String property,
                        java.lang.String key)

clearFields

public void clearFields()

isDistinct

public boolean isDistinct()
Specified by:
isDistinct in interface ISearch

setDistinct

public IMutableSearch setDistinct(boolean distinct)
Specified by:
setDistinct in interface IMutableSearch

getResultMode

public int getResultMode()
Description copied from interface: ISearch
Result mode tells the search what form to use for the results. Options include RESULT_AUTO, RESULT_ARRAY, RESULT_LIST , RESULT_MAP and RESULT_SINGLE .

Specified by:
getResultMode in interface ISearch
See Also:
ISearch.RESULT_AUTO, ISearch.RESULT_ARRAY, ISearch.RESULT_LIST, ISearch.RESULT_MAP, ISearch.RESULT_SINGLE

setResultMode

public Search setResultMode(int resultMode)
Specified by:
setResultMode in interface IMutableSearch

addFetch

public Search addFetch(java.lang.String property)

addFetches

public Search addFetches(java.lang.String... properties)

removeFetch

public void removeFetch(java.lang.String property)

clearFetches

public void clearFetches()

clear

public void clear()

getFirstResult

public int getFirstResult()
Description copied from interface: ISearch
Zero based index of first result record to return.

<= 0 for unspecified value.

Specified by:
getFirstResult in interface ISearch

setFirstResult

public Search setFirstResult(int firstResult)
Specified by:
setFirstResult in interface IMutableSearch

getPage

public int getPage()
Description copied from interface: ISearch
Zero based index of the page of records to return. The size of a page is determined by maxResults. If both page and maxResults are specified (i.e. > 0), the first result returned is calculated by page * maxResults.

firstResult has precedence over page. So if firstResult is specified (i.e. > 0), page is ignored.

<= 0 for unspecified value.

Specified by:
getPage in interface ISearch

setPage

public Search setPage(int page)
Specified by:
setPage in interface IMutableSearch

getMaxResults

public int getMaxResults()
Description copied from interface: ISearch
The maximum number of records to return. Also used as page size when calculating the first record to return based on page.

<= 0 for unspecified value.

Specified by:
getMaxResults in interface ISearch

setMaxResults

public Search setMaxResults(int maxResults)
Specified by:
setMaxResults in interface IMutableSearch

clearPaging

public void clearPaging()

copy

public Search copy()
Create a copy of this search. All collections are copied into new collections, but them items in those collections are not duplicated; they still point to the same objects.


equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getFilters

public java.util.List<Filter> getFilters()
Specified by:
getFilters in interface ISearch

setFilters

public Search setFilters(java.util.List<Filter> filters)
Specified by:
setFilters in interface IMutableSearch

getSorts

public java.util.List<Sort> getSorts()
Specified by:
getSorts in interface ISearch

setSorts

public Search setSorts(java.util.List<Sort> sorts)
Specified by:
setSorts in interface IMutableSearch

getFields

public java.util.List<Field> getFields()
Specified by:
getFields in interface ISearch

setFields

public Search setFields(java.util.List<Field> fields)
Specified by:
setFields in interface IMutableSearch

getFetches

public java.util.List<java.lang.String> getFetches()
Specified by:
getFetches in interface ISearch

setFetches

public Search setFetches(java.util.List<java.lang.String> fetches)
Specified by:
setFetches in interface IMutableSearch


Copyright © 2008-2010 eBM WebSourcing. All Rights Reserved.