public void License() { using (SessionNoServer session = new SessionNoServer(systemDir)) { Database database; session.BeginUpdate(); for (uint i = 60000000; i < 60000010; i++) { database = session.NewDatabase(i); Assert.NotNull(database); } session.Commit(); session.BeginUpdate(); for (uint i = 60000000; i < 60000010; i++) { database = session.OpenDatabase(i); Assert.NotNull(database); } session.Commit(); session.BeginUpdate(); for (uint i = 60000000; i < 60000010; i++) { database = session.OpenDatabase(i); session.DeleteDatabase(database); } session.Commit(); } }
private void button1_Click(object sender, RoutedEventArgs e) { session.BeginUpdate(); IndexRoot indexRoot = (IndexRoot)session.Open(Oid.Encode(IndexRoot.PlaceInDatabase, 1, 1)); Placement docPlacement = new Placement(Document.PlaceInDatabase); foreach (string str in listBoxPagesToAdd.Items) { Document doc = null; try { if (str.Contains(".html") || str.Contains(".htm") || str.Contains("http") || str.Contains("aspx")) { doc = parseHtml(str, indexRoot); } else { doc = parseTextFile(str, indexRoot, docPlacement); } } catch (WebException ex) { Console.WriteLine(ex.ToString()); } } createGlobalInvertedIndex(indexRoot); listBoxPagesToAdd.Items.Clear(); List <Document> docs = indexRoot.repository.documentSet.ToList <Document>().Take(50).ToList <Document>(); inDbListBox.ItemsSource = docs; session.Commit(); session.BeginRead(); updateDataGrids(indexRoot); session.Commit(); }
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(); } }
public void aaaFakeLicenseDatabase() { Assert.Throws <NoValidVelocityDBLicenseFoundException>(() => { using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); Database database; License license = new License("Mats", 1, null, null, null, 99999, DateTime.MaxValue, 9999, 99, 9999); Placement placer = new Placement(License.PlaceInDatabase, 1, 1, 1); license.Persist(placer, session); for (uint i = 10; i < 20; i++) { database = session.NewDatabase(i); Assert.NotNull(database); } session.Commit(); File.Copy(Path.Combine(systemDir, "20.odb"), Path.Combine(systemDir, "4.odb")); session.BeginUpdate(); for (uint i = 21; i < 30; i++) { database = session.NewDatabase(i); Assert.NotNull(database); } session.RegisterClass(typeof(BTreeSet <int>)); session.RegisterClass(typeof(BTreeSet <long>)); session.RegisterClass(typeof(BTreeSet <DateTime>)); session.RegisterClass(typeof(BTreeSet <double>)); session.RegisterClass(typeof(BTreeMap <string, double>)); session.Commit(); } }); }
public void TwoUpdaters2() { Assert.Throws <OpenDatabaseException>(() => { UInt64 id; try { using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); Man man = new Man(); man.Persist(session, man); id = man.Id; session.Commit(); session.BeginUpdate(); man.Age = ++man.Age; session.FlushUpdates(); using (SessionNoServer session2 = new SessionNoServer(systemDir)) { session2.BeginRead(); Man man2 = (Man)session2.Open(id); Assert.Less(man2.Age, man.Age); man2.Age = ++man.Age; // We'll get the OpenDatabase exception here since we are not in an update transaction session2.Commit(); } session.Commit(); } } finally { System.GC.Collect(); } }); }
public void aaaFakeLicenseDatabase() { using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); Database database; License license = new License("Mats", 1, null, null, null, 99999, DateTime.MaxValue, 9999, 99, 9999); Placement placer = new Placement(License.PlaceInDatabase, 1, 1, 1); license.Persist(placer, session); for (uint i = 10; i < 20; i++) { database = session.NewDatabase(i); Assert.NotNull(database); } session.Commit(); File.Copy(Path.Combine(systemDir, "20.odb"), Path.Combine(systemDir, "4.odb")); session.BeginUpdate(); for (uint i = 21; i < 30; i++) { database = session.NewDatabase(i); Assert.NotNull(database); } session.RegisterClass(typeof(VelocityDbSchema.Samples.Sample1.Person)); Graph g = new Graph(session); session.Persist(g); session.Commit(); } }
public void aaaFakeLicenseDatabase() { Assert.Throws<NoValidVelocityDBLicenseFoundException>(() => { using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); Database database; License license = new License("Mats", 1, null, null, null, 99999, DateTime.MaxValue, 9999, 99, 9999); Placement placer = new Placement(License.PlaceInDatabase, 1, 1, 1); license.Persist(placer, session); for (uint i = 10; i < 20; i++) { database = session.NewDatabase(i); Assert.NotNull(database); } session.Commit(); File.Copy(Path.Combine(systemDir, "20.odb"), Path.Combine(systemDir, "4.odb")); session.BeginUpdate(); for (uint i = 21; i < 30; i++) { database = session.NewDatabase(i); Assert.NotNull(database); } session.RegisterClass(typeof(VelocityDbSchema.Samples.Sample1.Person)); Graph g = new Graph(session); session.Persist(g); session.Commit(); } }); }
public void TwoUpdaters3() { Assert.Throws <OptimisticLockingFailed>(() => { UInt64 id; try { using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); Man man = new Man(); man.Persist(session, man); id = man.Id; session.Commit(); session.BeginUpdate(); man.Age = ++man.Age; session.FlushUpdates(); // fStream set for updated databases will cause other write sessions to fail updating these databases using (SessionNoServer session2 = new SessionNoServer(systemDir)) { session2.BeginUpdate(); Man man2 = (Man)session2.Open(id); Assert.Less(man2.Age, man.Age); man2.Age = ++man.Age; session2.Commit(); // OptimisticLockingFailed here } session.Commit(); session.Verify(); } } finally { System.GC.Collect(); } }); }
public void TwoUpdaters1() { Assert.Throws <OptimisticLockingFailed>(() => { UInt64 id; using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); Man man = new Man(); man.Persist(session, man); id = man.Id; session.Commit(); session.BeginUpdate(); man.Age = ++man.Age; Database db = session.NewDatabase(3567); using (SessionNoServer session2 = new SessionNoServer(systemDir)) { session2.BeginUpdate(); Man man2 = (Man)session2.Open(id); Assert.Less(man2.Age, man.Age); man2.Age = ++man.Age; session2.Commit(); } session.DeleteDatabase(db); session.Commit(); // OptimisticLockingFailed here session.Verify(); } }); }
public void TwoUpdaters1() { UInt64 id; using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); Man man = new Man(); man.Persist(session, man); id = man.Id; session.Commit(); session.BeginUpdate(); man.Age = ++man.Age; Database db = session.NewDatabase(3567); using (SessionNoServer session2 = new SessionNoServer(systemDir)) { session2.BeginUpdate(); Man man2 = (Man)session2.Open(id); Assert.Less(man2.Age, man.Age); man2.Age = ++man.Age; session2.Commit(); } session.DeleteDatabase(db); session.Commit(); // OptimisticLockingFailed here } }
public void AutoPlacementDbRollover(int howMany) { using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); FourPerPage f; for (UInt64 i = 0; i < 1000000; i++) { f = new FourPerPage(i); session.Persist(f); } session.Commit(); } using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginRead(); UInt32 dbNum = session.DatabaseNumberOf(typeof(FourPerPage)); Database db = session.OpenDatabase(dbNum); int ct = 0; foreach (FourPerPage f in db.AllObjects <FourPerPage>()) { ct++; } Assert.AreEqual(ct, howMany); session.Commit(); } }
static void CreateData() { using (SessionNoServer session = new SessionNoServer(s_systemDir)) { bool dirExist = Directory.Exists(session.SystemDirectory); if (dirExist) Directory.Delete(session.SystemDirectory, true); // remove systemDir from prior runs and all its databases. Directory.CreateDirectory(session.SystemDirectory); File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb")); DataCache.MaximumMemoryUse = 10000000000; // 10 GB, set this to what fits your case SessionBase.DefaultCompressPages = PageInfo.compressionKind.LZ4; session.BeginUpdate(); BTreeMap<Int64, VelocityDbList<Person>> btreeMap = new BTreeMap<Int64, VelocityDbList<Person>>(null, session); session.Persist(btreeMap); for (int i = 0; i < 100000; i++) { Person p = new Person(); GeoHash geohash = GeoHash.WithBitPrecision(p.Lattitude, p.Longitude); VelocityDbList<Person> personList; if (btreeMap.TryGetValue(geohash.LongValue, out personList)) personList.Add(p); else { personList = new VelocityDbList<Person>(1); //session.Persist(p); personList.Add(p); session.Persist(personList); btreeMap.Add(geohash.LongValue, personList); } } session.Commit(); } }
static void CreateData() { using (SessionNoServer session = new SessionNoServer(s_systemDir)) { bool dirExist = Directory.Exists(session.SystemDirectory); if (dirExist) { return; Directory.Delete(session.SystemDirectory, true); // remove systemDir from prior runs and all its databases. } Directory.CreateDirectory(session.SystemDirectory); File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb")); SessionBase.DefaultCompressPages = PageInfo.compressionKind.LZ4; session.BeginUpdate(); CompareGeoObj comparer = new CompareGeoObj(); var btreeSet = new BTreeSet<GeoObj>(comparer, session, 1000); for (int i = 0; i < s_numberOfSamples; i++) { var g = new GeoObj(); btreeSet.Add(g); } session.Persist(btreeSet); session.Commit(); Console.Out.WriteLine($@"Done creating {s_numberOfSamples} GeoHashSample GeoObj "); } }
static readonly string s_systemDir = "JsonExportImport"; // appended to SessionBase.BaseDatabasePath static void Main(string[] args) { try { int personCt = 0; using (SessionBase session = new SessionNoServer(s_systemDirToImport)) { session.BeginRead(); IEnumerable<string> personStringEnum = session.ExportToJson<Person>(); using (SessionBase sessionImport = new SessionNoServer(s_systemDir)) { sessionImport.BeginUpdate(); foreach (string json in personStringEnum) { Person person = sessionImport.ImportJson<Person>(json); sessionImport.Persist(person); personCt++; } session.Commit(); sessionImport.Commit(); Console.WriteLine("Imported " + personCt + " from Json strings"); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public void LocalDateTest() { LocalDate d1 = new LocalDate(2016, 1, 10); LocalDate d2 = new LocalDate(2016, 1, 1); LocalDate d1other = new LocalDate(2016, 1, 10); Assert.AreNotEqual(d1, d2); Assert.AreEqual(d1, d1other); using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); LocalDateField test1 = new LocalDateField("def", d1); session.Persist(test1); LocalDateField test = new LocalDateField("abc", d2); session.Persist(test); var result1 = session.AllObjects<LocalDateField>().First(t => t.Field2.Equals(d2)); // this works session.Commit(); } using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginRead(); var result2 = session.AllObjects<LocalDateField>().First(t => { var l = t.Field2; return l.Equals(d2); }); // this should work and doesnt session.Commit(); } }
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(); } }
public void CompareInt64() { using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); AllSupported obj = new AllSupported(2, session); CompareByField <AllSupported> compareByField = new CompareByField <AllSupported>("int64", session); BTreeSet <AllSupported> sortedSet = new BTreeSet <AllSupported>(compareByField, session, 1000, sizeof(Int64), true); for (int i = 0; i < 100000; i++) { obj = new AllSupported(1, session); obj.int64 = randGen.Next(Int32.MinValue, Int32.MaxValue) * randGen.Next(); sortedSet.Add(obj); } int ct = 0; //foreach (AllSupported currentObj in (IEnumerable<AllSupported>)sortedSet) // { // Console.WriteLine(currentObj.int32); // ct++; // } AllSupported prior = null; ct = 0; foreach (AllSupported currentObj in (IEnumerable <AllSupported>)sortedSet) { if (prior != null) { Assert.Less(prior.int64, currentObj.int64); } prior = currentObj; ct++; } session.Commit(); } }
public void hashCodeComparerStringTest() { Oid id; using (SessionNoServer session = new SessionNoServer(systemDir)) { Placement place = new Placement(223, 1, 1, UInt16.MaxValue, UInt16.MaxValue); session.Compact(); session.BeginUpdate(); HashCodeComparer<string> hashCodeComparer = new HashCodeComparer<string>(); BTreeSet<string> bTree = new BTreeSet<string>(hashCodeComparer, session); bTree.Persist(place, session); id = bTree.Oid; for (int i = 0; i < 100000; i++) { bTree.Add(i.ToString()); } session.Commit(); } using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginRead(); BTreeSet<string> bTree= (BTreeSet<string>)session.Open(id); int count = 0; foreach (string str in bTree) { count++; } Assert.True(100000 == count); session.Commit(); } }
static readonly string s_systemDir = "JsonExportImport"; // appended to SessionBase.BaseDatabasePath static void Main(string[] args) { try { int personCt = 0; using (SessionBase session = new SessionNoServer(s_systemDirToImport)) { session.BeginRead(); IEnumerable <string> personStringEnum = session.ExportToJson <Person>(); using (SessionBase sessionImport = new SessionNoServer(s_systemDir)) { sessionImport.BeginUpdate(); foreach (string json in personStringEnum) { Person person = sessionImport.ImportJson <Person>(json); sessionImport.Persist(person); personCt++; } session.Commit(); sessionImport.Commit(); Console.WriteLine("Imported " + personCt + " from Json strings"); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public void CreateCompareStruct(int number) { Oid id; using (SessionNoServer session = new SessionNoServer(systemDir)) { Placement place = new Placement((UInt32)number, 1, 1, UInt16.MaxValue, UInt16.MaxValue); session.BeginUpdate(); BTreeSetOidShort <Oid> bTree = new BTreeSetOidShort <Oid>(null, session); bTree.Persist(place, session); id = bTree.Oid; for (int i = 0; i < number; i++) { bTree.Add(new Oid((ulong)i)); } session.Commit(); } using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginRead(); BTreeSetOidShort <Oid> bTree = (BTreeSetOidShort <Oid>)session.Open(id); int count = 0; int prior = 0; foreach (Oid oid in bTree) { count++; Assert.True(oid.Id == (ulong)prior++); } Assert.True(number == count); session.Commit(); } }
static void Main(string[] args) { SessionBase.BaseDatabasePath = @"d:/Databases"; bool dirExist = Directory.Exists(Path.Combine(SessionBase.BaseDatabasePath, s_systemDir)); if (!dirExist) { ImdbImport.ImprortImdb(s_systemDir); } KevinBaconNumbers kevinBaconNumbers = new KevinBaconNumbers(); using (SessionNoServer session = new SessionNoServer(s_systemDir)) { try { session.BeginRead(); kevinBaconNumbers.calculateNumbers(session); kevinBaconNumbers.printResults(); session.Commit(); } catch (Exception e) { session.Abort(); Console.WriteLine(e.ToString()); } } }
public void SingleReaderSingleUpdater1() { using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); Man man = new Man(); man.Persist(session, man); session.Commit(); } UInt64 id; using (SessionNoServer session = new SessionNoServer(systemDir, 5000)) { session.BeginUpdate(); Man man = new Man(); man.Persist(session, man); id = man.Id; using (SessionNoServer session2 = new SessionNoServer(systemDir)) { session2.BeginRead(); Man man2 = (Man)session2.Open(id); Assert.Null(man2); session2.Commit(); } session.Commit(); } }
public void CompareDateTime() { using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); AllSupported obj; CompareByField <AllSupported> compareByField = new CompareByField <AllSupported>("dateTime", session); BTreeSet <AllSupported> sortedSet = new BTreeSet <AllSupported>(compareByField, session, 1000, sizeof(long), true); for (int i = 0; i < 20000; i++) { obj = new AllSupported(1); obj.dateTime = DateTime.FromBinary(randGen.Next(Int32.MinValue, Int32.MaxValue) * randGen.Next()); sortedSet.Add(obj); } int ct = 0; AllSupported prior = null; foreach (AllSupported currentObj in (IEnumerable <AllSupported>)sortedSet) { if (prior != null) { Assert.Less(prior.dateTime, currentObj.dateTime); } prior = currentObj; ct++; } session.Commit(); } }
static readonly string systemDir = "Sample3"; // appended to SessionBase.BaseDatabasePath static void Main(string[] args) { try { using (SessionNoServer session = new SessionNoServer(systemDir)) { Console.WriteLine("Running with databases in directory: " + session.SystemDirectory); session.BeginUpdate(); Person robinHood = new Person("Robin", "Hood", 30); Person billGates = new Person("Bill", "Gates", 56, robinHood); Person steveJobs = new Person("Steve", "Jobs", 56, billGates); robinHood.BestFriend = billGates; session.Persist(steveJobs); steveJobs.Friends.Add(billGates); steveJobs.Friends.Add(robinHood); billGates.Friends.Add(billGates); robinHood.Friends.Add(steveJobs); session.Commit(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
static void createInvertedIndex() { using (SessionNoServer session = new SessionNoServer(s_systemDir)) { session.BeginUpdate(); session.EnableAutoPageFlush = false; // so that threads don't stomb on each other Console.WriteLine(DateTime.Now.ToString() + ", start creating inverted index"); ParallelOptions pOptions = new ParallelOptions(); pOptions.MaxDegreeOfParallelism = 2; // set to what is appropriate for your computer (cores & memory size) //pOptions.MaxDegreeOfParallelism = 1; // appears to work best with only 16GB of memory IndexRoot indexRoot = (IndexRoot)session.Open(Oid.Encode(IndexRoot.PlaceInDatabase, 1, 1)); BTreeSet <Document> documentSet = indexRoot.repository.documentSet; List <Database> dbs = session.OpenAllDatabases(true); Parallel.ForEach <Database>(dbs, pOptions, (Database db, ParallelLoopState loop) => // method invoked by the loop on each iteration { if (db.DatabaseNumber >= Document.PlaceInDatabase) { createDocumentInvertedIndex(session, db, documentSet); } }); session.Commit(); Console.WriteLine(DateTime.Now.ToString() + ", done creating inverted index"); } }
public void hashCodeComparerStringTest() { Oid id; using (SessionNoServer session = new SessionNoServer(systemDir)) { Placement place = new Placement(223, 1, 1, UInt16.MaxValue, UInt16.MaxValue); session.Compact(); session.BeginUpdate(); HashCodeComparer <string> hashCodeComparer = new HashCodeComparer <string>(); BTreeSet <string> bTree = new BTreeSet <string>(hashCodeComparer, session); bTree.Persist(place, session); id = bTree.Oid; for (int i = 0; i < 100000; i++) { bTree.Add(i.ToString()); } session.Commit(); } using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginRead(); BTreeSet <string> bTree = (BTreeSet <string>)session.Open(id); int count = 0; foreach (string str in bTree) { count++; } Assert.True(100000 == count); session.Commit(); } }
public void AddSomeBicycles() { try { using (SessionNoServer session = new SessionNoServer(s_systemDir)) { session.BeginUpdate(); for (int i = 0; i < 1000000; i++) { Bicycle bicycle = new Bicycle(); bicycle.Color = "red"; session.Persist(bicycle); } for (int i = 0; i < 10; i++) { Bicycle bicycle = new Bicycle(); bicycle.Color = "blue"; session.Persist(bicycle); } for (int i = 0; i < 10; i++) { Bicycle bicycle = new Bicycle(); bicycle.Color = "yellow"; session.Persist(bicycle); } session.Commit(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
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()); } }
public void LookupCompareFields(int bTreeDatabaseNumber) { using (SessionNoServer session = new SessionNoServer(systemDir)) { Person personPrior = null, person; session.BeginRead(); BTreeSet <Person> bTree = (BTreeSet <Person>)session.Open(Oid.Encode((uint)bTreeDatabaseNumber, 1, 1)); BTreeSetIterator <Person> itr = bTree.Iterator(); int ct = 0; while ((person = itr.Next()) != null) { if (personPrior != null) { Assert.LessOrEqual(personPrior.FirstName, person.FirstName); } ct++; personPrior = person; } int ct2 = 0; personPrior = null; foreach (Person pers in (IEnumerable <Person>)bTree) { if (personPrior != null) { Assert.LessOrEqual(personPrior.FirstName, pers.FirstName); } ct2++; personPrior = pers; } session.Commit(); Assert.AreEqual(ct, ct2); } }
public void CreateTicksCompareFields(int numberOfTicks, int nodeSize) { using (SessionNoServer session = new SessionNoServer(systemDir, 2000, false)) { //session.SetTraceAllDbActivity(); session.BeginUpdate(); CompareByField <Tick> compareByField = new CompareByField <Tick>("<Bid>k__BackingField", session, true); //compareByField.AddFieldToCompare("<Timestamp>k__BackingField"); BTreeSet <Tick> bTree = new BTreeSet <Tick>(compareByField, session, (UInt16)nodeSize, sizeof(double) + sizeof(UInt64), true); Placement place = new Placement((UInt32)numberOfTicks, 1, 1, UInt16.MaxValue, UInt16.MaxValue); Placement ticksPlace = new Placement((UInt32)numberOfTicks, 10000, 1, UInt16.MaxValue, UInt16.MaxValue); bTree.Persist(place, session); int i = 0; int dublicates = 0; foreach (var record in Tick.GenerateRandom((ulong)numberOfTicks)) { session.Persist(record, ticksPlace); if (bTree.Add(record)) { i++; } else { dublicates++; } } session.Commit(); Console.WriteLine("Done creating and sorting with BTreeSet<Tick> " + i + " Tick objects by Bid value. Number of dublicates (not added to BTreeSet): " + dublicates); } }
static readonly string systemDir = "QuickStart"; // appended to SessionBase.BaseDatabasePath static int Main(string[] args) { using (SessionNoServer session = new SessionNoServer(systemDir)) { Console.WriteLine("Running with databases in directory: " + session.SystemDirectory); try { session.BeginUpdate(); Company company = new Company(); company.Name = "MyCompany"; session.Persist(company); Employee employee1 = new Employee(); employee1.Employer = company; employee1.FirstName = "John"; employee1.LastName = "Walter"; session.Persist(employee1); session.Commit(); } catch (Exception ex) { Trace.WriteLine(ex.Message); session.Abort(); } } Retrieve(); return(0); }
static void createTopLevelInvertedIndex() { Console.WriteLine(DateTime.Now.ToString() + ", start creating top level inverted index"); using (SessionNoServer session = new SessionNoServer(s_systemDir)) { Placement wordPlacement = new Placement(Lexicon.PlaceInDatabase, 2, 1, 1000, 50000, true, false, UInt32.MaxValue, false); session.BeginUpdate(); IndexRoot indexRoot = (IndexRoot)session.Open(Oid.Encode(IndexRoot.PlaceInDatabase, 1, 1)); BTreeSetOidShort <Word> wordSet = indexRoot.lexicon.WordSet; BTreeSet <Document> documentSet = indexRoot.repository.documentSet; Word existingWord = null; foreach (Document doc in documentSet) { foreach (Word word in doc.WordSet) { WordHit wordHit = doc.WordHit[word]; if (wordSet.TryGetKey(word, ref existingWord)) { existingWord.GlobalCount = existingWord.GlobalCount + (uint)wordHit.Count; } else { existingWord = new WordGlobal(word.aWord, session, (uint)wordHit.Count); existingWord.Persist(wordPlacement, session); indexRoot.lexicon.WordSet.Add(existingWord); } existingWord.DocumentHit.AddFast(doc); } doc.Indexed = true; } session.Commit(); Console.WriteLine(DateTime.Now.ToString() + ", done creating top level inverted index"); } }
public void aaaE_Chris() { var person = new PersonChris() { Name = "John", Address = "123 Blah St" }; using (var session1 = new SessionNoServer(s_systemDir)) { // Persist instance of Person within transaction session1.BeginUpdate(); session1.Persist(person); session1.Commit(); // Create new transaction and make changes to Person and add child object Job session1.BeginUpdate(); person.Name = "Bob"; person.Jobs.Add(new Job { Name = "clean house" }); // Do not commit previous transaction (keep open) and attempt to read person using another session and a read transaction using (var session2 = new SessionNoServer(s_systemDir)) { session2.BeginRead(); uint dbNum = session2.DatabaseNumberOf(typeof(PersonChris)); Database db = session2.OpenDatabase(dbNum); var person1 = db.AllObjects <PersonChris>().First(); // IOException is thrown here session2.Commit(); } } }
static readonly string systemDir = "QuickStart"; // appended to SessionBase.BaseDatabasePath static int Main(string[] args) { using (SessionNoServer session = new SessionNoServer(systemDir)) { Console.WriteLine("Running with databases in directory: " + session.SystemDirectory); try { session.BeginUpdate(); Company company = new Company(); company.Name = "MyCompany"; session.Persist(company); Employee employee1 = new Employee(); employee1.Employer = company; employee1.FirstName = "John"; employee1.LastName = "Walter"; session.Persist(employee1); session.Commit(); } catch (Exception ex) { Trace.WriteLine(ex.Message); session.Abort(); } } Retrieve(); return 0; }
public void CompareInt16() { using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); AllSupported obj = new AllSupported(1); CompareByField <AllSupported> compareByField = new CompareByField <AllSupported>("int16", session); BTreeSet <AllSupported> sortedSet = new BTreeSet <AllSupported>(compareByField, session, 1000, sizeof(Int16), true); for (int i = 0; i < 100000; i++) { obj = new AllSupported(1); obj.int16 = (Int16)randGen.Next(Int16.MinValue, Int16.MaxValue); sortedSet.Add(obj); } int ct = 0; AllSupported prior = null; foreach (AllSupported currentObj in (IEnumerable <AllSupported>)sortedSet) { if (prior != null) { Assert.Less(prior.int16, currentObj.int16); } prior = currentObj; ct++; } session.Commit(); } }
public void CompareInt32DescendingComparisonArray() { #if DEBUG Assert.Throws <NotImplementedException>(() => { using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); AllSupported obj = new AllSupported(2); CompareByField <AllSupported> compareByField = new CompareByField <AllSupported>("int32", session, false, false, false); BTreeSet <AllSupported> sortedSet = new BTreeSet <AllSupported>(compareByField, session, 1000, sizeof(Int32), true); for (int i = 0; i < 100000; i++) { obj = new AllSupported(1); obj.int32 = randGen.Next(Int32.MinValue, Int32.MaxValue); sortedSet.Add(obj); } int ct = 0; AllSupported prior = null; foreach (AllSupported currentObj in (IEnumerable <AllSupported>)sortedSet) { if (prior != null) { Assert.Greater(prior.int32, currentObj.int32); } prior = currentObj; ct++; } session.Commit(); } }); #endif }
private void Save <T>() where T : DynamicDictionary, new() { using (SessionNoServer session = new SessionNoServer(SystemDir)) { dynamic person = CreatePerson <T>(); dynamic person2 = CreatePerson2 <T>(person); OutputProperties("Person", person); OutputProperties("Person2", person2); session.BeginUpdate(); _personId = session.Persist(person); _person2Id = session.Persist(person2); if (typeof(T) == typeof(PersistableDynamicDictionary)) { session.Persist(new PersistableDynamicDictionary() { TypeName = "Test", ["Test"] = "Hello" }); session.Persist(new PersistableDynamicDictionary() { TypeName = "Test", ["Test"] = "World" }); } session.Commit(); } }
static void CreateData() { using (SessionNoServer session = new SessionNoServer(s_systemDir)) { bool dirExist = Directory.Exists(session.SystemDirectory); if (dirExist) { return; Directory.Delete(session.SystemDirectory, true); // remove systemDir from prior runs and all its databases. } Directory.CreateDirectory(session.SystemDirectory); File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb")); SessionBase.DefaultCompressPages = PageInfo.compressionKind.LZ4; session.BeginUpdate(); CompareGeoObj comparer = new CompareGeoObj(); var btreeSet = new BTreeSet <GeoObj>(comparer, session, 1000); for (int i = 0; i < s_numberOfSamples; i++) { var g = new GeoObj(); btreeSet.Add(g); } session.Persist(btreeSet); session.Commit(); Console.Out.WriteLine($@"Done creating {s_numberOfSamples} GeoHashSample GeoObj "); } }
public void CompareString(int compArraySize) { using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); AllSupported obj = new AllSupported(1); CompareByField<AllSupported> compareByField = new CompareByField<AllSupported>("aString", session); BTreeSet<AllSupported> sortedSet = new BTreeSet<AllSupported>(compareByField, session, 1000, (ushort) compArraySize); for (int i = 0; i < 10000; i++) { obj = new AllSupported(1); obj.aString = RandomString(10); sortedSet.Add(obj); } obj = new AllSupported(1); obj.aString = null; sortedSet.Add(obj); int ct = 0; AllSupported prior = null; foreach (AllSupported currentObj in (IEnumerable<AllSupported>)sortedSet) { if (prior != null) { if (prior.aString != null) if (currentObj.aString == null) Assert.Fail("Null is < than a non NULL"); else Assert.Less(prior.aString, currentObj.aString); } prior = currentObj; ct++; } session.Commit(); } }
public void LocalDateTest() { LocalDate d1 = new LocalDate(2016, 1, 10); LocalDate d2 = new LocalDate(2016, 1, 1); LocalDate d1other = new LocalDate(2016, 1, 10); Assert.AreNotEqual(d1, d2); Assert.AreEqual(d1, d1other); using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); LocalDateField test1 = new LocalDateField("def", d1); session.Persist(test1); LocalDateField test = new LocalDateField("abc", d2); session.Persist(test); var result1 = session.AllObjects <LocalDateField>().First(t => t.Field2.Equals(d2)); // this works session.Commit(); } using (var session = new SessionNoServerShared(systemDir)) { session.BeginRead(); var result2 = session.AllObjects <LocalDateField>().First(t => { var l = t.Field2; return(l.Equals(d2)); }); // this should work and doesnt session.Commit(); } }
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; } }
public void CompareInt32Descending() { using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); AllSupported obj = new AllSupported(2, session); CompareByField <AllSupported> compareByField = new CompareByField <AllSupported>("int32", session, false, false, false); BTreeSet <AllSupported> sortedSet = new BTreeSet <AllSupported>(compareByField, session, 1000); for (int i = 0; i < 100000; i++) { obj = new AllSupported(1, session); obj.int32 = randGen.Next(Int32.MinValue, Int32.MaxValue); sortedSet.Add(obj); } int ct = 0; AllSupported prior = null; foreach (AllSupported currentObj in (IEnumerable <AllSupported>)sortedSet) { if (prior != null) { Assert.Greater(prior.int32, currentObj.int32); } prior = currentObj; ct++; } session.Commit(); } }
public void Verify(string dir) { using (SessionNoServer session = new SessionNoServer(dir)) { session.BeginRead(); session.Verify(); session.Commit(); } }
static VelocityDB() { string systemDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "VelocityDB", "Databases", "MvCSample"); if (Directory.Exists(systemDir)) Directory.Delete(systemDir, true); // remove systemDir from prior runs and all its databases. Session = new SessionNoServer(systemDir); Session.BeginUpdate(); Session.Commit(); }
static VelocityDBStatic() { string systemDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "VelocityDB", "Databases", "MvCSample"); foreach (string f in Directory.EnumerateFiles(systemDir)) if (f.Contains("4.odb") == false) File.Delete(f); Session = new SessionNoServer(systemDir); Session.BeginUpdate(); Session.Commit(); }
public void CsvExport() { using (SessionNoServer session = new SessionNoServer(systemDir)) { session.Compact(); session.BeginRead(); session.ExportToCSV(csvExportDir); session.Commit(); } }
public void CsvImport() { using (SessionNoServer session = new SessionNoServer(systemDirCvsImport)) { session.BeginUpdate(); session.ImportFromCSV(csvExportDir); session.Commit(); } Verify(systemDirCvsImport); }
static void Main(string[] args) { SessionNoServer session = new SessionNoServer(systemDir); session.BeginUpdate(); Person robinHood = new Person("Robin", "Hood", 30); Person billGates = new Person("Bill", "Gates", 56, robinHood); Person steveJobs = new Person("Steve", "Jobs", 56, billGates); robinHood.BestFriend = billGates; session.Persist(steveJobs); // the other persons will be persisted implicetly by reachability from "Steve Jobs" person object session.Commit(); }
public void OneMillionFindSingleRecordInTheMiddle() { using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginRead(); var result = (from ComputerFileData computerFileData in session.AllObjects<ComputerFileData>() where computerFileData.FileID == 500000 select computerFileData).First(); session.Commit(); } }
/// <summary> /// Get a list of all <see cref="Database"/> used. /// </summary> /// <param name="path">Path to database directory on server relative to server setting <see cref="SessionBase.BaseDatabasePath"/></param> /// <returns>All databases in use</returns> public IEnumerable<string> Get(string path) { using (SessionNoServer session = new SessionNoServer(path)) { session.BeginRead(); List<Database> dbList = session.OpenAllDatabases(); foreach (Database db in dbList) yield return db.ToString(); session.Commit(); } }
// 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; } }
public void DoFileFolderTest() { using (SessionNoServer session = new SessionNoServer(s_systemDir)) { session.NotifyBeforeCommit = NotifyBeforeCommit; session.BeginUpdate(); DirectoryInfo dirInfo = new DirectoryInfo(s_sampleFolder); Folder folder = new Folder(dirInfo.Name, null, session); CreateDirectoriesAndFiles(dirInfo, folder, session); session.Persist(folder); session.Commit(); } }
/// <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(); } }
public void Create1Root() { using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); IssueTracker issueTracker = new IssueTracker(10, session); User user = new User(null, "*****@*****.**", "Mats", "Persson", "matspca"); session.Persist(user); PermissionScheme permissions = new PermissionScheme(user); issueTracker.Permissions = permissions; session.Persist(issueTracker); session.Commit(); } }
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(); } }
static readonly string systemDir = "Sample1"; // appended to SessionBase.BaseDatabasePath static int Main(string[] args) { SessionNoServer session = new SessionNoServer(systemDir); Console.WriteLine("Running with databases in directory: " + session.SystemDirectory); session.BeginUpdate(); Person person = new Person("Robin", "Hood", 30); session.Persist(person); person = new Person("Bill", "Gates", 56); session.Persist(person); person = new Person("Steve", "Jobs", 56); session.Persist(person); session.Commit(); return 0; }
public void SingleReaderSingleUpdater2() { UInt64 id; using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); Man man = new Man(); man.Persist(session, man); id = man.Id; session.Commit(); session.BeginUpdate(); man.Age = ++man.Age; using (SessionNoServer session2 = new SessionNoServer(systemDir)) { session2.BeginRead(); Man man2 = (Man)session2.Open(id); Assert.Less(man2.Age, man.Age); session2.Commit(); } session.Commit(); } System.GC.Collect(); }
public string Get(string path, int id = 0) { using (SessionNoServer session = new SessionNoServer(path)) { session.BeginRead(); Graph graph = Graph.Open(session, id); using (MemoryStream ms = new MemoryStream()) { graph.ExportToGraphJson(ms); session.Commit(); return Encoding.UTF8.GetString(ms.ToArray()); } } }
public string Get(string path, UInt64 id) { using (SessionNoServer session = new SessionNoServer(path)) { session.BeginRead(); object obj = session.Open(id); JsonSerializerSettings jsonSettings = new JsonSerializerSettings(); jsonSettings.TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Full; jsonSettings.TypeNameHandling = TypeNameHandling.All; jsonSettings.PreserveReferencesHandling = PreserveReferencesHandling.Objects; jsonSettings.ContractResolver = new FieldsOnlyContractResolver(); string json = JsonConvert.SerializeObject(obj, jsonSettings); session.Commit(); return json; } }