org.mmbase.storage.search.legacy
Class ConstraintParser

Package class diagram package ConstraintParser
java.lang.Object
  extended by org.mmbase.storage.search.legacy.ConstraintParser

public class ConstraintParser
extends Object

Parser, tries to parse a SQL-search-condition for a query to a Constraint object.

This class is provided for the sole purpose of alignment of old code with the new SearchQuery framework, and should not be called by new code.

A SQL-search-condition can be one of these forms:

A simple-SQL-search-condition string can be of one of these forms: A field can be one of these forms: A value can be one of these forms: A string-search-condition can be of this form: searchterms can be of one of these forms: 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 StringSearchConstraint for more info on string-search constraints.

A search condition that is not of one of these forms will be converted to a 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.

Since:
MMBase-1.7
Version:
$Id: ConstraintParser.java 45316 2011-02-18 20:47:28Z michiel $
Author:
Rob van Maris

Field Summary
protected static QueryContext BRIDGE
           
protected  QueryContext queryContext
           
 
Constructor Summary
ConstraintParser(Query query)
           
ConstraintParser(QueryContext queryContext, SearchQuery query)
          Creates a new instance of ConstraintParser
 
Method Summary
static String convertClauseToDBS(QueryContext queryContext, String constraints)
          Converts a constraint by turning all 'quoted' fields into database supported fields.
static StepField getField(QueryContext queryContext, String token, List<? extends Step> steps)
          Creates StepField corresponding to field indicated by token, of one of the specified steps.
(package private) static StepField getField(QueryContext queryContext, String token, List<BasicStep> steps, SearchQuery query)
          Creates StepField corresponding to field indicated by token, of one of the specified steps.
(package private)  StepField getField(String token)
          Parses a field string, and produces a corresponding StepField object.
static StepField getField(String token, List<? extends Step> steps)
           
(package private)  BasicConstraint parseCondition(ListIterator<String> iTokens)
          Parses SQL-search-condition string from list of tokens, and produces a corresponding BasicConstraint object.
(package private)  BasicConstraint parseSimpleCondition(ListIterator<String> iTokens)
          Parses a simple-SQL-search-condition string from list of tokens, and produces a corresponding BasicConstraint object.
(package private) 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.
 Constraint toConstraint(String sqlConstraint)
          Parses SQL-search-condition, and produces a corresponding Constraint object.
(package private) 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.
static boolean validConstraints(String constraints)
          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)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

queryContext

protected final QueryContext queryContext

BRIDGE

protected static final QueryContext BRIDGE
Constructor Detail

ConstraintParser

public ConstraintParser(QueryContext queryContext,
                        SearchQuery query)
Creates a new instance of ConstraintParser

Parameters:
query -

ConstraintParser

public ConstraintParser(Query query)
Method Detail

convertClauseToDBS

public static String convertClauseToDBS(QueryContext queryContext,
                                        String constraints)
Converts a constraint by turning all 'quoted' fields into database supported fields. XXX: todo: escape characters for '[' and ']'.

Parameters:
constraints - constraints to convert
Returns:
converted constraint
Since:
MMBase-1.8.1 (moved from org.mmbase.bridge.util.Queries)

validConstraints

public static boolean validConstraints(String constraints)
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
Returns:
is valid constraint
Since:
MMBase-1.8.1 (moved from org.mmbase.bridge.util.Queries)

parseValue

static Object parseValue(Iterator<String> iTokens,
                         StepField field)
                  throws NumberFormatException
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.
field - The field.
Returns:
A String or Double object representing the 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)
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.
Returns:
List of tokens.

getField

public static StepField getField(QueryContext queryContext,
                                 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:

Parameters:
token - The token.
steps - The steps.
Returns:
The field.

getField

public static StepField getField(String token,
                                 List<? extends Step> steps)

getField

static StepField getField(QueryContext queryContext,
                          String token,
                          List<BasicStep> steps,
                          SearchQuery query)
Creates StepField corresponding to field indicated by token, of one of the specified steps.

A field can be one of these forms:

Parameters:
token - The token.
steps - The steps.
query - The used query
Returns:
The field.
Since:
MMBase-1.7.1

toConstraint

public Constraint toConstraint(String sqlConstraint)
Parses SQL-search-condition, and produces a corresponding Constraint object.

See above for the format of a SQL-search-condition.

Parameters:
sqlConstraint - The non-null SQL constraint string.
Returns:
The constraint.

getField

StepField getField(String token)
Parses a field string, and produces a corresponding StepField object.

See above for the format of a field

Parameters:
token - The token.
Returns:
The field.

parseCondition

BasicConstraint parseCondition(ListIterator<String> iTokens)
Parses SQL-search-condition string from list of tokens, and produces a corresponding BasicConstraint object.

See above for the format of a SQL-search-condition

Parameters:
iTokens - Tokens iterator, must be positioned before the (first) token representing the condition.
Returns:
The constraint.

parseSimpleCondition

BasicConstraint parseSimpleCondition(ListIterator<String> iTokens)
Parses a simple-SQL-search-condition string from list of tokens, and produces a corresponding BasicConstraint object.

See above for the format of a simple-SQL-search-condition

Parameters:
iTokens - Tokens iterator, must be positioned before the (first) token representing the condition.
Returns:
The constraint.


MMBase2 Bridge 2.0-SNAPSHOT - 2013-03-30T06:34