示例#1
0
        public override async Task <JMXSchema> SaveSchemaAsync(JMXSchema schema)
        {
            var mdb = Factory.GetMdbContext();

            schema = await NormalizeSchemaAsync(mdb, schema);

            int id = (await SqlServerHelper.IsSql17(mdb)) ?
                     await mdb.ExecuteAsync <int>(SqlServer.AddSysSchemas,
                                                  new MdbParameter("@ObjectSchema", schema.ToString()),
                                                  new MdbParameter("@Version", schema_version)) :
                     await mdb.ExecuteAsync <int>(SqlServer.AddSysSchemas,
                                                  new MdbParameter("@uid", schema.UID),
                                                  new MdbParameter("@SysAreaSchemaName", schema.ObjectName.AreaName),
                                                  new MdbParameter("@ObjectType", (int)schema.DbObjectType),
                                                  new MdbParameter("@ObjectName", schema.ObjectName.ObjectName),
                                                  new MdbParameter("@DbObjectName", schema.DbObjectName.ObjectName),
                                                  new MdbParameter("@ObjectSchema", schema.ToString()),
                                                  new MdbParameter("@Version", schema_version));

            schema.ID = id;
            _schemaCache[schema.ObjectName] = schema;
            return(schema);
        }
示例#2
0
        public override async Task <JMXSchema> SaveSchemaAsync(JMXSchema schema)
        {
            var mdb = Factory.GetMdbContext();

            schema = await NormalizeSchemaAsync(mdb, schema);

            long id = await mdb.ExecuteAsync <long>(SQLite.AddSysSchemas,
                                                    new MdbParameter("@uid", schema.UID),
                                                    new MdbParameter("@SysAreaID",
                                                                     await mdb.ExecuteAsync <long>($"Select ID From SysAreas Where SchemaName = '{schema.ObjectName.AreaName}'")),
                                                    new MdbParameter("@ObjectType", (int)schema.DbObjectType),
                                                    new MdbParameter("@ObjectName", schema.ObjectName.ObjectName),
                                                    new MdbParameter("@DbObjectName", schema.DbObjectName.ObjectName),
                                                    new MdbParameter("@ObjectSchema", schema.ToString()),
                                                    new MdbParameter("@Version", schema_version),
                                                    new MdbParameter("@UpdateTime", DateTime.Now),
                                                    new MdbParameter("@DateBegin", DateTime.Now.Date),
                                                    new MdbParameter("@DateEnd", DateTime.MinValue) { NullIfEmpty = true },
                                                    new MdbParameter("@PreviosID", 0) { NullIfEmpty = true });

            schema.ID = Convert.ToInt32(id);
            lock (objLock)
                _schemaCache[schema.ObjectName] = schema;
            foreach (var fk in schema.ForeignKeys)
            {
                if (fk.RefObjectName.IsEmpty())
                {
                    throw new ArgumentNullException("Property RefObjectName can't be empty");
                }
                lock (objLock)
                {
                    if (_parentRelations.ContainsKey(fk.RefObjectName))
                    {
                        _parentRelations[fk.RefObjectName].Add(schema.ObjectName);
                    }
                    else
                    {
                        _parentRelations.Add(fk.RefObjectName, new List <string>()
                        {
                            schema.ObjectName
                        });
                    }
                }
            }
            return(schema);
        }
示例#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");
            }
        }