public class AdvancedCriteria
extends java.lang.Object
The server-side AdvancedCriteria handling feature is only available with the Power and Enterprise Editions of SmartClient; the Pro Edition is limited to ordinary criteria handling on the server side)
AdvancedCriteria objects can be created directly in java. For example:
AdvancedCriteria criteria = new AdvancedCriteria(DefaultOperators.And, new Criterion[]{ new SimpleCriterion("countryCode", "contains", "C"), new SimpleCriterion("countryName", "startsWith", "C") });
In addition to building a raw AdvancedCriteria object as described above, the DataSource.parseAdvancedCriteria(Map)
and Evaluator.parseAdvancedCriteria(Map)
methods may be used to create AdvancedCriteria based on simple fieldName / value mappings.
Also an AdvancedCriteria instance can be retrieved from a DSRequest via DSRequest.getAdvancedCriteria()
These same AdvancedCriteria objects can be directly created server side, and applied to a DSRequest via DSRequest.setAdvancedCriteria(AdvancedCriteria)
.
Modifier and Type | Field and Description |
---|---|
static java.lang.String | CONSTRUCTOR_NAME _constructor attribute value |
Constructor and Description |
---|
AdvancedCriteria(Criterion _criteria) Convert existing Criterion to AdvancedCriteria. |
AdvancedCriteria(Operator operator, Criterion[] criteria) Combine an array of criterion into AdvancedCriteria instance using operator. |
AdvancedCriteria(java.lang.String operator, Criterion[] criteria) Combine an array of criterion into AdvancedCriteria instance using operator in the format of String. |
Modifier and Type | Method and Description |
---|---|
Criterion | asCriterion() Convert AdvancedCriteria into Criterion format. |
void | convertRelativeDates() Converts any relative dates in this AdvancedCriteria into absolute dates with now as the relative point in time. |
void | convertRelativeDates(DataSource ds) Converts any relative dates in this AdvancedCriteria into absolute dates with now as the relative point in time. |
void | convertRelativeDates(java.util.Date baseDate) Converts any relative dates in this AdvancedCriteria into absolute dates with now as the relative point in time. |
void | convertRelativeDates(java.util.Date baseDate, DataSource ds) Converts any relative dates in this AdvancedCriteria into absolute dates with now as the relative point in time. |
static AdvancedCriteria | decodeClientCriteria(java.lang.String clientCriteria) Decodes a client side criteria which has been serialized for storage. |
static AdvancedCriteria | fromCollections(java.lang.Object criteria) Creates an AdvancedCriteria object from Java collections. |
static AdvancedCriteria | fromCollections(java.lang.Object criteria, OperatorBase operator) Creates an AdvancedCriteria object from Java collections. |
static AdvancedCriteria | fromCollections(java.lang.Object criteria, java.lang.String operator) Creates an AdvancedCriteria object from Java collections. |
java.util.Map | getCriteriaAsMap() Convert AdvancedCriteria into Map object. |
Criterion | getFieldCriterion(java.lang.String fieldName) Returns the depth-first match of a criterion matching the given fieldName. |
java.util.Set | getFieldCriterions(java.lang.String fieldName) Returns all criterions matching the given fieldName. |
java.lang.Object | getFieldValue(java.lang.String fieldName) Returns the depth-first value of a criterion matching the given fieldName. |
public static final java.lang.String CONSTRUCTOR_NAME
public AdvancedCriteria(Criterion _criteria)
_criteria
- - criteria to use in AdvancedCriteria.public AdvancedCriteria(Operator operator, Criterion[] criteria)
AdvancedCriteria criteria = new AdvancedCriteria(DefaultOperators.And, new Criterion[]{ new SimpleCriterion("countryCode", "contains", "C"), new SimpleCriterion("countryName", "startsWith", "C") });You can pass another AdvancedCriteria in the array of criteria by using
AdvancedCriteria.asCriterion()
method.operator
- - operator that will be used to combine criteria.criteria
- - criteria that will be combined.public AdvancedCriteria(java.lang.String operator, Criterion[] criteria)
AdvancedCriteria criteria = new AdvancedCriteria("and", new Criterion[]{ new SimpleCriterion("countryCode", "contains", "C"), new SimpleCriterion("countryName", "startsWith", "C") });You can pass another AdvancedCriteria in the array of criteria by using
AdvancedCriteria.asCriterion()
method.operator
- - operator that will be used to combine criteria.criteria
- - criterias that will be combined.public java.lang.Object getFieldValue(java.lang.String fieldName)
fieldName
- - name of field to search value for.public Criterion getFieldCriterion(java.lang.String fieldName)
fieldName
- - name of field to search value for.public void convertRelativeDates()
AdvancedCriteria.convertRelativeDates(DataSource)
See DataSource.convertRelativeDates(Criterion)
for more information on relative date conversion.
public void convertRelativeDates(DataSource ds)
DataSource.convertRelativeDates(Criterion)
for more information on relative date conversion. Note that this API is able to distinguish between "date" and "datetime" fields, unlike AdvancedCriteria.convertRelativeDates()
.ds
- the DataSource associated with this AdvancedCriteria. The dataSource definition is used to determine whether a Java Date value should be treated as a logical "date" or a "datetime"DataSource.convertRelativeDates(Criterion)
public void convertRelativeDates(java.util.Date baseDate)
DataSource.convertRelativeDates(Criterion)
for more information on relative date conversion. Note that this API is not able to distinguish between "date" and "datetime" fields, so it may not convert values as you expect. If this causes a problem in your use case, consider using AdvancedCriteria.convertRelativeDates(Date, DataSource)
or DataSource.convertRelativeDates(Criterion, Date, DataSource)
baseDate
- the point in time to convert the relative dates against. If null, it will be defaulted to now.DataSource.convertRelativeDates(Criterion)
public void convertRelativeDates(java.util.Date baseDate, DataSource ds)
DataSource.convertRelativeDates(Criterion)
for more information on relative date conversion. Note that this API is able to distinguish between "date" and "datetime" fields, unlike AdvancedCriteria.convertRelativeDates(Date)
baseDate
- the point in time to convert the relative dates against. If null, it will be defaulted to now.ds
- the DataSource associated with this AdvancedCriteria. The dataSource definition is used to determine whether a Java Date value should be treated as a logical "date" or a "datetime"DataSource.convertRelativeDates(Criterion, Date, DataSource)
public static AdvancedCriteria decodeClientCriteria(java.lang.String clientCriteria) throws java.lang.Exception
clientCriteria
- a string of the encoded/serialized criteria to decode.java.lang.Exception
- if there is a problem parsing the client criteria.DataSource.convertRelativeDates(Criterion)
public java.util.Set getFieldCriterions(java.lang.String fieldName)
fieldName
- - name of field to search value for.public java.util.Map getCriteriaAsMap()
public static AdvancedCriteria fromCollections(java.lang.Object criteria)
You may pass collections reflecting simple or advanced criteria to this method.
If criteria were passed as simple Criteria this method will convert them to the more general AdvancedCriteria format by turning them into an AND Criterion containing one or more "equals" Criteria.
Note that AdvancedCriteria will only be able to be executed by the built-in server DataSources (JPA, Hibernate, SQL) in Power Edition and above.
criteria
- - criteria in java collections (nested maps) formatpublic static AdvancedCriteria fromCollections(java.lang.Object criteria, java.lang.String operator)
You may pass collections reflecting simple or advanced criteria to this method.
If criteria were passed as simple Criteria this method will convert them to the more general AdvancedCriteria format by turning them into an AND Criterion containing one or more Criteria with the operator specified by the operator argument to this method.
Note that AdvancedCriteria will only be able to be executed by the built-in server DataSources (JPA, Hibernate, SQL) in Power Edition and above.
criteria
- - criteria in java collections (nested maps) formatoperator
- - default operator to usepublic static AdvancedCriteria fromCollections(java.lang.Object criteria, OperatorBase operator)
You may pass collections reflecting simple or advanced criteria to this method.
If criteria were passed as simple Criteria this method will convert them to the more general AdvancedCriteria format by turning them into an AND Criterion containing one or more Criteria with the operator specified by the operator argument to this method.
Note that AdvancedCriteria will only be able to be executed by the built-in server DataSources (JPA, Hibernate, SQL) in Power Edition and above.
criteria
- - criteria in java collections (nested maps) formatoperator
- - default operator to usepublic Criterion asCriterion()