当前位置: 首页>>代码示例>>C#>>正文


C# SessionNoServer.OpenDatabase方法代码示例

本文整理汇总了C#中SessionNoServer.OpenDatabase方法的典型用法代码示例。如果您正苦于以下问题:C# SessionNoServer.OpenDatabase方法的具体用法?C# SessionNoServer.OpenDatabase怎么用?C# SessionNoServer.OpenDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SessionNoServer的用法示例。


在下文中一共展示了SessionNoServer.OpenDatabase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateLocationSameHost

 public void CreateLocationSameHost()
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginUpdate();
     DatabaseLocation remoteLocation = new DatabaseLocation(Dns.GetHostName(), location2Dir, locationStartDbNum, locationEndDbNum, session, PageInfo.compressionKind.LZ4, 0);
     remoteLocation = session.NewLocation(remoteLocation);
     Database database = session.NewDatabase(remoteLocation.StartDatabaseNumber);
     Assert.NotNull(database);
     session.Commit();
   }
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginUpdate();
     Database database = session.OpenDatabase(locationStartDbNum, false);
     Assert.NotNull(database);
     session.DeleteDatabase(database);
     session.Commit();
   }
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginUpdate();
     foreach (DatabaseLocation loc in session.DatabaseLocations)
       Console.WriteLine(loc.ToStringDetails(session, false));
     session.DeleteLocation(session.DatabaseLocations.LocationForDb(locationStartDbNum));
     foreach (DatabaseLocation loc in session.DatabaseLocations)
       Console.WriteLine(loc.ToStringDetails(session, false));
     session.Commit();
   }
 }
开发者ID:MerlinBrasil,项目名称:VelocityDB,代码行数:30,代码来源:DatabaseLocationTest.cs

示例2: Get

 // GET api/database/suppliertracking/15
 public string Get(string path, UInt32 id)
 {
   using (SessionNoServer session = new SessionNoServer(path))
   {
     session.BeginRead();
     Database db = session.OpenDatabase(id);
     string dbName = db.ToString();
     session.Commit();
     return dbName;
   }
 }
开发者ID:VelocityDB,项目名称:VelocityDB,代码行数:12,代码来源:DatabaseController.cs

示例3: Get

 /// <summary>
 /// Get the names of all persitent types used.
 /// </summary>
 /// <param name="path">Path to database directory on server relativer to server setting <see cref="SessionBase.BaseDatabasePath"/></param>
 /// <returns>All type names registered in the database schema</returns>
 public IEnumerable<string> Get(string path)
 {
   using (SessionNoServer session = new SessionNoServer(path))
   {
     session.BeginRead();
     Database db = session.OpenDatabase(1);
     var e = db.AllObjects<VelocityDbType>(false);
     var types = session.ExportToJson<VelocityDbType>(false, false);
     List<string> stringList = new List<String>();
     foreach (VelocityDbType t in e)
       yield return t.Type.ToGenericTypeString();
     session.Commit();
   }
 }
开发者ID:MerlinBrasil,项目名称:VelocityDB,代码行数:19,代码来源:TypeController.cs

示例4: cDeleteDatabases

 public void cDeleteDatabases()
 {
   Database database;
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginUpdate();
     for (uint i = 50000000; i < 50001000; i++)
     {
       database = session.OpenDatabase(i);
       session.DeleteDatabase(database);
     }
     session.Commit();
   }
 }
开发者ID:MerlinBrasil,项目名称:VelocityDB,代码行数:14,代码来源:DatabaseTest.cs

示例5: Main

    static readonly string s_systemDir = "UpdateClass"; // appended to SessionBase.BaseDatabasePath

    static int Main(string[] args)
    {
      try
      {
        UpdatedClass updatedClassObject;
        int ct1 = 0;
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          session.BeginUpdate();
          session.UpdateClass(typeof(UpdatedClass)); // call this when you have updated the class since first storing instances of this type or since last call to UpdateClass
          UInt32 dbNum = session.DatabaseNumberOf(typeof(UpdatedClass));
          foreach (UpdatedClass obj in session.AllObjects<UpdatedClass>())
          {
            Console.Write(obj.ToString() + " has members: ");
            foreach (DataMember member in obj.GetDataMembers())
            {
              Console.Write(member.ToString() + " ");
            }
            Console.WriteLine();
            obj.UpdateTypeVersion(); // comment out if you DO NOT want to migrate this object to the latest version of the class
            ct1++;
          }
          int ct2 = 0;
          Database db = session.OpenDatabase(dbNum, true, false);
          if (db != null)
            foreach (UpdatedClass obj in db.AllObjects<UpdatedClass>())
              ct2++;
          Debug.Assert(ct1 == ct2);         
          updatedClassObject = new UpdatedClass();
          session.Persist(updatedClassObject);
          session.Commit();
        }
      }
      catch (Exception ex)
      {
        Console.WriteLine(ex.ToString());
        return 1;
      }
      return 0;
    }
开发者ID:VelocityDB,项目名称:VelocityDB,代码行数:42,代码来源:UpdateClass.cs

示例6: QuerySomeBicycles

 public void QuerySomeBicycles()
 {
   try
   {
     using (SessionNoServer session = new SessionNoServer(s_systemDir))
     {
       session.BeginRead();
       Database db = session.OpenDatabase(session.DatabaseNumberOf(typeof(Bicycle)));
       Bicycle b1 = db.AllObjects<Bicycle>().ElementAt(50005);
       Bicycle b2 = db.AllObjects<Bicycle>().ElementAt<Bicycle>(50005);
       if (b1 != b2)
         throw new UnexpectedException("b1 != b2");
       var src = from Bicycle bike in db.AllObjects<Bicycle>() where bike.Color == "blue" select bike;
       foreach (Bicycle bike in src)
         Console.WriteLine(bike.ToStringDetails(session));
       session.Commit();
     }      
   }
   catch (Exception ex)
   {
     Console.WriteLine(ex.ToString());
   }
 }
开发者ID:MerlinBrasil,项目名称:VelocityDB,代码行数:23,代码来源:OneDbPerClass.cs

示例7: aCreateDatabases

 public void aCreateDatabases()
 {
   Database database;
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginUpdate();
     for (uint i = 50000000; i < 50001000; i++)
     {
       database = session.NewDatabase(i);
       Assert.NotNull(database);
     }
     session.Commit();
   }
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginUpdate();
     for (uint i = 50000000; i < 50001000; i++)
     {
       database = session.OpenDatabase(i);
       Assert.NotNull(database);
     }
     session.Commit();
   }
 }
开发者ID:MerlinBrasil,项目名称:VelocityDB,代码行数:24,代码来源:DatabaseTest.cs

示例8: ConcurrentUpdates

    public void ConcurrentUpdates(bool serverSession, int numberofThreads, bool optimisticLocking)
    {
      using (SessionBase session = new SessionNoServer(systemDir))
      {
        session.BeginRead();
        Database db = session.OpenDatabase(FixedSize.PlaceInDatabase, false, false);
        if (db != null)
          Console.WriteLine("ConcurrentUpdates start, Number of FixedSize objects: " + db.AllObjects<FixedSize>().Count);
      }

      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginUpdate();
        FixedSize fixedSize = new FixedSize();
        session.Persist(fixedSize);
        session.Commit();
      }
      Thread[] threads = new Thread[numberofThreads];
      for (int i = 0; i < numberofThreads; i++)
        threads[i] = new Thread(() =>
          {
            SessionBase session;
            if (serverSession)
              session = new ServerClientSession(systemDir, null, 500, optimisticLocking);
            else
              session = new SessionNoServer(systemDir, 500, optimisticLocking);
            try
            {
              for (int j = 0; j < 10; j++)
                try
                {
                  using (var transaction = session.BeginUpdate())
                  {
                    session.SetTraceDbActivity(FixedSize.PlaceInDatabase);
                    session.SetTraceDbActivity(2);
                    Trace.Listeners.Add(new ConsoleTraceListener());
                    session.CrossTransactionCacheAllDatabases();
                    for (int k = 0; k < 4200; k++)
                    {
                      FixedSize fixedSize = new FixedSize();
                      session.Persist(fixedSize);
                      if (k == 4000 && Thread.CurrentThread.ManagedThreadId % 3 != 0)
                        session.FlushUpdates();
                    }
                    session.Commit();
                    if (!serverSession)
                      session.Compact();
                    Console.WriteLine("Commit OK for thread " + Thread.CurrentThread.ManagedThreadId + " Transaction: " + j);
                  }
                }
                catch (PageUpdateLockException ex)
                {
                  Console.WriteLine("Commit failed (OptimisticLockingFailed) for thread " + Thread.CurrentThread.ManagedThreadId + " Transaction: " + j);
                  Console.WriteLine(ex.ToString());
                }
                catch (OptimisticLockingFailed ex)
                {
                  Console.WriteLine("Commit failed (OptimisticLockingFailed) for thread " + Thread.CurrentThread.ManagedThreadId + " Transaction: " + j);
                  Console.WriteLine(ex.ToString());
                }
                catch (Exception ex)
                {
                  Console.WriteLine("Commit failed for thread " + Thread.CurrentThread.ManagedThreadId + " Transaction: " + j);
                  Console.WriteLine(ex.ToString());
                }
            }
            finally
            {
              session.Dispose();
            }
          });
      foreach (Thread thread in threads)
        thread.Start();
      bool keepWaiting = true;
      while (keepWaiting)
      {
        keepWaiting = false;
        foreach (Thread thread in threads)
          if (thread.IsAlive)
          {
            keepWaiting = true;
            thread.Join(500);
          }
      }
      using (SessionBase session = new SessionNoServer(systemDir))
      {
        session.BeginRead();
        Database db = session.OpenDatabase(FixedSize.PlaceInDatabase, false, false);
        if (db != null)
          Console.WriteLine("ConcurrentUpdates finished, number of FixedSize objects: " + db.AllObjects<FixedSize>().Count);
      }
    }
开发者ID:VelocityDB,项目名称:VelocityDB,代码行数:92,代码来源:ConcurrentUpdaters.cs

示例9: MainWindow

    public MainWindow()
    {
      const ushort btreeNodeSize = 5000;
      GCSettings.LatencyMode = GCLatencyMode.Batch;// try to keep the WeakIOptimizedPersistableReference objects around longer      
      dataGridList = new List<DataGrid>();
      dataTableList = new List<DataTable>();
      InitializeComponent();
      session = new SessionNoServer(s_systemDir);
      Placement placerIndexRoot = new Placement(IndexRoot.PlaceInDatabase);
      session.BeginUpdate();
      Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
      File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb"), true);
      IndexRoot indexRoot;
      Database db = session.OpenDatabase(IndexRoot.PlaceInDatabase, false, false);
      if (db == null)
      {
        session.NewDatabase(IndexRoot.PlaceInDatabase, 0, "IndexRoot");
        session.NewDatabase(Lexicon.PlaceInDatabase, 0, "Lexicon");
        session.NewDatabase(Document.PlaceInDatabase, 0, "Document");
        session.NewDatabase(Repository.PlaceInDatabase, 0, "Repository");
        session.NewDatabase(DocumentText.PlaceInDatabase, 0, "DocumentText");
        session.NewDatabase(Word.PlaceInDatabase, 0, "Word");
        indexRoot = new IndexRoot(btreeNodeSize, session);
        if (Directory.Exists(s_booksDir))
        {
          string[] directoryTextFiles = Directory.GetFiles(s_booksDir, "*.txt");
          foreach (string fileName in directoryTextFiles)
          {
            listBoxPagesToAdd.Items.Add(fileName);
          }
        }
        else
        {
          wordMinCt.Text = 1.ToString();
          listBoxPagesToAdd.Items.Add("http://www.VelocityDB.com/");
          // other database products
          listBoxPagesToAdd.Items.Add("https://foundationdb.com/");
          listBoxPagesToAdd.Items.Add("http://www.oracle.com/us/products/database/index.html");
          listBoxPagesToAdd.Items.Add("http://www-01.ibm.com/software/data/db2/");
          listBoxPagesToAdd.Items.Add("http://www.versant.com/");
          listBoxPagesToAdd.Items.Add("http://web.progress.com/en/objectstore/");
          listBoxPagesToAdd.Items.Add("https://www.mongodb.org/");
          listBoxPagesToAdd.Items.Add("http://cassandra.apache.org/");
          listBoxPagesToAdd.Items.Add("http://www.sybase.com/");
          listBoxPagesToAdd.Items.Add("http://www.mcobject.com/perst");
          listBoxPagesToAdd.Items.Add("http://www.marklogic.com/what-is-marklogic/");
          listBoxPagesToAdd.Items.Add("http://hamsterdb.com/");
          listBoxPagesToAdd.Items.Add("http://www.firebirdsql.org/");
          listBoxPagesToAdd.Items.Add("http://www.h2database.com/");
          listBoxPagesToAdd.Items.Add("http://www.oracle.com/technology/products/berkeley-db");
          listBoxPagesToAdd.Items.Add("http://www.scimore.com/");
          listBoxPagesToAdd.Items.Add("http://www.stsdb.com/");
          listBoxPagesToAdd.Items.Add("http://www.sqlite.org/about.html");
          listBoxPagesToAdd.Items.Add("http://www.mysql.com/products/enterprise/techspec.html");
          listBoxPagesToAdd.Items.Add("http://www.objectivity.com");
          listBoxPagesToAdd.Items.Add("http://vistadb.net/");
          listBoxPagesToAdd.Items.Add("http://www.google.com/search?q=object+database&sourceid=ie7&rls=com.microsoft:en-us:IE-SearchBox&ie=&oe=");
        }
        indexRoot.Persist(session, indexRoot);
      }
      else
        indexRoot = (IndexRoot)session.Open(Oid.Encode(IndexRoot.PlaceInDatabase, 1, 1));

      if (indexRoot.repository.documentSet.Count > 0)
      {
        List<Document> docs = indexRoot.repository.documentSet.ToList<Document>().Take(50).ToList<Document>();
        inDbListBox.ItemsSource = docs;
      }
      updateDataGrids(indexRoot);
      session.Commit();
      //verify();
    }
开发者ID:VelocityDB,项目名称:VelocityDB,代码行数:72,代码来源:TextIndexer.xaml.cs

示例10: CreateDataAndIterateSession

    public void CreateDataAndIterateSession(int numObj)
    {
      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginUpdate();
        UInt32 dbNum = session.DatabaseNumberOf(typeof(NotSharingPage));
        Database db = session.OpenDatabase(dbNum, true, false);
        if (db != null)
          session.DeleteDatabase(db);
        dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeA));
        db = session.OpenDatabase(dbNum, true, false);
        if (db != null)
          session.DeleteDatabase(db);
        dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB));
        db = session.OpenDatabase(dbNum, true, false);
        if (db != null)
          session.DeleteDatabase(db);
        session.Commit();
      }

      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginUpdate();
        UInt32 dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB));
        Placement place = new Placement(dbNum, 100);
        for (int i = 0; i < numObj; i++)
        {
          NotSharingPage ns = new NotSharingPage();
          session.Persist(ns);
          SharingPageTypeA sA = new SharingPageTypeA();
          session.Persist(sA);
          SharingPageTypeB sB = new SharingPageTypeB();
          if (i % 5 == 0)
            sB.Persist(session, place);
          else if (i % 1001 == 0)
            sB.Persist(session, sA);
          else if (i % 3001 == 0)
            sB.Persist(session, ns);
          else
            session.Persist(sB);
        }
        session.Commit();
      }

      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginRead();
        UInt32 dbNum = session.DatabaseNumberOf(typeof(NotSharingPage));
        Database db = session.OpenDatabase(dbNum);
        AllObjects<NotSharingPage> all = session.AllObjects<NotSharingPage>(true, false);
        OfType all2 = session.OfType(typeof(NotSharingPage), true, false);
        dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeA));
        Database dbA = session.OpenDatabase(dbNum);
        dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB));
        Database dbB = session.OpenDatabase(dbNum);
        AllObjects<SharingPageTypeA> allA = session.AllObjects<SharingPageTypeA>(true, false);
        AllObjects<SharingPageTypeB> allB = session.AllObjects<SharingPageTypeB>(true, false);
        int start = numObj / 2;
        NotSharingPage ns = all.ElementAt(numObj - 1); // zero based index so deduct one
        NotSharingPage ns2 = (NotSharingPage)all2.ElementAt(numObj - 1);
        Assert.AreEqual(ns, ns2);
        SharingPageTypeA sA = allA.ElementAt(15);
        SharingPageTypeB sB = allB.ElementAt(10);
        for (int i = start; i < numObj; i++)
          ns = all.ElementAt(i);
        //for (int i = start; i < numObj; i++)
        //  ns = all.Skip(i).T
        //for (int i = start; i < numObj; i++)
        //  sA = allA.ElementAt(i);
        all.Skip(100);
        all2.Skip(100);
        for (int i = start; i < numObj; i += 5)
        {
          ns = all.ElementAt(i);
          ns2 = (NotSharingPage)all2.ElementAt(i);
          Assert.AreEqual(ns, ns2);
        }
        for (int i = 5; i < 100; i += 5)
          sB = allB.ElementAt(i);
        for (int i = 0; i < numObj; i += 45000)
          ns = all.ElementAt(i);
        session.Commit();
        session.BeginUpdate();
        session.DeleteDatabase(db);
        session.DeleteDatabase(dbA);
        session.DeleteDatabase(dbB);
        session.Commit();
      }
    }
开发者ID:VelocityDB,项目名称:VelocityDB,代码行数:89,代码来源:ADatabaseIteration.cs

示例11: CreateDataAndIterateDb

    public void CreateDataAndIterateDb(int numObj)
    {
      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.Verify();
        session.BeginUpdate();
        UInt32 dbNum = session.DatabaseNumberOf(typeof(NotSharingPage));
        Database db = session.OpenDatabase(dbNum, true, false);
        if (db != null)
          session.DeleteDatabase(db);
        dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeA));
        db = session.OpenDatabase(dbNum, true, false);
        if (db != null)
          session.DeleteDatabase(db);
        dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB));
        db = session.OpenDatabase(dbNum, true, false);
        if (db != null)
          session.DeleteDatabase(db);
        session.Commit();
      }

      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.Verify();
        session.BeginUpdate();
        UInt32 dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB));
        Placement place = new Placement(dbNum, 100);
        for (int i = 0; i < numObj; i++)
        {
          NotSharingPage ns = new NotSharingPage();
          session.Persist(ns);
          SharingPageTypeA sA = new SharingPageTypeA();
          session.Persist(sA);
          SharingPageTypeB sB = new SharingPageTypeB();
          if (i % 5 == 0)
            sB.Persist(session, place);
          else if (i % 1001 == 0)
            sB.Persist(session, sA);
          else if (i % 3001 == 0)
            sB.Persist(session, ns);
          else
            session.Persist(sB);
        }
        session.Commit();
      }

      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginRead();
        session.Verify();
        UInt32 dbNum = session.DatabaseNumberOf(typeof(NotSharingPage));
        Database db = session.OpenDatabase(dbNum);
        AllObjects<NotSharingPage> all = db.AllObjects<NotSharingPage>();
        ulong ct = all.Count();
        dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeA));
        OfType ofType = db.OfType(typeof(NotSharingPage));
        ulong ct2 = ofType.Count();
        Assert.AreEqual(ct, ct2);
        Database dbA = session.OpenDatabase(dbNum);
        dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB));
        Database dbB = session.OpenDatabase(dbNum);
        AllObjects<SharingPageTypeA> allA = dbA.AllObjects<SharingPageTypeA>();
        AllObjects<SharingPageTypeB> allB = dbB.AllObjects<SharingPageTypeB>();
        OfType allA2 = dbA.OfType(typeof(SharingPageTypeA));
        int start = numObj / 2;
        NotSharingPage ns = all.ElementAt(numObj);
        SharingPageTypeA sA = allA.ElementAt(numObj);
        SharingPageTypeA sA2 = (SharingPageTypeA)allA2.ElementAt(numObj);
        Assert.AreEqual(sA, sA2);
        sA = allA.ElementAt(10);
        sA2 = (SharingPageTypeA)allA2.ElementAt(10);
        Assert.AreEqual(sA, sA2);
        //MethodInfo method = typeof(Database).GetMethod("AllObjects");
        //MethodInfo generic = method.MakeGenericMethod(sA.GetType());
        //dynamic itr = generic.Invoke(dbA, new object[]{ true });
        //SharingPageTypeA sAb = itr.ElementAt(numObj);
        //Assert.AreEqual(sA, sAb);
        //SharingPageTypeA sAc = itr.ElementAt(numObj);
        SharingPageTypeB sB = allB.ElementAt(numObj);
        List<NotSharingPage> notSharingPageList = all.Skip(100).ToList();
        List<SharingPageTypeA> sharingPageTypeA = allA.Take(5).Skip(100).ToList();
        for (int i = start; i < numObj; i++)
          sA = allA.ElementAt(i);
        for (int i = start; i < numObj; i += 5)
          ns = all.ElementAt(i);
        for (int i = start; i < numObj; i += 5)
          sB = allB.ElementAt(i);
        for (int i = 0; i < numObj; i += 45000)
          ns = all.ElementAt(i);
        int allB_count = (int) allB.Count();
        for (int i = 0; i < allB_count - 1; i++)
        {
          Assert.NotNull(allB.ElementAt(i));
        }
        session.Commit();
        session.BeginUpdate();
        session.DeleteDatabase(db);
        session.DeleteDatabase(dbA);
        session.DeleteDatabase(dbB);
        session.Commit();
//.........这里部分代码省略.........
开发者ID:VelocityDB,项目名称:VelocityDB,代码行数:101,代码来源:ADatabaseIteration.cs

示例12: bSyncDeletedDatabases

    public void bSyncDeletedDatabases()
    {
      using (SessionBase session = new SessionNoServer(s_sync1))
      {
        using (var trans = session.BeginUpdate())
        {
          for (uint i = 10; i < 14; i++)
          {
            var database = session.OpenDatabase(i);
            session.DeleteDatabase(database);
          }
          session.Commit();
        }
      }

      using (SessionBase readFromSession = new SessionNoServer(s_sync1))
      {
        using (SessionBase updateSession = new SessionNoServer(s_sync2))
        {
          updateSession.SyncWith(readFromSession);
        }
      }

      using (SessionBase readFromSession = new SessionNoServer(s_sync1))
      {
        readFromSession.BeginRead();
        using (SessionBase updateSession = new SessionNoServer(s_sync2))
        {
          using (var trans = updateSession.BeginRead())
          {
            Assert.AreEqual(updateSession.OpenAllDatabases().Count, readFromSession.OpenAllDatabases().Count - 1); // - 1 due to additional change tracking databases in original 
          }
        }
      }
    }
开发者ID:VelocityDB,项目名称:VelocityDB,代码行数:35,代码来源:SyncTest.cs

示例13: UnpersistCompareFields

 public void UnpersistCompareFields(int bTreeDatabaseNumber)
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginUpdate();
     BTreeSet<Person> bTree = (BTreeSet<Person>)session.Open(Oid.Encode((uint)bTreeDatabaseNumber, 1, 1));
     BTreeSetIterator<Person> itr = bTree.Iterator();
     itr.GoToLast();
     itr.Remove();
     session.Abort();
     session.BeginUpdate();
     bTree = (BTreeSet<Person>)session.Open(Oid.Encode((uint)bTreeDatabaseNumber, 1, 1));
     bTree.Unpersist(session);
     session.Commit();
     session.BeginRead();
     Database db = session.OpenDatabase((uint)bTreeDatabaseNumber, false);
     foreach (Page page in db)
       foreach (OptimizedPersistable obj in page)
         if (obj.PageNumber > 0)
           Assert.Fail("No objects should remain in this database");
     session.Commit();
   }
 }
开发者ID:MerlinBrasil,项目名称:VelocityDB,代码行数:23,代码来源:BTreeTest.cs

示例14: Main

    static void Main(string[] args)
    {
      long triangles = 0;
      try
      {
        using (SessionNoServer session = new SessionNoServer(systemDir))
        {
          int numberOfWorkerThreads = -1;
          if (args.Length > 0)
          {
            if (!int.TryParse(args[0], out numberOfWorkerThreads))
              Console.WriteLine("First parameter is numberOfWorkerThreads which must be an Int32");
          }
          bool useLinq = args.Length > 1;
          Placement btreePlace = new Placement(40, 1, 1, 10000, 65500, true);
          Placement edgeInfoPlace = new Placement(40, 10000, 1, 10000, 65500, true);
          session.BeginUpdate();
          BTreeMap<int, int[]> edges;
          BTreeMapIterator<int, int[]> edgesItr;
          int[] edge = null;
          Database edgeDb = session.OpenDatabase(40, false, false);
          if (edgeDb != null)
          {
            session.Commit();
            session.BeginRead();
            edges = (BTreeMap<int, int[]>)session.Open(40, 1, 1, false);
          }
          else
          {
            DatabaseLocation location = session.DatabaseLocations.Default();
            //location.CompressPages = false; // no compression should make it faster (?) 
            session.NewDatabase(40, 395, "Edges");
            edges = new BTreeMap<int, int[]>(null, session, 6000);
            edges.Persist(btreePlace, session, true);
            edgesItr = edges.Iterator();
            using (StreamReader stream = new StreamReader(edgesInputFile, true))
            {
              int a;
              int b;
              string line;
              string[] fields;
              while ((line = stream.ReadLine()) != null)
              {
                fields = line.Split(' ');
                if (!int.TryParse(fields[0], out a))
                  break;
                b = int.Parse(fields[1]);
                if (a != b)
                {
                  if (edgesItr.CurrentKey() == a || edgesItr.GoTo(a))
                  {
                    edge = edgesItr.CurrentValue();
                    Array.Resize(ref edge, edge.Length + 1);
                    edge[edge.Length - 1] = b;
                    edgesItr.ReplaceValue(ref edge); // we need to update the value in the BTreeMap
                  }
                  else
                  {
                    edge = new int[1];
                    edge[0] = b;
                    edges.Add(a, edge);
                  }
                }
              }
            }
            edgesItr = edges.Iterator();
            while (edgesItr.MoveNext())
            {
              edge = edgesItr.CurrentValue();
              Array.Sort(edge);
              edgesItr.ReplaceValue(ref edge);
            }
            session.Commit();
            session.BeginRead();
          }
          Console.WriteLine("Number of Nodes found: " + edges.Count);
          if (useLinq)
            Console.WriteLine("Query using LINQ");
          if (numberOfWorkerThreads > 0)           
            Console.WriteLine("Start of triangle discovery using " + numberOfWorkerThreads + " threads, time is " + DateTime.Now);
          else if (numberOfWorkerThreads < 0)
            Console.WriteLine("Start of triangle discovery using system automatically selected number of threads, time is " + DateTime.Now);
          else
            Console.WriteLine("Start of triangle discovery using main thread, time is " + DateTime.Now);

          // Start counting triangles !
          if (numberOfWorkerThreads != 0)
          {
            if (useLinq)
            { // Please help, I have not figured out how to properly do the triangle query using LINQ
              int[] edge2values = null;
              if (numberOfWorkerThreads > 0)
                triangles = (from KeyValuePair<int, int[]> edgeFrom in edges
                           from int edgeTo1 in edgeFrom.Value
                           where edgeFrom.Key < edgeTo1
                           from int edgeTo2 in edgeFrom.Value
                           where edgeFrom.Key < edgeTo2 && edgeTo2 > edgeTo1 && edges.TryGetValue(edgeTo1, out edge2values) && Array.BinarySearch(edge2values, edgeTo2) >= 0
                           select edge).AsParallel().WithDegreeOfParallelism(numberOfWorkerThreads).Count();
              else
                triangles =  (from KeyValuePair<int, int[]> edgeFrom in edges
//.........这里部分代码省略.........
开发者ID:MerlinBrasil,项目名称:VelocityDB,代码行数:101,代码来源:TriangleCounter.cs

示例15: SingleReaderSingleUpdater4

 [TestCase(false)] // test will fail if pessimistic locking is used
 public void SingleReaderSingleUpdater4(bool useReaderCommit)
 {
   using (SessionNoServer updater = new SessionNoServer(systemDir, 5000)) 
   using (SessionNoServer reader = new SessionNoServer(systemDir, 5000))
   {
     updater.SetTraceAllDbActivity();
     reader.SetTraceAllDbActivity();
     updater.BeginUpdate();
     UInt32 dbNum = updater.DatabaseNumberOf(typeof(Man));
     Database db = updater.OpenDatabase(dbNum, true, false);
     if (db != null)
       updater.DeleteDatabase(db);
     updater.Commit();
     updater.BeginUpdate();
     Man man = new Man();
     for (int i = 0; i < 100; i++)
     {
       man = new Man();
       updater.Persist(man);
     }
     updater.Commit();
     reader.BeginRead();
     updater.BeginUpdate();
     db = reader.OpenDatabase(dbNum);
     foreach (Page page in db)
       Assert.True(page.PageInfo.VersionNumber == 1);
     if (useReaderCommit)
       reader.Commit();
     if (useReaderCommit)
       reader.BeginRead();
     else
       reader.ForceDatabaseCacheValidation();
     for (int i = 1; i < 25; i++)
     {
       db = reader.OpenDatabase(dbNum);
       foreach (Page page in db)
       {
         if (page.PageNumber > 1) // skip AutoPlacemnt page
         {
           Assert.True(page.PageInfo.VersionNumber == (ulong)i);
           Man man2 = (Man)reader.Open(dbNum, page.PageNumber, 1, false);
           Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true);
         }
       }
       if (useReaderCommit)
       {
         reader.Commit();
         reader.BeginRead();
       }
       else
         reader.ForceDatabaseCacheValidation();
       updater.Commit();
       updater.BeginUpdate();
     }
     Database db2 = reader.OpenDatabase(dbNum);
     db = updater.OpenDatabase(dbNum);
     for (int i = 25; i < 50; i++)
     {
       foreach (Page page in db)
       {
         if (page.PageNumber > 1)
         {
           Assert.True(page.PageInfo.VersionNumber == (ulong)i);
           Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true);
         }
       }
       updater.Commit();
       updater.BeginUpdate();
       db2 = reader.OpenDatabase(dbNum);
       foreach (Page page in db2)
       {
         if (page.PageNumber > 1)
         {
           //Assert.True(page.PageInfo.VersionNumber == (ulong)i + 1);
           Man man2 = (Man)reader.Open(dbNum, page.PageNumber, 1, false);
         }
       }
       reader.ClearPageCache();
       System.GC.Collect();
     }
     reader.Commit();
     updater.Commit();
   }
 }
开发者ID:MerlinBrasil,项目名称:VelocityDB,代码行数:85,代码来源:ReadersWithUpdater.cs


注:本文中的SessionNoServer.OpenDatabase方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。