com.apelon.modules.dts.editor.tql
Class TQLFunctionAdapter

java.lang.Object
  extended by com.apelon.modules.dts.editor.tql.TQLFunctionAdapter
All Implemented Interfaces:
TQLFunction

public abstract class TQLFunctionAdapter
extends java.lang.Object
implements TQLFunction

Basic implementation of a TQLFunction. User functions can extend this class to get default behaviors. isAggregator and forceFullSearch return false. validateArgument returns the empty string (all arguments are accepted). At a minimum, the getName and extractValues methods must be overridden. Includes a helper method for extracting the default string value of an attribute.

Copyright (c) 2013 Apelon, Inc. All rights reserved.

Since:
4.0

Constructor Summary
TQLFunctionAdapter()
           
 
Method Summary
protected  java.lang.String extractValue(java.lang.Object obj, TQLField field)
          Return the default string value of a DTS Attribute, e.g.
 java.lang.String[] extractValues(java.lang.Object[] objs, TQLField field)
          Return the result(s) of the function as applied to the argument objects.
 boolean forceFullSearch(java.lang.String op, java.lang.String value)
          Return whether this function, when used in a selector with the operator op and argument value, should search all objects in the TQL Context.
 java.lang.String getName()
          Return the base name of this user function (without the initial "%")
 boolean isAggregator()
          Return whether this function returns one value for each extractValues argument object or one value for all the arguments (an aggregator).
 java.lang.String validateArgument(TQLField field)
          Test if the specified function argument is valid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TQLFunctionAdapter

public TQLFunctionAdapter()
Method Detail

getName

public java.lang.String getName()
Description copied from interface: TQLFunction
Return the base name of this user function (without the initial "%")

Specified by:
getName in interface TQLFunction
Returns:
base name of the function

isAggregator

public boolean isAggregator()
Description copied from interface: TQLFunction
Return whether this function returns one value for each extractValues argument object or one value for all the arguments (an aggregator). The value of this method is typically false. Some functions, such as COUNT, are aggregators and must be handled as 'independent' export attributes. In this case, they must return true to isAggregator() and the length of the returned array will be one, not the size of the argument array.

Specified by:
isAggregator in interface TQLFunction
Returns:
true if the function returns a single value independent of the number of extractValues arguments

forceFullSearch

public boolean forceFullSearch(java.lang.String op,
                               java.lang.String value)
Description copied from interface: TQLFunction
Return whether this function, when used in a selector with the operator op and argument value, should search all objects in the TQL Context. This is typically false and search optimizers/accelerators can be used. The COUNT function, on the other hand, must search all concepts when a value of zero is acceptable: COUNT(MyProp) < 2. In this case, forceFullSearch must return true to inhibit optimization. Returning true generally has negative performance implications.

Specified by:
forceFullSearch in interface TQLFunction
Returns:
true if the function selector expression must search all concepts

validateArgument

public java.lang.String validateArgument(TQLField field)
Description copied from interface: TQLFunction
Test if the specified function argument is valid. Called during query parse.

Specified by:
validateArgument in interface TQLFunction
Parameters:
field - the TQLField that defines the argument
Returns:
empty string if argument is valid, otherwise the error message

extractValues

public java.lang.String[] extractValues(java.lang.Object[] objs,
                                        TQLField field)
Description copied from interface: TQLFunction
Return the result(s) of the function as applied to the argument objects. The field argument can be used to determine the type of object used in the invocation if multiple types are permitted, e.g. an inverse association vs. a regular association.

Specified by:
extractValues in interface TQLFunction
Parameters:
objs - the array of objects resulting from evaluating the function argument
field - the TQLField object that defines the object
Returns:
the String array of function values, this array can be of different size than objs

extractValue

protected java.lang.String extractValue(java.lang.Object obj,
                                        TQLField field)
Return the default string value of a DTS Attribute, e.g. name of a Concept, value of a DTSProperty.

Parameters:
obj - object as passed in extractValues
Returns:
string value of obj