Esempio n. 1
0
        public static void BeyondSQL()
        {
            DBPlatform.DeleteDB();

            var db = new DB(1);

            db.GetConfig().EnsureTable <MemberInc>("MemberInc", "ID");
            db.GetConfig().EnsureUpdateIncrementIndex <MemberInc>("MemberInc", "Version");
            var auto = db.Open();

            WriteLine("Update Increment");
            Write("Number increasing: ");

            MemberInc m = new MemberInc();

            m.ID   = 1;
            m.Name = "Andy";

            auto.Insert("MemberInc", m);
            var mg = auto.Get <MemberInc>("MemberInc", 1L);

            Write(mg.Version + ".  ");

            auto.Update("MemberInc", mg);
            mg = auto.Get <MemberInc>("MemberInc", 1L);
            Write(mg.Version + ".  ");

            auto.Update("MemberInc", mg);
            mg = auto.Get <MemberInc>("MemberInc", 1L);
            WriteLine(mg.Version + ".  ");

            WriteLine("Selecting Tracer");
            using (var boxTracer = auto.Cube())
            {
                bool   keepTrace   = true;
                Member tra         = boxTracer["MemberInc", 1L].Select <Member>(keepTrace);
                String currentName = tra.Name;

                {
                    // another box changes the name
                    MemberInc mm = new MemberInc();
                    mm.ID   = 1;
                    mm.Name = "Kelly";
                    auto.Update("MemberInc", mm.ID, mm);
                }

                // Change detected
                if (!boxTracer.Commit().Equals(CommitResult.OK))
                {
                    Write("Detected '" + currentName + "' has changed, ");
                }
            }
            Member nm = auto.Get <Member>("MemberInc", 1L);

            WriteLine("new name is '" + nm.Name + "'");

            db.Dispose();
        }
Esempio n. 2
0
        public static StringBuilder PMain()
        {
            StringBuilder sb = new StringBuilder();

            try
            {
                DBPlatform.DeleteDB();
                using (var server = new MyServer())
                {
                    using (var db = server.GetInstance())
                    {
                        // UpdateIncrement,version number from box.NewId(byte.MaxValue, 1);
                        sb.Append("\r\n\r\n*Version Control \r\n");
                        MemberInc m = new MemberInc();
                        m.ID   = 1;
                        m.Name = "Andy";

                        sb.Append("number increasing: ");
                        db.Get().Insert("MemberInc", m);
                        MemberInc mg = db.Get().SelectKey <MemberInc>(
                            "MemberInc", 1L);
                        sb.Append(mg.Version);

                        db.Get().Update("MemberInc", mg);
                        mg = db.Get().SelectKey <MemberInc>("MemberInc",
                                                            1L);
                        sb.Append(" " + mg.Version);
                        db.Get().Update("MemberInc", mg);
                        mg = db.Get().SelectKey <MemberInc>("MemberInc",
                                                            1L);
                        sb.Append(" " + mg.Version);

                        // Selecting Tracer
                        sb.Append("\r\n*Selecting Tracer \r\n");
                        using (var boxTracer = db.Cube())
                        {
                            bool   keepTrace = true;
                            Member tra       = boxTracer.Bind("MemberInc", 1L)
                                               .Select <Member>(keepTrace);
                            String currentName = tra.Name;

                            {
                                // another box changes the name
                                MemberInc mm = new MemberInc();
                                mm.ID   = 1;
                                mm.Name = "Kelly";
                                db.Get().Update("MemberInc", mm.ID, mm);
                            }

                            // will auto rollback
                            if (boxTracer.Commit().Equals(CommitResult.OK))
                            {
                                throw new Exception();
                            }
                            else
                            {
                                sb.Append("the name '" + currentName + "' is changed,");
                            }
                        }
                        Member nm = db.Get().SelectKey <Member>("MemberInc", 1L);
                        sb.Append("new name is '" + nm.Name + "'");
                    }
                }
            }
            catch (Exception ex)
            {
                sb.Append(ex.ToString());
            }
            return(sb);
        }