org.eobjects.metamodel.query
Class FilterItem

java.lang.Object
  extended by org.eobjects.metamodel.util.BaseObject
      extended by org.eobjects.metamodel.query.FilterItem
All Implemented Interfaces:
Serializable, Cloneable, IRowFilter, QueryItem

public class FilterItem
extends BaseObject
implements QueryItem, Cloneable, IRowFilter

Represents a filter in a query that resides either within a WHERE clause or a HAVING clause

See Also:
FilterClause, OperatorType, LogicalOperator, Serialized Form

Constructor Summary
FilterItem(FilterItem... items)
          Creates a compound filter item based on other filter items.
FilterItem(List<FilterItem> items)
          Creates a composite filter item based on other filter items.
FilterItem(LogicalOperator logicalOperator, FilterItem... items)
          Creates a compound filter item based on other filter items.
FilterItem(LogicalOperator logicalOperator, List<FilterItem> items)
          Creates a compound filter item based on other filter items.
FilterItem(SelectItem selectItem, OperatorType operator, Object operand)
          Creates a single filter item based on a SelectItem, an operator and an operand.
FilterItem(String expression)
          Creates a single unvalidated filter item based on a expression.
 
Method Summary
 boolean accept(Row row)
          Filters a row
static Object appendOperator(StringBuilder sb, Object operand, OperatorType operator)
           
protected  FilterItem clone()
           
protected  void decorateIdentity(List<Object> identifiers)
          Subclasses should implement this method and add all fields to the list that are to be included in equals(...) and hashCode() evaluation
 boolean evaluate(Row row)
          Does a "manual" evaluation, useful for CSV data and alike, where queries cannot be created.
 int getChildItemCount()
          Get the number of child items, if this is a compound filter item.
 FilterItem[] getChildItems()
          Gets the FilterItems that this filter item consists of, if it is a compound filter item.
 String getExpression()
           
 LogicalOperator getLogicalOperator()
           
 Object getOperand()
           
 OperatorType getOperator()
           
 int getOrItemCount()
          Deprecated. use getChildItemCount() instead.
 FilterItem[] getOrItems()
          Deprecated. use getChildItems() instead
 Query getQuery()
           
 SelectItem getSelectItem()
           
 boolean isCompoundFilter()
          Determines whether this FilterItem is a compound filter or not (ie. if it has child items or not)
 boolean isReferenced(Column column)
           
 FilterItem setQuery(Query query)
           
 String toSql()
           
 String toSql(boolean includeSchemaInColumnPaths)
          Parses the constraint as a SQL Where-clause item
 String toString()
           
 
Methods inherited from class org.eobjects.metamodel.util.BaseObject
classEquals, equals, hashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FilterItem

public FilterItem(SelectItem selectItem,
                  OperatorType operator,
                  Object operand)
           throws IllegalArgumentException
Creates a single filter item based on a SelectItem, an operator and an operand.

Parameters:
selectItem - the selectItem to put constraints on, cannot be null
operator - The operator to use. Can be OperatorType.EQUALS_TO, OperatorType.DIFFERENT_FROM, OperatorType.GREATER_THAN,OperatorType.LESS_THAN
operand - The operand. Can be a constant like null or a String, a Number, a Boolean, a Date, a Time, a DateTime. Or another SelectItem
Throws:
IllegalArgumentException - if the SelectItem is null or if the combination of operator and operand does not make sense.

FilterItem

public FilterItem(String expression)
Creates a single unvalidated filter item based on a expression. Expression based filters are typically NOT datastore-neutral but are available for special "hacking" needs. Expression based filters can only be used for JDBC based datastores since they are translated directly into SQL.

Parameters:
expression - An expression to use for the filter, for example "YEAR(my_date) = 2008".

FilterItem

public FilterItem(List<FilterItem> items)
Creates a composite filter item based on other filter items. Each provided filter items will be OR'ed meaning that if one of the evaluates as true, then the composite filter will be evaluated as true

Parameters:
items - a list of items to include in the composite

FilterItem

public FilterItem(LogicalOperator logicalOperator,
                  List<FilterItem> items)
Creates a compound filter item based on other filter items. Each provided filter item will be combined according to the LogicalOperator.

Parameters:
logicalOperator - the logical operator to apply
items - a list of items to include in the composite

FilterItem

public FilterItem(LogicalOperator logicalOperator,
                  FilterItem... items)
Creates a compound filter item based on other filter items. Each provided filter item will be combined according to the LogicalOperator.

Parameters:
logicalOperator - the logical operator to apply
items - an array of items to include in the composite

FilterItem

public FilterItem(FilterItem... items)
Creates a compound filter item based on other filter items. Each provided filter items will be OR'ed meaning that if one of the evaluates as true, then the compound filter will be evaluated as true

Parameters:
items - an array of items to include in the composite
Method Detail

getSelectItem

public SelectItem getSelectItem()

getOperator

public OperatorType getOperator()

getOperand

public Object getOperand()

getExpression

public String getExpression()

getQuery

public Query getQuery()
Specified by:
getQuery in interface QueryItem

getLogicalOperator

public LogicalOperator getLogicalOperator()

setQuery

public FilterItem setQuery(Query query)
Specified by:
setQuery in interface QueryItem

toSql

public String toSql()
Specified by:
toSql in interface QueryItem

toSql

public String toSql(boolean includeSchemaInColumnPaths)
Parses the constraint as a SQL Where-clause item

Specified by:
toSql in interface QueryItem

appendOperator

public static Object appendOperator(StringBuilder sb,
                                    Object operand,
                                    OperatorType operator)

evaluate

public boolean evaluate(Row row)
Does a "manual" evaluation, useful for CSV data and alike, where queries cannot be created.


clone

protected FilterItem clone()
Overrides:
clone in class Object

isReferenced

public boolean isReferenced(Column column)

decorateIdentity

protected void decorateIdentity(List<Object> identifiers)
Description copied from class: BaseObject
Subclasses should implement this method and add all fields to the list that are to be included in equals(...) and hashCode() evaluation

Specified by:
decorateIdentity in class BaseObject

getOrItems

@Deprecated
public FilterItem[] getOrItems()
Deprecated. use getChildItems() instead

Gets the FilterItems that this filter item consists of, if it is a compound filter item.

Returns:

getOrItemCount

@Deprecated
public int getOrItemCount()
Deprecated. use getChildItemCount() instead.

Gets the number of child items, if this is a compound filter item.

Returns:

getChildItemCount

public int getChildItemCount()
Get the number of child items, if this is a compound filter item.

Returns:

getChildItems

public FilterItem[] getChildItems()
Gets the FilterItems that this filter item consists of, if it is a compound filter item.

Returns:

isCompoundFilter

public boolean isCompoundFilter()
Determines whether this FilterItem is a compound filter or not (ie. if it has child items or not)

Returns:

toString

public String toString()
Specified by:
toString in interface QueryItem
Overrides:
toString in class BaseObject

accept

public boolean accept(Row row)
Description copied from interface: IRowFilter
Filters a row

Specified by:
accept in interface IRowFilter
Returns:
true if the row is valid according to the filter


Copyright © 2007-2013. All Rights Reserved.