예제 #1
0
        public void FixtureSetup()
        {
            var provider = new NHibernateProvider();

            _config = provider.CreateConfiguration();

            _sessionFactory = provider.CreateSessionFactory(_config);

            _session = _sessionFactory.OpenSession();

            provider.ExportSchema(_config, _session.Connection);

            using (var trans = _session.BeginTransaction())
            {
                var modelCreator = new NHibernateQueryingModel();
                modelCreator.CreateModel(_session);
                trans.Commit();
            }

            _query = new QueryAdapter(_session);

            QueryableExtensions.EagerFetchingProvider = new EagerFetchingProvider();
            QueryableExtensions.LazyQueryingProvider  = new LazyResultProvider();
            QueryableExtensions.AsyncQueryingProvider = new AsyncQueryProvider();
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SessionFactory"/> class.
        /// </summary>
        /// <param name="configuration">
        /// The configuration.
        /// </param>
        public SessionFactory(IConfiguration configuration)
        {
            configuration.Configure();

            // Ensure mapping files are embedded in assembly
            this._factory = configuration.BuildSessionFactory();
        }
예제 #3
0
        /// <summary>
        /// Configures NHibernate
        /// </summary>
        public void Configure()
        {
            // Arashi.Core.NHibernate

             configuration = new Configuration();
             configuration.Configure();
             configuration = configuration.AddAssembly("Arashi.Core.NHibernate");

             SessionFactory = configuration.BuildSessionFactory();
        }
        /// <summary>
        /// Create new session factory with new or cached config.
        /// </summary>
        /// <param name="config">Config from Spring</param>
        /// <returns>Session factory</returns>
        protected override global::NHibernate.ISessionFactory NewSessionFactory(Configuration config)
        {
            global::NHibernate.ISessionFactory sf = null;
            if (needCreateConfig)
            {
                sf = base.NewSessionFactory(config);
            }
            else
            {
                var formatter = new BinaryFormatter();
                var cache     = Path.Combine(currentPath, "config.cache");
                using (var stream = new FileStream(cache, FileMode.Open))
                {
                    var cachedConfig = (Configuration)formatter.Deserialize(stream);
                    sf = base.NewSessionFactory(cachedConfig);
                }
            }

            return(sf);
        }
예제 #5
0
        private void EnsureSessionFactory()
        {
            if (sessionFactory == null)
            {
                lock (sessionFactorySyncLock)
                {
                    if (sessionFactory == null)
                    {
                        IPersistenceConfigurer configurer = persistenceConfigurerMap[providerName];

                        MethodInfo setConnectionString = configurer.GetType()
                                                         .GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod)
                                                         .First(metheod => metheod.Name == "ConnectionString" && metheod.GetParameters().Any() && metheod.GetParameters()[0].ParameterType.Equals(typeof(string)));

                        setConnectionString.Invoke(configurer, new[] { connectionString });

                        sessionFactory = Fluently.Configure()
                                         .Database(configurer)
                                         .Mappings(mapping => mapping.FluentMappings.AddFromAssemblyOf <Database>())
                                         .BuildSessionFactory();
                    }
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Gets a persistence test builder using a specified session instance.  A single session will be created
        /// during the lifetime of the test and it will be diposed at the end.
        /// </summary>
        /// <returns>The persistence test builder.</returns>
        /// <param name="sessionFactory">A session factory.</param>
        public static PersistenceTestBuilder UsingSessionFactory(global::NHibernate.ISessionFactory sessionFactory)
        {
            var sessionProvider = new SessionProvider(() => new SessionAdapter(sessionFactory.OpenSession()), true);

            return(new PersistenceTestBuilder(sessionProvider));
        }
예제 #7
0
 public DatabaseFactory()
 {
     sessionFactory = (new Configuration()).Configure().BuildSessionFactory();
 }
예제 #8
0
        private void EnsureSessionFactory()
        {
            if (sessionFactory == null)
            {
                lock (sessionFactorySyncLock)
                {
                    if (sessionFactory == null)
                    {
                        IPersistenceConfigurer configurer = persistenceConfigurerMap[providerName];

                        MethodInfo setConnectionString = configurer.GetType()
                                                                 .GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod)
                                                                 .First(method => method.Name == "ConnectionString" && method.GetParameters().Any() && method.GetParameters()[0].ParameterType.Equals(typeof(string)));
                        setConnectionString.Invoke(configurer, new[] { connectionString });

                        sessionFactory = Fluently.Configure()
                                                 .Database(configurer)
                                                 .Mappings(mapping=>mapping.FluentMappings.AddFromAssemblyOf<Database>())
                                                 .ExposeConfiguration(BuildSchema)
                                                 .BuildSessionFactory();
                    }
                }
            }
        }