{
return new OutputConditionNullFactory();
}
// Check if a variable is present
VariableMetaData variableMetaData = null;
if (outputLimitSpec.getVariableName() != null)
{
variableMetaData = statementContext.getVariableService().getVariableMetaData(outputLimitSpec.getVariableName());
if (variableMetaData == null) {
throw new ExprValidationException("Variable named '" + outputLimitSpec.getVariableName() + "' has not been declared");
}
String message = VariableServiceUtil.checkVariableContextName(statementContext.getContextDescriptor(), variableMetaData);
if (message != null) {
throw new ExprValidationException(message);
}
}
if(outputLimitSpec.getDisplayLimit() == OutputLimitLimitType.FIRST)
{
if (isGrouped) {
return new OutputConditionNullFactory();
}
if (!isWithHavingClause) {
return new OutputConditionFirstFactory(outputLimitSpec, statementContext, isGrouped, isWithHavingClause);
}
}
if(outputLimitSpec.getRateType() == OutputLimitRateType.CRONTAB)
{
return new OutputConditionCrontabFactory(outputLimitSpec.getCrontabAtSchedule(), statementContext);
}
else if(outputLimitSpec.getRateType() == OutputLimitRateType.WHEN_EXPRESSION)
{
return new OutputConditionExpressionFactory(outputLimitSpec.getWhenExpressionNode(), outputLimitSpec.getThenExpressions(), statementContext, outputLimitSpec.getAndAfterTerminateExpr(), outputLimitSpec.getAndAfterTerminateThenExpressions());
}
else if(outputLimitSpec.getRateType() == OutputLimitRateType.EVENTS)
{
if (log.isDebugEnabled())
{
log.debug(".createCondition creating OutputConditionCount with event rate " + outputLimitSpec);
}
if ((variableMetaData != null) && (!JavaClassHelper.isNumericNonFP(variableMetaData.getType())))
{
throw new IllegalArgumentException("Variable named '" + outputLimitSpec.getVariableName() + "' must be type integer, long or short");
}
int rate = -1;
if (outputLimitSpec.getRate() != null)
{
rate = outputLimitSpec.getRate().intValue();
}
return new OutputConditionCountFactory(rate, variableMetaData);
}
else if (outputLimitSpec.getRateType() == OutputLimitRateType.TERM)
{
if (outputLimitSpec.getAndAfterTerminateExpr() == null && (outputLimitSpec.getAndAfterTerminateThenExpressions() == null || outputLimitSpec.getAndAfterTerminateThenExpressions().isEmpty())) {
return new OutputConditionTermFactory();
}
else {
return new OutputConditionExpressionFactory(new ExprConstantNodeImpl(false), Collections.<OnTriggerSetAssignment>emptyList(), statementContext, outputLimitSpec.getAndAfterTerminateExpr(), outputLimitSpec.getAndAfterTerminateThenExpressions());
}
}
else {
if (log.isDebugEnabled())
{
log.debug(".createCondition creating OutputConditionTime with interval length " + outputLimitSpec.getRate());
}
if ((variableMetaData != null) && (!JavaClassHelper.isNumeric(variableMetaData.getType())))
{
throw new IllegalArgumentException("Variable named '" + outputLimitSpec.getVariableName() + "' must be of numeric type");
}
return new OutputConditionTimeFactory(outputLimitSpec.getTimePeriodExpr(), statementContext);