public SampleDynamicMBean()
        {
            var rowType = new CompositeType("Row", "Row", new[] {"ID", "Name"}, new[] {"Unique ID", "Name"},
                                         new[] {SimpleType.Integer, SimpleType.String});
             _tabularType = new TabularType("Table", "Table", rowType, new[] {"ID"});
             _tabularValue = new TabularDataSupport(_tabularType);

             _nestedCompositeValueType = new CompositeType("Nested composite value", "Nested composite value",
                                                       new[] {"NestedItem1", "NestedItem2"},
                                                       new[] {"Nested item 1", "Nested item 2"},
                                                       new[] {SimpleType.String, SimpleType.Double});
             _compositeValueType = new CompositeType("Composite value", "Composite value",
                                                 new[] {"Item1", "Item2", "Item3"},
                                                 new[] {"Item 1", "Item 2", "Item 3"},
                                                 new[]
                                                    {SimpleType.Integer, SimpleType.Boolean, _nestedCompositeValueType});

             var innerRowType = new CompositeType("Row", "Row", new[] {"ID", "Name", "CompositeValue"},
                                              new[] {"Unique ID", "Name", "Composite Value"},
                                              new[] {SimpleType.Integer, SimpleType.String, _compositeValueType});
             _innerTabularType = new TabularType("Inner table", "Inner table", innerRowType, new[] {"ID"});
             var outerRowType = new CompositeType("Outer Row", "Outer Row", new[] {"ID", "Value"},
                                              new[] {"Unique ID", "Tabular value"},
                                              new[] {SimpleType.Integer, _innerTabularType});
             _outerTabularType = new TabularType("Outer table", "Outer table", outerRowType, new[] {"ID"});
             _nestedTabularValue = new TabularDataSupport(_outerTabularType);
        }
Exemple #2
0
        private static ITabularData ExtractTabularValue(TabularType openType, CompositeData[] value)
        {
            var tabularValue = new TabularDataSupport(openType);

            tabularValue.PutAll(value.Select(x => ExtractCompositeValue(openType.RowType, x)));
            return(tabularValue);
        }
Exemple #3
0
        public SampleDynamicMBean()
        {
            var rowType = new CompositeType("Row", "Row", new[] { "ID", "Name" }, new[] { "Unique ID", "Name" },
                                            new[] { SimpleType.Integer, SimpleType.String });

            _tabularType  = new TabularType("Table", "Table", rowType, new[] { "ID" });
            _tabularValue = new TabularDataSupport(_tabularType);

            _nestedCompositeValueType = new CompositeType("Nested composite value", "Nested composite value",
                                                          new[] { "NestedItem1", "NestedItem2" },
                                                          new[] { "Nested item 1", "Nested item 2" },
                                                          new[] { SimpleType.String, SimpleType.Double });
            _compositeValueType = new CompositeType("Composite value", "Composite value",
                                                    new[] { "Item1", "Item2", "Item3" },
                                                    new[] { "Item 1", "Item 2", "Item 3" },
                                                    new[]
                                                    { SimpleType.Integer, SimpleType.Boolean, _nestedCompositeValueType });

            var innerRowType = new CompositeType("Row", "Row", new[] { "ID", "Name", "CompositeValue" },
                                                 new[] { "Unique ID", "Name", "Composite Value" },
                                                 new[] { SimpleType.Integer, SimpleType.String, _compositeValueType });

            _innerTabularType = new TabularType("Inner table", "Inner table", innerRowType, new[] { "ID" });
            var outerRowType = new CompositeType("Outer Row", "Outer Row", new[] { "ID", "Value" },
                                                 new[] { "Unique ID", "Tabular value" },
                                                 new[] { SimpleType.Integer, _innerTabularType });

            _outerTabularType   = new TabularType("Outer table", "Outer table", outerRowType, new[] { "ID" });
            _nestedTabularValue = new TabularDataSupport(_outerTabularType);
        }
 public SampleDynamicMBean()
 {
     _rowType = new CompositeType("Row", "Row", new[] { "ID", "Name" }, new[] { "Unique ID", "Name" },
                                  new[] { SimpleType.Integer, SimpleType.String });
     _tabularType = new TabularType("Table", "Table", _rowType, new[] { "ID" });
     _tabularValue = new TabularDataSupport(_tabularType);
     _arrayType = new ArrayType(1, SimpleType.Decimal);
 }
Exemple #5
0
 public SampleDynamicMBean()
 {
     _rowType = new CompositeType("Row", "Row", new[] { "ID", "Name" }, new[] { "Unique ID", "Name" },
                                  new[] { SimpleType.Integer, SimpleType.String });
     _tabularType  = new TabularType("Table", "Table", _rowType, new[] { "ID" });
     _tabularValue = new TabularDataSupport(_tabularType);
     _arrayType    = new ArrayType(1, SimpleType.Decimal);
 }
Exemple #6
0
 public void TestEqualityOperator()
 {
     for (int i = 0; i < _values.Length; i++)
     {
         TabularType left   = (TabularType)_values[i][0];
         TabularType right  = (TabularType)_values[i][1];
         bool        result = (bool)_values[i][2];
         Assert.AreEqual(result, left == right);
         Assert.AreEqual(result, right == left);
     }
 }
Exemple #7
0
        public void CollectionMapperCanHandleMappingCollectionToTabular()
        {
            OpenType mappedType = mapper.MapType(typeof(IEnumerable <TestCollectionElement>), MapType);

            Assert.AreEqual(OpenTypeKind.TabularType, mappedType.Kind);

            TabularType tabuarType = (TabularType)mappedType;

            Assert.AreEqual(tabuarType.IndexNames.Count, 1);
            Assert.IsTrue(tabuarType.IndexNames.Contains("CollectionIndex"));
            Assert.AreEqual(3, tabuarType.RowType.KeySet.Count);
            Assert.IsTrue(tabuarType.RowType.ContainsKey("IntValue"));
            Assert.IsTrue(tabuarType.RowType.ContainsKey("StringValue"));
            Assert.IsTrue(tabuarType.RowType.ContainsKey("CollectionIndex"));
            Assert.AreEqual(SimpleType.Integer, tabuarType.RowType.GetOpenType("IntValue"));
            Assert.AreEqual(SimpleType.String, tabuarType.RowType.GetOpenType("StringValue"));
            Assert.AreEqual(SimpleType.Integer, tabuarType.RowType.GetOpenType("CollectionIndex"));

            List <TestCollectionElement> value = new List <TestCollectionElement>();

            value.Add(new TestCollectionElement(1, "1"));
            value.Add(new TestCollectionElement(2, "2"));
            value.Add(new TestCollectionElement(3, "3"));

            object mappedValue = mapper.MapValue(typeof(IEnumerable <TestCollectionElement>), mappedType, value, MapValue);

            Assert.IsTrue(mappedValue is ITabularData);
            ITabularData table = (ITabularData)mappedValue;

            Assert.AreEqual(3, table.Count);
            ICompositeData el = table[new object[] { 0 }];

            Assert.AreEqual(1, el["IntValue"]);
            Assert.AreEqual("1", el["StringValue"]);
            el = table[new object[] { 1 }];
            Assert.AreEqual(2, el["IntValue"]);
            Assert.AreEqual("2", el["StringValue"]);
            el = table[new object[] { 2 }];
            Assert.AreEqual(3, el["IntValue"]);
            Assert.AreEqual("3", el["StringValue"]);
        }
        public object MapValue(Type plainNetType, OpenType mappedType, object value, MapValueDelegate mapNestedValueCallback)
        {
            if (value == null)
            {
                return(null);
            }
            Type elementType = GetElementType(plainNetType);

            if (mappedType.Kind == OpenTypeKind.ArrayType)
            {
                if (value.GetType().IsArray)
                {
                    return(value);
                }
                else
                {
                    ArrayList   result          = new ArrayList();
                    IEnumerable enumerableValue = (IEnumerable)value;
                    foreach (object o in enumerableValue)
                    {
                        result.Add(o);
                    }
                    return(result.ToArray(elementType));
                }
            }
            else
            {
                TabularType  tabularType     = (TabularType)mappedType;
                ITabularData result          = new TabularDataSupport(tabularType, 0);
                IEnumerable  enumerableValue = (IEnumerable)value;
                int          index           = 0;
                foreach (object o in enumerableValue)
                {
                    ICompositeData element = (ICompositeData)mapNestedValueCallback(elementType, MakeElementType(tabularType.RowType), o);
                    result.Put(MakeRowValue(element, index, tabularType.RowType));
                    index++;
                }
                return(result);
            }
        }
Exemple #9
0
        public OpenDynamic()
        {
            _tabularType = Tabular.Type("Table", "Table")
                           .WithIndexColumn("ID", "UniqueID").TypedAs(SimpleType.Integer)
                           .WithColumn("Name", "Name").TypedAs(SimpleType.String);

            _tabularValue = new TabularDataSupport(_tabularType);

            _outerTabularType = Tabular.Type("Outer table", "Outer table")
                                .WithIndexColumn("ID", "Unique ID").TypedAs(SimpleType.Integer)
                                .WithColumn("Value", "Tabular value").TypedAs(
                Tabular.Type("Inner table", "Inner table")
                .WithIndexColumn("ID", "Unique ID").TypedAs(SimpleType.Integer)
                .WithColumn("Name", "Name").TypedAs(SimpleType.String)
                .WithColumn("CompositeValue", "Composite Value").TypedAs(
                    Composite.Type("Composite value", "Composite value")
                    .WithItem("Item1", "Item 2").TypedAs(SimpleType.Integer)
                    .WithItem("Item2", "Item 2").TypedAs(SimpleType.Boolean)
                    .WithItem("Item3", "Item 3").TypedAs(
                        Composite.Type("Nested", "Nested composite")
                        .WithItem("NestedItem1", "NestedItem1").TypedAs(SimpleType.String)
                        .WithItem("NestedItem2", "NestedItem2").TypedAs(SimpleType.Double))));

            _nestedTabularValue = new TabularDataSupport(_outerTabularType);

            _beanInfoGetter = MBean.Info <OpenDynamic>("Sample dynamic MBean")
                              .WithAttributes(
                MBean.WritableAttribute("Attribute", "Sample attribute").TypedAs(TabularType),
                MBean.WritableAttribute("NestedTableAttribute", "Nested Table Attribute").TypedAs(NestedTabularType)
                )
                              .WithOperations(
                MBean.MutatorOperation("DoSomething", "Does somthing").WithParameters(
                    MBean.Parameter("First", "First parameter").TypedAs(SimpleType.Double),
                    MBean.Parameter("Second", "Second parameter").TypedAs(TabularType)
                    ).Returning(SimpleType.Void)
                )
                              .AndNothingElse();
        }
Exemple #10
0
        public OpenDynamic()
        {
            _tabularType = Tabular.Type("Table", "Table")
            .WithIndexColumn("ID", "UniqueID").TypedAs(SimpleType.Integer)
            .WithColumn("Name", "Name").TypedAs(SimpleType.String);

             _tabularValue = new TabularDataSupport(_tabularType);

             _outerTabularType = Tabular.Type("Outer table", "Outer table")
            .WithIndexColumn("ID", "Unique ID").TypedAs(SimpleType.Integer)
            .WithColumn("Value", "Tabular value").TypedAs(
               Tabular.Type("Inner table", "Inner table")
                  .WithIndexColumn("ID", "Unique ID").TypedAs(SimpleType.Integer)
                  .WithColumn("Name", "Name").TypedAs(SimpleType.String)
                  .WithColumn("CompositeValue", "Composite Value").TypedAs(
                     Composite.Type("Composite value", "Composite value")
                        .WithItem("Item1", "Item 2").TypedAs(SimpleType.Integer)
                        .WithItem("Item2", "Item 2").TypedAs(SimpleType.Boolean)
                        .WithItem("Item3", "Item 3").TypedAs(
                           Composite.Type("Nested", "Nested composite")
                              .WithItem("NestedItem1", "NestedItem1").TypedAs(SimpleType.String)
                              .WithItem("NestedItem2", "NestedItem2").TypedAs(SimpleType.Double))));

             _nestedTabularValue = new TabularDataSupport(_outerTabularType);

             _beanInfoGetter = MBean.Info<OpenDynamic>("Sample dynamic MBean")
            .WithAttributes(
               MBean.WritableAttribute("Attribute", "Sample attribute").TypedAs(TabularType),
               MBean.WritableAttribute("NestedTableAttribute", "Nested Table Attribute").TypedAs(NestedTabularType)
            )
            .WithOperations(
               MBean.MutatorOperation("DoSomething", "Does somthing").WithParameters(
                  MBean.Parameter("First", "First parameter").TypedAs(SimpleType.Double),
                  MBean.Parameter("Second", "Second parameter").TypedAs(TabularType)
               ).Returning(SimpleType.Void)
            )
            .AndNothingElse();
        }
 private static ITabularData ExtractTabularValue(TabularType openType, CompositeData[] value)
 {
     var tabularValue = new TabularDataSupport(openType);
     tabularValue.PutAll(value.Select(x => ExtractCompositeValue(openType.RowType, x)));
     return tabularValue;
 }
        public override SqlStatement VisitCreateFunctionStatement(PlSqlParser.CreateFunctionStatementContext context)
        {
            var  functionName = Name.Object(context.objectName());
            bool orReplace    = context.OR() != null && context.REPLACE() != null;

            var body = context.body();
            var call = context.callSpec();

            SqlType returnType;

            var returnTypeSpec = context.functionReturnType();

            if (returnTypeSpec.TABLE() != null)
            {
                returnType = new TabularType();
            }
            else if (returnTypeSpec.DETERMINISTIC() != null)
            {
                returnType = Function.DynamicType;
            }
            else
            {
                var typeInfo = new DataTypeVisitor().Visit(returnTypeSpec.primitive_type());
                if (!typeInfo.IsPrimitive)
                {
                    throw new NotSupportedException(String.Format("The return type of function '{0}' ('{1}') is not primitive.",
                                                                  functionName, typeInfo));
                }

                returnType = PrimitiveTypes.Resolve(typeInfo.TypeName, typeInfo.Metadata);
            }

            RoutineParameter[] parameters = null;
            if (context.parameter() != null &&
                context.parameter().Length > 0)
            {
                parameters = context.parameter().Select(Parameter.Routine).ToArray();
            }

            if (body != null)
            {
                var functionBody = Visit(body);

                if (!(functionBody is PlSqlBody))
                {
                    throw new ParseCanceledException("Invalid function body.");
                }

                var plsqlBody = ((PlSqlBody)functionBody).AsPlSqlStatement();

                var declarationArray = context.declaration();
                if (declarationArray != null && declarationArray.Length > 0)
                {
                    foreach (var declContext in declarationArray)
                    {
                        var declaration = Visit(declContext);
                        plsqlBody.Declarations.Add(declaration);
                    }
                }

                return(new CreateFunctionStatement(functionName, returnType, parameters, plsqlBody)
                {
                    ReplaceIfExists = orReplace
                });
            }

            var typeString    = InputString.AsNotQuoted(call.dotnetSpec().typeString.Text);
            var assemblyToken = InputString.AsNotQuoted(call.dotnetSpec().assemblyString);

            if (assemblyToken != null)
            {
                typeString = String.Format("{0}, {1}", typeString, assemblyToken);
            }

            return(new CreateExternalFunctionStatement(functionName, returnType, parameters, typeString));
        }
 public TabularDataType_Type(TabularType value)
     : base(value)
 {
     index         = value.IndexNames.ToArray();
     CompositeType = new CompositeDataType_Type(value.RowType);
 }