More dependency cleanup, less singleton usages, better testing implementations
This commit is contained in:
@@ -227,7 +227,7 @@ namespace Umbraco.Core
|
||||
|
||||
if (currentVersion != configStatus)
|
||||
{
|
||||
LogHelper.Info<ApplicationContext>("CurrentVersion different from configStatus: '" + currentVersion + "','" + configStatus + "'");
|
||||
Logger.Info<ApplicationContext>("CurrentVersion different from configStatus: '" + currentVersion + "','" + configStatus + "'");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace Umbraco.Core
|
||||
LegacyParameterEditorAliasConverter.CreateMappingsForCoreEditors();
|
||||
|
||||
//create database and service contexts for the app context
|
||||
var dbFactory = new DefaultDatabaseFactory(GlobalSettings.UmbracoConnectionName);
|
||||
var dbFactory = new DefaultDatabaseFactory(GlobalSettings.UmbracoConnectionName, LoggerResolver.Current.Logger);
|
||||
Database.Mapper = new PetaPocoMapper();
|
||||
var dbContext = new DatabaseContext(dbFactory, LoggerResolver.Current.Logger);
|
||||
var serviceContext = new ServiceContext(
|
||||
|
||||
@@ -499,7 +499,7 @@ namespace Umbraco.Core
|
||||
throw new InvalidOperationException("Cannot use MySql in Medium Trust configuration");
|
||||
}
|
||||
|
||||
var database = new UmbracoDatabase(_connectionString, ProviderName);
|
||||
var database = new UmbracoDatabase(_connectionString, ProviderName, _logger);
|
||||
var dbSchema = new DatabaseSchemaCreation(database, _logger, SqlSyntax);
|
||||
_result = dbSchema.ValidateSchema();
|
||||
}
|
||||
@@ -520,7 +520,7 @@ namespace Umbraco.Core
|
||||
|
||||
string message;
|
||||
|
||||
var database = new UmbracoDatabase(_connectionString, ProviderName);
|
||||
var database = new UmbracoDatabase(_connectionString, ProviderName, _logger);
|
||||
|
||||
// If MySQL, we're going to ensure that database calls are maintaining proper casing as to remove the necessity for checks
|
||||
// for case insensitive queries. In an ideal situation (which is what we're striving for), all calls would be case sensitive.
|
||||
@@ -590,7 +590,7 @@ namespace Umbraco.Core
|
||||
|
||||
_logger.Info<DatabaseContext>("Database upgrade started");
|
||||
|
||||
var database = new UmbracoDatabase(_connectionString, ProviderName);
|
||||
var database = new UmbracoDatabase(_connectionString, ProviderName, _logger);
|
||||
//var supportsCaseInsensitiveQueries = SqlSyntax.SupportsCaseInsensitiveQueries(database);
|
||||
|
||||
var message = GetResultMessageForMySql();
|
||||
|
||||
@@ -7,12 +7,11 @@ using log4net;
|
||||
namespace Umbraco.Core.Logging
|
||||
{
|
||||
///<summary>
|
||||
/// Used for logging
|
||||
/// Used for logging, ILogger should be used instead but this is available for static access to logging
|
||||
///</summary>
|
||||
/// <remarks>
|
||||
/// this wraps ILogger
|
||||
/// </remarks>
|
||||
[Obsolete("Use ILogger instead which is available on most base classes or accessed via LoggerResolver.Current or injected into WebApi or MVC services via the DependencyResolver")]
|
||||
public static class LogHelper
|
||||
{
|
||||
#region Error
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
|
||||
namespace Umbraco.Core.Persistence
|
||||
{
|
||||
@@ -15,7 +16,8 @@ namespace Umbraco.Core.Persistence
|
||||
internal class DefaultDatabaseFactory : DisposableObject, IDatabaseFactory
|
||||
{
|
||||
private readonly string _connectionStringName;
|
||||
public string ConnectionString { get; private set; }
|
||||
private readonly ILogger _logger;
|
||||
public string ConnectionString { get; private set; }
|
||||
public string ProviderName { get; private set; }
|
||||
|
||||
//very important to have ThreadStatic:
|
||||
@@ -25,35 +27,33 @@ namespace Umbraco.Core.Persistence
|
||||
|
||||
private static readonly object Locker = new object();
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor initialized with the GlobalSettings.UmbracoConnectionName
|
||||
/// </summary>
|
||||
public DefaultDatabaseFactory() : this(GlobalSettings.UmbracoConnectionName)
|
||||
/// <summary>
|
||||
/// Constructor accepting custom connection string
|
||||
/// </summary>
|
||||
/// <param name="connectionStringName">Name of the connection string in web.config</param>
|
||||
/// <param name="logger"></param>
|
||||
public DefaultDatabaseFactory(string connectionStringName, ILogger logger)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor accepting custom connection string
|
||||
/// </summary>
|
||||
/// <param name="connectionStringName">Name of the connection string in web.config</param>
|
||||
public DefaultDatabaseFactory(string connectionStringName)
|
||||
{
|
||||
Mandate.ParameterNotNullOrEmpty(connectionStringName, "connectionStringName");
|
||||
if (logger == null) throw new ArgumentNullException("logger");
|
||||
Mandate.ParameterNotNullOrEmpty(connectionStringName, "connectionStringName");
|
||||
_connectionStringName = connectionStringName;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor accepting custom connectino string and provider name
|
||||
/// </summary>
|
||||
/// <param name="connectionString">Connection String to use with Database</param>
|
||||
/// <param name="providerName">Database Provider for the Connection String</param>
|
||||
public DefaultDatabaseFactory(string connectionString, string providerName)
|
||||
/// <summary>
|
||||
/// Constructor accepting custom connectino string and provider name
|
||||
/// </summary>
|
||||
/// <param name="connectionString">Connection String to use with Database</param>
|
||||
/// <param name="providerName">Database Provider for the Connection String</param>
|
||||
/// <param name="logger"></param>
|
||||
public DefaultDatabaseFactory(string connectionString, string providerName, ILogger logger)
|
||||
{
|
||||
Mandate.ParameterNotNullOrEmpty(connectionString, "connectionString");
|
||||
if (logger == null) throw new ArgumentNullException("logger");
|
||||
Mandate.ParameterNotNullOrEmpty(connectionString, "connectionString");
|
||||
Mandate.ParameterNotNullOrEmpty(providerName, "providerName");
|
||||
ConnectionString = connectionString;
|
||||
ProviderName = providerName;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public UmbracoDatabase CreateDatabase()
|
||||
@@ -69,8 +69,8 @@ namespace Umbraco.Core.Persistence
|
||||
if (_nonHttpInstance == null)
|
||||
{
|
||||
_nonHttpInstance = string.IsNullOrEmpty(ConnectionString) == false && string.IsNullOrEmpty(ProviderName) == false
|
||||
? new UmbracoDatabase(ConnectionString, ProviderName)
|
||||
: new UmbracoDatabase(_connectionStringName);
|
||||
? new UmbracoDatabase(ConnectionString, ProviderName, _logger)
|
||||
: new UmbracoDatabase(_connectionStringName, _logger);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,8 +82,8 @@ namespace Umbraco.Core.Persistence
|
||||
{
|
||||
HttpContext.Current.Items.Add(typeof (DefaultDatabaseFactory),
|
||||
string.IsNullOrEmpty(ConnectionString) == false && string.IsNullOrEmpty(ProviderName) == false
|
||||
? new UmbracoDatabase(ConnectionString, ProviderName)
|
||||
: new UmbracoDatabase(_connectionStringName));
|
||||
? new UmbracoDatabase(ConnectionString, ProviderName, _logger)
|
||||
: new UmbracoDatabase(_connectionStringName, _logger));
|
||||
}
|
||||
return (UmbracoDatabase)HttpContext.Current.Items[typeof(DefaultDatabaseFactory)];
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace Umbraco.Core.Persistence.Factories
|
||||
var dto = new TemplateDto
|
||||
{
|
||||
Alias = entity.Alias,
|
||||
Design = entity.Content,
|
||||
Design = entity.Content ?? string.Empty,
|
||||
NodeDto = BuildNodeDto(entity)
|
||||
};
|
||||
|
||||
|
||||
@@ -53,12 +53,12 @@ namespace Umbraco.Core.Persistence.Migrations
|
||||
|
||||
public ICreateBuilder Create
|
||||
{
|
||||
get { return new CreateBuilder(Context); }
|
||||
get { return new CreateBuilder(Context, SqlSyntax); }
|
||||
}
|
||||
|
||||
public IDeleteBuilder Delete
|
||||
{
|
||||
get { return new DeleteBuilder(Context); }
|
||||
get { return new DeleteBuilder(Context, SqlSyntax); }
|
||||
}
|
||||
|
||||
public IExecuteBuilder Execute
|
||||
|
||||
@@ -1,20 +1,38 @@
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Migrations
|
||||
{
|
||||
public abstract class MigrationExpressionBase : IMigrationExpression
|
||||
{
|
||||
[Obsolete("Use the other constructors specifying an ISqlSyntaxProvider instead")]
|
||||
protected MigrationExpressionBase()
|
||||
: this(SqlSyntaxContext.SqlSyntaxProvider)
|
||||
{
|
||||
}
|
||||
|
||||
[Obsolete("Use the other constructors specifying an ISqlSyntaxProvider instead")]
|
||||
protected MigrationExpressionBase(DatabaseProviders current, DatabaseProviders[] databaseProviders)
|
||||
: this(current, databaseProviders, SqlSyntaxContext.SqlSyntaxProvider)
|
||||
{
|
||||
}
|
||||
|
||||
protected MigrationExpressionBase(ISqlSyntaxProvider sqlSyntax)
|
||||
{
|
||||
SqlSyntax = sqlSyntax;
|
||||
}
|
||||
|
||||
protected MigrationExpressionBase(DatabaseProviders current, DatabaseProviders[] databaseProviders, ISqlSyntaxProvider sqlSyntax)
|
||||
{
|
||||
SupportedDatabaseProviders = databaseProviders;
|
||||
SqlSyntax = sqlSyntax;
|
||||
CurrentDatabaseProvider = current;
|
||||
}
|
||||
|
||||
public virtual DatabaseProviders[] SupportedDatabaseProviders { get; private set; }
|
||||
public ISqlSyntaxProvider SqlSyntax { get; private set; }
|
||||
public virtual DatabaseProviders CurrentDatabaseProvider { get; private set; }
|
||||
|
||||
public bool IsExpressionSupported()
|
||||
|
||||
@@ -1,20 +1,37 @@
|
||||
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
||||
using System;
|
||||
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Migrations.Syntax.Alter.Expressions
|
||||
{
|
||||
public class AlterColumnExpression : MigrationExpressionBase
|
||||
{
|
||||
public AlterColumnExpression()
|
||||
public AlterColumnExpression(ISqlSyntaxProvider sqlSyntax)
|
||||
: base(sqlSyntax)
|
||||
{
|
||||
Column = new ColumnDefinition() { ModificationType = ModificationType.Alter };
|
||||
}
|
||||
|
||||
public AlterColumnExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders) : base(current, databaseProviders)
|
||||
public AlterColumnExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders, ISqlSyntaxProvider sqlSyntax)
|
||||
: base(current, databaseProviders, sqlSyntax)
|
||||
{
|
||||
Column = new ColumnDefinition() { ModificationType = ModificationType.Alter };
|
||||
}
|
||||
|
||||
[Obsolete("Use the constructor specifying an ISqlSyntaxProvider instead")]
|
||||
public AlterColumnExpression()
|
||||
: this(SqlSyntaxContext.SqlSyntaxProvider)
|
||||
{
|
||||
}
|
||||
|
||||
[Obsolete("Use the constructor specifying an ISqlSyntaxProvider instead")]
|
||||
public AlterColumnExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders)
|
||||
: this(current, databaseProviders, SqlSyntaxContext.SqlSyntaxProvider)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
public virtual string SchemaName { get; set; }
|
||||
public virtual string TableName { get; set; }
|
||||
public virtual ColumnDefinition Column { get; set; }
|
||||
@@ -25,7 +42,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Alter.Expressions
|
||||
// SqlSyntaxContext.SqlSyntaxProvider.GetQuotedColumnName(Column.Name),
|
||||
// SqlSyntaxContext.SqlSyntaxProvider.Format(Column));
|
||||
|
||||
return string.Format(SqlSyntaxContext.SqlSyntaxProvider.AlterColumn,
|
||||
return string.Format(SqlSyntaxContext.SqlSyntaxProvider.AlterColumn,
|
||||
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedTableName(TableName),
|
||||
SqlSyntaxContext.SqlSyntaxProvider.Format(Column));
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
||||
using System;
|
||||
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
||||
using Umbraco.Core.Persistence.Migrations.Syntax.Create.Column;
|
||||
using Umbraco.Core.Persistence.Migrations.Syntax.Create.Constraint;
|
||||
using Umbraco.Core.Persistence.Migrations.Syntax.Create.Expressions;
|
||||
@@ -6,20 +7,29 @@ using Umbraco.Core.Persistence.Migrations.Syntax.Create.ForeignKey;
|
||||
using Umbraco.Core.Persistence.Migrations.Syntax.Create.Index;
|
||||
using Umbraco.Core.Persistence.Migrations.Syntax.Create.Table;
|
||||
using Umbraco.Core.Persistence.Migrations.Syntax.Expressions;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Migrations.Syntax.Create
|
||||
{
|
||||
public class CreateBuilder : ICreateBuilder
|
||||
{
|
||||
private readonly IMigrationContext _context;
|
||||
private readonly ISqlSyntaxProvider _sqlSyntax;
|
||||
private readonly DatabaseProviders[] _databaseProviders;
|
||||
|
||||
public CreateBuilder(IMigrationContext context, params DatabaseProviders[] databaseProviders)
|
||||
public CreateBuilder(IMigrationContext context, ISqlSyntaxProvider sqlSyntax, params DatabaseProviders[] databaseProviders)
|
||||
{
|
||||
_context = context;
|
||||
_sqlSyntax = sqlSyntax;
|
||||
_databaseProviders = databaseProviders;
|
||||
}
|
||||
|
||||
[Obsolete("Use alternate ctor specifying ISqlSyntaxProvider instead")]
|
||||
public CreateBuilder(IMigrationContext context, params DatabaseProviders[] databaseProviders)
|
||||
:this(context, SqlSyntaxContext.SqlSyntaxProvider, databaseProviders)
|
||||
{
|
||||
}
|
||||
|
||||
public ICreateTableWithColumnSyntax Table(string tableName)
|
||||
{
|
||||
var expression = new CreateTableExpression { TableName = tableName };
|
||||
@@ -56,14 +66,14 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Create
|
||||
|
||||
public ICreateIndexForTableSyntax Index()
|
||||
{
|
||||
var expression = new CreateIndexExpression();
|
||||
var expression = new CreateIndexExpression(_sqlSyntax);
|
||||
_context.Expressions.Add(expression);
|
||||
return new CreateIndexBuilder(expression);
|
||||
}
|
||||
|
||||
public ICreateIndexForTableSyntax Index(string indexName)
|
||||
{
|
||||
var expression = new CreateIndexExpression { Index = { Name = indexName } };
|
||||
var expression = new CreateIndexExpression(_sqlSyntax) { Index = { Name = indexName } };
|
||||
_context.Expressions.Add(expression);
|
||||
return new CreateIndexBuilder(expression);
|
||||
}
|
||||
|
||||
@@ -1,24 +1,34 @@
|
||||
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
||||
using System;
|
||||
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
||||
using Umbraco.Core.Persistence.Migrations.Syntax.Delete.Column;
|
||||
using Umbraco.Core.Persistence.Migrations.Syntax.Delete.Constraint;
|
||||
using Umbraco.Core.Persistence.Migrations.Syntax.Delete.DefaultConstraint;
|
||||
using Umbraco.Core.Persistence.Migrations.Syntax.Delete.Expressions;
|
||||
using Umbraco.Core.Persistence.Migrations.Syntax.Delete.ForeignKey;
|
||||
using Umbraco.Core.Persistence.Migrations.Syntax.Delete.Index;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Migrations.Syntax.Delete
|
||||
{
|
||||
public class DeleteBuilder : IDeleteBuilder
|
||||
{
|
||||
private readonly IMigrationContext _context;
|
||||
private readonly ISqlSyntaxProvider _sqlSyntax;
|
||||
private readonly DatabaseProviders[] _databaseProviders;
|
||||
|
||||
public DeleteBuilder(IMigrationContext context, params DatabaseProviders[] databaseProviders)
|
||||
public DeleteBuilder(IMigrationContext context, ISqlSyntaxProvider sqlSyntax, params DatabaseProviders[] databaseProviders)
|
||||
{
|
||||
_context = context;
|
||||
_sqlSyntax = sqlSyntax;
|
||||
_databaseProviders = databaseProviders;
|
||||
}
|
||||
|
||||
[Obsolete("Use the other constructor specifying an ISqlSyntaxProvider instead")]
|
||||
public DeleteBuilder(IMigrationContext context, params DatabaseProviders[] databaseProviders)
|
||||
: this(context, SqlSyntaxContext.SqlSyntaxProvider, databaseProviders)
|
||||
{
|
||||
}
|
||||
|
||||
public void Table(string tableName)
|
||||
{
|
||||
var expression = new DeleteTableExpression { TableName = tableName };
|
||||
@@ -37,8 +47,8 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Delete
|
||||
public IDeleteForeignKeyFromTableSyntax ForeignKey()
|
||||
{
|
||||
var expression = _databaseProviders == null
|
||||
? new DeleteForeignKeyExpression()
|
||||
: new DeleteForeignKeyExpression(_context.CurrentDatabaseProvider, _databaseProviders);
|
||||
? new DeleteForeignKeyExpression(_sqlSyntax)
|
||||
: new DeleteForeignKeyExpression(_context.CurrentDatabaseProvider, _databaseProviders, _sqlSyntax);
|
||||
_context.Expressions.Add(expression);
|
||||
return new DeleteForeignKeyBuilder(expression);
|
||||
}
|
||||
@@ -46,8 +56,8 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Delete
|
||||
public IDeleteForeignKeyOnTableSyntax ForeignKey(string foreignKeyName)
|
||||
{
|
||||
var expression = _databaseProviders == null
|
||||
? new DeleteForeignKeyExpression { ForeignKey = { Name = foreignKeyName } }
|
||||
: new DeleteForeignKeyExpression(_context.CurrentDatabaseProvider, _databaseProviders) { ForeignKey = { Name = foreignKeyName } };
|
||||
? new DeleteForeignKeyExpression(_sqlSyntax) { ForeignKey = { Name = foreignKeyName } }
|
||||
: new DeleteForeignKeyExpression(_context.CurrentDatabaseProvider, _databaseProviders, _sqlSyntax) { ForeignKey = { Name = foreignKeyName } };
|
||||
_context.Expressions.Add(expression);
|
||||
return new DeleteForeignKeyBuilder(expression);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
|
||||
@@ -7,17 +8,31 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Delete.Expressions
|
||||
{
|
||||
public class DeleteForeignKeyExpression : MigrationExpressionBase
|
||||
{
|
||||
[Obsolete("Use the other constructors specifying an ILogger instead")]
|
||||
public DeleteForeignKeyExpression()
|
||||
{
|
||||
ForeignKey = new ForeignKeyDefinition();
|
||||
}
|
||||
|
||||
[Obsolete("Use the other constructors specifying an ILogger instead")]
|
||||
public DeleteForeignKeyExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders)
|
||||
: base(current, databaseProviders)
|
||||
{
|
||||
ForeignKey = new ForeignKeyDefinition();
|
||||
}
|
||||
|
||||
public DeleteForeignKeyExpression(ISqlSyntaxProvider sqlSyntax)
|
||||
: base(sqlSyntax)
|
||||
{
|
||||
ForeignKey = new ForeignKeyDefinition();
|
||||
}
|
||||
|
||||
public DeleteForeignKeyExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders, ISqlSyntaxProvider sqlSyntax)
|
||||
: base(current, databaseProviders, sqlSyntax)
|
||||
{
|
||||
ForeignKey = new ForeignKeyDefinition();
|
||||
}
|
||||
|
||||
public virtual ForeignKeyDefinition ForeignKey { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
@@ -34,10 +49,10 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Delete.Expressions
|
||||
if (string.IsNullOrEmpty(ForeignKey.Name))
|
||||
ForeignKey.Name = string.Format("{0}_ibfk_1", ForeignKey.ForeignTable.ToLower());
|
||||
|
||||
return string.Format(SqlSyntaxContext.SqlSyntaxProvider.DeleteConstraint,
|
||||
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedTableName(ForeignKey.ForeignTable),
|
||||
return string.Format(SqlSyntax.DeleteConstraint,
|
||||
SqlSyntax.GetQuotedTableName(ForeignKey.ForeignTable),
|
||||
"FOREIGN KEY",
|
||||
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedName(ForeignKey.Name));
|
||||
SqlSyntax.GetQuotedName(ForeignKey.Name));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(ForeignKey.Name))
|
||||
@@ -45,9 +60,9 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Delete.Expressions
|
||||
ForeignKey.Name = string.Format("FK_{0}_{1}_{2}", ForeignKey.ForeignTable, ForeignKey.PrimaryTable, ForeignKey.PrimaryColumns.First());
|
||||
}
|
||||
|
||||
return string.Format(SqlSyntaxContext.SqlSyntaxProvider.DeleteConstraint,
|
||||
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedTableName(ForeignKey.ForeignTable),
|
||||
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedName(ForeignKey.Name));
|
||||
return string.Format(SqlSyntax.DeleteConstraint,
|
||||
SqlSyntax.GetQuotedTableName(ForeignKey.ForeignTable),
|
||||
SqlSyntax.GetQuotedName(ForeignKey.Name));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,41 @@
|
||||
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
||||
using System;
|
||||
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Migrations.Syntax.Expressions
|
||||
{
|
||||
public class CreateIndexExpression : MigrationExpressionBase
|
||||
{
|
||||
public CreateIndexExpression()
|
||||
public CreateIndexExpression(ISqlSyntaxProvider sqlSyntax)
|
||||
: base(sqlSyntax)
|
||||
{
|
||||
Index = new IndexDefinition();
|
||||
}
|
||||
|
||||
public CreateIndexExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders, ISqlSyntaxProvider sqlSyntax)
|
||||
: base(current, databaseProviders, sqlSyntax)
|
||||
{
|
||||
Index = new IndexDefinition();
|
||||
}
|
||||
|
||||
public CreateIndexExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders) : base(current, databaseProviders)
|
||||
[Obsolete("Use alternate ctor specifying ISqlSyntaxProvider instead")]
|
||||
public CreateIndexExpression()
|
||||
: this(SqlSyntaxContext.SqlSyntaxProvider)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Obsolete("Use alternate ctor specifying ISqlSyntaxProvider instead")]
|
||||
public CreateIndexExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders)
|
||||
: this(current, databaseProviders, SqlSyntaxContext.SqlSyntaxProvider)
|
||||
{
|
||||
Index = new IndexDefinition();
|
||||
}
|
||||
|
||||
public virtual IndexDefinition Index { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return SqlSyntaxContext.SqlSyntaxProvider.Format(Index);
|
||||
return SqlSyntax.Format(Index);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
|
||||
@@ -14,7 +15,8 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
|
||||
{
|
||||
private readonly bool _skipIndexCheck;
|
||||
|
||||
internal AddIndexToCmsMacroPropertyTable(bool skipIndexCheck)
|
||||
internal AddIndexToCmsMacroPropertyTable(bool skipIndexCheck, ISqlSyntaxProvider sqlSyntax, ILogger logger)
|
||||
: base(sqlSyntax, logger)
|
||||
{
|
||||
_skipIndexCheck = skipIndexCheck;
|
||||
}
|
||||
@@ -26,7 +28,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
|
||||
|
||||
public override void Up()
|
||||
{
|
||||
var dbIndexes = _skipIndexCheck ? new DbIndexDefinition[]{} : SqlSyntaxContext.SqlSyntaxProvider.GetDefinedIndexes(Context.Database)
|
||||
var dbIndexes = _skipIndexCheck ? new DbIndexDefinition[]{} : SqlSyntax.GetDefinedIndexes(Context.Database)
|
||||
.Select(x => new DbIndexDefinition()
|
||||
{
|
||||
TableName = x.Item1,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.CodeDom;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
|
||||
@@ -15,7 +16,8 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
|
||||
{
|
||||
private readonly bool _skipIndexCheck;
|
||||
|
||||
internal AddIndexToCmsMacroTable(bool skipIndexCheck)
|
||||
internal AddIndexToCmsMacroTable(bool skipIndexCheck, ISqlSyntaxProvider sqlSyntax, ILogger logger)
|
||||
: base(sqlSyntax, logger)
|
||||
{
|
||||
_skipIndexCheck = skipIndexCheck;
|
||||
}
|
||||
|
||||
@@ -8,51 +8,84 @@ using Umbraco.Core.Logging;
|
||||
|
||||
namespace Umbraco.Core.Persistence
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the Umbraco implementation of the PetaPoco Database object
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Currently this object exists for 'future proofing' our implementation. By having our own inheritied implementation we
|
||||
/// can then override any additional execution (such as additional loggging, functionality, etc...) that we need to without breaking compatibility since we'll always be exposing
|
||||
/// this object instead of the base PetaPoco database object.
|
||||
/// </remarks>
|
||||
/// <summary>
|
||||
/// Represents the Umbraco implementation of the PetaPoco Database object
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Currently this object exists for 'future proofing' our implementation. By having our own inheritied implementation we
|
||||
/// can then override any additional execution (such as additional loggging, functionality, etc...) that we need to without breaking compatibility since we'll always be exposing
|
||||
/// this object instead of the base PetaPoco database object.
|
||||
/// </remarks>
|
||||
public class UmbracoDatabase : Database, IDisposeOnRequestEnd
|
||||
{
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly Guid _instanceId = Guid.NewGuid();
|
||||
/// <summary>
|
||||
/// Used for testing
|
||||
/// </summary>
|
||||
internal Guid InstanceId
|
||||
{
|
||||
get { return _instanceId; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Used for testing
|
||||
/// </summary>
|
||||
internal Guid InstanceId
|
||||
{
|
||||
get { return _instanceId; }
|
||||
}
|
||||
|
||||
public UmbracoDatabase(IDbConnection connection) : base(connection)
|
||||
{
|
||||
}
|
||||
[Obsolete("Use the other constructor specifying an ILogger instead")]
|
||||
public UmbracoDatabase(IDbConnection connection)
|
||||
: this(connection, LoggerResolver.Current.Logger)
|
||||
{
|
||||
}
|
||||
|
||||
public UmbracoDatabase(string connectionString, string providerName) : base(connectionString, providerName)
|
||||
{
|
||||
}
|
||||
[Obsolete("Use the other constructor specifying an ILogger instead")]
|
||||
public UmbracoDatabase(string connectionString, string providerName)
|
||||
: this(connectionString, providerName, LoggerResolver.Current.Logger)
|
||||
{
|
||||
}
|
||||
|
||||
public UmbracoDatabase(string connectionString, DbProviderFactory provider) : base(connectionString, provider)
|
||||
{
|
||||
}
|
||||
[Obsolete("Use the other constructor specifying an ILogger instead")]
|
||||
public UmbracoDatabase(string connectionString, DbProviderFactory provider)
|
||||
: this(connectionString, provider, LoggerResolver.Current.Logger)
|
||||
{
|
||||
}
|
||||
|
||||
public UmbracoDatabase(string connectionStringName) : base(connectionStringName)
|
||||
{
|
||||
}
|
||||
[Obsolete("Use the other constructor specifying an ILogger instead")]
|
||||
public UmbracoDatabase(string connectionStringName)
|
||||
: this(connectionStringName, LoggerResolver.Current.Logger)
|
||||
{
|
||||
}
|
||||
|
||||
public UmbracoDatabase(IDbConnection connection, ILogger logger)
|
||||
: base(connection)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public UmbracoDatabase(string connectionString, string providerName, ILogger logger)
|
||||
: base(connectionString, providerName)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public UmbracoDatabase(string connectionString, DbProviderFactory provider, ILogger logger)
|
||||
: base(connectionString, provider)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public UmbracoDatabase(string connectionStringName, ILogger logger)
|
||||
: base(connectionStringName)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public override IDbConnection OnConnectionOpened(IDbConnection connection)
|
||||
{
|
||||
// wrap the connection with a profiling connection that tracks timings
|
||||
return new StackExchange.Profiling.Data.ProfiledDbConnection(connection as DbConnection, MiniProfiler.Current);
|
||||
}
|
||||
|
||||
|
||||
public override void OnException(Exception x)
|
||||
{
|
||||
LogHelper.Info<UmbracoDatabase>(x.StackTrace);
|
||||
_logger.Info<UmbracoDatabase>(x.StackTrace);
|
||||
base.OnException(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using Umbraco.Core.Configuration;
|
||||
using System;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
|
||||
namespace Umbraco.Core.Persistence.UnitOfWork
|
||||
{
|
||||
@@ -7,61 +9,75 @@ namespace Umbraco.Core.Persistence.UnitOfWork
|
||||
/// </summary>
|
||||
public class PetaPocoUnitOfWorkProvider : IDatabaseUnitOfWorkProvider
|
||||
{
|
||||
private readonly IDatabaseFactory _dbFactory;
|
||||
private readonly IDatabaseFactory _dbFactory;
|
||||
|
||||
[Obsolete("Use the constructor specifying an ILogger instead")]
|
||||
public PetaPocoUnitOfWorkProvider()
|
||||
: this(new DefaultDatabaseFactory(GlobalSettings.UmbracoConnectionName, LoggerResolver.Current.Logger))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Obsolete("Use the constructor specifying an ILogger instead")]
|
||||
public PetaPocoUnitOfWorkProvider(string connectionString, string providerName)
|
||||
: this(new DefaultDatabaseFactory(connectionString, providerName, LoggerResolver.Current.Logger))
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Parameterless constructor uses defaults
|
||||
/// </summary>
|
||||
public PetaPocoUnitOfWorkProvider()
|
||||
: this(new DefaultDatabaseFactory(GlobalSettings.UmbracoConnectionName))
|
||||
public PetaPocoUnitOfWorkProvider(ILogger logger)
|
||||
: this(new DefaultDatabaseFactory(GlobalSettings.UmbracoConnectionName, logger))
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor accepting custom connectino string and provider name
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="connectionString">Connection String to use with Database</param>
|
||||
/// <param name="providerName">Database Provider for the Connection String</param>
|
||||
public PetaPocoUnitOfWorkProvider(string connectionString, string providerName) : this(new DefaultDatabaseFactory(connectionString, providerName))
|
||||
{}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor accepting an IDatabaseFactory instance
|
||||
/// </summary>
|
||||
/// <param name="dbFactory"></param>
|
||||
internal PetaPocoUnitOfWorkProvider(IDatabaseFactory dbFactory)
|
||||
{
|
||||
Mandate.ParameterNotNull(dbFactory, "dbFactory");
|
||||
_dbFactory = dbFactory;
|
||||
}
|
||||
|
||||
#region Implementation of IUnitOfWorkProvider
|
||||
public PetaPocoUnitOfWorkProvider(ILogger logger, string connectionString, string providerName)
|
||||
: this(new DefaultDatabaseFactory(connectionString, providerName, logger))
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a Unit of work with a new UmbracoDatabase instance for the work item/transaction.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// Each PetaPoco UOW uses it's own Database object, not the shared Database object that comes from
|
||||
/// the ApplicationContext.Current.DatabaseContext.Database. This is because each transaction should use it's own Database
|
||||
/// and we Dispose of this Database object when the UOW is disposed.
|
||||
/// </remarks>
|
||||
public IDatabaseUnitOfWork GetUnitOfWork()
|
||||
/// Constructor accepting an IDatabaseFactory instance
|
||||
/// </summary>
|
||||
/// <param name="dbFactory"></param>
|
||||
internal PetaPocoUnitOfWorkProvider(IDatabaseFactory dbFactory)
|
||||
{
|
||||
Mandate.ParameterNotNull(dbFactory, "dbFactory");
|
||||
_dbFactory = dbFactory;
|
||||
}
|
||||
|
||||
#region Implementation of IUnitOfWorkProvider
|
||||
|
||||
/// <summary>
|
||||
/// Creates a Unit of work with a new UmbracoDatabase instance for the work item/transaction.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// Each PetaPoco UOW uses it's own Database object, not the shared Database object that comes from
|
||||
/// the ApplicationContext.Current.DatabaseContext.Database. This is because each transaction should use it's own Database
|
||||
/// and we Dispose of this Database object when the UOW is disposed.
|
||||
/// </remarks>
|
||||
public IDatabaseUnitOfWork GetUnitOfWork()
|
||||
{
|
||||
return new PetaPocoUnitOfWork(_dbFactory.CreateDatabase());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Static helper method to return a new unit of work
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal static IDatabaseUnitOfWork CreateUnitOfWork()
|
||||
{
|
||||
var provider = new PetaPocoUnitOfWorkProvider();
|
||||
return provider.GetUnitOfWork();
|
||||
}
|
||||
/// <summary>
|
||||
/// Static helper method to return a new unit of work
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal static IDatabaseUnitOfWork CreateUnitOfWork(ILogger logger)
|
||||
{
|
||||
var provider = new PetaPocoUnitOfWorkProvider(logger);
|
||||
return provider.GetUnitOfWork();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,13 +14,15 @@ namespace Umbraco.Core.Standalone
|
||||
{
|
||||
private readonly string _connectionString;
|
||||
private readonly string _providerName;
|
||||
private readonly ILogger _logger;
|
||||
private ServiceContext _serviceContext;
|
||||
private readonly StandaloneCoreApplication _application;
|
||||
|
||||
public ServiceContextManager(string connectionString, string providerName, string baseDirectory)
|
||||
public ServiceContextManager(string connectionString, string providerName, string baseDirectory, ILogger logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_providerName = providerName;
|
||||
_logger = logger;
|
||||
|
||||
Trace.WriteLine("ServiceContextManager-Current AppDomain: " + AppDomain.CurrentDomain.FriendlyName);
|
||||
Trace.WriteLine("ServiceContextManager-Current AppDomain: " + AppDomain.CurrentDomain.BaseDirectory);
|
||||
@@ -53,8 +55,8 @@ namespace Umbraco.Core.Standalone
|
||||
//we have no request based cache when running standalone
|
||||
new NullCacheProvider());
|
||||
|
||||
var dbFactory = new DefaultDatabaseFactory(_connectionString, _providerName);
|
||||
var dbContext = new DatabaseContext(dbFactory);
|
||||
var dbFactory = new DefaultDatabaseFactory(_connectionString, _providerName, _logger);
|
||||
var dbContext = new DatabaseContext(dbFactory, _logger);
|
||||
Database.Mapper = new PetaPocoMapper();
|
||||
_serviceContext = new ServiceContext(
|
||||
new PetaPocoUnitOfWorkProvider(dbFactory),
|
||||
|
||||
Reference in New Issue
Block a user