public void BTreeMap1Populate() { int sessionId = 0; SessionBase session = null; try { session = SessionManager.SessionPool.GetSession(out sessionId); session.BeginUpdate(); var bTreeMap = new BTreeMapOwner(); _id = session.Persist(bTreeMap); for (int i = 0; i < numberOfZipCodes; i++) { string str = i.ToString(); var bTree = new BTreeSet <LocationWithinUSA>(); for (int j = 0; j < Math.Min(i, 1000); j++) { var loc = new LocationWithinUSA(); session.Persist(loc); bTree.AddFast(loc); } bTreeMap.LocationByZipCode.AddFast(str, bTree); } session.Commit(); } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } finally { SessionManager.SessionPool.FreeSession(sessionId, session); } }
public TokenStoreHit(SessionBase session) { var tree = new BTreeSet <Oid>(); session.Persist(tree); session.Persist(this); m_tokenInProduct = new WeakIOptimizedPersistableReference <BTreeSet <Oid> >(tree); }
public void SimpleTest1_0_0(bool bGenerateUnique, bool useServerSession) { using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { try { session.BeginUpdate(); session.CrossTransactionCacheAllDatabases(); //session.RegisterClass(typeof(RDerby1)); //Assert.True(session.Index<RDerby1>().Count == 0); // enter five records into data base Random random = new Random(); for (int i = 0; i < 5; i++) { RDerby1 classData; string added = "added" + i; if (bGenerateUnique) { classData = new RDerby1("test" + i + "_" + random.Next(), "name2" + i.ToString() + "_" + random.Next(), added); session.Persist(classData); } else { try { classData = new RDerby1("test" + i, "name2" + i.ToString(), added); session.Persist(classData); } catch (UniqueConstraintException) { Assert.Greater(i, 0); } } } try { session.Commit(); } catch (Exception ex) { throw new Exception("Exception occured while commiting records: " + ex.Message); } } catch (Exception ex) { // examine problem using breakpoint. throw new Exception("Exception occured while persisting records: " + ex.Message); } finally { } } Console.WriteLine(DisplayData(useServerSession)); }
public void createDatabaseLocations(SessionBase session) { session.BeginUpdate(); Person person = new Person("Mats", "Persson", 54); session.Persist(person); var otherLocation = new DatabaseLocation(session.SystemHostName, otherDbDir, otherStartdbId, session.DefaultDatabaseLocation().EndDatabaseNumber, session); Placement place = new Placement(otherStartdbId); Person person2 = new Person("Mats", "Persson", 27); session.Persist(place, person2); session.Commit(); verifyDatabaseLocations(session); }
public void TestAllObjects() { var obj1 = new PersistentClass("OBJ1"); _session.Persist(obj1); var obj2 = new PersistentClass("OBJ2"); _session.Persist(obj2); _session.Checkpoint(); var list = _session.AllObjects <PersistentClass>(); var computedCount = Enumerable.Count(list); Assert.AreEqual(2, computedCount); Assert.AreEqual(2, list.Count); }
/// <summary> /// Creates a user. /// </summary> /// <param name="user">The user.</param> /// <returns></returns> /// <exception cref="NullObjectException">If user is null.</exception> /// <exception cref="Exception">Any client error condition.</exception> public async Task CreateAsync(T user) { SessionBase session = Session; bool inUpdate = session.InUpdateTransaction; if (inUpdate == false) { if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); } session.Persist(user); m_aspNetIdentity.EmailToId.Add(user.Email, user.Id); m_aspNetIdentity.UserSet.Add(user); if (user.Email != user.UserName) { m_aspNetIdentity.UserNameToId.Add(user.UserName, user.Id); } if (inUpdate == false) { session.Commit(); } await Task.FromResult(true); }
public void IndexSample2(bool useServerSession) { CreateDirectoryAndCopyLicenseDb(); Random rd = new Random(); using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginUpdate(); for (int i = 0; i < 100; i++) { MeasurePoint p = new MeasurePoint(i + 1) { Data = new List <float>() }; for (int j = 0; j < 440000; j++) { p.Data.Add(rd.Next(100)); } session.Persist(p); } var value = session.DatabaseNumberOf(typeof(MeasurePoint)); Database db = session.OpenDatabase(value, false, false); if (db != null) { var q = from point in session.Index <MeasurePoint>("key", db) where point.Key == 10 select point; foreach (MeasurePoint obj in q) { Console.WriteLine(obj.Key + " " + obj.Data.Count); } } session.Commit(); } }
public void IOptimizedPersistableField(bool useServerSession) { using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginUpdate(); for (int i = 0; i < 10; i++) { var dict = new PersistableDynamicDictionary(); session.Persist(dict); } session.Commit(); } using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginRead(); session.TraceIndexUsage = true; DateTime now = DateTime.UtcNow; var q = from dict in session.Index <PersistableDynamicDictionary>("m_creationTime") where dict.CreationTime < now && dict.CreationTime >= now.AddYears(-1) select dict; Assert.GreaterOrEqual(q.Count(), 10); q = from dict in session.Index <PersistableDynamicDictionary>("m_creationTime") where dict.CreationTime > DateTime.UtcNow.AddYears(-1) select dict; Assert.GreaterOrEqual(q.Count(), 10); session.Commit(); } }
private void CopyFederationMenuItem_Click(object sender, RoutedEventArgs e) { MenuItem menuItem = (MenuItem)sender; FederationViewModel view = (FederationViewModel)menuItem.DataContext; FederationInfo info = view.Federationinfo; SessionBase session = view.Session; var lDialog = new System.Windows.Forms.FolderBrowserDialog() { Description = "Choose Federation Copy Folder", }; if (lDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string copyDir = lDialog.SelectedPath; if (session.InTransaction) { session.Commit(); // must not be in transaction while copying databases } session.CopyAllDatabasesTo(copyDir); session = info.GetSession(); session.BeginUpdate(); FederationCopyInfo copyInfo = new FederationCopyInfo(Dns.GetHostName(), copyDir); session.Persist(copyInfo); info.Update(); info.FederationCopies.Add(copyInfo); session.Commit(); MessageBox.Show("Databases copied to " + copyDir + " at " + DateTime.Now); } }
bool AddFederation(DirectoryInfo dirInfo) { FederationInfo info = new FederationInfo(); if (dirInfo != null) { info.SystemDbsPath = dirInfo.FullName; } ConnectionDialog popup = new ConnectionDialog(info); bool? result = popup.ShowDialog(); if (result != null && result.Value) { if (info.HostName == null || info.HostName.Length == 0) { info.HostName = SessionBase.LocalHost; } SessionBase session = m_viewModel.ActiveSession; if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); session.Persist(info); session.Commit(); m_viewModel = new AllFederationsViewModel(); base.DataContext = m_viewModel; return(true); } return(false); }
private void Create1000TestObjectsMenuItem_Click(object sender, RoutedEventArgs e) { MenuItem menuItem = (MenuItem)sender; FederationViewModel view = (FederationViewModel)menuItem.DataContext; FederationInfo info = view.Federationinfo; SessionBase session = view.Session; if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); //session.EnableSyncByTrackingChanges = true; try { for (int i = 0; i < 1000; i++) { VelocityDbList <OptimizedPersistable> list = new VelocityDbList <OptimizedPersistable>(); //for (int j = 0; j < 10; j++) // list.Add(new OptimizedPersistable()); session.Persist(list); } session.Commit(); m_viewModel = new AllFederationsViewModel(); base.DataContext = m_viewModel; } catch (Exception ex) { session.Abort(); MessageBox.Show(ex.Message); } }
void LockConflict(SessionBase sharedReadSession) { string host = null; Random r = new Random(5); SessionPool sessionPool = new SessionPool(3, () => new ServerClientSession(systemDir, host, 2000, false)); try { int iCounter = 0; int sessionId1 = -1; SessionBase session1 = null; for (int i = 0; i < 50; i++) { try { session1 = sessionPool.GetSession(out sessionId1); session1.BeginUpdate(); Dokument Doc_A = new Dokument(); Doc_A.Name = "Test A"; session1.Persist(Doc_A); Console.WriteLine(Doc_A.ToString()); int sessionId2 = -1; SessionBase session2 = null; try { session2 = sessionPool.GetSession(out sessionId2); session2.BeginUpdate(); Dokument Doc_B = new Dokument(); Doc_B.Name = "Test_B"; session2.Persist(Doc_B); Console.WriteLine(Doc_B.ToString()); session2.Commit(); } finally { sessionPool.FreeSession(sessionId2, session2); } session1.Commit(); sharedReadSession.ForceDatabaseCacheValidation(); session1.BeginRead(); ulong ct = session1.AllObjects <Dokument>(false).Count; Console.WriteLine("Number of Dokument found by normal session: " + ct); session1.Commit(); ct = sharedReadSession.AllObjects <Dokument>(false).Count; Console.WriteLine("Number of Dokument found by shared read session: " + ct); } finally { sessionPool.FreeSession(sessionId1, session1); } iCounter++; Console.WriteLine(" -> " + iCounter.ToString()); } } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } }
/// <summary> /// Persists this object. /// </summary> /// <param name="place">The placement rules to follow when persisting this object</param> /// <param name="session">The session managing this object</param> /// <param name="persistRefs">If true, objects referenced from this object will also be persisted</param> /// <param name="disableFlush">If true, disables possible flushing of updated pages while persisting this object; otherwise pasge flushing may occur</param> /// <returns>The object id of the persistent object</returns> public ulong Persist(SessionBase session, IOptimizedPersistable placeHint, bool persistRefs = true, bool disableFlush = false) { Placement place = new Placement(session, placeHint, this, persistRefs, UInt32.MaxValue, placeHint.FlushIfPageFull); return(session.Persist(place, this, session.OpenSchema(false), UInt16.MaxValue - 1, disableFlush)); }
//public BTreeMap<Word, UInt32> globalWordCount; public IndexRoot(ushort nodeSize, SessionBase session) { _lexicon = new Lexicon <string>(nodeSize, session); session.Persist(_lexicon); _repository = new Repository(nodeSize, session); _repository.Persist(session, _repository, true); //globalWordCount = new BTreeMap<Word, uint>(null, session); }
public void createDatabaseLocations(SessionBase session) { session.BeginUpdate(); Person person = new Person("Mats", "Persson", 54); session.Persist(person); session.Commit(); verifyDatabaseLocations(session); }
void parseMovie(SessionBase session, string line, ImdbRoot imdbRoot, ActingPerson acting) { line = new string(line.SkipWhile(aChar => aChar == '\t').ToArray <char>()); // skip any leading tabs string movieName = new string(line.TakeWhile(aChar => aChar != '(').ToArray <char>()); // start of year if (movieName.Length == 0 || movieName[0] != '\"') // then it is a TV series - skipping for now { line = line.Substring(movieName.Length + 1); string yearString = new string(line.TakeWhile(aChar => aChar != ')').ToArray <char>()); // end of year bool unknownYear = yearString == "????"; bool notEndOfMovieName = (yearString.Length < 4 || (yearString.Length > 4 && yearString[4] != '/') || Char.IsNumber(yearString[0]) == false || Char.IsNumber(yearString[1]) == false) && unknownYear == false; while (notEndOfMovieName) { movieName += "("; string extendedName = new string(line.TakeWhile(aChar => aChar != '(').ToArray <char>()); movieName += extendedName; line = line.Substring(extendedName.Length + 1); yearString = new string(line.TakeWhile(aChar => aChar != ')').ToArray <char>()); // end of year unknownYear = yearString == "????"; notEndOfMovieName = (yearString.Length < 4 || (yearString.Length > 4 && yearString[4] != '/') || Char.IsNumber(yearString[0]) == false || Char.IsNumber(yearString[1]) == false) && unknownYear == false; } movieName = movieName.TrimEnd(trimEndChars); line = line.Substring(yearString.Length + 1); yearString = new string(yearString.TakeWhile(aChar => aChar != '/').ToArray <char>()); // skip year string like 2010/I Int16 year; if (unknownYear) { year = 0; } else { year = Int16.Parse(yearString); } line = new string(line.SkipWhile(aChar => aChar != '(' && aChar != '[').ToArray <char>()); // start of role bool video = line.Length > 1 && line[0] == '(' && line[1] == 'V'; bool tv = line.Length > 2 && line[0] == '(' && line[1] == 'T' && line[2] == 'V'; if (tv == false && video == false) { string role = null; if (line.Length > 1 && line[0] == '[') { line = line.Substring(1); role = new string(line.TakeWhile(aChar => aChar != ']').ToArray <char>()); // end of role } Movie movie = new Movie(movieName, year, session); if (!imdbRoot.MovieSet.TryGetKey(movie, ref movie)) { session.Persist(movie); imdbRoot.MovieSet.Add(movie); } if (role != null) { acting.InMovieAs.Add(movie, role); } movie.Cast.Add(acting); } } }
public void createDatabaseLocations(SessionBase session) { session.BeginUpdate(); Person person = new Person("Mats", "Persson", 54); session.Persist(person); session.Commit(); verifyDatabaseLocations(session); }
T SessionPersist <T>(T obj) { lock (_session) { _session.Persist(obj); } return(obj); }
void Initialize() { SessionBase.BaseDatabasePath = Properties.Settings.Default.BaseDatabasePath; m_session = new SessionNoServer(Properties.Settings.Default.DatabaseManagerDirectory); try { m_session.BeginUpdate(); List<FederationViewModel> federationInfos = new List<FederationViewModel>(); List<FederationInfo> federationInfosToRemove = new List<FederationInfo>(); foreach (FederationInfo info in m_session.AllObjects<FederationInfo>()) { try { federationInfos.Add(new FederationViewModel(info)); } catch (Exception ex) { if (MessageBox.Show(ex.Message + " for " + info.HostName + " " + info.SystemDbsPath + " Remove this Database?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) federationInfosToRemove.Add(info); } } foreach (FederationInfo info in federationInfosToRemove) info.Unpersist(m_session); if (federationInfos.Count() == 0) { string host = Properties.Settings.Default.DatabaseManagerHost; if (host == null || host.Length == 0) host = Dns.GetHostName(); FederationInfo info = new FederationInfo(host, Properties.Settings.Default.DatabaseManagerDirectory, Properties.Settings.Default.TcpIpPortNumber, Properties.Settings.Default.DoWindowsAuthentication, null, Properties.Settings.Default.WaitForLockMilliseconds, Properties.Settings.Default.UseClientServer, "Database Manager"); m_session.Persist(info); m_session.Commit(); federationInfos.Add(new FederationViewModel(info)); } if (m_session.InTransaction) m_session.Commit(); m_federationViews = federationInfos; } catch (Exception ex) { if (m_session.InTransaction) m_session.Abort(); if (MessageBox.Show(ex.Message + " for " + SessionBase.LocalHost + " " + Properties.Settings.Default.DatabaseManagerDirectory + " Remove this Database?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { DirectoryInfo dir = new DirectoryInfo(Properties.Settings.Default.DatabaseManagerDirectory); dir.Delete(true); Initialize(); } } }
void parseMovie(SessionBase session, string line, ImdbRoot imdbRoot, ActingPerson acting) { line = new string(line.SkipWhile(aChar => aChar == '\t').ToArray<char>()); // skip any leading tabs string movieName = new string(line.TakeWhile(aChar => aChar != '(').ToArray<char>()); // start of year if (movieName.Length == 0 || movieName[0] != '\"') // then it is a TV series - skipping for now { line = line.Substring(movieName.Length + 1); string yearString = new string(line.TakeWhile(aChar => aChar != ')').ToArray<char>()); // end of year bool unknownYear = yearString == "????"; bool notEndOfMovieName = (yearString.Length < 4 || (yearString.Length > 4 && yearString[4] != '/') || Char.IsNumber(yearString[0]) == false || Char.IsNumber(yearString[1]) == false) && unknownYear == false; while (notEndOfMovieName) { movieName += "("; string extendedName = new string(line.TakeWhile(aChar => aChar != '(').ToArray<char>()); movieName += extendedName; line = line.Substring(extendedName.Length + 1); yearString = new string(line.TakeWhile(aChar => aChar != ')').ToArray<char>()); // end of year unknownYear = yearString == "????"; notEndOfMovieName = (yearString.Length < 4 || (yearString.Length > 4 && yearString[4] != '/') || Char.IsNumber(yearString[0]) == false || Char.IsNumber(yearString[1]) == false) && unknownYear == false; } movieName = movieName.TrimEnd(trimEndChars); line = line.Substring(yearString.Length + 1); yearString = new string(yearString.TakeWhile(aChar => aChar != '/').ToArray<char>()); // skip year string like 2010/I Int16 year; if (unknownYear) year = 0; else year = Int16.Parse(yearString); line = new string(line.SkipWhile(aChar => aChar != '(' && aChar != '[').ToArray<char>()); // start of role bool video = line.Length > 1 && line[0] == '(' && line[1] == 'V'; bool tv = line.Length > 2 && line[0] == '(' && line[1] == 'T' && line[2] == 'V'; if (tv == false && video == false) { string role = null; if (line.Length > 1 && line[0] == '[') { line = line.Substring(1); role = new string(line.TakeWhile(aChar => aChar != ']').ToArray<char>()); // end of role } Movie movie = new Movie(movieName, year, session); if (!imdbRoot.MovieSet.TryGetKey(movie, ref movie)) { session.Persist(movie); imdbRoot.MovieSet.Add(movie); } if (role != null) acting.InMovieAs.Add(movie, role); movie.Cast.Add(acting); } } }
//[TestCase(true)] //[TestCase(false)] public void CreateDataWithBackupServerAutoPlacement(bool useServerSession) { int loops = 100000; int j; if (Directory.Exists(backupDir)) { Directory.Delete(backupDir, true); // remove systemDir from prior runs and all its databases. } Directory.CreateDirectory(backupDir); using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { Man aMan = null; Woman aWoman = null; const bool isBackupLocation = true; session.BeginUpdate(); // we need to have backup locations special since server is not supposed to do encryption or compression DatabaseLocation backupLocation = new DatabaseLocation(Dns.GetHostName(), backupDir, backupLocationStartDbNum, UInt32.MaxValue, session, PageInfo.compressionKind.None, PageInfo.encryptionKind.noEncryption, isBackupLocation, session.DatabaseLocations.Default()); session.NewLocation(backupLocation); for (j = 1; j <= loops; j++) { aMan = new Man(null, aMan, DateTime.Now); session.Persist(aMan); aWoman = new Woman(aMan, aWoman); session.Persist(aWoman); aMan.m_spouse = new WeakIOptimizedPersistableReference <VelocityDbSchema.Person>(aWoman); if (j % 1000000 == 0) { Console.WriteLine("Loop # " + j); } } UInt64 id = aWoman.Id; Console.WriteLine("Commit, done Loop # " + j); session.Commit(); } }
public Folder(string name, Folder parentFolder, SessionBase session) : base(name) { CompareByField <FileInDb> comparerByFileName = new CompareByField <FileInDb>("m_name", session, false, true); m_files = new BTreeSet <FileInDb>(comparerByFileName, session, 10000, CommonTypes.s_sizeOfUInt32); CompareByField <Folder> comparerByFolderName = new CompareByField <Folder>("m_name", session, false, true); m_folders = new BTreeSet <Folder>(comparerByFolderName, session, 10000, CommonTypes.s_sizeOfUInt32); session.Persist(this); if (parentFolder != null) { Update(); m_folderRelation = new Relation <Folder, Folder>(this, parentFolder); } }
void CreateDirectoriesAndFiles(DirectoryInfo dirInfo, Folder folder, SessionBase session) { foreach (DirectoryInfo dir in dirInfo.GetDirectories()) { Folder subFolder = new Folder(dir.Name, folder, session); CreateDirectoriesAndFiles(dir, subFolder, session); } foreach (FileInfo fileInfo in dirInfo.GetFiles()) { FileInDb file = new FileInDb(fileInfo.Name, folder); byte[] bytes = File.ReadAllBytes(fileInfo.FullName); FileContent fileContent = new FileContent(bytes); session.Persist(fileContent, 10000); file.Content = fileContent; } }
public void AddActsPersisted(int count, SessionBase session) { InsertDefaultAct(session); for (int i = 1; i < count; i++) { var act = new Act { QueryHelper = QueryHelper, Name = Acts.Count < ActNames.Count ? ActNames[Acts.Count] : GenerateUniqueName(8), Notes = GenerateNotes() }; session.Persist(act); Acts.Add(act); } }
void CreateDirectoriesAndFiles(DirectoryInfo dirInfo, Folder folder, SessionBase session) { foreach (DirectoryInfo dir in dirInfo.GetDirectories()) { Folder subFolder = new Folder(dir.Name, folder, session); CreateDirectoriesAndFiles(dir, subFolder, session); } foreach (FileInfo fileInfo in dirInfo.GetFiles()) { FileInDb file = new FileInDb(fileInfo.Name, folder); byte[] bytes = File.ReadAllBytes(fileInfo.FullName); FileContent fileContent = new FileContent(bytes); session.Persist(fileContent); file.Content = fileContent; } }
private void AddMenuItem_Click(object sender, RoutedEventArgs e) { FederationInfo info = new FederationInfo(); ConnectionDialog popup = new ConnectionDialog(info); bool? result = popup.ShowDialog(); if (result != null && result.Value) { SessionBase session = m_viewModel.ActiveSession; session.BeginUpdate(); session.Persist(info); session.Commit(); m_viewModel = new AllFederationsViewModel(); base.DataContext = m_viewModel; } }
void ParseActors(SessionBase session, ImdbRoot imdbRoot) { using (FileStream stream = File.OpenRead(System.IO.Path.Combine(imdbTextFilesDir, "actors.list.gz"))) { using (GZipStream decompress = new GZipStream(stream, CompressionMode.Decompress)) { using (System.IO.StreamReader file = new System.IO.StreamReader(decompress)) { string line; int lineNumber = 0; while ((line = file.ReadLine()) != null) { // skip all the intro stuff lineNumber++; if (line.Length > 5 && line[0] == '-' && line[5] == '\t') { break; } } while ((line = file.ReadLine()) != null) { lineNumber++; string actorName = new string(line.TakeWhile(aChar => aChar != '\t').ToArray <char>()); // end of name if (line.Length > 10 && line[0] == '-' && line[1] == '-' && line[2] == '-' && line[3] == '-') { break; // signals end of input } line = line.Substring(actorName.Length + 1); Actor actor = new Actor(actorName, session); session.Persist(actor); imdbRoot.ActorSet.Add(actor); parseMovie(session, line, imdbRoot, actor); while ((line = file.ReadLine()) != null) { if (line.Length == 0) { break; } lineNumber++; parseMovie(session, line, imdbRoot, actor); } } } } } }
public AllFederationsViewModel() { SessionBase.BaseDatabasePath = Properties.Settings.Default.BaseDatabasePath; m_session = new SessionNoServer(Properties.Settings.Default.DatabaseManagerDirectory); m_session.BeginUpdate(); List <FederationViewModel> federationInfos = new List <FederationViewModel>(); foreach (FederationInfo info in m_session.AllObjects <FederationInfo>()) { try { federationInfos.Add(new FederationViewModel(info)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (federationInfos.Count() == 0) { string host = Properties.Settings.Default.DatabaseManagerHost; if (host == null || host.Length == 0) { host = Dns.GetHostName(); } FederationInfo info = new FederationInfo(host, Properties.Settings.Default.DatabaseManagerDirectory, Properties.Settings.Default.TcpIpPortNumber, Properties.Settings.Default.DoWindowsAuthentication, null, Properties.Settings.Default.UseClientServer, "Database Manager"); m_session.Persist(info); m_session.Commit(); federationInfos.Add(new FederationViewModel(info)); } if (m_session.InTransaction) { m_session.Commit(); } m_federationViews = new ReadOnlyCollection <FederationViewModel>(federationInfos); }
public void AddArtistsPersisted(int count, SessionBase session) { var names = new HashSet <string>(count); for (int i = 0; i < count; i++) { var artist = new Artist { QueryHelper = QueryHelper, Notes = GenerateNotes() }; do { artist.Forename = GetRandomForename(); artist.Surname = GetRandomSurname(); } while (names.Contains(artist.Name)); names.Add(artist.Name); session.Persist(artist); Artists.Add(artist); } }
public AllFederationsViewModel() { SessionBase.BaseDatabasePath = Properties.Settings.Default.BaseDatabasePath; m_session = new SessionNoServer(Properties.Settings.Default.DatabaseManagerDirectory); m_session.BeginUpdate(); List<FederationViewModel> federationInfos = new List<FederationViewModel>(); foreach (FederationInfo info in m_session.AllObjects<FederationInfo>()) { try { federationInfos.Add(new FederationViewModel(info)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (federationInfos.Count() == 0) { string host = Properties.Settings.Default.DatabaseManagerHost; if (host == null || host.Length == 0) host = Dns.GetHostName(); FederationInfo info = new FederationInfo(host, Properties.Settings.Default.DatabaseManagerDirectory, Properties.Settings.Default.TcpIpPortNumber, Properties.Settings.Default.DoWindowsAuthentication, null, Properties.Settings.Default.UseClientServer, "Database Manager"); m_session.Persist(info); m_session.Commit(); federationInfos.Add(new FederationViewModel(info)); } if (m_session.InTransaction) m_session.Commit(); m_federationViews = new ReadOnlyCollection<FederationViewModel>(federationInfos); }
private void CopyFederationMenuItem_Click(object sender, RoutedEventArgs e) { MenuItem menuItem = (MenuItem)sender; FederationViewModel view = (FederationViewModel)menuItem.DataContext; FederationInfo info = view.Federationinfo; SessionBase session = view.Session; var lDialog = new System.Windows.Forms.FolderBrowserDialog() { Description = "Choose Federation Copy Folder", }; if (lDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string copyDir = lDialog.SelectedPath; session.CopyAllDatabasesTo(copyDir); session = info.Session; session.BeginUpdate(); FederationCopyInfo copyInfo = new FederationCopyInfo(Dns.GetHostName(), copyDir); session.Persist(copyInfo); info.Update(); info.FederationCopies.Add(copyInfo); session.Commit(); } }
public AllSupported(Int32 arraySize, SessionBase session) { _uint64EnumArray = new UInt64Enum[arraySize]; if (arraySize > 1) { _uint64EnumArray[1] = UInt64Enum.dd; } enum16list = new List <Int16Enum>(arraySize); aSnake = new PersistenceByInterfaceSnake("Curly", 1, true, 58); jaggedArray[0] = new int[] { 1, 3, 5, 7, 9 }; jaggedArray[1] = new int[] { 0, 2, 4, 6 }; jaggedArray[2] = new int[] { 11, 22 }; m_nullabledateTime = null; m_nullableByte = null; m_enumByte = ByteEnum.b; m_enumInt16 = Int16Enum.c; m_enumInt32 = Int32Enum.f; m_enumInt64 = Int64Enum.ff; m_enumUInt64 = UInt64Enum.ff; ListEnumUInt64 = new List <UInt64Enum>(); ListEnumUInt64.Add(m_enumUInt64); ListEnumUInt64Nullable = new List <UInt64Enum?>(); ListEnumUInt64Nullable.Add(null); ListEnumUInt64Nullable.Add(m_enumUInt64); m_objectArray = new object[arraySize]; m_objectInterfaceArray = new ISomeStuff[arraySize]; byteArray = new byte[arraySize]; charArray = new char[arraySize]; m_weakRefArray = new WeakIOptimizedPersistableReference <IOptimizedPersistable> [arraySize]; uint16Array = new UInt16[arraySize]; uint32Array = new UInt32[arraySize]; uint64Array = new UInt64[arraySize]; int16Array = new Int16[arraySize]; int32Array = new Int32[arraySize]; int64Array = new Int64[arraySize]; floatArray = new float[arraySize]; doubleArray = new double[arraySize]; dateTimeArray = new DateTime[arraySize]; oidArray = new Oid[arraySize]; nullablebyteArray = new byte?[arraySize]; nullablecharArray = new char?[arraySize]; nullableuint16Array = new UInt16?[arraySize]; nullableuint32Array = new UInt32?[arraySize]; nullableuint64Array = new UInt64?[arraySize]; nullableint16Array = new Int16?[arraySize]; nullableint32Array = new Int32?[arraySize]; nullableint64Array = new Int64?[arraySize]; nullablefloatArray = new float?[arraySize]; nullabledoubleArray = new double?[arraySize]; nullableDateTimeArray = new DateTime?[arraySize]; nullableDecimalArray = new Decimal?[arraySize]; nullableGuidArray = new Guid?[arraySize]; nullableOidArray = new Oid?[arraySize]; listByte = new List <byte>(arraySize); // just samples of what Key can be personList = new List <Person>(arraySize); m_petListOidShort = new List <Pet>(arraySize); petListLongOid = new List <Pet>(arraySize); petList2 = new ArrayList(arraySize); int32List = new List <Int32>(arraySize); uint32List = new List <UInt32>(arraySize); uint64List = new List <ulong>(arraySize); oidList = new List <Oid>(arraySize); nullableoidList = new List <Oid?>(arraySize); personHashSet = new VelocityDbHashSet <Person>(); person = new Person(); personHashSet.Add(person); //session.Persist(personHashSet); session.Persist(person); _weakRefToPerson = new WeakReferencedConnection <Person>(person); timeSpan = new TimeSpan(1, 0, 0); personArrayOidShort = new Person[arraySize]; if (arraySize > 1) { personArrayOidShort[1] = new Person(); } personArrayOidShort[0] = null; personListShort = new List <Person>(arraySize); personListShort.Add(null); personListShort.Add(null); personListShort.Add(new Person()); aPet = new Cat("Boze", 5); m_petListOidShort.Add(aPet); m_petListOidShort.Add(null); aPet = new Cat("Fendy", 4); // create a new cat so that first cat is created within same database as owner (OidShort) petListLongOid.Add(aPet); petList2.Add(aPet); uint32List.Add(5555); int32List.Add(-66666); uint64List.Add(8989898988989); doubleArray[0] = 0.2323232323232; aSlot = new Slot(); aSlot.value = new Person(); m_slots = new Slot[5]; enum16list.Add(m_enumInt16); nullableoidList.Add(new Oid((ulong)4444)); nullableoidList.Add(null); nullableoidList.Add(new Oid((ulong)8888)); if (arraySize > 0) { oidArray[0] = new Oid((ulong)99999); nullableOidArray[0] = new Oid((ulong)99999); nullableint32Array[0] = 5; } if (arraySize > 2) { m_objectArray[1] = this; m_objectInterfaceArray[2] = this; oidArray[2] = new Oid((ulong)66666); nullableOidArray[2] = new Oid((ulong)66666); nullableint32Array[2] = 6; } for (int i = 0; i < 5; i++) { m_slots[i].hashCode = i; m_slots[i].value = new Person(); m_slots[i].next = i + 1; } }
public void SandeepGraph(bool useServerSession) { bool 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 (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginUpdate(); session.DefaultDatabaseLocation().CompressPages = PageInfo.compressionKind.None; Graph g = new Graph(session); session.Persist(g); // SCHEMA VertexType userType = g.NewVertexType("User"); // Add a node type for the movies, with a unique identifier and two indexed Propertys VertexType movieType = g.NewVertexType("MOVIE"); PropertyType movieTitleType = g.NewVertexProperty(movieType, "TITLE", DataType.String, PropertyKind.Indexed); PropertyType movieYearType = g.NewVertexProperty(movieType, "YEAR", DataType.Integer, PropertyKind.Indexed); PropertyType objectPropertyType = g.NewVertexProperty(movieType, "object", DataType.Object, PropertyKind.NotIndexed); PropertyType objectPropertyTypeIndexed = g.NewVertexProperty(movieType, "object2", DataType.IOptimizedPersistable, PropertyKind.Indexed); Vertex mVickyCB = movieType.NewVertex(); mVickyCB.SetProperty(movieTitleType, "Vicky Cristina Barcelona"); mVickyCB.SetProperty(movieYearType, (int)(2008)); OptimizedPersistable pObj = new OptimizedPersistable(); session.Persist(pObj); mVickyCB.SetProperty(objectPropertyType, pObj); pObj = new OptimizedPersistable(); session.Persist(pObj); mVickyCB.SetProperty(objectPropertyTypeIndexed, pObj); Vertex mMatsCB = movieType.NewVertex(); mMatsCB.SetProperty(movieTitleType, "Mats Cristina Barcelona"); mMatsCB.SetProperty(movieYearType, (int)(2008)); pObj = new OptimizedPersistable(); session.Persist(pObj); mMatsCB.SetProperty(objectPropertyType, pObj); session.Commit(); session.BeginUpdate(); try { mMatsCB.SetProperty(objectPropertyTypeIndexed, null); throw new UnexpectedException(); } catch (NullObjectException) { } mMatsCB.Remove(); session.Commit(); //session.Persist(g); //session.Commit(); } using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginUpdate(); Graph g = Graph.Open(session); VertexType movieType = g.FindVertexType("MOVIE"); Assert.NotNull(movieType); } Task taskB = new Task(() => WatchUser()); taskB.Start(); Task taskA = new Task(() => CreateUser()); taskA.Start(); taskB.Wait(); taskA.Wait(); }
public void Save(SessionBase session) { session.Persist(this); }
public void Save(SessionBase session) { session.Persist(this); }
void createInitialObjects(IssueTracker issueTracker, User user, SessionBase session) { Project project = new Project(user, "VelocityDB", "Object Database Management System"); session.Persist(project); issueTracker.ProjectSet.Add(project); Component webSite = new Component(user, "Web Site", "VelocityDB.com", project); session.Persist(webSite); issueTracker.ComponentSet.Add(webSite); Component samples = new Component(user, "Samples", "Samples applications provided", project); session.Persist(samples); issueTracker.ComponentSet.Add(samples); Component collections = new Component(user, "Collections", "Any of the collection classes", project); session.Persist(collections); issueTracker.ComponentSet.Add(collections); Component performance = new Component(user, "Performance", "Any performance issue", project); session.Persist(performance); issueTracker.ComponentSet.Add(performance); ProductVersion version = new ProductVersion(user, "5.0.16", "First initial version", new DateTime(2015, 11, 29)); session.Persist(version); issueTracker.VersionSet.Add(version); version = new ProductVersion(user, "4.7", "June 13 version", new DateTime(2015, 06, 13)); session.Persist(version); issueTracker.VersionSet.Add(version); }
/// <summary> /// Persists this object. /// </summary> /// <param name="place">The placement rules to follow when persisting this object</param> /// <param name="session">The session managing this object</param> /// <param name="persistRefs">If true, objects referenced from this object will also be persisted</param> /// <param name="disableFlush">If true, disables possible flushing of updated pages while persisting this object; otherwise pasge flushing may occur</param> /// <returns>The object id of the persistent object</returns> public virtual UInt64 Persist(Placement place, SessionBase session, bool persistRefs = true, bool disableFlush = false, Queue<IOptimizedPersistable> toPersist = null) { return session.Persist(place, this, session.OpenSchema(false), place.MaxObjectsPerPage, disableFlush, toPersist); }
/// <summary> /// Persists this object. /// </summary> /// <param name="placeHint">Use placement as specified by this object type, see <see cref="OptimizedPersistable.PlacementDatabaseNumber"/>, <see cref="OptimizedPersistable.ObjectsPerPage()"/> and <see cref="OptimizedPersistable.PagesPerDatabase()"/></param> /// <param name="session">The session managing this object</param> /// <param name="persistRefs">Persist any referenced object now or delay until flush/commit</param> /// <param name="disableFlush">Controlls possible flushing of updated pages. Set to true if you want to prevent updated pages from being flushed to disk and setting such pages to a non updated state.</param> /// <returns>The object id of the persistent object</returns> public virtual UInt64 Persist(SessionBase session, IOptimizedPersistable placeHint, bool persistRefs = true, bool disableFlush = false) { Placement place = new Placement(session, placeHint, this, persistRefs, UInt32.MaxValue, placeHint.FlushIfPageFull); return session.Persist(place, this, session.OpenSchema(false), UInt16.MaxValue - 1, disableFlush); }
void ParseActors(SessionBase session, ImdbRoot imdbRoot) { using (FileStream stream = File.OpenRead(System.IO.Path.Combine(imdbTextFilesDir, "actors.list.gz"))) { using (GZipStream decompress = new GZipStream(stream, CompressionMode.Decompress)) { using (System.IO.StreamReader file = new System.IO.StreamReader(decompress)) { string line; int lineNumber = 0; while ((line = file.ReadLine()) != null) { // skip all the intro stuff lineNumber++; if (line.Length > 5 && line[0] == '-' && line[5] == '\t') break; } while ((line = file.ReadLine()) != null) { lineNumber++; string actorName = new string(line.TakeWhile(aChar => aChar != '\t').ToArray<char>()); // end of name if (line.Length > 10 && line[0] == '-' && line[1] == '-' && line[2] == '-' && line[3] == '-') break; // signals end of input line = line.Substring(actorName.Length + 1); Actor actor = new Actor(actorName, session); session.Persist(actor); imdbRoot.ActorSet.Add(actor); parseMovie(session, line, imdbRoot, actor); while ((line = file.ReadLine()) != null) { if (line.Length == 0) break; lineNumber++; parseMovie(session, line, imdbRoot, actor); } } } } } }
User lookupUser(IssueTracker issueTracker, SessionBase session) { string userEmail = this.User.Identity.Name; User user = new User(userEmail); string dataPath = HttpContext.Current.Server.MapPath("~/Database"); if (!issueTracker.UserSet.TryGetValue(user, ref user)) { CustomerContact existingCustomer = null; string firstName = null; string lastName = null; string userName = null; try { using (SessionNoServer session2 = new SessionNoServer(dataPath, 2000, true, true)) { session2.BeginRead(); Root velocityDbroot = session2.AllObjects<Root>(false).FirstOrDefault(); CustomerContact lookup = new CustomerContact(userEmail, null); velocityDbroot.customersByEmail.TryGetKey(lookup, ref existingCustomer); session2.Commit(); firstName = existingCustomer.FirstName; lastName = existingCustomer.LastName; userName = existingCustomer.UserName; } } catch (System.Exception ex) { this.errorLabel.Text = ex.ToString(); } user = new User(null, userEmail, firstName, lastName, userName); session.Persist(user); issueTracker.UserSet.Add(user); } return user; }
public InvertedIndex(SessionBase session, HashCodeComparer <TokenType <string> > hashCodeComparer) { m_stringLexicon = new Lexicon <string>(session, hashCodeComparer); session.Persist(m_stringLexicon); }
public Interaction(Customer customer, User user, SessionBase session) { session.Persist(this); customer.AddInteraction(this); user.AddInteraction(this); }