Package com.espertech.esper.epl.variable

Examples of com.espertech.esper.epl.variable.VariableMetaData


import java.util.concurrent.atomic.AtomicReference;

public class ASTExprHelper {

    public static ExprNode resolvePropertyOrVariableIdentifier(String identifier, VariableService variableService, StatementSpecRaw spec) {
        VariableMetaData metaData = variableService.getVariableMetaData(identifier);
        if (metaData != null) {
            ExprVariableNodeImpl exprNode = new ExprVariableNodeImpl(metaData, null);
            spec.setHasVariables(true);
            addVariableReference(spec, metaData.getVariableName());
            String message = VariableServiceUtil.checkVariableContextName(spec.getOptionalContextName(), metaData);
            if (message != null) {
                throw ASTWalkException.from(message);
            }
            return exprNode;
View Full Code Here


    {
      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);
View Full Code Here

        {
            String leadingIdentifier = ctx.getChild(0).getChild(0).getText();
            String streamOrNestedPropertyName = ASTUtil.escapeDot(leadingIdentifier);
            propertyName = ASTUtil.getPropertyName(ctx, 2);

            VariableMetaData variableMetaData = variableService.getVariableMetaData(leadingIdentifier);
            if (variableMetaData != null)
            {
                exprNode = new ExprVariableNodeImpl(variableMetaData, propertyName);
                statementSpec.setHasVariables(true);
                String message = VariableServiceUtil.checkVariableContextName(statementSpec.getOptionalContextName(), variableMetaData);
                if (message != null) {
                    throw ASTWalkException.from(message);
                }
                ASTExprHelper.addVariableReference(statementSpec, variableMetaData.getVariableName());
            }
            else if (contextDescriptor != null && contextDescriptor.getContextPropertyRegistry().isContextPropertyPrefix(streamOrNestedPropertyName)) {
                exprNode = new ExprContextPropertyNode(propertyName);
            }
            else {
                exprNode = new ExprIdentNodeImpl(propertyName, streamOrNestedPropertyName);
            }
        }

        VariableMetaData variableMetaData = variableService.getVariableMetaData(propertyName);
        if (variableMetaData != null) {
            exprNode = new ExprVariableNodeImpl(variableMetaData, null);
            statementSpec.setHasVariables(true);
            String message = VariableServiceUtil.checkVariableContextName(statementSpec.getOptionalContextName(), variableMetaData);
            if (message != null) {
                throw ASTWalkException.from(message);
            }
            ASTExprHelper.addVariableReference(statementSpec, variableMetaData.getVariableName());
        }

        ASTExprHelper.exprCollectAddSubNodesAddParentNode(exprNode, ctx, astExprNodeMap);
    }
View Full Code Here

    }

    private AggSvcGroupByReclaimAgedEvalFuncFactory getEvaluationFunction(final VariableService variableService, String hintValue, String optionalContextName)
            throws ExprValidationException
    {
        final VariableMetaData variableMetaData = variableService.getVariableMetaData(hintValue);
        if (variableMetaData != null) {
            if (!JavaClassHelper.isNumeric(variableMetaData.getType())) {
                throw new ExprValidationException("Variable type of variable '" + variableMetaData.getVariableName() + "' is not numeric");
            }
            String message = VariableServiceUtil.checkVariableContextName(optionalContextName, variableMetaData);
            if (message != null) {
                throw new ExprValidationException(message);
            }
            return new AggSvcGroupByReclaimAgedEvalFuncFactory() {
                public AggSvcGroupByReclaimAgedEvalFunc make(AgentInstanceContext agentInstanceContext) {
                    VariableReader reader = variableService.getReader(variableMetaData.getVariableName(), agentInstanceContext.getAgentInstanceId());
                    return new AggSvcGroupByReclaimAgedEvalFuncVariable(reader);
                }
            };
        }
        else
View Full Code Here

        this.unmatchedListener = listener;
    }

    public void setVariableValue(String variableName, Object variableValue) throws EPException
    {
        VariableMetaData metaData = services.getVariableService().getVariableMetaData(variableName);
        checkVariable(variableName, metaData, true, false);

        services.getVariableService().getReadWriteLock().writeLock().lock();
        try {
            services.getVariableService().checkAndWrite(variableName, VariableService.NOCONTEXT_AGENTINSTANCEID, variableValue);
View Full Code Here

    }

    public Object getVariableValue(String variableName) throws EPException
    {
        services.getVariableService().setLocalVersion();
        VariableMetaData metaData = services.getVariableService().getVariableMetaData(variableName);
        if (metaData == null) {
            throw new VariableNotFoundException("Variable by name '" + variableName + "' has not been declared");
        }
        if (metaData.getContextPartitionName() != null) {
            throw new VariableNotFoundException("Variable by name '" + variableName + "' has been declared for context '" + metaData.getContextPartitionName() + "' and cannot be read without context partition selector");
        }
        VariableReader reader = services.getVariableService().getReader(variableName, VariableService.NOCONTEXT_AGENTINSTANCEID);
        Object value = reader.getValue();
        if (value == null || reader.getVariableMetaData().getEventType() == null) {
            return value;
View Full Code Here

    public Map<String, List<ContextPartitionVariableState>> getVariableValue(Set<String> variableNames, ContextPartitionSelector contextPartitionSelector) throws VariableNotFoundException {
        services.getVariableService().setLocalVersion();
        String contextPartitionName = null;
        for (String variableName : variableNames) {
            VariableMetaData metaData = services.getVariableService().getVariableMetaData(variableName);
            if (metaData == null) {
                throw new VariableNotFoundException("Variable by name '" + variableName + "' has not been declared");
            }
            if (metaData.getContextPartitionName() == null) {
                throw new VariableNotFoundException("Variable by name '" + variableName + "' is a global variable and not context-partitioned");
            }
            if (contextPartitionName == null) {
                contextPartitionName = metaData.getContextPartitionName();
            }
            else {
                if (!contextPartitionName.equals(metaData.getContextPartitionName())) {
                    throw new VariableNotFoundException("Variable by name '" + variableName + "' is a declared for context '" + metaData.getContextPartitionName() + "' however the expected context is '" + contextPartitionName + "'");
                }
            }
        }
        ContextManager contextManager = services.getContextManagementService().getContextManager(contextPartitionName);
        if (contextManager == null) {
View Full Code Here

    {
        services.getVariableService().setLocalVersion();
        Map<String, Object> values = new HashMap<String, Object>();
        for (String variableName : variableNames)
        {
            VariableMetaData metaData = services.getVariableService().getVariableMetaData(variableName);
            checkVariable(variableName, metaData, false, false);
            VariableReader reader = services.getVariableService().getReader(variableName, VariableService.NOCONTEXT_AGENTINSTANCEID);
            if (reader == null)
            {
                throw new VariableNotFoundException("Variable by name '" + variableName + "' has not been declared");
View Full Code Here

        return values;
    }

    public Class getVariableType(String variableName)
    {
        VariableMetaData metaData = services.getVariableService().getVariableMetaData(variableName);
        if (metaData == null) {
            return null;
        }
        return metaData.getType();
    }
View Full Code Here

    {
        // verify
        for (Map.Entry<String, Object> entry : variableValues.entrySet())
        {
            String variableName = entry.getKey();
            VariableMetaData metaData = services.getVariableService().getVariableMetaData(variableName);
            checkVariable(variableName, metaData, true, requireContextPartitioned);
        }

        // set values
        services.getVariableService().getReadWriteLock().writeLock().lock();
View Full Code Here

TOP

Related Classes of com.espertech.esper.epl.variable.VariableMetaData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.