/// <summary> /// Generate the database for the configuration required. /// </summary> /// <param name="configFileName"></param> public static void GenerateDbFor(String configFileName) { NhibConfigData configData = GetOrCreateConfigData(configFileName); SchemaExport se = new SchemaExport(configData.Configuration); se.Create(false, true); }
private static NhibConfigData GetOrCreateConfigData(String configFileName) { NhibConfigData retvalue = factories.SafeGet(configFileName); if (null == retvalue) { //This is the first time we ask for this configuration global::NHibernate.Cfg.Configuration config = new global::NHibernate.Cfg.Configuration(); XDocument doc = XDocument.Load(configFileName); XElement connStringElement = (from e in doc.Descendants() where e.Attribute("name") != null && e.Attribute("name").Value == "connection.connection_string" select e).Single(); String cnName = connStringElement.Value; connStringElement.Value = ConfigurationRegistry.ConnectionString(connStringElement.Value).ConnectionString; using (XmlReader reader = doc.CreateReader()) { config.Configure(reader); } ISessionFactory factory = config.BuildSessionFactory(); retvalue = new NhibConfigData() { Configuration = config, SessionFactory = factory, ConnectionName = cnName }; factories.Add(configFileName, retvalue); } return(retvalue); }
public static ISession GetSessionFor(String configFileName) { Object obj = CurrentContext.GetData(GetContextSessionKeyForConfigFileName(configFileName)); if (null != obj) { //We have a session on the stack, but, it is valid? ISession contextSession = ((SessionData)obj).Session; if (contextSession.IsOpen) { return(contextSession); } //Session is not valid, remove from the context. CurrentContext.ReleaseData(GetContextSessionKeyForConfigFileName(configFileName)); } //If we reach here we have no context connection or the context connection was disposed. NhibConfigData configData = GetOrCreateConfigData(configFileName); ISession session = null; if (GlobalTransactionManager.IsInTransaction) { DataAccess.ConnectionData data = DataAccess.GetActualConnectionData(configData.ConnectionName); session = configData.SessionFactory.OpenSession(data.Connection); } else { session = configData.SessionFactory.OpenSession(); } CurrentContext.SetData( GetContextSessionKeyForConfigFileName(configFileName), new SessionData() { Session = session, connectionName = configData.ConnectionName }); return(session); }
private static NhibConfigData GetOrCreateConfigData(String configFileName) { NhibConfigData retvalue = factories.SafeGet(configFileName); if (null == retvalue) { //This is the first time we ask for this configuration global::NHibernate.Cfg.Configuration config = new global::NHibernate.Cfg.Configuration(); XDocument doc = XDocument.Load(configFileName); XElement connStringElement = (from e in doc.Descendants() where e.Attribute("name") != null && e.Attribute("name").Value == "connection.connection_string" select e).Single(); String cnName = connStringElement.Value; connStringElement.Value = ConfigurationRegistry.ConnectionString(connStringElement.Value).ConnectionString; using (XmlReader reader = doc.CreateReader()) { config.Configure(reader); } ISessionFactory factory = config.BuildSessionFactory(); retvalue = new NhibConfigData() { Configuration = config, SessionFactory = factory, ConnectionName = cnName }; factories.Add(configFileName, retvalue); } return retvalue; }