コード例 #1
0
ファイル: FieldViewModel.cs プロジェクト: timotrob/VelocityDB
        public Array GetFieldAsArray()
        {
            IOptimizedPersistable parentObj = (IOptimizedPersistable)m_session.Open(m_parentId, false, null, false, 0, Int32.MaxValue);
            object memberObj = m_member.GetMemberValue(parentObj.WrappedObject);

            return(memberObj as Array);
        }
コード例 #2
0
        void calculateNumbers(SessionBase session)
        {
            ImdbRoot     imdbRoot = (ImdbRoot)session.Open(session.DatabaseNumberOf(typeof(ImdbRoot)), 2, 1, false);
            ActingPerson kevin    = new Actor("Bacon, Kevin (I)", session);

            if (!imdbRoot.ActingByNameSet.TryGetKey(kevin, ref kevin))
            {
                Console.WriteLine("Couldn't find actor Kevin Bacon!");
            }
            else
            {
                unchasedMovie = kevin.InMovieAs.ToList <Movie>();
                resultArray[bacon]++; // Kevin Bacon himself
                while (unchasedMovie.Count > 0)
                {
                    bacon++;
                    processsMovies(session);
                    foreach (ActingPerson acting in unchasedPerson)
                    {
                        foreach (Movie movie in (IEnumerable <Movie>)acting.InMovieAs)
                        {
                            if (chasedMovie.Contains(movie.ShortId) == false)
                            {
                                unchasedMovie.Add(movie);
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
 IEnumerable <T> SessionOpen <T>(IEnumerable <ulong> oids)
 {
     foreach (var i in oids)
     {
         yield return(_session.Open <T>(i));
     }
 }
コード例 #4
0
    void NotifyBeforeCommit(SessionBase session)
    {
      var newlyPersisted = session.NewOids;
      Console.Out.WriteLine("Number of newly persisted: " + newlyPersisted.Count);
      foreach (var id in newlyPersisted)
      {
        var pObj = session.Open(id);
      }

      var newlyUnpersisted = session.DeletedOids;
      Console.Out.WriteLine("Number of newly unpersisted: " + newlyUnpersisted.Count);

      var updated = session.UpdatedOids;
      Console.Out.WriteLine("Number of updated: " + updated.Count);
      foreach (var id in updated)
      {
        var pObj = session.Open(id);
      }
    }
コード例 #5
0
        static public string ExportToJson <T>(this SessionBase session, UInt64 id)
        {
            object obj = session.Open(id);
            JsonSerializerSettings jsonSettings = new JsonSerializerSettings();

            jsonSettings.TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple;
            jsonSettings.TypeNameHandling           = TypeNameHandling.All;
            jsonSettings.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
            jsonSettings.ContractResolver           = new FieldsOnlyContractResolver();
            return(JsonConvert.SerializeObject(obj, jsonSettings));
        }
コード例 #6
0
        public object Get([BindRequired, FromQuery] string path, [BindRequired, FromQuery] string id)
        {
            if (path == null)
            {
                return("Path no set");
            }
            if (id == null)
            {
                return("object Id not specified (as string)");
            }

            try
            {
                var         pool      = GetSessionPool(path);
                int         sessionId = -1;
                SessionBase session   = null;
                try
                {
                    session = pool.GetSession(out sessionId);
                    UInt64 Id;
                    if (id.Contains('-'))
                    {
                        Id = Oid.IdFromString(id);
                    }
                    else
                    {
                        UInt64.TryParse(id, out Id);
                    }
                    if (Id != 0)
                    {
                        session.BeginRead();
                        var obj = session.Open <IOptimizedPersistable>(Id);
                        session.Commit();
                        if (obj == null)
                        {
                            return($"object with id {id} does not exist");
                        }
                        return(new TypePlusObj(obj));
                    }
                    return(null);
                }
                finally
                {
                    if (session != null)
                    {
                        pool.FreeSession(sessionId, session);
                    }
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
コード例 #7
0
 /// <summary>
 ///   Returns an object the specified generic type, of which there is only expected
 ///   to be one, if found, otherwise a null reference.
 /// </summary>
 internal TPersistable?FindSingleton <TPersistable>(SessionBase session)
     where TPersistable : OptimizedPersistable
 {
     return(SchemaExistsOnDatabase(session)
 ? session.Open(
                session.DatabaseNumberOf(typeof(TPersistable)),
                // Why page number 2? I don't know, but it works for fetching singleton
                // objects. See 'Looking up objects' in the VelocityDB manual.
                // ReSharper disable once ArgumentsStyleNamedExpression
                2, 1, update: session.InUpdateTransaction) as TPersistable
 : null);
 }
コード例 #8
0
        void NotifyBeforeCommit(SessionBase session)
        {
            var newlyPersisted = session.NewOids;

            Console.Out.WriteLine("Number of newly persisted: " + newlyPersisted.Count);
            foreach (var id in newlyPersisted)
            {
                var pObj = session.Open(id);
            }

            var newlyUnpersisted = session.DeletedOids;

            Console.Out.WriteLine("Number of newly unpersisted: " + newlyUnpersisted.Count);

            var updated = session.UpdatedOids;

            Console.Out.WriteLine("Number of updated: " + updated.Count);
            foreach (var id in updated)
            {
                var pObj = session.Open(id);
            }
        }
コード例 #9
0
        static void createDocumentInvertedIndex(SessionBase session, Database db, BTreeSet <Document> documentSet)
        {
            UInt32    dbNum            = db.DatabaseNumber;
            Document  doc              = null;
            Document  inputDoc         = new Document(db.Id);
            Placement wordPlacement    = new Placement(inputDoc.DatabaseNumber, 20000, 1, 25000, 65000, true, false, 1, false);
            Placement wordHitPlacement = new Placement(inputDoc.DatabaseNumber, 40000, 1, 25000, 65500, true, false, 1, false);
            //session.SetTraceDbActivity(db.DatabaseNumber);
            BTreeSetIterator <Document> iterator = documentSet.Iterator();

            iterator.GoTo(inputDoc);
            inputDoc = iterator.Current();
            while (inputDoc != null && inputDoc.Page.Database.DatabaseNumber == dbNum)
            {
                doc = (Document)session.Open(inputDoc.Page.Database, inputDoc.Id); // if matching database is availeble, use it to speed up lookup
                DocumentText    docText    = doc.Content;
                string          text       = docText.Text.ToLower();
                MatchCollection tagMatches = Regex.Matches(text, "[a-z][a-z.$]+");
                UInt64          wordCt     = 0;
                WordHit         wordHit;
                Word            word;
                if (++s_docCountIndexed % 50000 == 0)
                {
                    Console.WriteLine(DateTime.Now.ToString() + ", done indexing article: " + s_docCountIndexed);
                }
                BTreeSetOidShort <Word> wordSet = doc.WordSet;
                foreach (Match m in tagMatches)
                {
                    word = new Word(m.Value);
                    if (wordSet.TryGetKey(word, ref word))
                    {
                        //wordHit = doc.WordHit[word]; // to costly to add tight now - figure out a better way ?
                        //wordHit.Add(wordCt);
                    }
                    else
                    {
                        word = new Word(m.Value);
                        word.Persist(wordPlacement, session);
                        wordSet.Add(word);
                        wordHit = new WordHit(doc, wordCt++, session);
                        //wordHit.Persist(wordHitPlacement, session);
                        doc.WordHit.ValuePlacement = wordHitPlacement;
                        doc.WordHit.AddFast(word, wordHit);
                    }
                }
                inputDoc = iterator.Next();
            }
            session.FlushUpdates(db);
            session.ClearCachedObjects(db); // free up memory for objects we no longer need to have cached
            Console.WriteLine(DateTime.Now.ToString() + ", done indexing article: " + s_docCountIndexed + " Database: " + dbNum + " is completed.");
        }
コード例 #10
0
        void LoadChild(DataMember member, object memberObj)
        {
            bool listWithItems = false;

            if (member.Field != null && member.Field.FieldType.IsGenericType && member.Field.FieldType.GetGenericTypeDefinition() == typeof(List <>))
            {
                IList list = (IList)memberObj;
                listWithItems = list != null && list.Count > 0;
            }
            IOptimizedPersistable pObj = (IOptimizedPersistable)m_session.Open(m_objectId, false, null, false, 0, Int32.MaxValue);

            if (pObj != null)
            {
                if (member.Field != null && memberObj != null & (member.Field.FieldType.IsArray || member.HasId || listWithItems || member.WeakIOptimizedPersistableReference))
                {
                    base.Children.Add(new FieldViewModel(pObj, member, this, m_session));
                }
                else
                {
                    base.Children.Add(new FieldViewModelNoExpansions(pObj, member, this, m_session));
                }
            }
        }
コード例 #11
0
        public void BTreeMap2Iterate()
        {
            int         sessionId = 0;
            SessionBase session   = null;

            try
            {
                session = SessionManager.SessionPool.GetSession(out sessionId);
                session.BeginRead();
                var bTreeMap  = session.Open <BTreeMapOwner>(_id);
                int zipCodeCt = 0;
                foreach (var p in bTreeMap.LocationByZipCode)
                {
                    session.Commit();
                    session.BeginUpdate();
                    var v = p.Value;
                    foreach (var l in v)
                    {
                        l.Address1 = "2034 Cordoba PL";
                    }
                    var k = p.Key;
                    zipCodeCt++;
                    session.Commit();
                    session.BeginRead();
                }
                Assert.AreEqual(numberOfZipCodes, zipCodeCt);
                session.Commit();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
            finally
            {
                SessionManager.SessionPool.FreeSession(sessionId, session);
            }
        }
コード例 #12
0
 void calculateNumbers(SessionBase session)
 {
   ImdbRoot imdbRoot = (ImdbRoot)session.Open(session.DatabaseNumberOf(typeof(ImdbRoot)), 2, 1, false);
   ActingPerson kevin = new Actor("Bacon, Kevin (I)", session);
   if (!imdbRoot.ActingByNameSet.TryGetKey(kevin, ref kevin))
     Console.WriteLine("Couldn't find actor Kevin Bacon!");
   else
   {
     unchasedMovie = kevin.InMovieAs.ToList<Movie>();
     resultArray[bacon]++; // Kevin Bacon himself       
     while (unchasedMovie.Count > 0)
     {
       bacon++;
       processsMovies(session);
       foreach (ActingPerson acting in unchasedPerson)
       {
         foreach (Movie movie in (IEnumerable<Movie>)acting.InMovieAs)
           if (chasedMovie.Contains(movie.ShortId) == false)
             unchasedMovie.Add(movie);
       }
     }
   }
 }
コード例 #13
0
ファイル: Wikipedia.cs プロジェクト: VelocityDB/VelocityDB
 static void createDocumentInvertedIndex(SessionBase session, Database db, BTreeSet<Document> documentSet)
 {
   UInt32 dbNum = db.DatabaseNumber;
   Document doc = null;
   Document inputDoc = new Document(db.Id);
   Placement wordPlacement = new Placement(inputDoc.DatabaseNumber, 20000, 1, 25000, 65000, true, false, 1, false);
   Placement wordHitPlacement = new Placement(inputDoc.DatabaseNumber, 40000, 1, 25000, 65500, true, false, 1, false);
   //session.SetTraceDbActivity(db.DatabaseNumber);
   BTreeSetIterator<Document> iterator = documentSet.Iterator();
   iterator.GoTo(inputDoc);
   inputDoc = iterator.Current();
   while (inputDoc != null && inputDoc.Page.Database.DatabaseNumber == dbNum)
   {
     doc = (Document)session.Open(inputDoc.Page.Database, inputDoc.Id); // if matching database is availeble, use it to speed up lookup
     DocumentText docText = doc.Content;
     string text = docText.Text.ToLower();
     MatchCollection tagMatches = Regex.Matches(text, "[a-z][a-z.$]+");
     UInt64 wordCt = 0;
     WordHit wordHit;
     Word word;
     if (++s_docCountIndexed % 50000 == 0)
       Console.WriteLine(DateTime.Now.ToString() + ", done indexing article: " + s_docCountIndexed);
     BTreeSetOidShort<Word> wordSet = doc.WordSet;
     foreach (Match m in tagMatches)
     {
       word = new Word(m.Value);
       if (wordSet.TryGetKey(word, ref word))
       {
         //wordHit = doc.WordHit[word]; // to costly to add tight now - figure out a better way ?
         //wordHit.Add(wordCt);
       }
       else
       {
         word = new Word(m.Value);
         word.Persist(wordPlacement, session);
         wordSet.Add(word);
         wordHit = new WordHit(doc, wordCt++, session);
         //wordHit.Persist(wordHitPlacement, session);
         doc.WordHit.ValuePlacement = wordHitPlacement;
         doc.WordHit.AddFast(word, wordHit);
       }
     }
     inputDoc = iterator.Next();
   }
   session.FlushUpdates(db);
   session.ClearCachedObjects(db); // free up memory for objects we no longer need to have cached
   Console.WriteLine(DateTime.Now.ToString() + ", done indexing article: " + s_docCountIndexed + " Database: " + dbNum + " is completed.");
 }
コード例 #14
0
ファイル: Sync.cs プロジェクト: VelocityDB/VelocityDB
 static public void SyncWith(this SessionBase sessionToUpdate, SessionBase sessionToRead, Func<SessionBase, UInt64, Change, bool> doUpdate)
 {
   UInt64 currentVersion;
   UInt64 pageToReadVersion;
   bool conflictFound = false;
   using (var reader = sessionToRead.BeginRead())
   {
     Changes changes = (Changes)sessionToRead.Open(5, 1, 1, false);
     if (changes != null)
     {
       using (var updater = sessionToUpdate.BeginUpdate())
       {
         var dbs = sessionToUpdate.OpenAllDatabases();
         ReplicaSync matchingReplicaSync = null;
         foreach (ReplicaSync sync in sessionToUpdate.AllObjects<ReplicaSync>())
         {
           if (sync.SyncFromHost == sessionToRead.SystemHostName && sync.SyncFromPath == sessionToRead.SystemDirectory)
           {
             matchingReplicaSync = sync;
             break;
           }
         }
         if (changes.ChangeList.Count > 0)
         {
           foreach (TransactionChanges transactionChanges in changes.ChangeList)
           {
             if (matchingReplicaSync == null || matchingReplicaSync.TransactionNumber < transactionChanges.TransactionNumber)
             {
               foreach (Change change in transactionChanges.ChangeList)
               {
                 Database dbToUpdate = sessionToUpdate.OpenDatabase(change.DatabaseId, false, false);
                 Database dbToRead = sessionToRead.OpenDatabase(change.DatabaseId, false, false);
                 string dbName = dbToRead != null ? dbToRead.Name : null;
                 if (change.Deleted)
                 {
                   if (dbToUpdate == null) // does not exist
                     continue;
                   if (change.PageId == 0) // Database delete
                   {
                     currentVersion = dbToUpdate.Page.PageInfo.VersionNumber;
                     if (currentVersion < change.Version)
                       sessionToUpdate.DeleteDatabase(dbToUpdate);
                     else
                     {
                       conflictFound = true;
                       if (doUpdate(sessionToUpdate, currentVersion, change))
                         sessionToUpdate.DeleteDatabase(dbToUpdate);
                     }
                   }
                   else
                   {
                     Page page = sessionToUpdate.OpenPage(dbToUpdate, change.PageId);
                     if (page == null) // page does not exist
                       continue;
                     currentVersion = page.PageInfo.VersionNumber;
                     if (currentVersion < change.Version)
                       sessionToUpdate.DeletePage(dbToUpdate, page);
                     else
                     {
                       conflictFound = true;
                       if (doUpdate(sessionToUpdate, currentVersion, change))
                         sessionToUpdate.DeleteDatabase(dbToUpdate);
                     }
                   }
                 }
                 else
                 {
                   if (dbToUpdate == null) // does not exist
                     dbToUpdate = sessionToUpdate.NewDatabase(change.DatabaseId, 0, dbName);
                   if (change.PageId > 0)
                   {
                     Page pageToUpdate = sessionToUpdate.OpenPage(dbToUpdate, change.PageId);
                     Page pageToRead = sessionToRead.OpenPage(dbToRead, change.PageId);
                     if (pageToRead == null) // upcoming (not yet processed) changes must have deleted this page
                       continue;
                     currentVersion = pageToUpdate == null ? 0 : pageToUpdate.PageInfo.VersionNumber;
                     pageToReadVersion = pageToRead.PageInfo.VersionNumber;
                     if (currentVersion < pageToReadVersion || dbToUpdate.IsNew)
                       sessionToUpdate.ReplacePage(dbToUpdate, pageToUpdate, pageToRead);
                     else
                     {
                       conflictFound = true;
                       if (doUpdate(sessionToUpdate, currentVersion, change))
                         sessionToUpdate.ReplacePage(dbToUpdate, pageToUpdate, pageToRead);
                     }
                   }
                 }
               }
             }
           }
           UInt64 lastTransactionNumber = changes.ChangeList.Last().TransactionNumber;
           if (matchingReplicaSync != null)
             matchingReplicaSync.TransactionNumber = lastTransactionNumber;
           if (conflictFound)
           {
             sessionToUpdate.Verify();
           }
           sessionToUpdate.Commit();
           if (matchingReplicaSync == null)
           {
             sessionToUpdate.BeginUpdate(); // separate transaction or else gets confused with databases added by sync
             matchingReplicaSync = new ReplicaSync(sessionToRead, lastTransactionNumber);
             sessionToUpdate.Persist(matchingReplicaSync);
             sessionToUpdate.Commit();
           }
         }
       }
     }
   }
 }
コード例 #15
0
        static public void SyncWith(this SessionBase sessionToUpdate, SessionBase sessionToRead, Func <SessionBase, UInt64, Change, bool> doUpdate)
        {
            UInt64 currentVersion;
            UInt64 pageToReadVersion;
            bool   conflictFound = false;

            using (var reader = sessionToRead.BeginRead())
            {
                Changes changes = (Changes)sessionToRead.Open(5, 1, 1, false);
                if (changes != null)
                {
                    using (var updater = sessionToUpdate.BeginUpdate())
                    {
                        var         dbs = sessionToUpdate.OpenAllDatabases();
                        ReplicaSync matchingReplicaSync = null;
                        foreach (ReplicaSync sync in sessionToUpdate.AllObjects <ReplicaSync>())
                        {
                            if (sync.SyncFromHost == sessionToRead.SystemHostName && sync.SyncFromPath == sessionToRead.SystemDirectory)
                            {
                                matchingReplicaSync = sync;
                                break;
                            }
                        }
                        if (changes.ChangeList.Count > 0)
                        {
                            foreach (TransactionChanges transactionChanges in changes.ChangeList)
                            {
                                if (matchingReplicaSync == null || matchingReplicaSync.TransactionNumber < transactionChanges.TransactionNumber)
                                {
                                    foreach (Change change in transactionChanges.ChangeList)
                                    {
                                        Database dbToUpdate = sessionToUpdate.OpenDatabase(change.DatabaseId, false, false);
                                        Database dbToRead   = sessionToRead.OpenDatabase(change.DatabaseId, false, false);
                                        string   dbName     = dbToRead != null ? dbToRead.Name : null;
                                        if (change.Deleted)
                                        {
                                            if (dbToUpdate == null) // does not exist
                                            {
                                                continue;
                                            }
                                            if (change.PageId == 0) // Database delete
                                            {
                                                currentVersion = dbToUpdate.Page.PageInfo.VersionNumber;
                                                if (currentVersion < change.Version)
                                                {
                                                    sessionToUpdate.DeleteDatabase(dbToUpdate);
                                                }
                                                else
                                                {
                                                    conflictFound = true;
                                                    if (doUpdate(sessionToUpdate, currentVersion, change))
                                                    {
                                                        sessionToUpdate.DeleteDatabase(dbToUpdate);
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                Page page = sessionToUpdate.OpenPage(dbToUpdate, change.PageId);
                                                if (page == null) // page does not exist
                                                {
                                                    continue;
                                                }
                                                currentVersion = page.PageInfo.VersionNumber;
                                                if (currentVersion < change.Version)
                                                {
                                                    sessionToUpdate.DeletePage(dbToUpdate, page);
                                                }
                                                else
                                                {
                                                    conflictFound = true;
                                                    if (doUpdate(sessionToUpdate, currentVersion, change))
                                                    {
                                                        sessionToUpdate.DeleteDatabase(dbToUpdate);
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (dbToUpdate == null) // does not exist
                                            {
                                                dbToUpdate = sessionToUpdate.NewDatabase(change.DatabaseId, 0, dbName);
                                            }
                                            if (change.PageId > 0)
                                            {
                                                Page pageToUpdate = sessionToUpdate.OpenPage(dbToUpdate, change.PageId);
                                                Page pageToRead   = sessionToRead.OpenPage(dbToRead, change.PageId);
                                                if (pageToRead == null) // upcoming (not yet processed) changes must have deleted this page
                                                {
                                                    continue;
                                                }
                                                currentVersion    = pageToUpdate == null ? 0 : pageToUpdate.PageInfo.VersionNumber;
                                                pageToReadVersion = pageToRead.PageInfo.VersionNumber;
                                                if (currentVersion < pageToReadVersion || dbToUpdate.IsNew)
                                                {
                                                    sessionToUpdate.ReplacePage(dbToUpdate, pageToUpdate, pageToRead);
                                                }
                                                else
                                                {
                                                    conflictFound = true;
                                                    if (doUpdate(sessionToUpdate, currentVersion, change))
                                                    {
                                                        sessionToUpdate.ReplacePage(dbToUpdate, pageToUpdate, pageToRead);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            UInt64 lastTransactionNumber = changes.ChangeList.Last().TransactionNumber;
                            if (matchingReplicaSync != null)
                            {
                                matchingReplicaSync.TransactionNumber = lastTransactionNumber;
                            }
                            if (conflictFound)
                            {
                                sessionToUpdate.Verify();
                            }
                            sessionToUpdate.Commit();
                            if (matchingReplicaSync == null)
                            {
                                sessionToUpdate.BeginUpdate(); // separate transaction or else gets confused with databases added by sync
                                matchingReplicaSync = new ReplicaSync(sessionToRead, lastTransactionNumber);
                                sessionToUpdate.Persist(matchingReplicaSync);
                                sessionToUpdate.Commit();
                            }
                        }
                    }
                }
            }
        }
コード例 #16
0
        public ActionResult Put([BindRequired, FromQuery] string path, [FromBody] TypePlusObj obj)
        {
            if (path == null)
            {
                return(BadRequest("path not set"));
            }

            try
            {
                var         pool      = GetSessionPool(path);
                int         sessionId = -1;
                SessionBase session   = null;
                try
                {
                    session = pool.GetSession(out sessionId);
                    if (session.InTransaction)
                    {
                        session.Abort();
                    }
                    session.BeginUpdate();
                    var id = Oid.IdFromString(obj.Id);
                    OptimizedPersistable pObj = null;
                    if (id != 0)
                    {
                        pObj = session.Open <OptimizedPersistable>(id);
                    }
                    string objAsString = obj.Obj.ToString();
                    var    pObj2       = JsonConvert.DeserializeObject(objAsString, obj.Type, _jsonSettings);
                    if (pObj != null)
                    {
                        pObj.Update();
                        UpdateFields(pObj, pObj2);
                        session.Commit();
                        return(Ok($"{obj.Id} updated"));
                    }
                    else if (pObj2 != null)
                    {
                        var pId = session.Persist(pObj2);
                        session.Commit();
                        return(Ok(new Oid(pId).ToString()));
                    }
                    session.Abort();
                    return(BadRequest($"Failed to deserialize json to object of type: {obj.Type}"));
                }
                catch (Exception ex)
                {
                    session.Abort();
                    return(BadRequest(ex.Message));
                }
                finally
                {
                    if (session != null)
                    {
                        pool.FreeSession(sessionId, session);
                    }
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
コード例 #17
0
        public Array GetFieldAsArray()
        {
            TypeVersion parentObj = m_session.Open <TypeVersion>(m_parentId);

            return(null); // TO DO, FIX IT!
        }
コード例 #18
0
        public void Recover1(SessionBase session)
        {
            Database db = null;

            session.BeginUpdate();
            session.RegisterClass(typeof(SortedSetAny <int>));
            session.RegisterClass(typeof(SortedSetAny <float>));
            db = session.OpenDatabase(88, true, false);
            if (db != null)
            {
                session.DeleteDatabase(db);
            }
            db = session.OpenDatabase(89, true, false);
            if (db != null)
            {
                session.DeleteDatabase(db);
            }
            session.Commit();
            session.BeginUpdate();
            db = session.NewDatabase(88);
            session.FlushUpdates();
            session.Abort();
            session.BeginUpdate();
            db = session.NewDatabase(88);
            SortedSetAny <float> floatSet;
            Oid       floatSetOid;
            string    dbPath = System.IO.Path.Combine(systemDir, "89.odb");
            Placement place  = new Placement(88);

            for (int i = 0; i < 10; i++)
            {
                floatSet = new SortedSetAny <float>();
                floatSet.Persist(place, session);
                floatSetOid = floatSet.Oid;
            }
            db = session.NewDatabase(89);
            session.Commit();
            File.Delete(dbPath);
            session.BeginUpdate();
            db = session.NewDatabase(89);
            session.Commit();
            FileInfo info = new FileInfo(dbPath);

            info.CopyTo(dbPath + "X");
            session.BeginUpdate();
            SortedSetAny <int> intSet;

            place = new Placement(89);
            for (int i = 0; i < 10; i++)
            {
                intSet = new SortedSetAny <int>();
                intSet.Persist(place, session);
            }
            db = session.OpenDatabase(88);
            var list = db.AllObjects <SortedSetAny <float> >();

            foreach (SortedSetAny <float> set in list)
            {
                set.Unpersist(session);
            }
            db = session.OpenDatabase(89);
            session.Commit();
            intSet = null;
            db     = null; // release refs so that cached data isn't stale
            File.Delete(dbPath);
            info = new FileInfo(dbPath + "X");
            info.MoveTo(dbPath);
            session.BeginUpdate();
            intSet = (SortedSetAny <int>)session.Open(89, 1, 1, false);
            Debug.Assert(intSet == null);
            object o = session.Open(88, 1, 1, false);

            floatSet = (SortedSetAny <float>)o;
            Debug.Assert(floatSet != null);
            session.Checkpoint();
            db = session.OpenDatabase(88);
            session.DeleteDatabase(db);
            db = session.OpenDatabase(89);
            session.DeleteDatabase(db);
            session.Commit();
        }
コード例 #19
0
 public void Recover1(SessionBase session)
 {
   Database db = null;
   session.BeginUpdate();
   db = session.OpenDatabase(88, true, false);
   if (db != null)
     session.DeleteDatabase(db);
   db = session.OpenDatabase(89, true, false);
   if (db != null)
     session.DeleteDatabase(db);
   session.Commit();
   session.BeginUpdate();
   db = session.NewDatabase(88);
   session.FlushUpdates();
   session.Abort();
   session.BeginUpdate();
   db = session.NewDatabase(88);
   SortedSetAny<float> floatSet;
   Oid floatSetOid;
   string dbPath = System.IO.Path.Combine(systemDir, "89.odb");
   Placement place = new Placement(88);
   for (int i = 0; i < 10; i++)
   {
     floatSet = new SortedSetAny<float>();
     floatSet.Persist(place, session);
     floatSetOid = floatSet.Oid;
   }
   db = session.NewDatabase(89);
   session.Commit();
   File.Delete(dbPath);
   session.BeginUpdate();
   db = session.NewDatabase(89);
   session.Commit();
   FileInfo info = new FileInfo(dbPath);
   info.CopyTo(dbPath + "X");
   session.BeginUpdate();
   SortedSetAny<int> intSet;
   place = new Placement(89);
   for (int i = 0; i < 10; i++)
   {
     intSet = new SortedSetAny<int>();
     intSet.Persist(place, session);
   }
   db = session.OpenDatabase(88);
   var list = db.AllObjects<SortedSetAny<float>>();
   foreach (SortedSetAny<float> set in list)
     set.Unpersist(session);
   db = session.OpenDatabase(89);
   session.Commit();
   intSet = null;
   db = null; // release refs so that cached data isn't stale
   File.Delete(dbPath);
   info = new FileInfo(dbPath + "X");
   info.MoveTo(dbPath);
   session.BeginUpdate();
   intSet = (SortedSetAny<int>)session.Open(89, 1, 1, false);
   Debug.Assert(intSet == null);
   object o = session.Open(88, 1, 1, false);
   floatSet = (SortedSetAny<float>)o;
   Debug.Assert(floatSet != null);
   session.Commit();
   session.BeginUpdate();
   db = session.OpenDatabase(88);
   session.DeleteDatabase(db);
   db = session.OpenDatabase(89);
   session.DeleteDatabase(db);
   session.Commit();
 }