public BenchmarkRelationPartialView() { _fc = new InMemoryFileCollection(); var lowDb = new KeyValueDB(_fc); _db = new ObjectDB(); _db.Open(lowDb, true); using var tr = _db.StartTransaction(); var table = tr.GetRelation <IPersonTable>(); for (var i = 0; i < 10000; i++) { var p = new Person { ParentId = 1, PersonId = i, Age = (ulong)(i / 128), Name = "Lorem ipsum " + i, Children = Enumerable.Range(0, 100).Select(j => new Person { ParentId = i, PersonId = i * 100 + j, Name = "Lorem ipsum child " + j, Age = (ulong)j }).ToList() }; table.Upsert(p); } tr.Commit(); _tr = _db.StartReadOnlyTransaction(); _table = _tr.GetRelation <IPersonTable>(); }
/// <summary> /// Registers the person. /// </summary> /// <param name="person">The person.</param> /// <returns> /// true if it succeeds /// </returns> /// <exception cref="System.Exception">Person is already registered!</exception> public Person RegisterPerson(Person person) { PersonOfferor offeror; PersonBidder bidder; IPersonTable personTable = this.tablesProvider.GetPersonTable(); IPersonBidderTable personBidderTable = this.tablesProvider.GetPersonBidderTable(); IPersonOfferorTable personOfferorTable = this.tablesProvider.GetPersonOfferorTable(); try { if (person.IdPerson != 0) { throw new Exception("Person is already registered!"); } person.ValidateObject(); Person exists = personTable.FetchPersonByPhone(person.Phone); if (exists != null) { person = exists; //// to update the id. return(person); } } catch (Exception e) { Log.Info("RegisterPerson: " + e.Message); throw e; } //// at this point person doesn't exist into db. //// the actual insert personTable.InsertPerson(person); person = personTable.FetchPersonByPhone(person.Phone); //// in order to update Id offeror = new PersonOfferor() { Person = person }; bidder = new PersonBidder() { Person = person }; personOfferorTable.InsertPersonOfferor(person.IdPerson, offeror); personBidderTable.InsertPersonBidder(person.IdPerson, bidder); Log.Info("RegisterPerson: " + person.Name + " person id =" + person.IdPerson + " inserted with success."); return(person); }
/// <summary> /// Prevents a default instance of the <see cref="DomainDataStorage"/> class from being created. /// </summary> private DomainDataStorage() { string connectionString = ConfigurationManager.ConnectionStrings["MySQL"].ConnectionString; this.databaseConneection = new MySqlConnection(connectionString); this.auctionTable = this.databaseConneection.As <IAuctionTable>(); this.bidTable = this.databaseConneection.As <IBidTable>(); this.categoryTable = this.databaseConneection.As <ICategoryTable>(); this.currencyTable = this.databaseConneection.As <ICurrencyTable>(); this.personBidderTable = this.databaseConneection.As <IPersonBidderTable>(); this.personMarkTable = this.databaseConneection.As <IPersonMarkTable>(); this.personOfferorTable = this.databaseConneection.As <IPersonOfferorTable>(); this.personTable = this.databaseConneection.As <IPersonTable>(); this.productTable = this.databaseConneection.As <IProductTable>(); }
/// <summary> /// Gets the person by phone. /// </summary> /// <param name="phone">The phone.</param> /// <returns>the found person</returns> public Person GetPersonByPhone(string phone) { IPersonTable personTable = this.tablesProvider.GetPersonTable(); return(personTable.FetchPersonByPhone(phone)); }