/// <summary> /// Test with NO conversation and "connection.release_mode" /// "auto"(<see cref="ConnectionReleaseMode.AfterTransaction"/>). /// </summary> private void connection_release_mode_auto_no_conversation() { //with NO conversation and "connection.release_mode" "auto"(AfterTransaction) //forcing "auto" by reflection. Settings settings = ((SessionFactoryImpl)this.SessionFactory).Settings; ConnectionReleaseMode connReleaseModeOriginal = settings.ConnectionReleaseMode; this.setConnectionReleaseModeByReflection(settings, ConnectionReleaseMode.AfterTransaction); //with no conversation SessionScopeSettings sessionScopeSettings = new SessionScopeSettings(this.sessionFactory); ConnectionCreationTrackingDbProvider.Count = 0; using (new SessionScope(sessionScopeSettings, true)) { ISession sessionNoConv = this.SessionFactory.GetCurrentSession(); SPCMasterEnt masterEnt2 = sessionNoConv.Get <SPCMasterEnt>(2); Assert.AreEqual(1, ConnectionCreationTrackingDbProvider.Count, "ConnectionCreationTrackingDbProvider.Count"); Assert.AreEqual(1, masterEnt2.SPCDetailEntList.Count, "masterEnt2.SPCDetailEntList.Count"); Assert.AreEqual(2, ConnectionCreationTrackingDbProvider.Count, "ConnectionCreationTrackingDbProvider.Count"); SPCMasterEnt masterEnt3 = sessionNoConv.Get <SPCMasterEnt>(3); Assert.AreEqual(3, ConnectionCreationTrackingDbProvider.Count, "ConnectionCreationTrackingDbProvider.Count"); Assert.AreEqual(1, masterEnt3.SPCDetailEntList.Count, "masterEnt3.SPCDetailEntList.Count"); Assert.AreEqual(4, ConnectionCreationTrackingDbProvider.Count, "ConnectionCreationTrackingDbProvider.Count"); } this.setConnectionReleaseModeByReflection(settings, connReleaseModeOriginal); }
protected void Page_Load(object sender, EventArgs e) { this.Session["result"] = "NOT OK"; try { if ("endA_FreeEnded".Equals(this.Request["command"])) { this.Conversation.StartResumeConversation(); /* * Producing the error "HibernateException: Session is closed..." This is because in * "SessionPerConversationScope.LazySessionPerConversationHolder.CloseConversation(IConversationState)" * we are closing the "SessionPerConversationScope.LazySessionPerConversationHolder.activeConversation" * instead of parameter "conversation" (BUG). */ this.ConversationA.EndConversation(); this.ConversationA.ConversationManager.FreeEnded(); this.Conversation.ConversationManager.PauseConversations(); } this.Conversation.StartResumeConversation(); //database access ISession session = this.Conversation.SessionFactory.GetCurrentSession(); SPCMasterEnt sPCMasterEnt = session.Get <SPCMasterEnt>(1); this.Session["result"] = "OK"; } catch (Exception ex) { this.Session["result"] = ex.Message; } }
private void LoopSPCMasterEnt(SPCMasterEnt sPCMasterEnt, String desc) { foreach (SPCDetailEnt sPCDetailEntItem in sPCMasterEnt.SPCDetailEntList) { LOG.Debug(String.Format("Page_Load({1}): sPCDetailEntItem.Description={0}", sPCDetailEntItem.Description, desc)); } }
protected void Page_Load(object sender, EventArgs e) { this.Session["result"] = "NOT OK"; this.Conversation.StartResumeConversation(); //database access ISession session = this.Conversation.SessionFactory.GetCurrentSession(); SPCMasterEnt sPCMasterEnt = session.Get <SPCMasterEnt>(1); this.Session["result"] = "OK"; }
/// <summary> /// Test with conversation and "connection.release_mode" /// "auto"(<see cref="ConnectionReleaseMode.AfterTransaction"/>). /// </summary> /// <remarks> /// Here we can see that every statement causes a closing of the IDbConnection. /// </remarks> private void connection_release_mode_auto() { //with conversation and "connection.release_mode" "auto"(AfterTransaction) //forcing "auto" by reflection. Settings settings = ((SessionFactoryImpl)this.SessionFactory).Settings; ConnectionReleaseMode connReleaseModeOriginal = settings.ConnectionReleaseMode; this.setConnectionReleaseModeByReflection(settings, ConnectionReleaseMode.AfterTransaction); //((SessionFactoryImpl)this.sessionFactory).Settings.ConnectionReleaseMode = ConnectionReleaseMode.AfterTransaction; ConnectionCreationTrackingDbProvider.Count = 0; this.Conversation.StartResumeConversation(); ISession sessionA = this.SessionFactory.GetCurrentSession(); SPCDetailEnt detailEnt = sessionA.Get <SPCDetailEnt>(1); Assert.AreEqual(1, ConnectionCreationTrackingDbProvider.Count, "ConnectionCreationTrackingDbProvider.Count"); SessionScopeSettings sessionScopeSettings = new SessionScopeSettings(this.sessionFactory); sessionScopeSettings.SingleSession = true; SPCMasterEnt masterEnt; using (new SessionScope(sessionScopeSettings, false)) { ISession sessionB = this.SessionFactory.GetCurrentSession(); masterEnt = sessionB.Get <SPCMasterEnt>(1); Assert.AreEqual(2, ConnectionCreationTrackingDbProvider.Count, "ConnectionCreationTrackingDbProvider.Count"); Assert.AreSame(sessionA, sessionB, "sessionA, sessionB"); } SPCMasterEnt masterEnt2 = sessionA.Get <SPCMasterEnt>(2); Assert.AreEqual(3, ConnectionCreationTrackingDbProvider.Count, "ConnectionCreationTrackingDbProvider.Count"); Assert.AreEqual(1, masterEnt2.SPCDetailEntList.Count, "masterEnt2.SPCDetailEntList.Count"); Assert.AreEqual(4, ConnectionCreationTrackingDbProvider.Count, "ConnectionCreationTrackingDbProvider.Count"); SPCMasterEnt masterEnt3 = sessionA.Get <SPCMasterEnt>(3); Assert.AreEqual(5, ConnectionCreationTrackingDbProvider.Count, "ConnectionCreationTrackingDbProvider.Count"); Assert.AreEqual(1, masterEnt3.SPCDetailEntList.Count, "masterEnt3.SPCDetailEntList.Count"); Assert.AreEqual(6, ConnectionCreationTrackingDbProvider.Count, "ConnectionCreationTrackingDbProvider.Count"); //Renew the conversation. this.Conversation.EndConversation(); this.Conversation.ConversationManager.FreeEnded(); this.Conversation = (IConversationState)this.applicationContext.GetObject("convConnectionReleaseModeIssue"); this.setConnectionReleaseModeByReflection(settings, connReleaseModeOriginal); }
public void Test() { ISession sessionNoConv = this.SessionFactory.GetCurrentSession(); SPCMasterEnt masterEnt2 = sessionNoConv.Get <SPCMasterEnt>(2); Assert.AreEqual(1, masterEnt2.SPCDetailEntList.Count, "masterEnt2.SPCDetailEntList.Count"); SPCMasterEnt masterEnt3 = sessionNoConv.Get <SPCMasterEnt>(3); Assert.AreEqual(1, masterEnt3.SPCDetailEntList.Count, "masterEnt3.SPCDetailEntList.Count"); Assert.AreEqual(1, ConnectionCreationTrackingDbProvider.Count, "ConnectionCreationTrackingDbProvider.Count"); }
protected void Page_Load(object sender, EventArgs e) { if (this.Request["endConversation"] != null && bool.Parse(this.Request["endConversation"])) { this.Conversation.EndConversation(); } else { this.Conversation.StartResumeConversation(); ISession session = this.SessionFactory.GetCurrentSession(); SPCMasterEnt sPCMasterEnt = session.Get <SPCMasterEnt>(1); this.Session["sPCMasterEnt"] = sPCMasterEnt; } }
protected void Page_Load(object sender, EventArgs e) { try { this.Conversation.StartResumeConversation(); SPCMasterEnt sPCMasterEnt = (SPCMasterEnt)this.Session["sPCMasterEnt"]; foreach (SPCDetailEnt sPCDetailEntItem in sPCMasterEnt.SPCDetailEntList) { LOG.Debug(String.Format("Page_Load: sPCDetailEntItem.Description={0}", sPCDetailEntItem.Description)); } this.Session["messageTest"] = "no lazy error"; } catch (LazyInitializationException lex) { this.Session["messageTest"] = lex.GetType().FullName + ": " + lex.Message + "\n" + lex.StackTrace; } catch (Exception ex) { this.Session["messageTest"] = ex.GetType().FullName + ": " + ex.Message + "\n" + ex.StackTrace; } }
protected void Page_Load(object sender, EventArgs e) { this.ConversationA.StartResumeConversation(); SPCMasterEnt sPCMasterEntA = this.SessionFactory.GetCurrentSession().Get <SPCMasterEnt>(1); this.ConversationB.StartResumeConversation(); SPCMasterEnt sPCMasterEntB = this.SessionFactory.GetCurrentSession().Get <SPCMasterEnt>(1); //testeRaizeLazy_A try { this.LoopSPCMasterEnt(sPCMasterEntA, "sPCMasterEntA"); } catch (LazyInitializationException) { this.Session["testeRaizeLazy_A"] = "OK"; } catch (Exception ex) { this.Session["testeRaizeLazy_A"] = ex.ToString(); } //testeRaizeLazy_B this.ConversationA.StartResumeConversation(); try { this.LoopSPCMasterEnt(sPCMasterEntB, "sPCMasterEntB"); } catch (LazyInitializationException) { this.Session["testeRaizeLazy_B"] = "OK"; } catch (Exception ex) { this.Session["testeRaizeLazy_B"] = ex.ToString(); } //testeNoRaizeLazy_A this.ConversationA.StartResumeConversation(); try { this.LoopSPCMasterEnt(sPCMasterEntA, "sPCMasterEntA"); this.Session["testeNoRaizeLazy_A"] = "OK"; } catch (Exception ex) { this.Session["testeNoRaizeLazy_A"] = ex.ToString(); } //testeNoRaizeLazy_B this.ConversationB.StartResumeConversation(); try { this.LoopSPCMasterEnt(sPCMasterEntB, "sPCMasterEntB"); this.Session["testeNoRaizeLazy_B"] = "OK"; } catch (Exception ex) { this.Session["testeNoRaizeLazy_B"] = ex.ToString(); } this.ConversationA.EndConversation(); this.ConversationB.EndConversation(); }