Minor code cleanup
This commit is contained in:
@@ -7,7 +7,6 @@ using System.Text;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using NPoco;
|
using NPoco;
|
||||||
using StackExchange.Profiling;
|
using StackExchange.Profiling;
|
||||||
using Umbraco.Cms.Core.Composing;
|
|
||||||
using Umbraco.Cms.Infrastructure.Migrations.Install;
|
using Umbraco.Cms.Infrastructure.Migrations.Install;
|
||||||
using Umbraco.Cms.Infrastructure.Persistence.FaultHandling;
|
using Umbraco.Cms.Infrastructure.Persistence.FaultHandling;
|
||||||
using Umbraco.Extensions;
|
using Umbraco.Extensions;
|
||||||
@@ -62,6 +61,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence
|
|||||||
_connectionRetryPolicy = connectionRetryPolicy;
|
_connectionRetryPolicy = connectionRetryPolicy;
|
||||||
_commandRetryPolicy = commandRetryPolicy;
|
_commandRetryPolicy = commandRetryPolicy;
|
||||||
_mapperCollection = mapperCollection;
|
_mapperCollection = mapperCollection;
|
||||||
|
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,6 +79,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence
|
|||||||
SqlContext = sqlContext;
|
SqlContext = sqlContext;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_bulkSqlInsertProvider = bulkSqlInsertProvider;
|
_bulkSqlInsertProvider = bulkSqlInsertProvider;
|
||||||
|
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,6 +87,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence
|
|||||||
{
|
{
|
||||||
EnableSqlTrace = EnableSqlTraceDefault;
|
EnableSqlTrace = EnableSqlTraceDefault;
|
||||||
NPocoDatabaseExtensions.ConfigureNPocoBulkExtensions();
|
NPocoDatabaseExtensions.ConfigureNPocoBulkExtensions();
|
||||||
|
|
||||||
if (_mapperCollection != null)
|
if (_mapperCollection != null)
|
||||||
{
|
{
|
||||||
Mappers.AddRange(_mapperCollection);
|
Mappers.AddRange(_mapperCollection);
|
||||||
@@ -104,11 +106,14 @@ namespace Umbraco.Cms.Infrastructure.Persistence
|
|||||||
{
|
{
|
||||||
var command = base.CreateCommand(connection, commandType, sql, args);
|
var command = base.CreateCommand(connection, commandType, sql, args);
|
||||||
|
|
||||||
if (!DatabaseType.IsSqlCe()) return command;
|
if (!DatabaseType.IsSqlCe())
|
||||||
|
return command;
|
||||||
|
|
||||||
foreach (DbParameter parameter in command.Parameters)
|
foreach (DbParameter parameter in command.Parameters)
|
||||||
|
{
|
||||||
if (parameter.Value == DBNull.Value)
|
if (parameter.Value == DBNull.Value)
|
||||||
parameter.DbType = DbType.String;
|
parameter.DbType = DbType.String;
|
||||||
|
}
|
||||||
|
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
@@ -128,17 +133,12 @@ namespace Umbraco.Cms.Infrastructure.Persistence
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string InstanceId
|
public string InstanceId =>
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
#if DEBUG_DATABASES
|
#if DEBUG_DATABASES
|
||||||
return _instanceGuid.ToString("N").Substring(0, 8) + ':' + _spid;
|
_instanceGuid.ToString("N").Substring(0, 8) + ':' + _spid;
|
||||||
#else
|
#else
|
||||||
return _instanceId ?? (_instanceId = _instanceGuid.ToString("N").Substring(0, 8));
|
_instanceId ??= _instanceGuid.ToString("N").Substring(0, 8);
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool InTransaction { get; private set; }
|
public bool InTransaction { get; private set; }
|
||||||
@@ -175,8 +175,11 @@ namespace Umbraco.Cms.Infrastructure.Persistence
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
_enableCount = value;
|
_enableCount = value;
|
||||||
|
|
||||||
if (_enableCount == false)
|
if (_enableCount == false)
|
||||||
|
{
|
||||||
SqlCount = 0;
|
SqlCount = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,11 +196,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence
|
|||||||
|
|
||||||
internal IEnumerable<CommandInfo> Commands => _commands;
|
internal IEnumerable<CommandInfo> Commands => _commands;
|
||||||
|
|
||||||
public int BulkInsertRecords<T>(IEnumerable<T> records)
|
public int BulkInsertRecords<T>(IEnumerable<T> records) => _bulkSqlInsertProvider.BulkInsertRecords(this, records);
|
||||||
{
|
|
||||||
return _bulkSqlInsertProvider.BulkInsertRecords(this, records);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the <see cref="DatabaseSchemaResult"/> for the database
|
/// Returns the <see cref="DatabaseSchemaResult"/> for the database
|
||||||
@@ -206,6 +205,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence
|
|||||||
{
|
{
|
||||||
var dbSchema = _databaseSchemaCreatorFactory.Create(this);
|
var dbSchema = _databaseSchemaCreatorFactory.Create(this);
|
||||||
var databaseSchemaValidationResult = dbSchema.ValidateSchema();
|
var databaseSchemaValidationResult = dbSchema.ValidateSchema();
|
||||||
|
|
||||||
return databaseSchemaValidationResult;
|
return databaseSchemaValidationResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,8 +263,10 @@ namespace Umbraco.Cms.Infrastructure.Persistence
|
|||||||
{
|
{
|
||||||
_logger.LogError(ex, "Exception ({InstanceId}).", InstanceId);
|
_logger.LogError(ex, "Exception ({InstanceId}).", InstanceId);
|
||||||
_logger.LogDebug("At:\r\n{StackTrace}", Environment.StackTrace);
|
_logger.LogDebug("At:\r\n{StackTrace}", Environment.StackTrace);
|
||||||
|
|
||||||
if (EnableSqlTrace == false)
|
if (EnableSqlTrace == false)
|
||||||
_logger.LogDebug("Sql:\r\n{Sql}", CommandToString(LastSQL, LastArgs));
|
_logger.LogDebug("Sql:\r\n{Sql}", CommandToString(LastSQL, LastArgs));
|
||||||
|
|
||||||
base.OnException(ex);
|
base.OnException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,22 +289,22 @@ namespace Umbraco.Cms.Infrastructure.Persistence
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
_cmd = cmd;
|
_cmd = cmd;
|
||||||
|
|
||||||
base.OnExecutingCommand(cmd);
|
base.OnExecutingCommand(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string CommandToString(DbCommand cmd)
|
private string CommandToString(DbCommand cmd) => CommandToString(cmd.CommandText, cmd.Parameters.Cast<DbParameter>().Select(x => x.Value).ToArray());
|
||||||
{
|
|
||||||
return CommandToString(cmd.CommandText, cmd.Parameters.Cast<DbParameter>().Select(x => x.Value).ToArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
private string CommandToString(string sql, object[] args)
|
private string CommandToString(string sql, object[] args)
|
||||||
{
|
{
|
||||||
var text = new StringBuilder();
|
var text = new StringBuilder();
|
||||||
#if DEBUG_DATABASES
|
#if DEBUG_DATABASES
|
||||||
text.Append(InstanceId);
|
text.Append(InstanceId);
|
||||||
text.Append(": ");
|
text.Append(": ");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
NPocoSqlExtensions.ToText(sql, args, text);
|
NPocoSqlExtensions.ToText(sql, args, text);
|
||||||
|
|
||||||
return text.ToString();
|
return text.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,11 +327,14 @@ namespace Umbraco.Cms.Infrastructure.Persistence
|
|||||||
{
|
{
|
||||||
Text = cmd.CommandText;
|
Text = cmd.CommandText;
|
||||||
var parameters = new List<ParameterInfo>();
|
var parameters = new List<ParameterInfo>();
|
||||||
foreach (IDbDataParameter parameter in cmd.Parameters) parameters.Add(new ParameterInfo(parameter));
|
foreach (IDbDataParameter parameter in cmd.Parameters)
|
||||||
|
parameters.Add(new ParameterInfo(parameter));
|
||||||
|
|
||||||
Parameters = parameters.ToArray();
|
Parameters = parameters.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Text { get; }
|
public string Text { get; }
|
||||||
|
|
||||||
public ParameterInfo[] Parameters { get; }
|
public ParameterInfo[] Parameters { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ using Umbraco.Cms.Core.Logging;
|
|||||||
using Umbraco.Cms.Core.Notifications;
|
using Umbraco.Cms.Core.Notifications;
|
||||||
using Umbraco.Cms.Core.Runtime;
|
using Umbraco.Cms.Core.Runtime;
|
||||||
using Umbraco.Cms.Core.Services;
|
using Umbraco.Cms.Core.Services;
|
||||||
using Umbraco.Cms.Infrastructure.Migrations.Install;
|
|
||||||
using Umbraco.Cms.Infrastructure.Migrations.Upgrade;
|
|
||||||
using Umbraco.Cms.Infrastructure.Persistence;
|
using Umbraco.Cms.Infrastructure.Persistence;
|
||||||
using Umbraco.Extensions;
|
using Umbraco.Extensions;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user