Exemple #1
0
        public object GetRealObject(StreamingContext context)
        {
            // the SessionFactory that was serialized only has values in the properties
            // "name" and "uuid".  In here convert the serialized SessionFactory into
            // an instance of the SessionFactory in the current AppDomain.
            //log.Debug("Resolving serialized SessionFactory");

            // look for the instance by uuid - this will work when a SessionFactory
            // is serialized and deserialized in the same AppDomain.
            ISessionFactory result = SessionFactoryObjectFactory.GetInstance(uuid);

            if (result == null)
            {
                // if we were deserialized into a different AppDomain, look for an instance with the
                // same name.
                result = SessionFactoryObjectFactory.GetNamedInstance(name);
                if (result == null)
                {
                    throw new NullReferenceException("Could not find a SessionFactory named " + name + " or identified by uuid " + uuid);
                }
            }


            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Closes the session factory, releasing all held resources.
        /// <list>
        /// <item>cleans up used cache regions and "stops" the cache provider.</item>
        /// <item>close the ADO.NET connection</item>
        /// </list>
        /// </summary>
        public void Close()
        {
            isClosed = true;

            // settings.CacheProvider.Stop();

            try
            {
                settings.ConnectionProvider.Dispose();
            }
            finally
            {
                SessionFactoryObjectFactory.RemoveInstance(uuid, name);
            }
        }
Exemple #3
0
        public SessionFactoryImpl(Configuration cfg, Settings settings)
        {
            this.settings = settings;

            //settings.CacheProvider.Start(null);

            #region Persisters

            entityPersisters = new Dictionary <string, IEntityPersister>();
            foreach (ClassMetadata model in cfg.ClassMappings)
            {
                //string cacheRegion = model.EntityName;
                //ICacheConcurrencyStrategy cache;
                //if (!caches.TryGetValue(cacheRegion, out cache))
                //{
                //    cache =CacheFactory.CreateCache(model.CacheConcurrencyStrategy, cacheRegion, model.IsMutable, settings, properties);
                //    if (cache != null)
                //    {
                //        caches.Add(cacheRegion, cache);
                //    }
                //}

                IEntityPersister cp = new EntityPersister(model, this);  // PersisterFactory.CreateClassPersister(model, cache, this, mapping);
                entityPersisters[model.EntityName] = cp;
            }

            #endregion

            #region Serialization info

            name = settings.SessionFactoryName;

            uuid = Guid.NewGuid().ToString("N");

            SessionFactoryObjectFactory.AddInstance(uuid, name, this);

            #endregion

            currentSessionContext = BuildCurrentSessionContext();
        }