Package net.sf.basedb.util.jep
Class ReporterFunction
java.lang.Object
net.sf.basedb.util.jep.ReporterFunction
- All Implemented Interfaces:
JepExpressionFunction
,JepFunction
,org.nfunk.jep.function.PostfixMathCommandI
A JEP function class that adds a
rep(string)
or mrep(string)
function to a JEP expression parser. The function will look up the value of the reporter
property with the given name. For example:
rep('sequence')
If the mrep
variant is used, the master reporter table is used,
otherwise the actual query can decide if it should use cloned reporter information
or not.
To be able to use this function it must be registered with the JEP parser and, before the expression is evaluated, a reporter object must be set. For example we can evaluate an expression for every reporter object:
DbControl dc = ... RawBioAssay assay = ... String expression = "rep('sequence')"; ReporterFunction rep = new RepFunction(); JEP jep = JepUtil.newJep(expression, rep); DataResultIterator<RawData> result = assay.getRawData().iterate(dc); while (result.hasNext()) { rep.setReporter(result.next().getReporter()); String value = jep.getValue(); // Do something with the value } result.close();
- Version:
- 2.0
- Author:
- Nicklas
- See Also:
- Last modified
- $Date: 2015-04-20 11:08:18 +0200 (må, 20 apr 2015) $
-
Field Summary
Modifier and TypeFieldDescriptionprivate final DbControl
private final boolean
private final Metadata<ReporterData>
private int
private ReporterData
-
Constructor Summary
ConstructorDescriptionCreate a new instance of this function.ReporterFunction
(boolean master) Create a new instance of this function.ReporterFunction
(DbControl dc, RawDataType rawDataType) Create a new instance of this function working with reporters. -
Method Summary
Modifier and TypeMethodDescriptionboolean
checkNumberOfParameters
(int n) Get the name of this function.int
Get the current reporter object used when evaluating the JEP expression.Get the value of the specified property of the current raw data object.void
void
setCurNumberOfParameters
(int n) void
setReporter
(ReporterData reporter) Set a new reporter object that will be used the next time the JEP expression is evaluated.toExpression
(Node node) Use theDynamic.reporter(String)
method to create an expression referencing a reporter property.
-
Field Details
-
metaData
-
dc
-
master
private final boolean master -
numParameters
private int numParameters -
reporter
-
-
Constructor Details
-
ReporterFunction
public ReporterFunction()Create a new instance of this function. The new instance cannot be used to dynamically evaluate expressions. It should only be used for converting JEP formulas toExpression
:s. -
ReporterFunction
public ReporterFunction(boolean master) Create a new instance of this function. The new instance cannot be used to dynamically evaluate expressions. It should only be used for converting JEP formulas toExpression
:s. If- Parameters:
master
- TRUE to force using the master reporter table, FALSE to let the query decide- Since:
- 3.1
-
ReporterFunction
Create a new instance of this function working with reporters.
-
-
Method Details
-
getFunctionName
Description copied from interface:JepFunction
Get the name of this function. It is used when registering the function with aJEP
parser.- Specified by:
getFunctionName
in interfaceJepFunction
- Returns:
- The string "rep" or "mrep"
- See Also:
-
toExpression
Use theDynamic.reporter(String)
method to create an expression referencing a reporter property.- Specified by:
toExpression
in interfaceJepExpressionFunction
- Parameters:
node
- The node representing this function- Returns:
- An
Expression
object
-
getNumberOfParameters
public int getNumberOfParameters()- Specified by:
getNumberOfParameters
in interfaceorg.nfunk.jep.function.PostfixMathCommandI
- Returns:
- Always 1
-
setCurNumberOfParameters
public void setCurNumberOfParameters(int n) - Specified by:
setCurNumberOfParameters
in interfaceorg.nfunk.jep.function.PostfixMathCommandI
-
checkNumberOfParameters
public boolean checkNumberOfParameters(int n) - Specified by:
checkNumberOfParameters
in interfaceorg.nfunk.jep.function.PostfixMathCommandI
-
run
- Specified by:
run
in interfaceorg.nfunk.jep.function.PostfixMathCommandI
- Throws:
ParseException
-
setReporter
Set a new reporter object that will be used the next time the JEP expression is evaluated.- Parameters:
reporter
- The reporter object to use
-
getReporter
Get the current reporter object used when evaluating the JEP expression. -
raw
Get the value of the specified property of the current raw data object. This method uses Hibernate metadata to find the value.- Parameters:
propertyName
- The name of the raw data property- Returns:
- an java.lang.Object
- Throws:
ParseException
- If the argument is null or 'reporter' not specified.
-