public void Run(RegressionEnvironment env)
            {
                string epl;

                epl = "@Name('MyTestStmt') @Description('MyTestStmt description') @Tag(Name=\"UserId\", Value=\"value\") " +
                      "select * from SupportBean";
                env.CompileDeploy(epl).AddListener("MyTestStmt");
                TryAssertion(env.Statement("MyTestStmt"));
                var name = (NameAttribute) AnnotationUtil.FindAnnotation(
                    env.Statement("MyTestStmt").Annotations,
                    typeof(NameAttribute));
                Assert.AreEqual("MyTestStmt", name.Value);
                env.UndeployAll();

                // try lowercase
                epl = "@Name('MyTestStmt') @Description('MyTestStmt description') @Tag(Name=\"UserId\", Value=\"value\") " +
                      " select * from SupportBean";
                env.CompileDeploy(epl).AddListener("MyTestStmt");
                TryAssertion(env.Statement("MyTestStmt"));
                env.UndeployAll();

                // try fully-qualified
                epl = "@" +
                      typeof(NameAttribute).Name +
                      "('MyTestStmt') @Description('MyTestStmt description') @Tag(Name=\"UserId\", Value=\"value\") " +
                      "select * from SupportBean";
                env.CompileDeploy(epl).AddListener("MyTestStmt");
                TryAssertion(env.Statement("MyTestStmt"));
                env.UndeployAll();

                // hint tests
                Assert.IsNull(HintEnum.DISABLE_RECLAIM_GROUP.GetHint(null));
                Assert.IsNull(HintEnum.DISABLE_RECLAIM_GROUP.GetHint(new Attribute[0]));
                env.CompileDeploy("@Hint('ITERATE_ONLY') select * from SupportBean");
                env.CompileDeploy("@Hint('ITERATE_ONLY,DISABLE_RECLAIM_GROUP') select * from SupportBean");
                env.CompileDeploy("@Hint('ITERATE_ONLY,DISABLE_RECLAIM_GROUP,ITERATE_ONLY') select * from SupportBean");
                env.CompileDeploy("@Hint('  iterate_only ') select * from SupportBean");

                var annos = env
                    .CompileDeploy("@Hint('DISABLE_RECLAIM_GROUP') @Name('s0') select * from SupportBean")
                    .Statement("s0")
                    .Annotations;
                Assert.AreEqual("DISABLE_RECLAIM_GROUP", HintEnum.DISABLE_RECLAIM_GROUP.GetHint(annos).Value);

                annos = env
                    .CompileDeploy("@Hint('ITERATE_ONLY,ITERATE_ONLY,DISABLE_RECLAIM_GROUP,ITERATE_ONLY') @Name('s1') select * from SupportBean")
                    .Statement("s1")
                    .Annotations;
                Assert.AreEqual(
                    "ITERATE_ONLY,ITERATE_ONLY,DISABLE_RECLAIM_GROUP,ITERATE_ONLY",
                    HintEnum.DISABLE_RECLAIM_GROUP.GetHint(annos).Value);

                annos = env
                    .CompileDeploy("@Hint('ITERATE_ONLY,reclaim_group_aged=10') @Name('s2') select * from SupportBean")
                    .Statement("s2")
                    .Annotations;
                var hint = HintEnum.RECLAIM_GROUP_AGED.GetHint(annos);
                Assert.AreEqual("10", HintEnum.RECLAIM_GROUP_AGED.GetHintAssignedValue(hint));

                annos = env
                    .CompileDeploy("@Hint('reclaim_group_aged=11') @Name('s3') select * from SupportBean")
                    .Statement("s3")
                    .Annotations;
                hint = HintEnum.RECLAIM_GROUP_AGED.GetHint(annos);
                Assert.AreEqual("11", HintEnum.RECLAIM_GROUP_AGED.GetHintAssignedValue(hint));

                annos = env
                    .CompileDeploy("@Hint('index(one, two)') @Name('s4') select * from SupportBean")
                    .Statement("s4")
                    .Annotations;
                Assert.AreEqual("one, two", HintEnum.INDEX.GetHintAssignedValues(annos)[0]);

                env.UndeployAll();

                // NoLock
                env.CompileDeploy("@Name('s0') @NoLock select * from SupportBean");
                Assert.AreEqual(
                    1,
                    AnnotationUtil.FindAnnotations(env.Statement("s0").Annotations, typeof(NoLockAttribute)).Count);

                env.UndeployAll();
            }
        private void RunAssertionBuiltin(EPServiceProvider epService)
        {
            var stmtText = "@Name('MyTestStmt') @Description('MyTestStmt description') @Tag(Name=\"UserId\", Value=\"value\") select * from Bean";
            var stmt     = epService.EPAdministrator.CreateEPL(stmtText);

            Assert.IsTrue(((EPStatementSPI)stmt).IsNameProvided);
            TryAssertion(stmt);
            stmt.Dispose();
            var name = (NameAttribute)AnnotationUtil.FindAnnotation(stmt.Annotations, typeof(NameAttribute));

            Assert.AreEqual("MyTestStmt", name.Value);

            // try lowercase
            var stmtTextLower = "@Name('MyTestStmt') @Description('MyTestStmt description') @Tag(Name=\"UserId\", Value=\"value\") select * from Bean";

            stmt = epService.EPAdministrator.CreateEPL(stmtTextLower);
            TryAssertion(stmt);
            stmt.Dispose();

            // try pattern
            stmtText = "@Name('MyTestStmt') @Description('MyTestStmt description') @Tag(Name='UserId', Value='value') every Bean";
            stmt     = epService.EPAdministrator.CreatePattern(stmtText);
            TryAssertion(stmt);
            stmt.Dispose();

            stmtText = "@" + typeof(NameAttribute).FullName + "('MyTestStmt') @Description('MyTestStmt description') @Tag(Name=\"UserId\", Value=\"value\") every Bean";
            stmt     = epService.EPAdministrator.CreatePattern(stmtText);
            TryAssertion(stmt);

            epService.EPAdministrator.CreateEPL("@Hint('ITERATE_ONLY') select * from Bean");
            epService.EPAdministrator.CreateEPL("@Hint('ITERATE_ONLY,DISABLE_RECLAIM_GROUP') select * from Bean");
            epService.EPAdministrator.CreateEPL("@Hint('ITERATE_ONLY,DISABLE_RECLAIM_GROUP,ITERATE_ONLY') select * from Bean");
            epService.EPAdministrator.CreateEPL("@Hint('  iterate_only ') select * from Bean");

            // test statement name override
            stmtText = "@Name('MyAnnotatedName') select * from Bean";
            stmt     = epService.EPAdministrator.CreateEPL(stmtText, "MyABCStmt");
            Assert.AreEqual("MyABCStmt", stmt.Name);

            // hint tests
            Assert.IsNull(HintEnum.DISABLE_RECLAIM_GROUP.GetHint(null));
            Assert.IsNull(HintEnum.DISABLE_RECLAIM_GROUP.GetHint(new Attribute[0]));

            var annos = epService.EPAdministrator.CreateEPL("@Hint('DISABLE_RECLAIM_GROUP') select * from Bean").Annotations;

            Assert.AreEqual("DISABLE_RECLAIM_GROUP", HintEnum.DISABLE_RECLAIM_GROUP.GetHint(annos).Value);

            annos = epService.EPAdministrator.CreateEPL("@Hint('ITERATE_ONLY,ITERATE_ONLY,DISABLE_RECLAIM_GROUP,ITERATE_ONLY') select * from Bean").Annotations;
            Assert.AreEqual("ITERATE_ONLY,ITERATE_ONLY,DISABLE_RECLAIM_GROUP,ITERATE_ONLY", HintEnum.DISABLE_RECLAIM_GROUP.GetHint(annos).Value);

            annos = epService.EPAdministrator.CreateEPL("@Hint('ITERATE_ONLY,reclaim_group_aged=10') select * from Bean").Annotations;
            var hint = HintEnum.RECLAIM_GROUP_AGED.GetHint(annos);

            Assert.AreEqual("10", HintEnum.RECLAIM_GROUP_AGED.GetHintAssignedValue(hint));

            annos = epService.EPAdministrator.CreateEPL("@Hint('reclaim_group_aged=11') select * from Bean").Annotations;
            hint  = HintEnum.RECLAIM_GROUP_AGED.GetHint(annos);
            Assert.AreEqual("11", HintEnum.RECLAIM_GROUP_AGED.GetHintAssignedValue(hint));

            annos = epService.EPAdministrator.CreateEPL("@Hint('Index(one, two)') select * from Bean").Annotations;
            Assert.AreEqual("one, two", HintEnum.INDEX.GetHintAssignedValues(annos)[0]);

            stmt.Dispose();

            // NoLock
            stmt = epService.EPAdministrator.CreateEPL("@NoLock select * from Bean");
            Assert.IsNotNull(AnnotationUtil.FindAnnotation(stmt.Annotations, typeof(NoLockAttribute)));
            Assert.AreEqual(1, AnnotationUtil.FindAnnotations(stmt.Annotations, typeof(NoLockAttribute)).Count);

            stmt.Dispose();
        }
Exemplo n.º 3
0
        public static ConfigurationCommonEventTypeXMLDOM Configure(
            StatementBaseInfo @base,
            StatementCompileTimeServices services)
        {
            var config      = new ConfigurationCommonEventTypeXMLDOM();
            var annotations = @base.StatementRawInfo.Annotations;

            var schemaAnnotations = AnnotationUtil.FindAnnotations(annotations, typeof(XMLSchemaAttribute));

            if (schemaAnnotations == null || schemaAnnotations.IsEmpty())
            {
                throw new ExprValidationException("Required annotation @" + nameof(XMLSchemaAttribute) + " could not be found");
            }

            if (schemaAnnotations.Count > 1)
            {
                throw new ExprValidationException("Found multiple @" + nameof(XMLSchemaAttribute) + " annotations but expected a single annotation");
            }

            var schema = (XMLSchemaAttribute)schemaAnnotations[0];

            if (string.IsNullOrEmpty(schema.RootElementName))
            {
                throw new ExprValidationException(
                          "Required annotation field 'RootElementName' for annotation @" + nameof(XMLSchemaAttribute) + " could not be found");
            }

            config.RootElementName                  = schema.RootElementName.Trim();
            config.SchemaResource                   = NullIfEmpty(schema.SchemaResource);
            config.SchemaText                       = NullIfEmpty(schema.SchemaText);
            config.IsXPathPropertyExpr              = schema.XPathPropertyExpr;
            config.DefaultNamespace                 = schema.DefaultNamespace;
            config.IsEventSenderValidatesRoot       = schema.EventSenderValidatesRoot;
            config.IsAutoFragment                   = schema.AutoFragment;
            config.XPathFunctionResolver            = NullIfEmpty(schema.XPathFunctionResolver);
            config.XPathVariableResolver            = NullIfEmpty(schema.XPathVariableResolver);
            config.IsXPathResolvePropertiesAbsolute = schema.XPathResolvePropertiesAbsolute;
            config.RootElementNamespace             = NullIfEmpty(schema.RootElementNamespace);

            var prefixes = AnnotationUtil.FindAnnotations(annotations, typeof(XMLSchemaNamespacePrefixAttribute));

            foreach (var prefixAnnotation in prefixes)
            {
                var prefix = (XMLSchemaNamespacePrefixAttribute)prefixAnnotation;
                config.AddNamespacePrefix(prefix.Prefix, prefix.Namespace);
            }

            var fields = AnnotationUtil.FindAnnotations(annotations, typeof(XMLSchemaFieldAttribute));

            foreach (var fieldAnnotation in fields)
            {
                var field = (XMLSchemaFieldAttribute)fieldAnnotation;
                var rtype = GetResultType(field.Type);
                if (string.IsNullOrWhiteSpace(field.EventTypeName))
                {
                    var castToType = NullIfEmpty(field.CastToType);
                    config.AddXPathProperty(field.Name, field.XPath, rtype, castToType);
                }
                else
                {
                    config.AddXPathPropertyFragment(field.Name, field.XPath, rtype, field.EventTypeName);
                }
            }

            return(config);
        }