public void createDatabaseLocations(SessionBase session) { session.BeginUpdate(); Person person = new Person("Mats", "Persson", 54); session.Persist(person); session.Commit(); verifyDatabaseLocations(session); }
public void InitDatabase() { if (Directory.Exists(testDir)) Directory.Delete(testDir, true); Directory.CreateDirectory(testDir); File.Copy(licensePath, testDir + "4.odb"); _session = new SessionNoServer(testDir); _session.BeginUpdate(); }
public void moveDatabaseLocations(SessionBase session, string updatedHostName, string newPath) { session.BeginUpdate(false); DatabaseLocation bootLocation = session.DatabaseLocations.LocationForDb(0); DatabaseLocation locationNew = new DatabaseLocation(updatedHostName, newPath, bootLocation.StartDatabaseNumber, bootLocation.EndDatabaseNumber, session, bootLocation.CompressPages, bootLocation.PageEncryption, bootLocation.IsBackupLocation, bootLocation.BackupOfOrForLocation); bootLocation = session.NewLocation(locationNew); session.Commit(false); }
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(); } } }
/// <summary> /// Adds a user to a role. /// </summary> /// <param name="user">The user.</param> /// <param name="roleName">Name of the role.</param> /// <returns></returns> public Task AddToRoleAsync(T user, string roleName) { SessionBase session = Session; bool inUpdate = session.InUpdateTransaction; if (inUpdate == false) { if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); } user.Roles.Add(new IdentityRole(roleName)); if (inUpdate == false) { session.Commit(); } return(Task.FromResult(0)); }
/// <summary> /// Sets the user's email. /// </summary> /// <param name="user">The user's email.</param> /// <param name="email">The email to set to the user's identity.</param> /// <returns></returns> /// <exception cref="NullObjectException">If user is null.</exception> /// <exception cref="Exception">Any client error condition.</exception> public Task SetEmailAsync(T user, string email) { SessionBase session = Session; bool inUpdate = session.InUpdateTransaction; if (inUpdate == false) { if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); } user.Email = email; if (inUpdate == false) { session.Commit(); } return(Task.FromResult(0)); }
/// <summary> /// Creates a role as an asynchronous operation. /// </summary> /// <param name="role">The role.</param> /// <returns></returns> /// <exception cref="VelocityDBAspNetIdentityException"></exception> public async Task CreateAsync(T role) { SessionBase session = Session; bool inUpdate = session.InUpdateTransaction; if (inUpdate == false) { if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); } m_aspNetIdentity.RoleSet.Add(role); if (inUpdate == false) { session.Commit(); } await Task.FromResult(true); }
/// <summary> /// Sets the user's email confirmed flag. /// </summary> /// <param name="user">The user.</param> /// <param name="confirmed">if set to <c>true</c> the user's email has been confirmed.</param> /// <returns></returns> /// <exception cref="NullObjectException">if user is null.</exception> /// <exception cref="Exception">Any client error condition.</exception> public Task SetEmailConfirmedAsync(T user, bool confirmed) { SessionBase session = Session; bool inUpdate = session.InUpdateTransaction; if (inUpdate == false) { if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); } user.EmailConfirmed = confirmed; if (inUpdate == false) { session.Commit(); } return(Task.FromResult(0)); }
/// <summary> /// Increments the access failed count for 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 <int> IncrementAccessFailedCountAsync(T user) { SessionBase session = Session; bool inUpdate = session.InUpdateTransaction; if (inUpdate == false) { if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); } user.AccessFailedCount = user.AccessFailedCount + 1; if (inUpdate == false) { session.Commit(); } return(await Task.FromResult(user.AccessFailedCount)); }
/// <summary> /// Sets a flag indicating two factor authentication is enabled for a user. /// </summary> /// <param name="user">The user.</param> /// <param name="enabled">if set to <c>true</c> <see cref="IdentityUser.TwoFactorEnabled"/>enabled.</param> /// <returns></returns> /// <exception cref="NullObjectException">If user is null.</exception> /// <exception cref="Exception">Any client error condition.</exception> public Task SetTwoFactorEnabledAsync(T user, bool enabled) { SessionBase session = Session; bool inUpdate = session.InUpdateTransaction; if (inUpdate == false) { if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); } user.TwoFactorEnabled = enabled; if (inUpdate == false) { session.Commit(); } return(Task.FromResult(0)); }
/// <summary> /// Sets the phone number for a user. /// </summary> /// <param name="user">The user.</param> /// <param name="phoneNumber">The phone number.</param> /// <returns></returns> /// <exception cref="NullObjectException">If user is null.</exception> /// <exception cref="Exception">Any client error condition.</exception> public Task SetPhoneNumberAsync(T user, string phoneNumber) { SessionBase session = Session; bool inUpdate = session.InUpdateTransaction; if (inUpdate == false) { if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); } user.PhoneNumber = phoneNumber; if (inUpdate == false) { session.Commit(); } return(Task.FromResult(0)); }
/// <summary> /// Sets the lockout end date. /// </summary> /// <param name="user">The user.</param> /// <param name="lockoutEnd">The lockout end.</param> /// <returns></returns> /// <exception cref="NullObjectException">If user is null.</exception> /// <exception cref="Exception">Any client error condition.</exception> public Task SetLockoutEndDateAsync(T user, DateTimeOffset lockoutEnd) { SessionBase session = Session; bool inUpdate = session.InUpdateTransaction; if (inUpdate == false) { if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); } user.LockoutEndDateUtc = lockoutEnd.UtcDateTime; if (inUpdate == false) { session.Commit(); } return(Task.FromResult(0)); }
/// <summary> /// Sets the security stamp. /// </summary> /// <param name="user">The user.</param> /// <param name="stamp">The stamp.</param> /// <returns></returns> public Task SetSecurityStampAsync(T user, string stamp) { SessionBase session = Session; bool inUpdate = session.InUpdateTransaction; if (inUpdate == false) { if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); } user.SecurityStamp = stamp; if (inUpdate == false) { session.Commit(); } return(Task.FromResult(0)); }
/// <summary> /// Sets the password hash for a user. /// </summary> /// <param name="user">The user.</param> /// <param name="passwordHash">The password hash.</param> /// <returns></returns> /// <exception cref="KeyNotFoundException">All server responses other than Success.</exception> /// <exception cref="Exception">Any client error condition.</exception> public Task SetPasswordHashAsync(T user, string passwordHash) { SessionBase session = Session; bool inUpdate = session.InUpdateTransaction; if (inUpdate == false) { if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); } user.PasswordHash = passwordHash; if (inUpdate == false) { session.Commit(); } return(Task.FromResult(0)); }
/// <summary> /// Removes a claim from a user. /// </summary> /// <param name="user">The user.</param> /// <param name="claim">The claim.</param> /// <returns></returns> public Task RemoveClaimAsync(T user, Claim claim) { SessionBase session = Session; bool inUpdate = session.InUpdateTransaction; if (inUpdate == false) { if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); } user.Claims.Remove(claim); if (inUpdate == false) { session.Commit(); } return(Task.FromResult(0)); }
private void RestoreDatabaseLocationMenuItem_Click(object sender, RoutedEventArgs e) { MenuItem menuItem = (MenuItem)sender; DatabaseLocationViewModel view = (DatabaseLocationViewModel)menuItem.DataContext; DatabaseLocation dbLocation = view.DatabaseLocation; SessionBase session = dbLocation.GetSession(); if (session.InTransaction) { session.Commit(); } //DatabaseLocationMutable newLocationMutable = new DatabaseLocationMutable(session); //newLocationMutable.DirectoryPath = dbLocation.DirectoryPath; //newLocationMutable.HostName = dbLocation.HostName; //var popup = new RestoreDialog(newLocationMutable); //bool? result = popup.ShowDialog(); //if (result != null && result.Value) { dbLocation.SetPage(null); // fake it as a transient object before restore ! dbLocation.Id = 0; // be careful about doing this kind of make transient tricks, references from objects like this are still persistent. // if (session.OptimisticLocking) // && session.GetType() == typeof(ServerClientSession)) { // session.Dispose(); // session = new ServerClientSession(session.SystemDirectory, session.SystemHostName, 2000, false, false); // need to use pessimstic locking for restore // = new SessionNoServer(session.SystemDirectory); // need to use pessimstic locking for restore } session.BeginUpdate(); try { session.RestoreFrom(dbLocation, DateTime.Now); session.Commit(false, true); // special flags when commit of a restore ... m_viewModel = new AllFederationsViewModel(); base.DataContext = m_viewModel; } catch (Exception ex) { session.Abort(); MessageBox.Show(ex.Message); } } }
private void RemoveDatabaseLocationMenuItem_Click(object sender, RoutedEventArgs e) { MenuItem menuItem = (MenuItem)sender; DatabaseLocationViewModel view = (DatabaseLocationViewModel)menuItem.DataContext; DatabaseLocation dbLocation = view.DatabaseLocation; SessionBase session = dbLocation.Session; session.BeginUpdate(); try { session.DeleteLocation(dbLocation); session.Commit(); m_viewModel = new AllFederationsViewModel(); base.DataContext = m_viewModel; } catch (Exception ex) { session.Abort(); MessageBox.Show(ex.Message); } }
/// <summary> /// Updates a user. /// </summary> /// <param name="user">The user.</param> /// <returns></returns> /// <exception cref="KeyNotFoundException">Any client error condition.</exception> public async Task UpdateAsync(T user) { SessionBase session = Session; bool inUpdate = session.InUpdateTransaction; if (inUpdate == false) { if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); } m_aspNetIdentity.UserSet.Remove(user); await Task.FromResult(m_aspNetIdentity.UserSet.Add(user)); if (inUpdate == false) { session.Commit(); } }
//[TestCase(false)] public void CreateDataWithBackupServer(bool useServerSession) { int loops = 30000; UInt16 objectsPerPage = 300; UInt16 pagesPerDatabase = 65000; 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)) { Placement place = new Placement(11, 1, 1, objectsPerPage, pagesPerDatabase); 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); aMan.Persist(place, session); aWoman = new Woman(aMan, aWoman); aWoman.Persist(place, session); 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(); } }
private void EditDatabaseLocationMenuItem_Click(object sender, RoutedEventArgs e) { MenuItem menuItem = (MenuItem)sender; DatabaseLocationViewModel view = (DatabaseLocationViewModel)menuItem.DataContext; DatabaseLocation dbLocation = view.DatabaseLocation; SessionBase session = dbLocation.Session; DatabaseLocationMutable newLocationMutable = new DatabaseLocationMutable(session); newLocationMutable.BackupOfOrForLocation = dbLocation.BackupOfOrForLocation; newLocationMutable.CompressPages = dbLocation.CompressPages; newLocationMutable.PageEncryption = dbLocation.PageEncryption; newLocationMutable.StartDatabaseNumber = dbLocation.StartDatabaseNumber; newLocationMutable.EndDatabaseNumber = dbLocation.EndDatabaseNumber; newLocationMutable.IsBackupLocation = dbLocation.IsBackupLocation; newLocationMutable.DirectoryPath = dbLocation.DirectoryPath; newLocationMutable.HostName = dbLocation.HostName; var popup = new NewDatabaseLocationDialog(newLocationMutable, dbLocation); bool?result = popup.ShowDialog(); if (result != null && result.Value) { try { DatabaseLocation newLocation = new DatabaseLocation(newLocationMutable.HostName, newLocationMutable.DirectoryPath, newLocationMutable.StartDatabaseNumber, newLocationMutable.EndDatabaseNumber, session, newLocationMutable.CompressPages, newLocationMutable.PageEncryption, newLocationMutable.IsBackupLocation, newLocationMutable.IsBackupLocation ? newLocationMutable.BackupOfOrForLocation : dbLocation.BackupOfOrForLocation); session.BeginUpdate(); session.NewLocation(newLocation); session.Commit(); m_viewModel = new AllFederationsViewModel(); base.DataContext = m_viewModel; } catch (Exception ex) { session.Abort(); MessageBox.Show(ex.Message); } } }
public void BTreeMap2Iterate() { int sessionId = 0; SessionBase session = null; try { session = SessionManager.SessionPool.GetSession(out sessionId); session.BeginRead(); var bTreeMap = session.Open <BTreeMapOwner>(_id); int zipCodeCt = 0; foreach (var p in bTreeMap.LocationByZipCode) { session.Commit(); session.BeginUpdate(); var v = p.Value; foreach (var l in v) { l.Address1 = "2034 Cordoba PL"; } var k = p.Key; zipCodeCt++; session.Commit(); session.BeginRead(); } Assert.AreEqual(numberOfZipCodes, zipCodeCt); session.Commit(); } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } finally { SessionManager.SessionPool.FreeSession(sessionId, session); } }
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); }
/// <summary> /// Ensures that the database locations system database file knows that the all the /// database files are in the current database folder, in case this is a copy of a /// database created in another folder, which may have been on another computer. /// </summary> public static void Localise(string databaseFolderPath) { Debug.WriteLine("DatabaseLocationHelper.Localise"); Session = new SessionNoServer(databaseFolderPath); var defaultDatabaseLocation = Session.DefaultDatabaseLocation(); if (!IsDatabaseLocationLocal(defaultDatabaseLocation)) { Debug.WriteLine(" Localising default database location"); Session.RelocateDefaultDatabaseLocation(); } Session.BeginUpdate(); foreach (var database in Session.Databases) { if (!IsDatabaseLocationLocal(database.Location)) { Debug.WriteLine($" Localising database location {database.Location}"); Session.RelocateDatabaseLocationFor( database.DatabaseNumber, SessionBase.LocalHost, Session.SystemDirectory); } } 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; 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(); } }
void AddDatabaseLocation(SessionBase session, string directory) { DatabaseLocationMutable newLocationMutable = new DatabaseLocationMutable(session); newLocationMutable.DirectoryPath = directory; var popup = new NewDatabaseLocationDialog(newLocationMutable, null); bool? result = popup.ShowDialog(); if (result != null && result.Value) { try { DatabaseLocation newLocation = new DatabaseLocation(newLocationMutable.HostName, newLocationMutable.DirectoryPath, newLocationMutable.StartDatabaseNumber, newLocationMutable.EndDatabaseNumber, session, newLocationMutable.CompressPages, newLocationMutable.PageEncryption, newLocationMutable.BackupOfOrForLocation != null, newLocationMutable.BackupOfOrForLocation); if (session.InTransaction) session.Commit(); session.BeginUpdate(); session.NewLocation(newLocation); session.Commit(); m_viewModel = new AllFederationsViewModel(); base.DataContext = m_viewModel; } catch (Exception ex) { session.Abort(); MessageBox.Show(ex.Message); } } }
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 ActionResult Put([BindRequired, FromQuery] string path, [FromBody] TypePlusObj obj) { if (path == null) { return(BadRequest("path not set")); } try { var pool = GetSessionPool(path); int sessionId = -1; SessionBase session = null; try { session = pool.GetSession(out sessionId); if (session.InTransaction) { session.Abort(); } session.BeginUpdate(); var id = Oid.IdFromString(obj.Id); OptimizedPersistable pObj = null; if (id != 0) { pObj = session.Open <OptimizedPersistable>(id); } string objAsString = obj.Obj.ToString(); var pObj2 = JsonConvert.DeserializeObject(objAsString, obj.Type, _jsonSettings); if (pObj != null) { pObj.Update(); UpdateFields(pObj, pObj2); session.Commit(); return(Ok($"{obj.Id} updated")); } else if (pObj2 != null) { var pId = session.Persist(pObj2); session.Commit(); return(Ok(new Oid(pId).ToString())); } session.Abort(); return(BadRequest($"Failed to deserialize json to object of type: {obj.Type}")); } catch (Exception ex) { session.Abort(); return(BadRequest(ex.Message)); } finally { if (session != null) { pool.FreeSession(sessionId, session); } } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public void Recover1(SessionBase session) { Database db = null; session.BeginUpdate(); db = session.OpenDatabase(88, true, false); if (db != null) session.DeleteDatabase(db); db = session.OpenDatabase(89, true, false); if (db != null) session.DeleteDatabase(db); session.Commit(); session.BeginUpdate(); db = session.NewDatabase(88); session.FlushUpdates(); session.Abort(); session.BeginUpdate(); db = session.NewDatabase(88); SortedSetAny<float> floatSet; Oid floatSetOid; string dbPath = System.IO.Path.Combine(systemDir, "89.odb"); Placement place = new Placement(88); for (int i = 0; i < 10; i++) { floatSet = new SortedSetAny<float>(); floatSet.Persist(place, session); floatSetOid = floatSet.Oid; } db = session.NewDatabase(89); session.Commit(); File.Delete(dbPath); session.BeginUpdate(); db = session.NewDatabase(89); session.Commit(); FileInfo info = new FileInfo(dbPath); info.CopyTo(dbPath + "X"); session.BeginUpdate(); SortedSetAny<int> intSet; place = new Placement(89); for (int i = 0; i < 10; i++) { intSet = new SortedSetAny<int>(); intSet.Persist(place, session); } db = session.OpenDatabase(88); var list = db.AllObjects<SortedSetAny<float>>(); foreach (SortedSetAny<float> set in list) set.Unpersist(session); db = session.OpenDatabase(89); session.Commit(); intSet = null; db = null; // release refs so that cached data isn't stale File.Delete(dbPath); info = new FileInfo(dbPath + "X"); info.MoveTo(dbPath); session.BeginUpdate(); intSet = (SortedSetAny<int>)session.Open(89, 1, 1, false); Debug.Assert(intSet == null); object o = session.Open(88, 1, 1, false); floatSet = (SortedSetAny<float>)o; Debug.Assert(floatSet != null); session.Commit(); session.BeginUpdate(); db = session.OpenDatabase(88); session.DeleteDatabase(db); db = session.OpenDatabase(89); session.DeleteDatabase(db); session.Commit(); }
static public void SyncWith(this SessionBase sessionToUpdate, SessionBase sessionToRead, Func <SessionBase, UInt64, Change, bool> doUpdate) { UInt64 currentVersion; UInt64 pageToReadVersion; bool conflictFound = false; using (var reader = sessionToRead.BeginRead()) { Changes changes = (Changes)sessionToRead.Open(5, 1, 1, false); if (changes != null) { using (var updater = sessionToUpdate.BeginUpdate()) { var dbs = sessionToUpdate.OpenAllDatabases(); ReplicaSync matchingReplicaSync = null; foreach (ReplicaSync sync in sessionToUpdate.AllObjects <ReplicaSync>()) { if (sync.SyncFromHost == sessionToRead.SystemHostName && sync.SyncFromPath == sessionToRead.SystemDirectory) { matchingReplicaSync = sync; break; } } if (changes.ChangeList.Count > 0) { foreach (TransactionChanges transactionChanges in changes.ChangeList) { if (matchingReplicaSync == null || matchingReplicaSync.TransactionNumber < transactionChanges.TransactionNumber) { foreach (Change change in transactionChanges.ChangeList) { Database dbToUpdate = sessionToUpdate.OpenDatabase(change.DatabaseId, false, false); Database dbToRead = sessionToRead.OpenDatabase(change.DatabaseId, false, false); string dbName = dbToRead != null ? dbToRead.Name : null; if (change.Deleted) { if (dbToUpdate == null) // does not exist { continue; } if (change.PageId == 0) // Database delete { currentVersion = dbToUpdate.Page.PageInfo.VersionNumber; if (currentVersion < change.Version) { sessionToUpdate.DeleteDatabase(dbToUpdate); } else { conflictFound = true; if (doUpdate(sessionToUpdate, currentVersion, change)) { sessionToUpdate.DeleteDatabase(dbToUpdate); } } } else { Page page = sessionToUpdate.OpenPage(dbToUpdate, change.PageId); if (page == null) // page does not exist { continue; } currentVersion = page.PageInfo.VersionNumber; if (currentVersion < change.Version) { sessionToUpdate.DeletePage(dbToUpdate, page); } else { conflictFound = true; if (doUpdate(sessionToUpdate, currentVersion, change)) { sessionToUpdate.DeleteDatabase(dbToUpdate); } } } } else { if (dbToUpdate == null) // does not exist { dbToUpdate = sessionToUpdate.NewDatabase(change.DatabaseId, 0, dbName); } if (change.PageId > 0) { Page pageToUpdate = sessionToUpdate.OpenPage(dbToUpdate, change.PageId); Page pageToRead = sessionToRead.OpenPage(dbToRead, change.PageId); if (pageToRead == null) // upcoming (not yet processed) changes must have deleted this page { continue; } currentVersion = pageToUpdate == null ? 0 : pageToUpdate.PageInfo.VersionNumber; pageToReadVersion = pageToRead.PageInfo.VersionNumber; if (currentVersion < pageToReadVersion || dbToUpdate.IsNew) { sessionToUpdate.ReplacePage(dbToUpdate, pageToUpdate, pageToRead); } else { conflictFound = true; if (doUpdate(sessionToUpdate, currentVersion, change)) { sessionToUpdate.ReplacePage(dbToUpdate, pageToUpdate, pageToRead); } } } } } } } UInt64 lastTransactionNumber = changes.ChangeList.Last().TransactionNumber; if (matchingReplicaSync != null) { matchingReplicaSync.TransactionNumber = lastTransactionNumber; } if (conflictFound) { sessionToUpdate.Verify(); } sessionToUpdate.Commit(); if (matchingReplicaSync == null) { sessionToUpdate.BeginUpdate(); // separate transaction or else gets confused with databases added by sync matchingReplicaSync = new ReplicaSync(sessionToRead, lastTransactionNumber); sessionToUpdate.Persist(matchingReplicaSync); sessionToUpdate.Commit(); } } } } } }
public void Recover1(SessionBase session) { Database db = null; session.BeginUpdate(); session.RegisterClass(typeof(SortedSetAny <int>)); session.RegisterClass(typeof(SortedSetAny <float>)); db = session.OpenDatabase(88, true, false); if (db != null) { session.DeleteDatabase(db); } db = session.OpenDatabase(89, true, false); if (db != null) { session.DeleteDatabase(db); } session.Commit(); session.BeginUpdate(); db = session.NewDatabase(88); session.FlushUpdates(); session.Abort(); session.BeginUpdate(); db = session.NewDatabase(88); SortedSetAny <float> floatSet; Oid floatSetOid; string dbPath = System.IO.Path.Combine(systemDir, "89.odb"); Placement place = new Placement(88); for (int i = 0; i < 10; i++) { floatSet = new SortedSetAny <float>(); floatSet.Persist(place, session); floatSetOid = floatSet.Oid; } db = session.NewDatabase(89); session.Commit(); File.Delete(dbPath); session.BeginUpdate(); db = session.NewDatabase(89); session.Commit(); FileInfo info = new FileInfo(dbPath); info.CopyTo(dbPath + "X"); session.BeginUpdate(); SortedSetAny <int> intSet; place = new Placement(89); for (int i = 0; i < 10; i++) { intSet = new SortedSetAny <int>(); intSet.Persist(place, session); } db = session.OpenDatabase(88); var list = db.AllObjects <SortedSetAny <float> >(); foreach (SortedSetAny <float> set in list) { set.Unpersist(session); } db = session.OpenDatabase(89); session.Commit(); intSet = null; db = null; // release refs so that cached data isn't stale File.Delete(dbPath); info = new FileInfo(dbPath + "X"); info.MoveTo(dbPath); session.BeginUpdate(); intSet = (SortedSetAny <int>)session.Open(89, 1, 1, false); Debug.Assert(intSet == null); object o = session.Open(88, 1, 1, false); floatSet = (SortedSetAny <float>)o; Debug.Assert(floatSet != null); session.Checkpoint(); db = session.OpenDatabase(88); session.DeleteDatabase(db); db = session.OpenDatabase(89); session.DeleteDatabase(db); session.Commit(); }
void Initialize() { SessionBase.BaseDatabasePath = Properties.Settings.Default.BaseDatabasePath; m_session = new SessionNoServer(Properties.Settings.Default.DatabaseManagerDirectory); try { m_session.BeginUpdate(); List <FederationSchemaViewModel> federationInfos = new List <FederationSchemaViewModel>(); List <FederationInfo> federationInfosToRemove = new List <FederationInfo>(); foreach (FederationInfo info in m_session.AllObjects <FederationInfo>()) { try { federationInfos.Add(new FederationSchemaViewModel(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 FederationSchemaViewModel(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(); } } }
public void sessionPoolTest() { const int numberOfSessions = 5; using (SessionPool pool = new SessionPool(numberOfSessions, () => new SessionNoServer(systemDir))) { { int sessionId = -1; SessionBase session = null; try { session = pool.GetSession(out sessionId); using (SessionBase.Transaction transaction = session.BeginUpdate()) { for (int i = 0; i < 1000; i++) { Man man = new Man(); session.Persist(man); } session.Commit(); } } catch (Exception e) { Console.WriteLine(e.Message); throw e; } finally { pool.FreeSession(sessionId, session); } } Parallel.ForEach(Enumerable.Range(0, numberOfSessions * 5), x => { int sessionId = -1; SessionBase session = null; try { session = pool.GetSession(out sessionId); if (session.InTransaction == false) { session.BeginRead(); } var allMen = session.AllObjects <Man>(); ulong allMenCt = allMen.Count(); foreach (Man man in allMen) { double lat = man.Latitude; } Console.WriteLine("Man Count is: " + allMenCt + " Session Id is: " + sessionId + " Current task id is: " + (Task.CurrentId.HasValue ? Task.CurrentId.Value.ToString() : "unknown")); } catch (Exception e) { session?.Abort(); Console.WriteLine(e.Message); throw e; } finally { pool.FreeSession(sessionId, session); } }); } }
public void IndexSample(bool useServerSession) { string brandName = "Toyota"; string color = "Blue"; int maxPassengers = 5; int fuelCapacity = 40; double litresPer100Kilometers = 5; DateTime modelYear = new DateTime(2003, 1, 1); string modelName = "Highlander"; int maxSpeed = 200; int odometer = 100000; string registrationState = "Texas"; string registrationPlate = "TX343434"; string insurancePolicy = "CAA7878787"; DriversLicense license = new DriversLicense("California", "B7788888", DateTime.Now + new TimeSpan(1825, 0, 0, 0)); Person person = new Person("Mats Persson", license); InsuranceCompany insuranceCompany = new InsuranceCompany("Allstate", "858727878"); Car car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed, odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy); using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginUpdate(); foreach (Database db in session.OpenAllDatabases(true)) { if (db.DatabaseNumber >= 10 || db.DatabaseNumber == SessionBase.IndexDescriptorDatabaseNumber) { session.DeleteDatabase(db); } } session.Commit(); session.BeginUpdate(); DatabaseLocation defaultLocation = session.DatabaseLocations.Default(); List <Database> dbList = session.OpenLocationDatabases(defaultLocation, true); foreach (Database db in dbList) { if (db.DatabaseNumber > Database.InitialReservedDatabaseNumbers) { session.DeleteDatabase(db); } } session.DeleteLocation(defaultLocation); session.Commit(); CreateDirectoryAndCopyLicenseDb(); } using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginUpdate(); session.Commit(); } using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginRead(); int ct = 0; var mIndex = session.Index <Motorcycle>(); if (mIndex != null) { foreach (Motorcycle mc in session.Index <Motorcycle>()) { Assert.NotNull(mc); ++ct; } } Assert.AreEqual(ct, 0); session.Commit(); } using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginUpdate(); for (int i = 0; i < 10000; i++) { Motorcycle mc = new Motorcycle(); session.Persist(mc); } session.Commit(); session.BeginUpdate(); int ct = 0; var mIndex = session.Index <Car>(); if (mIndex != null) { foreach (Car c in mIndex) { Assert.NotNull(c); ++ct; } } Assert.AreEqual(ct, 0); ct = 0; session.RegisterClass(typeof(Person)); foreach (Person p in session.AllObjects <Person>(true, false)) { Assert.NotNull(p); ++ct; } session.Commit(); session.BeginRead(); ct = 0; foreach (Motorcycle mc in session.AllObjects <Motorcycle>(false, true)) { Assert.NotNull(mc); ++ct; } Assert.AreEqual(ct, 10000); session.Commit(); session.BeginRead(); ct = 0; foreach (Motorcycle mc in session.AllObjects <Motorcycle>(false, true)) { Assert.NotNull(mc); ++ct; } Assert.AreEqual(ct, 10000); session.Abort(); session.BeginRead(); ct = 0; foreach (Motorcycle mc in session.AllObjects <Motorcycle>(false, true)) { Assert.NotNull(mc); ++ct; } Assert.AreEqual(ct, 10000); session.Commit(); session.BeginRead(); ct = 0; foreach (Motorcycle mc in session.Index <Motorcycle>()) { Assert.NotNull(mc); ++ct; } Assert.AreEqual(ct, 10000); session.Abort(); session.BeginRead(); ct = 0; foreach (Motorcycle mc in session.Index <Motorcycle>()) { Assert.NotNull(mc); ++ct; } Assert.AreEqual(ct, 10000); session.Commit(); try { ct = 0; foreach (Motorcycle mc in session.Index <Motorcycle>()) { Assert.NotNull(mc); ++ct; } Assert.AreEqual(ct, 10000); } catch (NotInTransactionException ex) { Console.WriteLine(ex.Message); } session.BeginUpdate(); ct = 0; foreach (Motorcycle mc in session.AllObjects <Motorcycle>(false, true)) { if (++ct % 2 == 0) { mc.Unpersist(session); } } ct = 0; foreach (Motorcycle mc in session.Index <Motorcycle>()) { ++ct; } Assert.AreEqual(ct, 5000); session.Abort(); session.BeginUpdate(); ct = 0; foreach (Motorcycle mc in session.AllObjects <Motorcycle>(false, true)) { if (++ct % 2 == 0) { mc.Unpersist(session); } } ct = 0; foreach (Motorcycle mc in session.Index <Motorcycle>()) { Assert.NotNull(mc); ++ct; } Assert.AreEqual(ct, 5000); ct = 0; foreach (Motorcycle mc in session.Index <Motorcycle>("cc")) { Assert.NotNull(mc); ++ct; } Assert.AreEqual(ct, 5000); ct = 0; try { foreach (Motorcycle mc in session.Index <Motorcycle>("ccx")) { Assert.NotNull(mc); ++ct; } Assert.AreEqual(ct, 5000); } catch (FieldDoesNotExistException) { } session.Commit(); session.BeginUpdate(); ct = 0; double prior = -44.0; foreach (Motorcycle mc in session.Index <Motorcycle>("cc")) { Assert.NotNull(mc); mc.CC = mc.CC - prior; prior = mc.CC; ++ct; } Assert.AreEqual(ct, 2500); for (int i = 0; i < 95000; i++) { Motorcycle mc = new Motorcycle(); session.Persist(mc); } session.FlushUpdates(); ct = 0; foreach (Motorcycle mc in session.Index <Motorcycle>()) { Assert.NotNull(mc); ++ct; } Assert.AreEqual(ct, 100000); session.Abort(); session.BeginUpdate(); ct = 0; prior = double.MinValue; foreach (Motorcycle mc in session.Index <Motorcycle>("cc")) { Assert.NotNull(mc); Assert.GreaterOrEqual(mc.CC, prior); prior = mc.CC; ++ct; if (ct < 25) { Console.Write(prior.ToString() + " "); } } ct = 0; prior = -44.0; foreach (Motorcycle mc in session.Index <Motorcycle>("cc")) { Assert.NotNull(mc); mc.CC = mc.CC - prior; prior = mc.CC; ++ct; } Assert.AreEqual(ct, 2500); session.Commit(); session.BeginUpdate(); ct = 0; prior = double.MinValue; foreach (Motorcycle mc in session.Index <Motorcycle>("cc")) { Assert.NotNull(mc); Assert.GreaterOrEqual(mc.CC, prior); prior = mc.CC; ++ct; } for (int i = 0; i < 95000; i++) { Motorcycle mc = new Motorcycle(); session.Persist(mc); DataBaseFileEntry dbEntry = new DataBaseFileEntry { Something = "Something" }; session.Persist(dbEntry); mc.AddChild(dbEntry); mc.AddChild(dbEntry); } session.FlushUpdates(); ct = 0; foreach (Motorcycle mc in session.Index <Motorcycle>()) { Assert.NotNull(mc); ++ct; } Assert.AreEqual(ct, 100000); session.Commit(); session.BeginRead(); session.Abort(); session.BeginUpdate(); foreach (Motorcycle mc in session.Index <Motorcycle>()) { Assert.NotNull(mc); VelocityDbList <DataBaseFileEntry> children = mc.Children; if (children != null && children.Count > 0) { mc.RemoveChild(children[0]); } ++ct; } session.Commit(); session.BeginRead(); ct = 0; prior = double.MinValue; foreach (Motorcycle mc in session.Index <Motorcycle>("cc")) { Assert.NotNull(mc); Assert.GreaterOrEqual(mc.CC, prior); prior = mc.CC; ++ct; } Assert.AreEqual(ct, 100000); session.Commit(); Console.WriteLine("Motorcycle index Test OK"); } using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginUpdate(); session.Persist(car); registrationState = "Maine"; car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed, odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy); session.Persist(car); color = "Red"; maxPassengers = 5; fuelCapacity = 50; litresPer100Kilometers = 8; modelYear = new DateTime(2006, 1, 1); brandName = "Toyota"; modelName = "Tacoma"; maxSpeed = 210; odometer = 50000; registrationState = "Texas"; registrationPlate = "TX343433"; insurancePolicy = "CAA7878777"; car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed, odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy); session.Persist(car); color = "Black"; maxPassengers = 5; fuelCapacity = 60; litresPer100Kilometers = 3; modelYear = new DateTime(2001, 1, 1); brandName = "Lincoln"; modelName = "Town Car"; maxSpeed = 220; odometer = 250000; registrationState = "Texas"; registrationPlate = "TX543433"; insurancePolicy = "CAA7878775"; for (int i = 0; i < 1; i++) { registrationState = RandomString(2); registrationPlate = RandomString(12); car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed, odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy); session.Persist(car); color = null; maxPassengers = i; fuelCapacity = 60; litresPer100Kilometers = 3; modelYear = new DateTime(2001, 1, 1); brandName = "Null Car"; modelName = null; maxSpeed = 220; odometer = 250000; insurancePolicy = null; } session.Commit(); } using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginRead(); Console.WriteLine("Blue Cars"); BTreeSet <Car> bTree = session.Index <Car>("color"); foreach (Car c in (from aCar in bTree where aCar.Color == "Blue" select aCar)) { Console.WriteLine(c.ToStringDetails(session)); } Console.WriteLine("Cars in fuel efficierncy order"); foreach (Car c in session.Index <Car>("litresPer100Kilometers")) { Console.WriteLine(c.ToStringDetails(session)); } Console.WriteLine("Vehicles ordered modelYear, brandName, modelName, color"); foreach (Vehicle v in session.Index <Vehicle>()) { Console.WriteLine(v.ToStringDetails(session)); } session.Commit(); } using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginUpdate(); // these LINQ statements will trigger a binary search lookup (not a linear serach) of the matching Car objects in the BTreeSet Car c = (from aCar in session.Index <Car>("color") where aCar.Color == "Blue" select aCar).First(); c.Color = "Green"; session.Commit(); } using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginUpdate(); // these LINQ statements will trigger a binary search lookup (not a linear serach) of the matching Car objects in the BTreeSet Car c = (from aCar in session.Index <Car>("color") where aCar.Color == "Green" select aCar).First(); UInt64 id = c.Id; session.DeleteObject(id); session.Abort(); session.BeginUpdate(); session.DeleteObject(id); session.Commit(); } using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { Stopwatch sw = new Stopwatch(); sw.Start(); session.BeginRead(); // these LINQ statements will trigger a binary search lookup (not a linear serach) of the matching Car objects in the BTreeSet Console.WriteLine("Blue Cars"); foreach (Car c in (from aCar in session.Index <Car>("color") where aCar.Color == "Blue" select aCar)) { Console.WriteLine(c.ToStringDetails(session)); } session.Commit(); sw.Stop(); Console.WriteLine(sw.Elapsed); } using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginUpdate(); for (int i = 0; i < 10000; i++) { // add some junk to make search harder car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, i, odometer, registrationState, registrationPlate + i, insuranceCompany, insurancePolicy); session.Persist(car); } session.Commit(); } using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginRead(); // these LINQ statements will trigger a binary search lookup (not a linear serach) of the matching Car objects in the BTreeSet Console.WriteLine("Blue Cars"); foreach (Car c in (from aCar in session.Index <Car>("color") where aCar.Color == "Blue" select aCar)) { Console.WriteLine(c.ToStringDetails(session)); } session.Commit(); } using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginUpdate(); Car c = (from aCar in session.Index <Car>("color") where aCar.Color == "Blue" select aCar).First(); c.Unpersist(session); session.Commit(); } using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginRead(); foreach (Car c in session.Index <Car>()) { Console.WriteLine(c.ToStringDetails(session)); } Console.WriteLine("Blue Cars"); foreach (Car c in (from aCar in session.Index <Car>() where aCar.Color == "Blue" select aCar)) { Console.WriteLine(c.ToStringDetails(session)); } session.Commit(); } using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginUpdate(); InsuranceCompany prior = insuranceCompany; try { for (int i = 0; i < 100000; i++) { insuranceCompany = new InsuranceCompany("AAA", "858787878"); insuranceCompany.Persist(session, prior); prior = insuranceCompany; } Assert.IsTrue(false); // should not get here } catch (UniqueConstraintException) { } session.Commit(); } using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginRead(); Database db = session.OpenDatabase(session.DatabaseNumberOf(typeof(InsuranceCompany))); var q = from company in session.Index <InsuranceCompany>("name", db) where company.Name == "AAA" select company; foreach (InsuranceCompany company in q) { Console.WriteLine(company.ToStringDetails(session)); // only one will match } session.Commit(); } using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginUpdate(); InsuranceCompany prior = insuranceCompany; try { for (int i = 0; i < 100000; i++) { insuranceCompany = new InsuranceCompany("AAA", "858787878"); session.Persist(insuranceCompany); } Assert.IsTrue(false); // should not get here } catch (UniqueConstraintException) { } session.Commit(); } using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginRead(); Database db = session.OpenDatabase(session.DatabaseNumberOf(typeof(InsuranceCompany))); var q = from company in session.Index <InsuranceCompany>("name", db) where company.Name == "AAA" select company; foreach (InsuranceCompany company in q) { Console.WriteLine(company.ToStringDetails(session)); // only one will match } bool exists = (from anEntry in session.Index <InsuranceCompany>("name", db) where anEntry.Name == "AAA" select 0).Any(); Assert.IsTrue(exists); session.Commit(); } using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginUpdate(); try { for (int i = 0; i < 100000; i++) { insuranceCompany = new InsuranceCompanySpecial("AAA", "858787878"); session.Persist(insuranceCompany); } Assert.IsTrue(false); // should not get here } catch (UniqueConstraintException) { } session.Commit(); } using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginUpdate(); try { for (int i = 0; i < 100000; i++) { insuranceCompany = new InsuranceCompanySpecial2("AAA", "858787878"); session.Persist(insuranceCompany); } Assert.IsTrue(false); // should not get here } catch (UniqueConstraintException) { } session.Commit(); } using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginRead(); Database db = session.OpenDatabase(session.DatabaseNumberOf(typeof(InsuranceCompanySpecial))); var q = from company in session.Index <InsuranceCompany>("name", db) where company.Name == "AAA" select company; foreach (InsuranceCompany company in q) { Console.WriteLine(company.ToStringDetails(session)); // only one will match } bool exists = (from anEntry in session.Index <InsuranceCompanySpecial>("name", db) where anEntry.Name == "AAA" select 0).Any(); Assert.IsTrue(exists); session.Commit(); } }