示例#1
0
        /// <summary>
        /// Serialize the state of the WM and the workspaces that have changed
        /// since the last serialization time.
        /// </summary>
        public static void Serialize()
        {
            // We should have a transaction open.
            Debug.Assert(LocalDb.HasTransaction());

            // Serialize the dirty objects.
            if (Wm.Cd.SerializationRevID != Wm.Cd.PermanentRevID)
            {
                Wm.Cd.SerializationRevID = Wm.Cd.PermanentRevID;
                SerializeObject("wm_core", Wm.Cd);
            }

            foreach (Workspace kws in KwsTree.Values)
            {
                if (kws.Cd.SerializationRevID != kws.Cd.PermanentRevID)
                {
                    kws.Cd.SerializationRevID = kws.Cd.PermanentRevID;
                    SerializeObject("kws_" + kws.InternalID + "_core", kws.Cd);
                }

                if (kws.Cd.KfsAd.SerializationRevID != kws.Cd.KfsAd.PermanentRevID)
                {
                    kws.Cd.KfsAd.SerializationRevID = kws.Cd.KfsAd.PermanentRevID;
                    SerializeObject("kws_" + kws.InternalID + "_kfs", kws.Cd.KfsAd);
                }
            }

            // Commit the lingering transaction.
            LocalDb.CommitTransaction();

            // Open a new lingering transaction.
            LocalDb.BeginTransaction();
        }
示例#2
0
        /// <summary>
        /// Create the initial database schema.
        /// </summary>
        private void CreateSchema()
        {
            KLogging.Log("Creating database schema.");

            m_db.BeginTransaction();

            String s =
                "CREATE TABLE 'db_version' ('version' INT PRIMARY KEY); " +
                "INSERT INTO db_version (version) VALUES (" + LatestDbVersion + "); " +
                "CREATE TABLE 'serialization' ('name' VARCHAR PRIMARY KEY, 'data' BLOB); " +
                "CREATE TABLE 'kws_list' ('kws_id' INT PRIMARY KEY, 'name' VARCHAR); " +
                "CREATE TABLE 'kanp_events' ('kws_id' INT, 'evt_id' INT, 'evt_data' BLOB, 'status' INT); " +
                "CREATE TABLE 'eanp_events' ('kws_id' INT, 'evt_id' INT, 'uuid' BLOB, 'evt_data' BLOB); " +
                "CREATE UNIQUE INDEX 'kanp_events_index_1' ON 'kanp_events' ('kws_id', 'evt_id'); " +
                "CREATE UNIQUE INDEX 'kanp_events_index_2' ON 'kanp_events' ('kws_id', 'status', 'evt_id'); " +
                "CREATE UNIQUE INDEX 'eanp_events_index_1' ON 'eanp_events' ('kws_id', 'evt_id'); ";

            m_db.ExecNQ(s);

            m_db.CommitTransaction();
        }