mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-11-08 02:24:56 +08:00
Cache generated mapping file
- Created a modified version of FluentNHibernate, including [Serializable] on GenericEnumWrapper class for it --HG-- branch : dev
This commit is contained in:
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
@@ -20,7 +20,6 @@ namespace Orchard.Data.Migration.Interpreters {
|
||||
private readonly ISession _session;
|
||||
private readonly Dialect _dialect;
|
||||
private readonly List<string> _sqlStatements;
|
||||
private readonly IDataServicesProviderFactory _dataServicesProviderFactory;
|
||||
private readonly ISessionFactoryHolder _sessionFactoryHolder;
|
||||
private readonly IReportsCoordinator _reportsCoordinator;
|
||||
|
||||
@@ -30,21 +29,18 @@ namespace Orchard.Data.Migration.Interpreters {
|
||||
ShellSettings shellSettings,
|
||||
ISessionLocator sessionLocator,
|
||||
IEnumerable<ICommandInterpreter> commandInterpreters,
|
||||
IDataServicesProviderFactory dataServicesProviderFactory,
|
||||
ISessionFactoryHolder sessionFactoryHolder,
|
||||
IReportsCoordinator reportsCoordinator) {
|
||||
_shellSettings = shellSettings;
|
||||
_commandInterpreters = commandInterpreters;
|
||||
_session = sessionLocator.For(typeof(DefaultDataMigrationInterpreter));
|
||||
_sqlStatements = new List<string>();
|
||||
_dataServicesProviderFactory = dataServicesProviderFactory;
|
||||
_sessionFactoryHolder = sessionFactoryHolder;
|
||||
_reportsCoordinator = reportsCoordinator;
|
||||
|
||||
Logger = NullLogger.Instance;
|
||||
|
||||
var parameters = _sessionFactoryHolder.GetSessionFactoryParameters();
|
||||
var configuration = _dataServicesProviderFactory.CreateProvider(parameters).BuildConfiguration(parameters);
|
||||
var configuration = _sessionFactoryHolder.GetConfiguration();
|
||||
_dialect = Dialect.GetDialect(configuration.Properties);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using NHibernate;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using NHibernate;
|
||||
using NHibernate.Cfg;
|
||||
using Orchard.Data.Providers;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Environment.ShellBuilders.Models;
|
||||
@@ -9,6 +12,7 @@ using Orchard.Logging;
|
||||
namespace Orchard.Data {
|
||||
public interface ISessionFactoryHolder : ISingletonDependency {
|
||||
ISessionFactory GetSessionFactory();
|
||||
Configuration GetConfiguration();
|
||||
SessionFactoryParameters GetSessionFactoryParameters();
|
||||
}
|
||||
|
||||
@@ -19,6 +23,7 @@ namespace Orchard.Data {
|
||||
private readonly IAppDataFolder _appDataFolder;
|
||||
|
||||
private ISessionFactory _sessionFactory;
|
||||
private Configuration _configuration;
|
||||
|
||||
public SessionFactoryHolder(
|
||||
ShellSettings shellSettings,
|
||||
@@ -46,17 +51,46 @@ namespace Orchard.Data {
|
||||
return _sessionFactory;
|
||||
}
|
||||
|
||||
public Configuration GetConfiguration() {
|
||||
lock ( this ) {
|
||||
if ( _configuration == null ) {
|
||||
_configuration = BuildConfiguration();
|
||||
}
|
||||
}
|
||||
return _configuration;
|
||||
}
|
||||
|
||||
private ISessionFactory BuildSessionFactory() {
|
||||
Logger.Debug("Building session factory");
|
||||
|
||||
var config = GetConfiguration();
|
||||
return config.BuildSessionFactory();
|
||||
}
|
||||
|
||||
private Configuration BuildConfiguration() {
|
||||
var parameters = GetSessionFactoryParameters();
|
||||
|
||||
var sessionFactory = _dataServicesProviderFactory
|
||||
.CreateProvider(parameters)
|
||||
.BuildConfiguration(parameters)
|
||||
.BuildSessionFactory();
|
||||
Configuration config = null;
|
||||
var bf = new BinaryFormatter();
|
||||
|
||||
return sessionFactory;
|
||||
var filename = _appDataFolder.MapPath(_appDataFolder.Combine("Sites", "mappings.bin"));
|
||||
if(_appDataFolder.FileExists(filename)) {
|
||||
Logger.Debug("Loading mappings from cached file");
|
||||
using ( var stream = File.OpenRead(filename) ) {
|
||||
config = bf.Deserialize(stream) as Configuration;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Logger.Debug("Generating mappings and cached file");
|
||||
config = _dataServicesProviderFactory
|
||||
.CreateProvider(parameters)
|
||||
.BuildConfiguration(parameters);
|
||||
|
||||
using ( var stream = File.OpenWrite(filename) ) {
|
||||
bf.Serialize(stream, config);
|
||||
}
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
public SessionFactoryParameters GetSessionFactoryParameters() {
|
||||
|
||||
Reference in New Issue
Block a user