mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
#20808: Fixing that if SessionConfigurationCache was disabled ShellDescriptorCache couldn't be disabled
Work Item: 20808
This commit is contained in:
@@ -18,7 +18,7 @@ namespace Orchard.Data.Migration.Interpreters {
|
||||
private readonly ShellSettings _shellSettings;
|
||||
private readonly ISessionLocator _sessionLocator;
|
||||
private readonly IEnumerable<ICommandInterpreter> _commandInterpreters;
|
||||
private readonly Dialect _dialect;
|
||||
private readonly Lazy<Dialect> _dialectLazy;
|
||||
private readonly List<string> _sqlStatements;
|
||||
private readonly ISessionFactoryHolder _sessionFactoryHolder;
|
||||
private readonly IReportsCoordinator _reportsCoordinator;
|
||||
@@ -40,8 +40,7 @@ namespace Orchard.Data.Migration.Interpreters {
|
||||
|
||||
Logger = NullLogger.Instance;
|
||||
T = NullLocalizer.Instance;
|
||||
var configuration = _sessionFactoryHolder.GetConfiguration();
|
||||
_dialect = Dialect.GetDialect(configuration.Properties);
|
||||
_dialectLazy = new Lazy<Dialect>(() => Dialect.GetDialect(sessionFactoryHolder.GetConfiguration().Properties));
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
@@ -59,9 +58,9 @@ namespace Orchard.Data.Migration.Interpreters {
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.Append(_dialect.CreateMultisetTableString)
|
||||
builder.Append(_dialectLazy.Value.CreateMultisetTableString)
|
||||
.Append(' ')
|
||||
.Append(_dialect.QuoteForTableName(PrefixTableName(command.Name)))
|
||||
.Append(_dialectLazy.Value.QuoteForTableName(PrefixTableName(command.Name)))
|
||||
.Append(" (");
|
||||
|
||||
var appendComma = false;
|
||||
@@ -80,7 +79,7 @@ namespace Orchard.Data.Migration.Interpreters {
|
||||
builder.Append(", ");
|
||||
}
|
||||
|
||||
builder.Append(_dialect.PrimaryKeyString)
|
||||
builder.Append(_dialectLazy.Value.PrimaryKeyString)
|
||||
.Append(" ( ")
|
||||
.Append(String.Join(", ", primaryKeys.ToArray()))
|
||||
.Append(" )");
|
||||
@@ -105,7 +104,7 @@ namespace Orchard.Data.Migration.Interpreters {
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.Append(_dialect.GetDropTableString(PrefixTableName(command.Name)));
|
||||
builder.Append(_dialectLazy.Value.GetDropTableString(PrefixTableName(command.Name)));
|
||||
_sqlStatements.Add(builder.ToString());
|
||||
|
||||
RunPendingStatements();
|
||||
@@ -162,7 +161,7 @@ namespace Orchard.Data.Migration.Interpreters {
|
||||
return;
|
||||
}
|
||||
|
||||
builder.AppendFormat("alter table {0} add ", _dialect.QuoteForTableName(PrefixTableName(command.TableName)));
|
||||
builder.AppendFormat("alter table {0} add ", _dialectLazy.Value.QuoteForTableName(PrefixTableName(command.TableName)));
|
||||
|
||||
Visit(builder, (CreateColumnCommand)command);
|
||||
_sqlStatements.Add(builder.ToString());
|
||||
@@ -174,8 +173,8 @@ namespace Orchard.Data.Migration.Interpreters {
|
||||
}
|
||||
|
||||
builder.AppendFormat("alter table {0} drop column {1}",
|
||||
_dialect.QuoteForTableName(PrefixTableName(command.TableName)),
|
||||
_dialect.QuoteForColumnName(command.ColumnName));
|
||||
_dialectLazy.Value.QuoteForTableName(PrefixTableName(command.TableName)),
|
||||
_dialectLazy.Value.QuoteForColumnName(command.ColumnName));
|
||||
_sqlStatements.Add(builder.ToString());
|
||||
}
|
||||
|
||||
@@ -185,12 +184,12 @@ namespace Orchard.Data.Migration.Interpreters {
|
||||
}
|
||||
|
||||
builder.AppendFormat("alter table {0} alter column {1} ",
|
||||
_dialect.QuoteForTableName(PrefixTableName(command.TableName)),
|
||||
_dialect.QuoteForColumnName(command.ColumnName));
|
||||
_dialectLazy.Value.QuoteForTableName(PrefixTableName(command.TableName)),
|
||||
_dialectLazy.Value.QuoteForColumnName(command.ColumnName));
|
||||
|
||||
// type
|
||||
if (command.DbType != DbType.Object) {
|
||||
builder.Append(GetTypeName(_dialect, command.DbType, command.Length, command.Precision, command.Scale));
|
||||
builder.Append(GetTypeName(_dialectLazy.Value, command.DbType, command.Length, command.Precision, command.Scale));
|
||||
}
|
||||
else {
|
||||
if(command.Length > 0 || command.Precision > 0 || command.Scale > 0) {
|
||||
@@ -212,8 +211,8 @@ namespace Orchard.Data.Migration.Interpreters {
|
||||
}
|
||||
|
||||
builder.AppendFormat("create index {1} on {0} ({2}) ",
|
||||
_dialect.QuoteForTableName(PrefixTableName(command.TableName)),
|
||||
_dialect.QuoteForColumnName(PrefixTableName(command.IndexName)),
|
||||
_dialectLazy.Value.QuoteForTableName(PrefixTableName(command.TableName)),
|
||||
_dialectLazy.Value.QuoteForColumnName(PrefixTableName(command.IndexName)),
|
||||
String.Join(", ", command.ColumnNames));
|
||||
|
||||
_sqlStatements.Add(builder.ToString());
|
||||
@@ -225,8 +224,8 @@ namespace Orchard.Data.Migration.Interpreters {
|
||||
}
|
||||
|
||||
builder.AppendFormat("drop index {0} ON {1}",
|
||||
_dialect.QuoteForColumnName(PrefixTableName(command.IndexName)),
|
||||
_dialect.QuoteForTableName(PrefixTableName(command.TableName)));
|
||||
_dialectLazy.Value.QuoteForColumnName(PrefixTableName(command.IndexName)),
|
||||
_dialectLazy.Value.QuoteForTableName(PrefixTableName(command.TableName)));
|
||||
_sqlStatements.Add(builder.ToString());
|
||||
}
|
||||
|
||||
@@ -251,11 +250,11 @@ namespace Orchard.Data.Migration.Interpreters {
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.Append("alter table ")
|
||||
.Append(_dialect.QuoteForTableName(PrefixTableName(command.SrcTable)));
|
||||
.Append(_dialectLazy.Value.QuoteForTableName(PrefixTableName(command.SrcTable)));
|
||||
|
||||
builder.Append(_dialect.GetAddForeignKeyConstraintString(PrefixTableName(command.Name),
|
||||
builder.Append(_dialectLazy.Value.GetAddForeignKeyConstraintString(PrefixTableName(command.Name),
|
||||
command.SrcColumns,
|
||||
_dialect.QuoteForTableName(PrefixTableName(command.DestTable)),
|
||||
_dialectLazy.Value.QuoteForTableName(PrefixTableName(command.DestTable)),
|
||||
command.DestColumns,
|
||||
false));
|
||||
|
||||
@@ -271,7 +270,7 @@ namespace Orchard.Data.Migration.Interpreters {
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendFormat("alter table {0} drop constraint {1}", _dialect.QuoteForTableName(PrefixTableName(command.SrcTable)), PrefixTableName(command.Name));
|
||||
builder.AppendFormat("alter table {0} drop constraint {1}", _dialectLazy.Value.QuoteForTableName(PrefixTableName(command.SrcTable)), PrefixTableName(command.Name));
|
||||
_sqlStatements.Add(builder.ToString());
|
||||
|
||||
RunPendingStatements();
|
||||
@@ -291,15 +290,15 @@ namespace Orchard.Data.Migration.Interpreters {
|
||||
}
|
||||
|
||||
// name
|
||||
builder.Append(_dialect.QuoteForColumnName(command.ColumnName)).Append(Space);
|
||||
builder.Append(_dialectLazy.Value.QuoteForColumnName(command.ColumnName)).Append(Space);
|
||||
|
||||
if (!command.IsIdentity || _dialect.HasDataTypeInIdentityColumn) {
|
||||
builder.Append(GetTypeName(_dialect, command.DbType, command.Length, command.Precision, command.Scale));
|
||||
if (!command.IsIdentity || _dialectLazy.Value.HasDataTypeInIdentityColumn) {
|
||||
builder.Append(GetTypeName(_dialectLazy.Value, command.DbType, command.Length, command.Precision, command.Scale));
|
||||
}
|
||||
|
||||
// append identity if handled
|
||||
if (command.IsIdentity && _dialect.SupportsIdentityColumns) {
|
||||
builder.Append(Space).Append(_dialect.IdentityColumnString);
|
||||
if (command.IsIdentity && _dialectLazy.Value.SupportsIdentityColumns) {
|
||||
builder.Append(Space).Append(_dialectLazy.Value.IdentityColumnString);
|
||||
}
|
||||
|
||||
// [default value]
|
||||
@@ -311,11 +310,11 @@ namespace Orchard.Data.Migration.Interpreters {
|
||||
builder.Append(command.IsNotNull
|
||||
? " not null"
|
||||
: !command.IsPrimaryKey && !command.IsUnique
|
||||
? _dialect.NullColumnString
|
||||
? _dialectLazy.Value.NullColumnString
|
||||
: string.Empty);
|
||||
|
||||
// append unique if handled, otherwise at the end of the satement
|
||||
if (command.IsUnique && _dialect.SupportsUnique) {
|
||||
if (command.IsUnique && _dialectLazy.Value.SupportsUnique) {
|
||||
builder.Append(" unique");
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.Data;
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using NHibernate.Dialect;
|
||||
using Orchard.Data.Migration.Schema;
|
||||
@@ -7,7 +8,7 @@ using Orchard.Localization;
|
||||
|
||||
namespace Orchard.Data.Migration.Interpreters {
|
||||
public class MySqlCommandInterpreter : ICommandInterpreter<AlterColumnCommand> {
|
||||
private readonly Dialect _dialect;
|
||||
private readonly Lazy<Dialect> _dialectLazy;
|
||||
private readonly ShellSettings _shellSettings;
|
||||
|
||||
public MySqlCommandInterpreter() {
|
||||
@@ -24,20 +25,19 @@ namespace Orchard.Data.Migration.Interpreters {
|
||||
ShellSettings shellSettings,
|
||||
ISessionFactoryHolder sessionFactoryHolder) {
|
||||
_shellSettings = shellSettings;
|
||||
var configuration = sessionFactoryHolder.GetConfiguration();
|
||||
_dialect = Dialect.GetDialect(configuration.Properties);
|
||||
_dialectLazy = new Lazy<Dialect>(() => Dialect.GetDialect(sessionFactoryHolder.GetConfiguration().Properties));
|
||||
}
|
||||
|
||||
public string[] CreateStatements(AlterColumnCommand command) {
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendFormat("alter table {0} modify column {1} ",
|
||||
_dialect.QuoteForTableName(PrefixTableName(command.TableName)),
|
||||
_dialect.QuoteForColumnName(command.ColumnName));
|
||||
_dialectLazy.Value.QuoteForTableName(PrefixTableName(command.TableName)),
|
||||
_dialectLazy.Value.QuoteForColumnName(command.ColumnName));
|
||||
|
||||
// type
|
||||
if (command.DbType != DbType.Object) {
|
||||
builder.Append(DefaultDataMigrationInterpreter.GetTypeName(_dialect, command.DbType, command.Length, command.Precision, command.Scale));
|
||||
builder.Append(DefaultDataMigrationInterpreter.GetTypeName(_dialectLazy.Value, command.DbType, command.Length, command.Precision, command.Scale));
|
||||
}
|
||||
else {
|
||||
if (command.Length > 0 || command.Precision > 0 || command.Scale > 0) {
|
||||
|
@@ -5,7 +5,7 @@ using Orchard.Environment.Configuration;
|
||||
|
||||
namespace Orchard.Data.Migration.Interpreters {
|
||||
public class SqlCeCommandInterpreter : ICommandInterpreter<DropIndexCommand> {
|
||||
private readonly Dialect _dialect;
|
||||
private readonly Lazy<Dialect> _dialectLazy;
|
||||
private readonly ShellSettings _shellSettings;
|
||||
|
||||
public string DataProvider {
|
||||
@@ -16,15 +16,14 @@ namespace Orchard.Data.Migration.Interpreters {
|
||||
ShellSettings shellSettings,
|
||||
ISessionFactoryHolder sessionFactoryHolder) {
|
||||
_shellSettings = shellSettings;
|
||||
var configuration = sessionFactoryHolder.GetConfiguration();
|
||||
_dialect = Dialect.GetDialect(configuration.Properties);
|
||||
_dialectLazy = new Lazy<Dialect>(() => Dialect.GetDialect(sessionFactoryHolder.GetConfiguration().Properties));
|
||||
}
|
||||
|
||||
public string[] CreateStatements(DropIndexCommand command) {
|
||||
|
||||
return new [] { String.Format("drop index {0}.{1}",
|
||||
_dialect.QuoteForTableName(PrefixTableName(command.TableName)),
|
||||
_dialect.QuoteForColumnName(PrefixTableName(command.IndexName)))
|
||||
_dialectLazy.Value.QuoteForTableName(PrefixTableName(command.TableName)),
|
||||
_dialectLazy.Value.QuoteForColumnName(PrefixTableName(command.IndexName)))
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -31,7 +31,10 @@ namespace Orchard.Environment {
|
||||
public string Value { get; set; }
|
||||
}
|
||||
|
||||
public readonly IDictionary<string, IEnumerable<PropertyEntry>> _config = new Dictionary<string, IEnumerable<PropertyEntry>>();
|
||||
// Needs to be static so when the class is first instantiated from OrchardStarter with the config file it is filled and then it's also available
|
||||
// when later used from shells. Since it's only written once and then not modified it can be a normal Dictionary even if reads are then concurrent
|
||||
// (also see "Thread Safety": http://msdn.microsoft.com/en-us/library/xfhwa508.aspx)
|
||||
public static readonly IDictionary<string, IEnumerable<PropertyEntry>> _config = new Dictionary<string, IEnumerable<PropertyEntry>>();
|
||||
|
||||
public HostComponentsConfigModule() {
|
||||
// Called by the framework, as this class is a "Module"
|
||||
@@ -72,14 +75,15 @@ namespace Orchard.Environment {
|
||||
if (!_config.TryGetValue(implementationType.FullName, out properties))
|
||||
return;
|
||||
|
||||
// build an array of actions on this type to assign loggers to member properties
|
||||
|
||||
// build an array of actions on this type to assign configurations to member properties
|
||||
var injectors = BuildPropertiesInjectors(implementationType, properties).ToArray();
|
||||
|
||||
// if there are no logger properties, there's no reason to hook the activated event
|
||||
// if there are no configurable properties, there's no reason to hook into the activated event
|
||||
if (!injectors.Any())
|
||||
return;
|
||||
|
||||
// otherwise, whan an instance of this component is activated, inject the loggers on the instance
|
||||
// otherwise, when an instance of this component is activated, inject the loggers on the instance
|
||||
registration.Activated += (s, e) => {
|
||||
foreach (var injector in injectors)
|
||||
injector(e.Context, e.Instance);
|
||||
|
Reference in New Issue
Block a user