/// <summary> /// Opens the gateway to the data store. /// </summary> /// <param name="sessionFactoryConfigName"></param> /// <param name="interceptor"></param> /// <returns>True if gateway was already open.</returns> /// <remarks>Gateway is open when session is open and connection is open.</remarks> private bool Open(string sessionFactoryConfigName, IInterceptor interceptor) { ISessionFactory sessionFactory = null; //if (string.IsNullOrEmpty(sessionFactoryConfigName)) //{ // //sessionFactory = NHibernateSessionFactoryManager.Instance.GetDefaultSessionFactory(); // throw new ArgumentNullException("sessionFactoryConfigName"); //} //else { sessionFactory = NHibernateHelper.GetSessionFactoryManager().GetSessionFactory(sessionFactoryConfigName); } _interceptor = interceptor; if (!_isSessionCreator) { throw new InvalidOperationException( "A gateway that is sharing the session of another gateway cannot be opened directly."); } bool wasOpen = true; if (_session == null || !_session.IsOpen) { wasOpen = false; if (_interceptor != null) { _session = sessionFactory.OpenSession(_interceptor); } else { _session = sessionFactory.OpenSession(); } } // Session is open, connection could be either open or closed. If connection // is closed, open it. Indicate that session was open. if (!_session.IsConnected) { wasOpen = false; _session.Reconnect(); } // call in OpenSession(_intercept) auto //if (_interceptor != null) //{ // _interceptor.SetSession(_session); //} return(wasOpen); }
/// <summary> /// Opens the gateway to the data store. /// </summary> /// <param name="sessionFactoryConfigName"></param> /// <returns>True if gateway was already open.</returns> /// <remarks>Gateway is open when session is open and connection is open.</remarks> private bool Open(string sessionFactoryConfigName) { ISessionFactory sessionFactory = NHibernateHelper.GetSessionFactoryManager().GetSessionFactory(sessionFactoryConfigName); if (!_isSessionCreator) { throw new InvalidOperationException( "A gateway that is sharing the session of another gateway cannot be opened directly."); } bool wasOpen = true; if (_session == null) { _session = sessionFactory.OpenStatelessSession(); } return(wasOpen); }
private void Load() { IClassMetadata classMetadata = m_sessionFactory.GetClassMetadata(m_persistentClass); if (classMetadata == null) { return; } Configuration conf = NHibernateHelper.GetSessionFactoryManager().GetConfigurationBySessionFactory(m_sessionFactory); var persistentClass = conf.GetClassMapping(m_persistentClass); m_idProperty = persistentClass.GetProperty(classMetadata.IdentifierPropertyName); this.TableName = persistentClass.Table.Name; for (int i = 0; i < classMetadata.PropertyNames.Length; ++i) { string s = classMetadata.PropertyNames[i]; NHibernate.Mapping.Property property = persistentClass.GetProperty(s); try { var it = property.ColumnIterator.GetEnumerator(); it.MoveNext(); if (it.Current != null && it.Current is NHibernate.Mapping.Column) { int length = ((NHibernate.Mapping.Column)it.Current).Length; bool nullability = classMetadata.PropertyNullability[i]; m_properties[s] = new EntityPropertyMetadata { Name = s, Length = length, NotNull = !nullability }; } } catch (System.InvalidOperationException) { } } //if (Attribute.IsDefined(m_persistentClass, typeof(NHibernate.Mapping.Attributes.ClassAttribute))) //{ // Attribute[] attrs = Attribute.GetCustomAttributes(m_persistentClass, typeof(NHibernate.Mapping.Attributes.ClassAttribute)); // if (attrs.Length > 0) // { // ClassAttribute attr = attrs[0] as ClassAttribute; // m_tableName = attr.Table; // } //} //m_propertyAttributes.Clear(); //PropertyInfo[] pInfos = m_persistentClass.GetProperties(); //foreach (PropertyInfo pInfo in pInfos) //{ // if (Attribute.IsDefined(pInfo, typeof(NHibernate.Mapping.Attributes.PropertyAttribute))) // { // Attribute[] attrs = Attribute.GetCustomAttributes(pInfo, typeof(NHibernate.Mapping.Attributes.PropertyAttribute)); // foreach(var i in attrs) // { // PropertyAttribute attr = i as PropertyAttribute; // m_propertyAttributes.Add(attr.Name == null ? pInfo.Name : attr.Name, attr); // } // } // else if (Attribute.IsDefined(pInfo, typeof(NHibernate.Mapping.Attributes.IdAttribute))) // { // Attribute[] attrs = Attribute.GetCustomAttributes(pInfo, typeof(NHibernate.Mapping.Attributes.IdAttribute)); // if (attrs.Length > 0) // { // m_idAttribute = attrs[0] as IdAttribute; // } // } //} }