Making the Sql Syntax Providers public and changing a few names and bits for consistency.

Adding resolver for the syntax providers and wiring it up in the boot manager.
This commit is contained in:
Morten Christensen
2013-03-09 10:43:34 -01:00
parent 836b0f39c2
commit 928d92fce4
63 changed files with 308 additions and 202 deletions

View File

@@ -4,7 +4,7 @@ using System.Data;
namespace Umbraco.Core.Persistence.SqlSyntax
{
internal class DbTypes<TSyntax>
public class DbTypes<TSyntax>
where TSyntax : ISqlSyntaxProvider
{
public DbType DbType;

View File

@@ -7,21 +7,20 @@ using Umbraco.Core.Persistence.DatabaseModelDefinitions;
namespace Umbraco.Core.Persistence.SqlSyntax
{
/// <summary>
/// Static class that provides simple access to the MySql SqlSyntax Providers singleton
/// Static class that provides simple access to the MySql SqlSyntax Provider
/// </summary>
internal static class MySqlSyntax
{
public static ISqlSyntaxProvider Provider { get { return MySqlSyntaxProvider.Instance; } }
public static ISqlSyntaxProvider Provider { get { return new MySqlSyntaxProvider(); } }
}
/// <summary>
/// Represents an SqlSyntaxProvider for MySql
/// </summary>
internal class MySqlSyntaxProvider : SqlSyntaxProviderBase<MySqlSyntaxProvider>
[SqlSyntaxProviderAttribute("MySql.Data.MySqlClient")]
public class MySqlSyntaxProvider : SqlSyntaxProviderBase<MySqlSyntaxProvider>
{
public static MySqlSyntaxProvider Instance = new MySqlSyntaxProvider();
private MySqlSyntaxProvider()
public MySqlSyntaxProvider()
{
DefaultStringLength = 255;
StringLengthColumnDefinitionFormat = StringLengthUnicodeColumnDefinitionFormat;

View File

@@ -1,28 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Umbraco.Core.Persistence.DatabaseAnnotations;
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
namespace Umbraco.Core.Persistence.SqlSyntax
{
/// <summary>
/// Static class that provides simple access to the Sql CE SqlSyntax Providers singleton
/// Static class that provides simple access to the Sql CE SqlSyntax Provider
/// </summary>
internal static class SqlCeSyntax
{
public static ISqlSyntaxProvider Provider { get { return SqlCeSyntaxProvider.Instance; } }
public static ISqlSyntaxProvider Provider { get { return new SqlCeSyntaxProvider(); } }
}
/// <summary>
/// Represents an SqlSyntaxProvider for Sql Ce
/// </summary>
internal class SqlCeSyntaxProvider : SqlSyntaxProviderBase<SqlCeSyntaxProvider>
[SqlSyntaxProviderAttribute("System.Data.SqlServerCe.4.0")]
public class SqlCeSyntaxProvider : SqlSyntaxProviderBase<SqlCeSyntaxProvider>
{
public static SqlCeSyntaxProvider Instance = new SqlCeSyntaxProvider();
private SqlCeSyntaxProvider()
public SqlCeSyntaxProvider()
{
StringLengthColumnDefinitionFormat = StringLengthUnicodeColumnDefinitionFormat;
StringColumnDefinition = string.Format(StringLengthColumnDefinitionFormat, DefaultStringLength);

View File

@@ -6,21 +6,20 @@ using Umbraco.Core.Persistence.DatabaseModelDefinitions;
namespace Umbraco.Core.Persistence.SqlSyntax
{
/// <summary>
/// Static class that provides simple access to the Sql Server SqlSyntax Providers singleton
/// Static class that provides simple access to the Sql Server SqlSyntax Provider
/// </summary>
internal static class SqlServerSyntax
{
public static ISqlSyntaxProvider Provider { get { return SqlServerSyntaxProvider.Instance; } }
public static ISqlSyntaxProvider Provider { get { return new SqlServerSyntaxProvider(); } }
}
/// <summary>
/// Represents an SqlSyntaxProvider for Sql Server
/// </summary>
internal class SqlServerSyntaxProvider : SqlSyntaxProviderBase<SqlServerSyntaxProvider>
[SqlSyntaxProviderAttribute("System.Data.SqlClient")]
public class SqlServerSyntaxProvider : SqlSyntaxProviderBase<SqlServerSyntaxProvider>
{
public static SqlServerSyntaxProvider Instance = new SqlServerSyntaxProvider();
private SqlServerSyntaxProvider()
public SqlServerSyntaxProvider()
{
StringLengthColumnDefinitionFormat = StringLengthUnicodeColumnDefinitionFormat;
StringColumnDefinition = string.Format(StringLengthColumnDefinitionFormat, DefaultStringLength);

View File

@@ -3,9 +3,9 @@
namespace Umbraco.Core.Persistence.SqlSyntax
{
/// <summary>
/// Singleton to handle the configuration of an SqlSyntaxProvider
/// Singleton to handle the configuration of a SqlSyntaxProvider
/// </summary>
internal static class SyntaxConfig
public static class SqlSyntaxContext
{
private static ISqlSyntaxProvider _sqlSyntaxProvider;
@@ -16,7 +16,7 @@ namespace Umbraco.Core.Persistence.SqlSyntax
if(_sqlSyntaxProvider == null)
{
throw new ArgumentNullException("SqlSyntaxProvider",
"You must set the singleton 'Umbraco.Core.Persistence.SqlSyntax.SyntaxConfig' to use an sql syntax provider");
"You must set the singleton 'Umbraco.Core.Persistence.SqlSyntax.SqlSyntaxContext' to use an sql syntax provider");
}
return _sqlSyntaxProvider;
}

View File

@@ -0,0 +1,21 @@
using System;
namespace Umbraco.Core.Persistence.SqlSyntax
{
/// <summary>
/// Attribute for implementations of an ISqlSyntaxProvider
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class SqlSyntaxProviderAttribute : Attribute
{
public SqlSyntaxProviderAttribute(string providerName)
{
ProviderName = providerName;
}
/// <summary>
/// Gets or sets the ProviderName that corresponds to the sql syntax in a provider.
/// </summary>
public string ProviderName { get; set; }
}
}

View File

@@ -15,7 +15,7 @@ namespace Umbraco.Core.Persistence.SqlSyntax
/// All Sql Syntax provider implementations should derive from this abstract class.
/// </remarks>
/// <typeparam name="TSyntax"></typeparam>
internal abstract class SqlSyntaxProviderBase<TSyntax> : ISqlSyntaxProvider
public abstract class SqlSyntaxProviderBase<TSyntax> : ISqlSyntaxProvider
where TSyntax : ISqlSyntaxProvider
{
protected SqlSyntaxProviderBase()

View File

@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.ObjectResolution;
namespace Umbraco.Core.Persistence.SqlSyntax
{
/// <summary>
/// A resolver to return all ISqlSyntaxProvider objects
/// </summary>
internal sealed class SqlSyntaxProvidersResolver : ManyObjectsResolverBase<SqlSyntaxProvidersResolver, ISqlSyntaxProvider>
{
/// <summary>
/// Constructor
/// </summary>
/// <param name="syntaxProviders"></param>
internal SqlSyntaxProvidersResolver(IEnumerable<Type> syntaxProviders)
: base(syntaxProviders)
{
}
/// <summary>
/// Gets the <see cref="ISqlSyntaxProvider"/> implementations.
/// </summary>
public IEnumerable<ISqlSyntaxProvider> SqlSyntaxProviders
{
get
{
return Values;
}
}
/// <summary>
/// Gets a <see cref="ISqlSyntaxProvider"/> by its attributed provider.
/// </summary>
/// <param name="providerName">ProviderName from the ConnectionString settings</param>
/// <returns><see cref="ISqlSyntaxProvider"/> that corresponds to the attributed provider or the default Sql Server Syntax Provider.</returns>
public ISqlSyntaxProvider GetByProviderNameOrDefault(string providerName)
{
var provider =
Values.FirstOrDefault(
x =>
x.GetType()
.FirstAttribute<SqlSyntaxProviderAttribute>()
.ProviderName.ToLowerInvariant()
.Equals(providerName.ToLowerInvariant()));
if (provider != null)
return provider;
return Values.First(x => x.GetType() == typeof (SqlServerSyntaxProvider));
}
}
}