Nhibernate Series II sessionstoragebase

Source: Internet
Author: User

Nhibernate Series II sessionstoragebase

Using nhib.pdf;
Using system. Web;
Using system. collections;
Namespace com. zfrong. Arch. Common. Data. NH. session. Storage
{
Internal abstract class sessionstoragebase: isessionstorage
{
Protected static object locker = new object ();
Protected static isessionstorage instance;

Const string sessionkeyname = "session _";

Const string sessionfactorykeyname = "sessionfactory _";
 
Protected abstract idictionary items
{
Get;

}
Public bool removesession (string key)
{
Key = string. Format ("{0}, {1}", sessionkeyname, key );
Isession session = (isession) This. items [Key];
If (session! = NULL & (session. isconnected | session. isopen ))
{
Session. Disconnect ();
Session. Close (); Session. Dispose ();
This. Items. Remove (key );
Return true;
}
Return false;
}
Public bool removesessionfactory (string key)
{
Key = string. Format ("{0}, {1}", sessionfactorykeyname, key );
Isessionfactory sessionfactory = (isessionfactory) This. items [Key];
If (sessionfactory! = NULL &&! Sessionfactory. isclosed)
{
Sessionfactory. Close (); sessionfactory. Dispose ();
This. Items. Remove (key );
Return true;
}
Return false;
}
Public isession getsession (string key)
{
Isession session = (isession) This. items [String. Format ("{0}, {1}", sessionkeyname, key)];
If (session! = NULL &&! Session. isconnected)
Session. Reconnect ();
Return session;
}

Public isessionfactory getsessionfactory (string key)
{
Return (isessionfactory) This. items [String. Format ("{0}, {1}", sessionfactorykeyname, key)];
}
Public void setsession (string key, isession value)
{
Key = string. Format ("{0}, {1}", sessionkeyname, key );
If (value! = NULL)
{
If (this. Items. Contains (key ))
{
This. items [Key] = value;
}
Else
{
This. Items. Add (Key, value );
}
}
Else
{
This. Items. Remove (key );
}
}
Public void setsessionfactory (string key, isessionfactory value)
{
Key = string. Format ("{0}, {1}", sessionfactorykeyname, key );
If (value! = NULL)
{
If (this. Items. Contains (key ))
{
This. items [Key] = value;
}
Else
{
This. Items. Add (Key, value );
}
}
Else
{
This. Items. Remove (key );
}
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.