示例#1
0
        private JMXSchema CreateTestSchema()
        {
            JMXSchema s = new JMXSchema("SysSchema")
            {
                DbObjectName = new JMXObjectName("dbo", "SysSchemas")
            };

            s.Attributes.Add(new JMXAttribute("ID")
            {
                DataType = MdbType.@int, Caption = "Identifier"
            });
            s.Attributes.Add(new JMXAttribute("AreaID")
            {
                DataType = MdbType.@int, Caption = "Identifier of SysArea"
            });
            s.Attributes.Add(new JMXAttribute("Name")
            {
                DataType = MdbType.@string, Caption = "Name of SysSchema"
            });
            s.PrimaryKey = new JMXPrimaryKey("PK_SysSchemas", "ID");
            s.Indexes.Add(new JMXIndex("IE1_SysSchemas", "Name"));
            var fk = new JMXForeignKey("FK1")
            {
                RefObjectName   = "SysCat.SysArea",
                RefDbObjectName = new JMXObjectName("SysCat", "SysAreas")
            };

            fk.AddKeyMember("AreaID");
            fk.AddRefKeyMember("ID");
            s.ForeignKeys.Add(fk);
            return(s);
        }
示例#2
0
        private static async Task NormalizeDetailsAsync(MdbContext mdb, JMXSchema schema)
        {
            foreach (var att in schema.Attributes.Where(a => a.DataType == MdbType.@object))
            {
                if (att.ObjectSchema == null)
                {
                    //For an object type attribute, you must specify a schema
                    throw new InvalidOperationException(Properties.Strings.S031_MetaStack_Core_ORM_JMXSchemaProviderDB_normalize_2);
                }

                att.ObjectSchema = await NormalizeSchemaAsync(mdb, att.ObjectSchema);

                att.ServerDataType = "varchar";
                att.DataSize       = new JMXDataSize(1);
                att.FieldName      = $"{JMXFactory.DETAIL_FIELD_PREFIX}{att.ObjectSchema.DbObjectName.AreaName}_{att.ObjectSchema.DbObjectName.ObjectName}";
                //check indexes fo FK
                if (!att.ObjectSchema.ForeignKeys.Any(fk => fk.RefDbObjectName.AreaName == schema.DbObjectName.AreaName &&
                                                      fk.RefDbObjectName.ObjectName == schema.DbObjectName.ObjectName))
                {
                    var fk = new JMXForeignKey($"FK_{att.ObjectSchema.DbObjectName.AreaName}_{att.ObjectSchema.DbObjectName.ObjectName}_{schema.DbObjectName.ObjectName}")
                    {
                        RefDbObjectName = schema.DbObjectName.ToString(),
                        RefObjectName   = schema.ObjectName.ToString()
                    };

                    foreach (var m in schema.PrimaryKey.KeyMembers)
                    {
                        string fieldName = $"{schema.ObjectName}{m.FieldName}";
                        if (!att.ObjectSchema.Attributes.Any(a => a.FieldName == fieldName))
                        {
                            var refAtt = schema.Attributes.FirstOrDefault(a => a.FieldName == m.FieldName);
                            var newAtt = new JMXAttribute(fieldName)
                            {
                                DataType       = refAtt.DataType,
                                ServerDataType = refAtt.ServerDataType,
                                Required       = true,
                                FieldName      = fieldName,
                                IsFK           = true,
                                DataSize       = refAtt.DataSize
                            };
                            att.ObjectSchema.Attributes.Add(newAtt);
                        }
                    }
                    //check for exists attribute $"{schema.ObjectName}{m.FieldName}" in att.ObjectSchema
                    fk.AddKeyMember(schema.PrimaryKey.KeyMembers.Select(m => $"{schema.ObjectName}{m.FieldName}").ToArray());
                    fk.AddRefKeyMember(schema.PrimaryKey.KeyMembers.Select(m => m.FieldName).ToArray());
                    att.ObjectSchema.ForeignKeys.Add(fk);
                }
            }
        }
示例#3
0
        public void SerializeTest()
        {
            using (FileLog _logger = new FileLog("ORMSchemaTest", new FileLogSettings()
            {
                DateFolderMask = "yyyy-MM-dd"
            }))
            {
                JMXAttribute a = new JMXAttribute("ID")
                {
                    DataType   = MdbType.@int,
                    IsNullable = false
                };
                string sa = a.ToString();
                //_logger.Debug(sa);
                a = JsonConvert.DeserializeObject <JMXAttribute>(sa);
                //_logger.Debug(a.ToString());
                Assert.AreEqual(sa, a.ToString());
                JMXPrimaryKey pk  = new JMXPrimaryKey("PK_SomeObjects", "SomeAtt", "NextAtt");
                string        spk = pk.ToString();
                //_logger.Debug(spk);
                pk = JsonConvert.DeserializeObject <JMXPrimaryKey>(spk);
                Assert.AreEqual(spk, pk.ToString());
                JMXSchema s = new JMXSchema("SysSchemas")
                {
                    DbObjectName = new JMXObjectName("SysCat", "SysSchemas")
                };
                s.Attributes.Add(a);
                s.PrimaryKey = pk;
                s.Indexes.Add(new JMXIndex("IE1_SysSchemas", "ID"));
                var fk = new JMXForeignKey("FK1")
                {
                    RefObjectName   = "SysCat.SysArea",
                    RefDbObjectName = new JMXObjectName("SysCat", "SysAreas")
                };
                fk.AddKeyMember("AreaID");
                fk.AddRefKeyMember("ID");
                s.ForeignKeys.Add(fk);
                string ss = s.ToString();
                _logger.Debug(ss);
                s = JsonConvert.DeserializeObject <JMXSchema>(ss);
                Assert.AreEqual(ss, s.ToString());
                _logger.Debug("Start speed test fo JMXObject parse from json string");


                JMXSchemaProviderFactory.RegisterProvider <JMXSchemaProviderMemory>();
                JMXSchemaProviderFactory.SetDefault(JMXSchemaProviderFactory.GetProvider <JMXSchemaProviderMemory>());
                JMXSchemaProviderFactory.Default.SaveSchema(creaateTestSchema());
                JMXObject o = new JMXObject("SysCat.SysSchema");
                for (int i = 0; i < 1000; i++)
                {
                    o.ParseJson(ss, null);
                }
                _logger.Debug("Finish speed test");
                _logger.Debug(o.ToString());
                _logger.Debug("Start speed test fo JMXSchema serialize to json string");
                for (int i = 0; i < 1000; i++)
                {
                    ss = JsonConvert.SerializeObject(s);
                }
                _logger.Debug("Finish speed test");
                _logger.Debug("Start speed test fo JMXSchema ToString method to json string");
                for (int i = 0; i < 1000; i++)
                {
                    ss = s.ToString();
                }
                _logger.Debug("Finish speed test");
                _logger.Debug("Start speed test fo JMXSchema parse from json string");
                for (int i = 0; i < 1000; i++)
                {
                    s = JsonConvert.DeserializeObject <JMXSchema>(ss);
                }
                _logger.Debug("Finish speed test");

                //JMXObject o = new JMXObject(JObject.Parse(ss));
                //_logger.Debug((o as JObject).ToString());
                //JsonSerializer serializer = new JsonSerializer();
                //JMXObject o = (JMXObject)serializer.Deserialize(new JTokenReader(JObject.Parse(ss)), typeof(JMXObject));
                //JMXObject o = new JMXObject("Test");
            }
        }
示例#4
0
        static SysCatItems()
        {
            JMXSchema s = new JMXSchema("Order")
            {
                DbObjectName = new JMXObjectName("dbo", "Orders"),
                Name         = "Orders",
                DirectAccess = DirectAccess.ForAll
            };

            s.Attributes.Add(new JMXAttribute("ID")
            {
                FieldName = "ID",
                DataType  = MdbType.@int,
                Identity  = new JMXIdentity(true),
                Required  = true,
                Name      = "ИД"
            });
            s.Attributes.Add(new JMXAttribute("MarketName")
            {
                FieldName      = "MarketName",
                DataType       = MdbType.@string,
                ServerDataType = "varchar",
                Width          = 30,
                Required       = true,
                Name           = "Market Name"
            });
            s.Attributes.Add(new JMXAttribute("RequestTime")
            {
                FieldName         = "RequestTime",
                DataType          = MdbType.dateTime,
                ServerDataType    = "datetime",
                DefaultConstraint = new JMXConstraint(JMXConstraintTypes.defaultConstraint, "GETDATE()"),
                Required          = true,
                Name = "Время запроса"
            });
            s.Attributes.Add(new JMXAttribute("RequestResult")
            {
                FieldName      = "RequestResult",
                DataType       = MdbType.@string,
                ServerDataType = "varchar",
                Width          = 256,
                Required       = false,
                Name           = "Результат запроса"
            });
            s.PrimaryKey = new JMXPrimaryKey("XPKOrders", "ID");
            //s.Indexes.Add(new JMXIndex("XIE1Orders", "RequestTime"));
            s.Indexes.Add(new JMXIndex("XIE2Orders", "MarketName"));
            _sysCatItemsList.Add(s);

            s = new JMXSchema("OrderDetail")
            {
                DbObjectName = new JMXObjectName("dbo", "OrderDetails"),
                Name         = "Order detail",
                DirectAccess = DirectAccess.ForAll
            };
            s.Attributes.Add(new JMXAttribute("OrderID")
            {
                FieldName = "OrderID",
                DataType  = MdbType.@int,
                Required  = true,
                Name      = "ИД запроса"
            });
            s.Attributes.Add(new JMXAttribute("IsBuy")
            {
                FieldName = "IsBuy",
                DataType  = MdbType.@bool,
                Required  = true,
                Name      = "Тип buy или sell"
            });
            s.Attributes.Add(new JMXAttribute("Quantity")
            {
                FieldName      = "Quantity",
                DataType       = MdbType.@decimal,
                ServerDataType = "decimal",
                DataSize       = new JMXDataSize(9, 8, 17),
                Required       = true,
                Name           = "Тип buy или sell"
            });
            s.Attributes.Add(new JMXAttribute("Rate")
            {
                FieldName      = "Rate",
                DataType       = MdbType.@decimal,
                ServerDataType = "decimal",
                DataSize       = new JMXDataSize(9, 8, 17),
                Required       = true,
                Name           = "Тип buy или sell"
            });
            s.Indexes.Add(new JMXIndex("XIE1OrderDetails", "OrderID")
            {
                ClusteredOption = 1
            });
            var fk = new JMXForeignKey("FK_OrderDetails_Orders")
            {
                RefDbObjectName = "dbo.Orders",
                RefObjectName   = "dbo.Order"
            };

            fk.AddKeyMember("OrderID");
            fk.AddRefKeyMember("ID");
            s.ForeignKeys.Add(fk);
            _sysCatItemsList.Add(s);


            //s = new JMXSchema("SysDataTypesRow");
            //s.DbObjectName = new JMXObjectName("dbo", "SysDataTypesRows");
            //s.Name = "Типы данных";
            //s.DirectAccess = DirectAccess.None;
            //s.Attributes.Add(new JMXAttribute("ID")
            //{
            //	FieldName = "ID",
            //	DataType = Data.MdbType.@int,
            //	Name = "ИД",
            //	Identity = new JMXIdentity(true),
            //	Required = true,
            //	ReadOnly = true,
            //});
            //s.Attributes.Add(new JMXAttribute("c_bit")
            //{
            //	FieldName = "c_bit",
            //	DataType = Data.MdbType.@bool,
            //	IsNullable = false
            //});
            //s.Attributes.Add(new JMXAttribute("c_tinyint")
            //{
            //	FieldName = "c_tinyint",
            //	DataType = Data.MdbType.@byte,
            //	IsNullable = true
            //});
            //s.Attributes.Add(new JMXAttribute("c_smallint")
            //{
            //	FieldName = "c_smallint",
            //	DataType = Data.MdbType.@short,
            //	IsNullable = true
            //});
            //s.Attributes.Add(new JMXAttribute("c_int")
            //{
            //	FieldName = "c_int",
            //	DataType = Data.MdbType.@int,
            //	IsNullable = true
            //});
            //s.Attributes.Add(new JMXAttribute("c_bigint")
            //{
            //	FieldName = "c_bigint",
            //	DataType = Data.MdbType.@long,
            //	ServerDataType = "bigint",
            //	IsNullable = true
            //});
            //s.Attributes.Add(new JMXAttribute("c_real")
            //{
            //	FieldName = "c_real",
            //	DataType = Data.MdbType.@float,
            //	ServerDataType = "real",
            //	IsNullable = true,
            //	DataSize = new JMXDataSize(sizeof(float), 4, 10)
            //});
            //s.Attributes.Add(new JMXAttribute("c_float")
            //{
            //	FieldName = "c_float",
            //	DataType = Data.MdbType.@float,
            //	ServerDataType = "float",
            //	IsNullable = true,
            //	DataSize = new JMXDataSize(sizeof(float), 8, 15)
            //});
            //s.Attributes.Add(new JMXAttribute("c_decimal")
            //{
            //	FieldName = "c_decimal",
            //	DataType = Data.MdbType.@decimal,
            //	ServerDataType = "decimal",
            //	DataSize = new JMXDataSize(sizeof(decimal), 4, 20),
            //	IsNullable = true
            //});
            //s.Attributes.Add(new JMXAttribute("c_money")
            //{
            //	FieldName = "c_money",
            //	DataType = Data.MdbType.@decimal,
            //	ServerDataType = "money",
            //	IsNullable = true,
            //	DefaultConstraint = new JMXConstraint(JMXConstraintTypes.defaultConstraint, "10")
            //});
            //s.Attributes.Add(new JMXAttribute("c_datetime")
            //{
            //	FieldName = "c_datetime",
            //	DataType = Data.MdbType.dateTime,
            //	ServerDataType = "datetime",
            //	IsNullable = true,
            //	CheckConstraint = new JMXConstraint(JMXConstraintTypes.checkConstraint, "c_datetime >= getdate() - 3")
            //});
            //s.Attributes.Add(new JMXAttribute("c_time")
            //{
            //	FieldName = "c_time",
            //	DataType = Data.MdbType.dateTime,
            //	ServerDataType = "time",
            //	IsNullable = true
            //});
            //s.Attributes.Add(new JMXAttribute("c_varchar")
            //{
            //	FieldName = "c_varchar",
            //	DataType = Data.MdbType.@string,
            //	ServerDataType = "varchar",
            //	Width = 255,
            //	IsNullable = true
            //});
            //s.Attributes.Add(new JMXAttribute("c_binary")
            //{
            //	FieldName = "c_binary",
            //	DataType = Data.MdbType.byteArray,
            //	ServerDataType = "binary",
            //	IsNullable = true
            //});
            //s.Attributes.Add(new JMXAttribute("c_guid")
            //{
            //	FieldName = "c_guid",
            //	DataType =  Data.MdbType.guid,
            //	IsNullable = true
            //});
            //s.Attributes.Add(new JMXAttribute("c_object")
            //{
            //	DataType =  Data.MdbType.@object,
            //	IsNullable = true,
            //	IsArray = true,

            //});
            ////s.PrimaryKey = new JMXPrimaryKey("PK_SysDataTypesRow", "ID");
            //_sysCatItemsList.Add(s);
            //var attObject = s.Attributes[s.Attributes.Count - 1];

            //s = new JMXSchema("SysDataTypesRowDetail");
            //s.DbObjectName = new JMXObjectName("dbo", "SysDataTypesRowDetails");
            //s.Name = "Дополнительные типы";
            //s.DirectAccess = DirectAccess.None;
            ////s.Attributes.Add(new JMXAttribute("SysDataTypesRowID")
            ////{
            ////	FieldName = "SysDataTypesRowID",
            ////	DataType = Data.MdbType.@int,
            ////	Name = "ИД типов данных",
            ////	Required = true,
            ////	ReadOnly = true,
            ////});
            //s.Attributes.Add(new JMXAttribute("ID")
            //{
            //	FieldName = "ID",
            //	DataType = Data.MdbType.@int,
            //	Name = "ИД",
            //	Identity = new JMXIdentity(true),
            //	Required = true,
            //	ReadOnly = true,
            //});
            //s.Attributes.Add(new JMXAttribute("PropertyName")
            //{
            //	FieldName = "PropertyName",
            //	DataType = Data.MdbType.@string,
            //	Name = "Наименование свойства",
            //	Width = 60,
            //	Required = true,
            //	ReadOnly = true,
            //});
            //s.Attributes.Add(new JMXAttribute("PropertyValue")
            //{
            //	FieldName = "PropertyValue",
            //	DataType = Data.MdbType.@string,
            //	Name = "Значение свойства",
            //	Width = 512,
            //	Required = true,
            //	ReadOnly = true,
            //});
            //s.PrimaryKey = new JMXPrimaryKey("PK_SysDataTypesRowDetails", "ID");
            ////var fk = new JMXForeignKey("FK_SysDataTypesRowDetails_SysDataTypesRows");
            ////fk.RefObject = new JMXObjectName("dbo.SysDataTypesRows");
            ////fk.RefObjectName = "SysDataTypesRow";
            ////fk.AddKeyMember("SysDataTypesRowID");
            ////fk.AddRefKeyMember("ID");
            ////s.ForeignKeys.Add(fk);

            //attObject.ObjectSchema = s;
        }