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 FixedSizeManyTest(int howMany) { using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); FixedSize fixedSize; FixedSize fixedSizePrior = new FixedSize(); for (int i = 0; i < howMany; i++) { fixedSize = new FixedSize(); fixedSize.Persist(session, fixedSizePrior); fixedSizePrior = fixedSize; } session.Commit(); } using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginRead(); Database db = session.OpenDatabase(FixedSize.PlaceInDatabase); foreach (Page page in db) { if (page.PageNumber > 0) { foreach (FixedSize fixedSize in page) { --howMany; Assert.NotNull(fixedSize); } } } 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 (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 TwoUpdaters2() { Assert.Throws <OpenDatabaseException>(() => { UInt64 id; try { using (var session = new SessionNoServerShared(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(); session.Verify(); } } finally { System.GC.Collect(); } }); }
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 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 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(); } } }
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 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(); } }
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()); } } }
static void Main(string[] args) { CreateData(); using (SessionNoServer session = new SessionNoServer(s_systemDir)) { session.BeginRead(); int ct = GeoHashQuery.SearchGeoHashIndex(session, 32.715736, -117.161087, 10000).Count; Console.WriteLine($@"GeoObj located in San Diego by 10000 meter radius: {ct}"); ct = GeoHashQuery.SearchGeoHashIndex(session, 32.715736, -117.161087, 100000).Count; Console.WriteLine($@"GeoObj located in San Diego by 100000 meter radius: {ct}"); ct = GeoHashQuery.SearchGeoHashIndex(session, 40.730610, -73.935242, 10000).Count; Console.WriteLine($@"GeoObj located in New York City by 10000 meter radius: {ct}"); ct = GeoHashQuery.SearchGeoHashIndex(session, 40.730610, -73.935242, 100000).Count; Console.WriteLine($@"GeoObj located in New York City by 100000 meter radius: {ct}"); // Sweden bounding box ct = GeoHashQuery.SearchGeoHashIndex(session, 55.34, 10.96, 69.06, 24.17).Count; Console.WriteLine($@"GeoObj located in Sweden: {ct}"); // Alaska bounding box ct = GeoHashQuery.SearchGeoHashIndex(session, 51.21, -169.01, 71.39, -129.99).Count; Console.WriteLine($@"GeoObj located in Alaska: {ct}"); // California bounding box ct = GeoHashQuery.SearchGeoHashIndex(session, 32.53, -124.42, 42.01, -114.13).Count; Console.WriteLine($@"GeoObj located in California: {ct}"); // USA bounding box //GeoHashQuery.SearchGeoHashIndex(session, 18.9, -67.0, 71.4, 172.4); //Console.WriteLine($@"Persons located in USA: {ct}"); } }
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()); } }
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 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 } } } }
public void dSyncDeletePages() { using (SessionBase session = new SessionNoServer(s_sync1)) { using (var trans = session.BeginUpdate()) { foreach (FourPerPage fourPerPage in session.AllObjects <FourPerPage>()) { fourPerPage.Unpersist(session); } 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.AllObjects <FourPerPage>().Count, readFromSession.AllObjects <FourPerPage>().Count); } } } }
public void cSyncNewPages() { using (SessionBase session = new SessionNoServer(s_sync1)) { using (var trans = session.BeginUpdate()) { for (uint i = 0; i < 100; i++) { FourPerPage fourPerPage = new FourPerPage(i); session.Persist(fourPerPage); } session.Commit(); } } using (SessionBase readFromSession = new SessionNoServer(s_sync1)) { using (var updateSession = new SessionNoServerShared(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.AllObjects <FourPerPage>().Count, readFromSession.AllObjects <FourPerPage>().Count); } } } }
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 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); } }
private void LoadByDynamicQuery() { using (SessionNoServer session = new SessionNoServer(SystemDir)) { Console.WriteLine("\nDynamic Query"); session.BeginRead(); // Query on the Dynamic Property, Iterates over AllObjects<T> // Note: This will throw an Exception if FirstName and LastName are not both defined on every DynamicDictionary. dynamic dynamicQuery1 = session.AllObjects <DynamicDictionary>() .FirstOrDefault(x => x["FirstName"] == "Ellen" && x["LastName"] == "Adams"); // Avoids Exception but still Iterates over AllObjects<T> dynamic dynamicQuery2 = session.AllObjects <DynamicDictionary>() .FirstOrDefault((x) => { dynamic dynX = x; return(dynX.ContainsProperty("FirstName") && dynX.ContainsProperty("LastName") && dynX.FirstName == "John" && dynX.LastName == "Doe"); }); // Dynamic Query Asserts AssertPerson(dynamicQuery1); AssertPerson2(dynamicQuery2); } }
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(); } }
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 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(); } }
public void DictionaryTest() { ulong id; using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); Dictionary <string, int> dict = new Dictionary <string, int>(); dict.Add("Mats", 52); dict.Add("Robin", 16); dict.Add("Kinga", 53); id = session.Persist(dict); var comp = dict.Comparer; session.Commit(); } using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginRead(); object dictObj = session.Open(id); Dictionary <string, int> dict = (Dictionary <string, int>)dictObj; var comp = dict.Comparer; if (dict["Mats"] != 52) { throw new Exception("failed"); } session.Commit(); } }
public void VelocityDB_SaveKunde_Test() { using (SessionNoServer session = new SessionNoServer(systemDir)) { try { session.BeginUpdate(); var kunde = new KundeVelocityDB(); kunde.Kto = "4711"; kunde.KtoFoerderer = "4712"; kunde.Periode = 2016006; session.Persist(kunde); session.Commit(); } catch (Exception e) { session.Abort(); } } using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginRead(); var kunden = session.AllObjects <KundeVelocityDB>(); var query = from k in kunden where k.Kto.Contains("4711") select k; Assert.AreEqual("4711", query.First()?.Kto); Assert.AreEqual("4712", query.First()?.KtoFoerderer); Assert.AreEqual(2016006, query.First()?.Periode); } }
public City City(string name) { using (SessionNoServer session = new SessionNoServer(SystemDir)) { session.BeginRead(); return(session.AllObjects <City>().SingleOrDefault(c => c.Name.Equals(name))); } }
public void SortedObjectsSample() { Oid bTreeId; using (SessionNoServer session = new SessionNoServer(systemDir)) { const UInt32 numberOfPersons = 100000; const ushort nodeMaxSize = 5000; const ushort comparisonByteArraySize = sizeof(UInt64); // enough room to hold entire idNumber of a Person const bool comparisonArrayIsCompleteKey = true; const bool addIdCompareIfEqual = false; VelocityDbSchema.Samples.AllSupportedSample.Person person; session.BeginUpdate(); //mySession.SetTraceAllDbActivity(); CompareByField <VelocityDbSchema.Samples.AllSupportedSample.Person> compareByField = new CompareByField <VelocityDbSchema.Samples.AllSupportedSample.Person>("m_idNumber", session, addIdCompareIfEqual); BTreeSet <VelocityDbSchema.Samples.AllSupportedSample.Person> bTree = new BTreeSet <VelocityDbSchema.Samples.AllSupportedSample.Person>(compareByField, session, nodeMaxSize, comparisonByteArraySize, comparisonArrayIsCompleteKey); session.Persist(bTree); // Persist the root of the BTree so that we have something persisted that can be flushed to disk if memory available becomes low for (int i = 0; i < numberOfPersons; i++) { person = new VelocityDbSchema.Samples.AllSupportedSample.Person(); session.Persist(person); bTree.Add(person); } bTreeId = bTree.Oid; session.Commit(); } using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginRead(); BTreeSet <VelocityDbSchema.Samples.AllSupportedSample.Person> bTree = (BTreeSet <VelocityDbSchema.Samples.AllSupportedSample.Person>)session.Open(bTreeId); foreach (VelocityDbSchema.Samples.AllSupportedSample.Person person in (IEnumerable <VelocityDbSchema.Samples.AllSupportedSample.Person>)bTree) { if (person.IdNumber > 196988888791402) { Console.WriteLine(person); break; } } session.Commit(); session.BeginRead(); // this LINQ statement will trigger a binary search lookup (not a linear serach) of the matching Person objects in the BTreeSet Console.WriteLine((from person in bTree where person.IdNumber > 196988888791402 select person).First()); session.Commit(); } }
public void Verify(string dir) { using (SessionNoServer session = new SessionNoServer(dir)) { session.BeginRead(); session.Verify(); session.Commit(); } }
public void VerifyOpenIssueTracker() { using (SessionNoServer session = new SessionNoServer(systemDir, 2000, true, true)) { session.BeginRead(); IssueTracker issueTracker = session.AllObjects <IssueTracker>(false).FirstOrDefault(); session.Commit(); } }
public void VerifyOpenIssueTracker() { using (SessionNoServer session = new SessionNoServer(systemDir, 2000, true, true)) { session.BeginRead(); IssueTracker issueTracker = (IssueTracker)session.Open(IssueTracker.PlaceInDatabase, 1, 1, false); session.Commit(); } }
public void CsvExport() { using (SessionNoServer session = new SessionNoServer(systemDir)) { session.Compact(); session.BeginRead(); session.ExportToCSV(csvExportDir); session.Commit(); } }
public MitchellClaimType ReadClaim(string claimNumber) { using (SessionBase session = new SessionNoServer(s_systemDir)) { session.BeginRead(); var claim = ReadClaim(claimNumber, session); session.Commit(); return(claim); } }
public IList <MitchellClaimType> FindClaims(DateTime lossDateFrom, DateTime lossDateTo) { using (SessionBase session = new SessionNoServer(s_systemDir)) { session.BeginRead(); var e = (from c in session.AllObjects <MitchellClaimType>() where c.LossDate >= lossDateFrom && c.LossDate <= lossDateTo select c).ToList(); session.Commit(); return(e); } }
/// <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 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(); } }
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(); } }
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()); } } }
/// <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 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; } }
private void Button_Click(object sender, RoutedEventArgs e) { using (SessionNoServer session = new SessionNoServer(systemDir)) { Console.WriteLine("Running with databases in directory: " + session.SystemDirectory); const UInt32 numberOfPersons = 10000; const ushort nodeMaxSize = 5000; const ushort comparisonByteArraySize = sizeof(UInt64); // enough room to hold entire idNumber of a Person const bool comparisonArrayIsCompleteKey = true; const bool addIdCompareIfEqual = false; Person person; session.BeginUpdate(); session.DefaultDatabaseLocation().CompressPages = PageInfo.compressionKind.None; //mySession.SetTraceAllDbActivity(); BTreeSet<string> stringSet = new BTreeSet<string>(null, session); BTreeSetOidShort<string> stringSetShort = new BTreeSetOidShort<string>(null, session); BTreeMap<string, string> stringMap = new BTreeMap<string, string>(null, session); BTreeMapOidShort<string, string> stringMapShort = new BTreeMapOidShort<string, string>(null, session); CompareByField<Person> compareByField = new CompareByField<Person>("idNumber", session, addIdCompareIfEqual); BTreeSet<Person> bTree = new BTreeSet<Person>(compareByField, session, nodeMaxSize, comparisonByteArraySize, comparisonArrayIsCompleteKey); session.Persist(bTree); // Persist the root of the BTree so that we have something persisted that can be flushed to disk if memory available becomes low for (int i = 0; i < numberOfPersons; i++) { person = new Person(); // session.Persist(person); bTree.AddFast(person); } session.Commit(); } using (SessionNoServer session = new SessionNoServer(systemDir)) { session.UseExternalStorageApi = true; session.BeginRead(); BTreeSet<Person> bTree = session.AllObjects<BTreeSet<Person>>().First(); foreach (Person person in (IEnumerable<Person>)bTree) { if (person.IdNumber > 196988888791402) { Console.WriteLine(person); break; } } session.Commit(); } }
static int Main(string[] args) { UInt64 id; AllSupported allSupported, allSupported2; AllSuportedSub4 sub4; try { using (SessionNoServer session = new SessionNoServer(s_systemDir)) { Console.WriteLine("Running with databases in directory: " + session.SystemDirectory); session.BeginUpdate(); File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb"), true); sub4 = new AllSuportedSub4(); session.Persist(sub4); id = sub4.Id; session.Commit(); } using (SessionNoServer session = new SessionNoServer(s_systemDir)) { session.BeginRead(); sub4 = (AllSuportedSub4)session.Open(id); session.Commit(); } using (SessionNoServer session = new SessionNoServer(s_systemDir)) { session.BeginUpdate(); allSupported = new AllSupported(3); session.Persist(allSupported); id = allSupported.Id; session.Commit(); } using (SessionNoServer session = new SessionNoServer(s_systemDir)) { session.BeginRead(); allSupported2 = (AllSupported)session.Open(id); session.Commit(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); return 1; } return 0; }
static void Main(string[] args) { try { using (SessionNoServer session = new SessionNoServer(s_systemDir)) { DatabaseLocation localLocation = new DatabaseLocation(Dns.GetHostName(), Path.Combine(session.SystemDirectory, "desEncryptedLocation"), desEncryptedStartDatabaseNumber, UInt32.MaxValue, session, PageInfo.compressionKind.LZ4, PageInfo.encryptionKind.desEncrypted); session.BeginUpdate(); session.NewLocation(localLocation); localLocation.DesKey = SessionBase.TextEncoding.GetBytes("5d9nndwy"); // Des keys are 8 bytes long 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(); } using (SessionNoServer session = new SessionNoServer(s_systemDir)) { // Des keys are not persisted in DatabaseLocation (for safety). Instead they are stored as *.des files // in the users document directory of the user that created the DatabaseLocation. These files can be copied // to other user's document directory when acccess is desired for other users. // Path to user document dir is given by C#: Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); session.BeginRead(); var allPersonsEnum = session.AllObjects<Person>(); foreach (Person obj in allPersonsEnum) { Person person = obj as Person; if (person != null) Console.WriteLine(person.FirstName); } session.Commit(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public void LargeObject() { // max length of an array is int.MaxValue, objects on a page are serialized to a single byte[] so this array must have a length < int.MaxValue UInt64 id; using (SessionNoServer session = new SessionNoServer(s_systemDir)) { session.BeginUpdate(); var large = new LargeObject((int) Math.Pow(2, 25)); // Math.Pow(2, 27) too large to handle with ToBase64String for csv export id = session.Persist(large); Assert.True(large.IsOK()); session.Commit(); } using (SessionNoServer session = new SessionNoServer(s_systemDir)) { session.BeginRead(); var large = session.Open<LargeObject>(id); Assert.True(large.IsOK()); session.Commit(); } }
public void ListWrapperTest() { // max length of an array is int.MaxValue, objects on a page are serialized to a single byte[] so this array must have a length < int.MaxValue UInt64 id; using (SessionNoServer session = new SessionNoServer(s_systemDir)) { session.BeginUpdate(); var f = new FourPerPage(1); id = session.Persist(f); Assert.True(f.IsOK()); session.Commit(); } using (SessionNoServer session = new SessionNoServer(s_systemDir)) { session.BeginRead(); var f = session.Open<FourPerPage>(id); Assert.True(f.IsOK()); session.Commit(); } }
public void LazyLoadDepth() { UInt64 id; using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); LazyLoadByDepth lazy = null; for (uint i = 1; i <= 100; i++) lazy = new LazyLoadByDepth(i, lazy); session.Persist(lazy); id = lazy.Id; session.Commit(); } using (SessionNoServer session = new SessionNoServer(systemDir)) { UInt32 ct = 100; session.BeginRead(); LazyLoadByDepth lazy = (LazyLoadByDepth)session.Open(id, false, false, 0); // load only the root of the object graph Assert.AreEqual(ct--, lazy.MyCt); Assert.IsNull(lazy.MyRefPeek); Assert.NotNull(lazy.MyRef); Assert.NotNull(lazy.MyRefPeek); lazy = lazy.MyRef; Assert.AreEqual(ct--, lazy.MyCt); Assert.IsNull(lazy.MyRefPeek); Assert.NotNull(lazy.MyRef); Assert.NotNull(lazy.MyRefPeek); lazy = lazy.MyRef; Assert.AreEqual(ct--, lazy.MyCt); Assert.IsNull(lazy.MyRefPeek); Assert.NotNull(lazy.MyRef); Assert.NotNull(lazy.MyRefPeek); lazy = lazy.MyRef; Assert.AreEqual(ct--, lazy.MyCt); Assert.IsNull(lazy.MyRefPeek); Assert.NotNull(lazy.MyRef); Assert.NotNull(lazy.MyRefPeek); session.Commit(); } }
public void LazyLoadProperty() { UInt64 id; using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); LazyLoadPropertyClass lazy = null; for (uint i = 1; i <= 10000; i++) lazy = new LazyLoadPropertyClass(i, lazy); session.Persist(lazy); id = lazy.Id; session.Commit(); } using (SessionNoServer session = new SessionNoServer(systemDir)) { UInt32 ct = 10000; session.BeginRead(); LazyLoadPropertyClass lazy = (LazyLoadPropertyClass)session.Open(id); Assert.AreEqual(ct--, lazy.MyCt); Assert.IsNull(lazy.MyRefPeek); Assert.NotNull(lazy.MyRef); Assert.NotNull(lazy.MyRefPeek); lazy = lazy.MyRef; Assert.AreEqual(ct--, lazy.MyCt); Assert.IsNull(lazy.MyRefPeek); Assert.NotNull(lazy.MyRef); Assert.NotNull(lazy.MyRefPeek); lazy = lazy.MyRef; Assert.AreEqual(ct--, lazy.MyCt); Assert.IsNull(lazy.MyRefPeek); Assert.NotNull(lazy.MyRef); Assert.NotNull(lazy.MyRefPeek); lazy = lazy.MyRef; Assert.AreEqual(ct--, lazy.MyCt); Assert.IsNull(lazy.MyRefPeek); Assert.NotNull(lazy.MyRef); Assert.NotNull(lazy.MyRefPeek); session.Commit(); } }
public void TooLargeObject() { Assert.Throws<OverflowException>(() => { UInt64 id; using (SessionNoServer session = new SessionNoServer(s_systemDir)) { session.BeginUpdate(); var large = new LargeObject((int)Math.Pow(2, 28)); id = session.Persist(large); Assert.True(large.IsOK()); session.Commit(); } using (SessionNoServer session = new SessionNoServer(s_systemDir)) { session.BeginRead(); var large = session.Open<LargeObject>(id); Assert.True(large.IsOK()); session.Commit(); } }); }
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 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 void HashSetAddNonPersisted() { UInt64 id; Person person = null; using (SessionNoServer session = new SessionNoServer(s_systemDir)) { session.BeginUpdate(); var hashSet = new HashSet<Person>(); for (int i = 0; i < 100; i++) { var p = new Person(); session.Persist(p); hashSet.Add(p); if (i == 47) { person = p; Assert.IsFalse(hashSet.Add(person)); } } id = session.Persist(hashSet); Assert.IsTrue(hashSet.Contains(person)); session.Commit(); } using (SessionNoServer session = new SessionNoServer(s_systemDir)) { session.BeginRead(); var hashSet = session.Open<HashSet<Person>>(id); Assert.AreEqual(100, hashSet.Count); int ct = 0; foreach (Person p in hashSet) ct++; Assert.IsTrue(hashSet.Contains(person)); Assert.IsFalse(hashSet.Add(person)); Assert.AreEqual(100, ct); session.Commit(); } }
protected void ForgotPasswordLinkButton_Click(object sender, EventArgs e) { try { using (SessionNoServer session = new SessionNoServer(dataPath, 2000, true, true)) { session.BeginRead(); Root root = (Root)session.Open(Root.PlaceInDatabase, 1, 1, false); if (root == null) { ErrorMessage.Text = "The entered email address is not registered with this website"; session.Abort(); return; } CustomerContact lookup = new CustomerContact(Email.Text, null); if (!root.customersByEmail.TryGetKey(lookup, ref lookup)) { ErrorMessage.Text = "The entered email address is not registered with this website"; session.Abort(); return; } session.Commit(); MailMessage message = new MailMessage("*****@*****.**", Email.Text); message.Subject = "Your password to VelocityWeb"; message.Body = "Password is: " + lookup.password; SmtpClient client = new SmtpClient("smtpout.secureserver.net", 80); System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("*****@*****.**", "xxxx"); client.Credentials = SMTPUserInfo; client.Send(message); ErrorMessage.Text = "Email with your password was send to: " + Email.Text; } } catch (System.Exception ex) { ErrorMessage.Text = ex.ToString(); } }
static void Retrieve() { using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginRead(); // get all companies from database IEnumerable<Company> companies = session.AllObjects<Company>(); // get all employees that FirstName contains "John" IEnumerable<Employee> employees = session.AllObjects<Employee>(); var query = from Employee emp in employees where emp.FirstName.Contains("John") select emp; foreach (Employee emp in query) { //do something with employee emp.ToString(); } // get all Employees that are over 30 years old and are from Berlin: var query2 = from Employee emp in employees where emp.Age > 30 && emp.City == "Berlin" select emp; foreach (Employee emp in query2) { //do something with employee emp.ToString(); } // get all Employees that work at "MyCompany" company: var query3 = from Employee emp in employees where emp.Employer.Name == "MyCompany" select new { emp.FirstName, emp.LastName }; session.Commit(); } }
static readonly string s_systemDir = "WorldCities"; // appended to SessionBase.BaseDatabasePath public MainWindow() { InitializeComponent(); errorMessage.Content = null; try { using (SessionNoServer session = new SessionNoServer(s_systemDir)) { try { session.BeginRead(); loadCities(session); session.Commit(); } catch (SystemDatabaseNotFoundWithReadonlyTransactionException) { } } } catch (Exception ex) { errorMessage.Content = ex.Message == null ? ex.ToString() : ex.Message; } }
public void aSyncNewDatabases() { using (SessionBase session = new SessionNoServer(s_sync1)) { session.EnableSyncByTrackingChanges = true; using (var trans = session.BeginUpdate()) { for (uint i = 10; i < 50; i++) { var database = session.NewDatabase(i); Assert.NotNull(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 } } } }
// Queries public void doQueries() { using (SessionNoServer session = new SessionNoServer(s_systemDir)) { session.BeginRead(); Graph g = Graph.Open(session); // it takes a while to open graph fresh from databases VertexType userType = g.FindVertexType("User"); EdgeType friendEdgeType = g.FindEdgeType("Friend"); PropertyType countryProperty = userType.FindProperty("country"); PropertyType incomeProperty = userType.FindProperty("income"); PropertyType friendshipStartProperty = friendEdgeType.FindProperty("start"); Vertex someUser = userType.GetVertex(1); Vertex someUser2 = userType.GetVertex(12282); var someUserFriends = from Edge e in someUser.GetEdges(friendEdgeType, Direction.Out) select e.Head; var someUser3LevelNetwork = someUser.Traverse(3, true, Direction.Out); HashSet<Edge> edges = new HashSet<Edge>(); Edge edge = (Edge)someUser.GetEdges(friendEdgeType, Direction.Out).Skip(1).First(); edges.Add(edge); HashSet<EdgeType> edgeTypesToTraverse = new HashSet<EdgeType>(); edgeTypesToTraverse.Add(friendEdgeType); // Find Shortest path between two given user ids List<List<Edge>> path = someUser.Traverse(4, false, Direction.Out, someUser2, edgeTypesToTraverse); Debug.Assert(path.Count > 0); var path2 = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(41), edgeTypesToTraverse); HashSet<Vertex> vertices = new HashSet<Vertex>(); vertices.Add(someUser2); var path3 = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(9465810), edgeTypesToTraverse, null, null, vertices); // path must include vertices var path3b = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(9465810), edgeTypesToTraverse, null, null, null, vertices); // path must NOT include vertices var path3c = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(9465810), edgeTypesToTraverse, null, null, null, null, edges); // path must include edges var path3d = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(9465810), edgeTypesToTraverse, null, null, null, null, null, edges); // path must NOT include edges HashSet<PropertyType> vertexPropertyTypes = new HashSet<PropertyType>(); vertexPropertyTypes.Add(incomeProperty); vertexPropertyTypes.Add(countryProperty); var path3e = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(9465810), edgeTypesToTraverse, null, null, null, null, null, edges, vertexPropertyTypes); // path must NOT include edges and at least one vertex in path must have property in propertyTypes var path3f = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(9465810), edgeTypesToTraverse, null, null, null, null, null, edges, null, vertexPropertyTypes); // path must NOT include edges and no vertex in path must have any property in propertyTypes HashSet<PropertyType> edgePropertyTypes = new HashSet<PropertyType>(); edgePropertyTypes.Add(friendshipStartProperty); var path3g = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(9465810), edgeTypesToTraverse, null, null, null, null, null, edges, null, null, edgePropertyTypes); var path3h = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(9465810), edgeTypesToTraverse, null, null, null, null, null, edges, null, null, null, edgePropertyTypes); var path3i = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(9465810), edgeTypesToTraverse, null, null, null, null, null, edges, null, null, null, null, p => { object pv = p.GetProperty(countryProperty); return pv != null && pv.Equals("Sweden"); }); var path3j = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(9465810), edgeTypesToTraverse, null, null, null, null, null, edges, null, null, null, null, null, p => { DateTime? pv = (DateTime?)p.GetProperty(friendshipStartProperty); return pv != null && pv.Value.CompareTo(DateTime.Now) > 0; }); var path4 = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(2798), edgeTypesToTraverse); var path5 = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(175), edgeTypesToTraverse); var path6 = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(1531), edgeTypesToTraverse); var path7 = someUser.Traverse(4, false, Direction.Out, userType.GetVertex(1537), edgeTypesToTraverse); Console.WriteLine(); // Get all the paths between two user ids var path8 = someUser.Traverse(4, true, Direction.Out, someUser2, edgeTypesToTraverse); path = someUser.Traverse(4, true, Direction.Out, userType.GetVertex(41), edgeTypesToTraverse); // Get the number of unique 2nd level friends a given user has (friends of my friends) var someUsers2ndLevelFriends = (from v in someUserFriends from Edge e in v.GetEdges(friendEdgeType, Direction.Out) select e.Head).Distinct(); Console.WriteLine("unique 2nd level friends a given user has"); int ct = 0; foreach (Vertex v in someUsers2ndLevelFriends) { if (++ct % 100 == 0) Console.WriteLine("User id: " + v.VertexId); } Console.WriteLine("Some user has: " + ct + " 2nd level friends"); Console.WriteLine(); // Get the top 10 users with most friends var top10mostFriends = from vertex in userType.GetTopNumberOfEdges(friendEdgeType, 10, Direction.Out) select vertex; Console.WriteLine("top 10 users with most friends"); foreach (Vertex v in top10mostFriends) { long count = v.GetNumberOfEdges(friendEdgeType, Direction.Out); Console.WriteLine("User id: " + v.VertexId + "\t number of friends: " + count); } Console.WriteLine(); session.Commit(); } }
static void QueryGraph() { using (SessionNoServer session = new SessionNoServer(systemDir)) { // Start a read only transaction session.BeginRead(); Graph g = Graph.Open(session); // Cache SCHEMA VertexType movieType = g.FindVertexType("Movie"); PropertyType movieTitleType = movieType.FindProperty("title"); VertexType actorType = g.FindVertexType("Actor"); PropertyType actorNameType = actorType.FindProperty("name"); // How many vertices do we have? Console.WriteLine("Number of Vertices: " + g.CountVertices()); // Find a movie by name Vertex movie = movieTitleType.GetPropertyVertex("The Matrix"); // Get all actors var actors = actorType.GetVertices(); // Count the actors int actorCount = actors.Count(); Console.WriteLine("Number of Actors: " + actorCount); // Get only the actors whose names end with “s” foreach (Vertex vertex in actors) { string actorName = (string) actorNameType.GetPropertyValue(vertex.VertexId); if (actorName.EndsWith("s")) Console.WriteLine("Found actor with name ending with \"s\" " + actorName); } // Get a count of property types var properties = session.AllObjects<PropertyType>(); Console.WriteLine("Number of Property types: " + properties.Count()); // All vertices and their edges var edges = g.GetEdges(); int edgeCount = edges.Count(); session.Commit(); } }