| java.lang.Object org.mmbase.storage.search.legacy.ConstraintParser
ConstraintParser | public class ConstraintParser (Code) | | Parser, tries to parse a SQL-search-condition for a query to a
org.mmbase.storage.search.Constraint Constraint object.
This class is provided for the sole purpose of alignment of old code with
the new
org.mmbase.storage.search.SearchQuery SearchQuery framework,
and should not be called by new code.
A SQL-search-condition can be one of these forms:
- [NOT] (SQL-search-condition)
- [NOT] simple-SQL-search-condition
- SQL-search-condition AND SQL-search-condition
- SQL-search-condition OR SQL-search-condition
A simple-SQL-search-condition string can be of one of these forms:
- field [NOT] LIKE value
- UPPER(field) [NOT] LIKE value
- LOWER(field) [NOT] LIKE value
- field IS [NOT] NULL
- field [NOT] IN
(value1, value2, ..)
- field [NOT] BETWEEN value1 AND value2
- UPPER(field) [NOT] BETWEEN value1 AND value2
- LOWER(field) [NOT] BETWEEN value1 AND value2
- field = value
- field = field2
- UPPER(field) = value
- LOWER(field) = value
- field == value
- field == field2
- field <= value
- field <= field2
- field < value
- field < field2
- field >= value
- field >= field2
- field > value
- field > field2
- field <> value
- field <> field2
- field != value
- field != field2
- string-search-condition
A field can be one of these forms:
- stepalias.fieldname
- fieldname (only when the query has just one step).
A value can be one of these forms:
- string between single quotes for string fields, example:
'A string value'
- numerical value for numerical fields, example:
123.456
- numerical value between single quotes for numerical fields, example"
'123.456'
A string-search-condition can be of this form:
- StringSearch(field,PHRASE|PROXIMITY|WORD,
FUZZY|LITERAL|SYNONYM,
searchterms,
casesensitive)
[.set(FUZZINESS,fuzziness)]
[.set(PROXIMITY_LIMIT,proximity)]
searchterms can be of one of these forms:
- 'term1'
- "term1"
- 'term1 term2'
- "term1 term2"
- etc...
casesensitive can be of one on these forms:
fuzziness must be a float value between 0.0 and 1.0,
proximity must be a int value > 0
See
org.mmbase.storage.search.StringSearchConstraintStringSearchConstraint for more info on string-search constraints.
A search condition that is not of one of these forms will be converted to a
org.mmbase.storage.search.LegacyConstraint LegacyConstraint , i.e.
in that case the search condition string will not be interpreted, but
instead be used "as-is".
Each time this occurs is logged with priority service to
category org.mmbase.storage.search.legacyConstraintParser.fallback .
author: Rob van Maris version: $Id: ConstraintParser.java,v 1.35 2007/11/28 10:17:47 michiel Exp $ since: MMBase-1.7 |
Method Summary | |
public static String | convertClauseToDBS(String constraints) Converts a constraint by turning all 'quoted' fields into
database supported fields. | public static StepField | getField(String token, List<? extends Step> steps) Creates StepField corresponding to field indicated by
token, of one of the specified steps.
A field can be one of these forms:
- stepalias.fieldname
- [stepalias.fieldname]
- fieldname (only when just one step is specified).
- [fieldname] (only when just one step is specified).
Parameters: token - The token. Parameters: steps - The steps. | static StepField | getField(String token, List<BasicStep> steps, SearchQuery query) Creates StepField corresponding to field indicated by
token, of one of the specified steps. | StepField | getField(String token) Parses a field string, and produces a corresponding
StepField object.
See
ConstraintParser above for the format of a
field
Parameters: token - The token. | BasicConstraint | parseCondition(ListIterator<String> iTokens) Parses SQL-search-condition string from list of tokens, and
produces a corresponding BasicConstraint object.
See
ConstraintParser above for the format of a
SQL-search-condition
Parameters: iTokens - Tokens iterator, must be positioned before the (first)token representing the condition. | BasicConstraint | parseSimpleCondition(ListIterator<String> iTokens) Parses a simple-SQL-search-condition string from list of tokens,
and produces a corresponding BasicConstraint object.
See
ConstraintParser above for the format of a
simple-SQL-search-condition
Parameters: iTokens - Tokens iterator, must be positioned before the (first)token representing the condition. | static Object | parseValue(Iterator<String> iTokens, StepField field) Parses string or numerical value from list of tokens, to match the type
of the specified field.
If the first token is not "'", it is interpreted as a numerical value,
otherwise it is required to be the first token of the sequence
"'", "value", "'", representing a string value for string fields, or
a numerical value for numerical fields.
Parameters: iTokens - Tokens iterator, must be positioned before the (first)token representing the value. Parameters: field - The field. | public Constraint | toConstraint(String sqlConstraint) Parses SQL-search-condition, and produces a corresponding
org.mmbase.storage.search.Constraint Constraint object.
See
ConstraintParser above for the format of a
SQL-search-condition.
Parameters: sqlConstraint - The non-null SQL constraint string. | static List<String> | tokenize(String sqlConstraint) Parses SQL search condition string into separate tokens, discarding
white spaces, concatenating strings between (single/double) quotes,
and replacing escaped (single/double) quotes in strings by the
original character.
Parameters: sqlConstraint - The SQL constraint string. | public static boolean | validConstraints(String constraints) |
ConstraintParser | public ConstraintParser(SearchQuery query)(Code) | | Creates a new instance of ConstraintParser
Parameters: query - |
convertClauseToDBS | public static String convertClauseToDBS(String constraints)(Code) | | Converts a constraint by turning all 'quoted' fields into
database supported fields.
XXX: todo: escape characters for '[' and ']'.
Parameters: constraints - constraints to convert converted constraint since: MMBase-1.8.1 (moved from org.mmbase.bridge.util.Queries) |
getField | public static StepField getField(String token, List<? extends Step> steps)(Code) | | Creates StepField corresponding to field indicated by
token, of one of the specified steps.
A field can be one of these forms:
- stepalias.fieldname
- [stepalias.fieldname]
- fieldname (only when just one step is specified).
- [fieldname] (only when just one step is specified).
Parameters: token - The token. Parameters: steps - The steps. The field. |
getField | static StepField getField(String token, List<BasicStep> steps, SearchQuery query)(Code) | | Creates StepField corresponding to field indicated by
token, of one of the specified steps.
A field can be one of these forms:
- stepalias.fieldname
- [stepalias.fieldname]
- fieldname (only when just one step is specified, or query is an instance of NodeQuery).
- [fieldname] (only when just one step is specified, or query is an instance of NodeQuery).
Parameters: token - The token. Parameters: steps - The steps. Parameters: query - The used query The field. since: MMBase-1.7.1 |
getField | StepField getField(String token)(Code) | | Parses a field string, and produces a corresponding
StepField object.
See
ConstraintParser above for the format of a
field
Parameters: token - The token. The field. |
parseCondition | BasicConstraint parseCondition(ListIterator<String> iTokens)(Code) | | Parses SQL-search-condition string from list of tokens, and
produces a corresponding BasicConstraint object.
See
ConstraintParser above for the format of a
SQL-search-condition
Parameters: iTokens - Tokens iterator, must be positioned before the (first)token representing the condition. The constraint. |
parseSimpleCondition | BasicConstraint parseSimpleCondition(ListIterator<String> iTokens)(Code) | | Parses a simple-SQL-search-condition string from list of tokens,
and produces a corresponding BasicConstraint object.
See
ConstraintParser above for the format of a
simple-SQL-search-condition
Parameters: iTokens - Tokens iterator, must be positioned before the (first)token representing the condition. The constraint. |
parseValue | static Object parseValue(Iterator<String> iTokens, StepField field) throws NumberFormatException(Code) | | Parses string or numerical value from list of tokens, to match the type
of the specified field.
If the first token is not "'", it is interpreted as a numerical value,
otherwise it is required to be the first token of the sequence
"'", "value", "'", representing a string value for string fields, or
a numerical value for numerical fields.
Parameters: iTokens - Tokens iterator, must be positioned before the (first)token representing the value. Parameters: field - The field. A String or Double object representingthe value. throws: NumberFormatException - when the first token is not (the start of)a valid value expression (it may be a field instead). |
tokenize | static List<String> tokenize(String sqlConstraint)(Code) | | Parses SQL search condition string into separate tokens, discarding
white spaces, concatenating strings between (single/double) quotes,
and replacing escaped (single/double) quotes in strings by the
original character.
Parameters: sqlConstraint - The SQL constraint string. List of tokens. |
validConstraints | public static boolean validConstraints(String constraints)(Code) | | returns false, when escaping wasnt closed, or when a ";" was found outside a escaped part (to prefent spoofing)
This is used by createQuery (i wonder if it still makes sense)
Parameters: constraints - constraint to check is valid constraint since: MMBase-1.8.1 (moved from org.mmbase.bridge.util.Queries) |
|
|