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


C# SessionNoServer.DatabaseNumberOf方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: Create1Vertices


//.........这里部分代码省略.........
       // session.Commit();
       // session.BeginRead();
        PropertyType adressProperty = g.FindVertexProperty(powerUserType, "Address");
        Vertex find1 = adressProperty.GetPropertyVertex(1, true);
        session.Abort();
        /*session.BeginUpdate();
        g.Unpersist(session);
        session.Commit();
        dirExist = Directory.Exists(systemDir);
        try
        {
          if (Directory.Exists(systemDir))
            Directory.Delete(systemDir, true); // remove systemDir from prior runs and all its databases.
          Directory.CreateDirectory(systemDir);
          File.Copy(licenseDbFile, Path.Combine(systemDir, "4.odb"));
        }
        catch
        {
          File.Copy(licenseDbFile, Path.Combine(systemDir, "4.odb"));
        }*/

      }

      using (SessionNoServer session = new SessionNoServer(systemDir, 5000, false, true))
      {
        session.BeginUpdate();
        session.DefaultDatabaseLocation().CompressPages = PageInfo.compressionKind.None;
        Graph g = new Graph(session, vertexIdSetPerVertexType);
        session.Persist(g);
        Graph g2 = new Graph(session);
        session.Persist(g2);
        Graph g3 = new Graph(session);
        session.Persist(g3);
        UInt32 dbNum = session.DatabaseNumberOf(typeof(Graph));
        Graph g4 = (Graph)session.Open(dbNum, 2, 1, true); // g4 == g
        Graph g5 = (Graph)session.Open(dbNum, 2, 2, true); // g5 == g2
        Graph g6 = (Graph)session.Open(dbNum, 2, 3, true); // g6 == g3
        for (int i = 4; i < 8; i++)
        {
          Graph gt = new Graph(session);
          session.Persist(gt);
        }
        Graph g7 = new Graph(session);
        Placement place = new Placement(dbNum, 15);
        session.Persist(place, g7);
        // SCHEMA
        VertexType userType = g.NewVertexType("User");
        VertexType locationType = g.NewVertexType("Location");
        VertexType aVertexType = g.NewVertexType("A");
        VertexType bVertexType = g.NewVertexType("B");
        VertexType cVertexType = g.NewVertexType("C");
        EdgeType uEdge = g.NewEdgeType("unrestricted", true);
        Vertex aVertex = g.NewVertex(aVertexType);
        Vertex bVertex = g.NewVertex(bVertexType);
        Vertex cVertex = g.NewVertex(cVertexType);
        Edge abEdge = (Edge)aVertex.AddEdge("unrestricted", bVertex);
        Edge bcEdge = (Edge)aVertex.AddEdge("unrestricted", cVertex);
        Dictionary<Vertex, HashSet<Edge>> traverse = aVertex.Traverse(uEdge, Direction.Out);
        abEdge.Remove();
        Dictionary<Vertex, HashSet<Edge>> traverse2 = aVertex.Traverse(uEdge, Direction.Out);

        EdgeType friendEdgeType = g.NewEdgeType("Friend", true, userType, userType);
        EdgeType userLocationEdgeType = g.NewEdgeType("UserLocation", true, userType, locationType);

        // DATA
        Random rand = new Random(5);
开发者ID:VelocityDB,项目名称:VelocityDB,代码行数:67,代码来源:VelocityGraphTest.cs

示例7: MultipleThreadsAdding

 public void MultipleThreadsAdding()
 {
   bool doClearAll = SessionBase.ClearAllCachedObjectsWhenDetectingUpdatedDatabase;
   SessionBase.ClearAllCachedObjectsWhenDetectingUpdatedDatabase = false;
   try
   {
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
       session.BeginUpdate();
       session.RegisterClass(typeof(AutoPlacement)); // build in type but not yet registered as a one
       session.RegisterClass(typeof(ObservableList<int>));
       session.RegisterClass(typeof(Dokument));
       UInt32 dbNum = session.DatabaseNumberOf(typeof(Dokument));
       Database db = session.OpenDatabase(dbNum, false, false);
       if (db == null)
         db = session.NewDatabase(dbNum, 0, typeof(Dokument).ToGenericTypeString());
       Dokument doc = new Dokument();
       session.Persist(doc);
       session.Commit();
     }
     using (ServerClientSessionShared sharedReadSession = new ServerClientSessionShared(systemDir))
     {
       sharedReadSession.BeginRead();
       Parallel.ForEach(Enumerable.Range(1, 3), (num) => LockConflict(sharedReadSession));
     }
   }
   finally
   {
     SessionBase.ClearAllCachedObjectsWhenDetectingUpdatedDatabase = doClearAll;
   }
 }
开发者ID:VelocityDB,项目名称:VelocityDB,代码行数:31,代码来源:MultipleUpdaters.cs

示例8: Main


//.........这里部分代码省略.........
          session.BeginRead();
          foreach (Car c in session.Index<Car>())
            Console.WriteLine(c.ToStringDetails(session));
          Console.WriteLine("Blue Cars");
          foreach (Car c in (from aCar in session.Index<Car>() where aCar.Color == "Blue" select aCar))
            Console.WriteLine(c.ToStringDetails(session));
          session.Commit();
          sw.Stop();
          Console.WriteLine(sw.Elapsed);
        }
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          Stopwatch sw = new Stopwatch();
          sw.Start();
          session.BeginUpdate();
          InsuranceCompany prior = insuranceCompany;
          try
          {
            for (int i = 0; i < 100000; i++)
            {
              insuranceCompany = new InsuranceCompany("AAA", "858787878");
              session.Persist(insuranceCompany);
            }
            Debug.Assert(false); // should not get here
          }
          catch (UniqueConstraintException)
          {
          }
          session.Commit();
          sw.Stop();
          Console.WriteLine(sw.Elapsed);
        }
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          session.TraceIndexUsage = true;
          Stopwatch sw = new Stopwatch();
          sw.Start();
          session.BeginRead();
          Database db = session.OpenDatabase(session.DatabaseNumberOf(typeof(InsuranceCompany)));
          var q = from company in session.Index<InsuranceCompany>("name", db) where company.Name == "AAA" select company;
          foreach (InsuranceCompany company in q)
            Console.WriteLine(company.ToStringDetails(session)); // only one will match
          session.Commit();
          sw.Stop();
          Console.WriteLine(sw.Elapsed);
        }

        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          Stopwatch sw = new Stopwatch();
          sw.Start();
          session.BeginUpdate();
          Customer joe = new Customer("Joe");
          session.Persist(joe);
          Customer karim = new Customer("Karim");
          session.Persist(karim);
          Customer tony = new Customer("Tony");
          session.Persist(tony);
          Customer wayne = new Customer("Wayne");
          session.Persist(wayne);
          Order order = new Order(joe);
          Payment payment = new Payment(order);
          order = new Order(karim);
          payment = new Payment(order);
          payment = new Payment(order);
          payment = new Payment(order);
          order = new Order(tony);
          payment = new Payment(order);
          payment = new Payment(order);
          order = new Order(wayne);
          payment = new Payment(order);
          session.Commit();
          sw.Stop();
          Console.WriteLine(sw.Elapsed);
        }

        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          session.TraceIndexUsage = true;
          Stopwatch sw = new Stopwatch();
          sw.Start();
          session.BeginRead();
          var karim = (from customer in session.Index<Customer>("m_name") where customer.Name == "Karim" select customer).FirstOrDefault();
          var karimOrders = karim.Orders;
          var karimOrderFromOrders = (from order in session.Index<Order>("m_customer") where order.Customer == karim select order).ToArray();
          session.Commit();
          session.BeginUpdate();
          karim = (from customer in session.Index<Customer>("m_name") where customer.Name == "Karim" select customer).FirstOrDefault();
          karim.StreetAddress = "1623 Bonita Ave";
          session.Commit();
          sw.Stop();
          Console.WriteLine(sw.Elapsed);
        }

      }
      catch (Exception ex)
      {
        Console.WriteLine(ex.ToString());
      }
    }
开发者ID:VelocityDB,项目名称:VelocityDB,代码行数:101,代码来源:Indexes.cs


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