Skip to content

Commit

Permalink
Change abstraction points for reverse engineering so SQL Server and S…
Browse files Browse the repository at this point in the history
…Qlite don't both implement the same IMetadataReader => IModel call
  • Loading branch information
Nate McMaster committed Oct 15, 2015
1 parent f773fb4 commit 7d512b9
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace Microsoft.Data.Entity.SqlServer.Design.ReverseEngineering
{
public class SqlServerMetadataModelProvider : RelationalMetadataModelProvider
{
private readonly IMetadataReader _metadataReader;
private readonly SqlServerLiteralUtilities _sqlServerLiteralUtilities;

private const int DefaultDateTimePrecision = 7;
Expand All @@ -29,24 +28,13 @@ public SqlServerMetadataModelProvider(
[NotNull] IRelationalTypeMapper typeMapper,
[NotNull] IMetadataReader metadataReader,
[NotNull] SqlServerLiteralUtilities sqlServerLiteralUtilities)
: base(loggerFactory, typeMapper)
: base(loggerFactory, typeMapper, metadataReader)
{
Check.NotNull(metadataReader, nameof(metadataReader));
Check.NotNull(sqlServerLiteralUtilities, nameof(sqlServerLiteralUtilities));

_metadataReader = metadataReader;
_sqlServerLiteralUtilities = sqlServerLiteralUtilities;
}

public override IModel GetModel([NotNull] string connectionString, [CanBeNull] TableSelectionSet tableSelectionSet)
{
Check.NotEmpty(connectionString, nameof(connectionString));

var schemaInfo = _metadataReader.GetSchema(connectionString, tableSelectionSet ?? TableSelectionSet.InclusiveAll);

return GetModel(schemaInfo);
}

protected override PropertyBuilder AddColumn([NotNull] EntityTypeBuilder builder, [NotNull] Column column)
{
var propertyBuilder = base.AddColumn(builder, column);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.Data.Entity.Metadata.Builders;
using Microsoft.Data.Entity.Metadata.Conventions;
using Microsoft.Data.Entity.Relational.Design.Model;
using Microsoft.Data.Entity.Relational.Design.ReverseEngineering.Internal;
using Microsoft.Data.Entity.Storage;
using Microsoft.Data.Entity.Utilities;
using Microsoft.Extensions.Logging;
Expand All @@ -18,7 +19,7 @@

namespace Microsoft.Data.Entity.Relational.Design.ReverseEngineering
{
public abstract class RelationalMetadataModelProvider : MetadataModelProvider
public class RelationalMetadataModelProvider : MetadataModelProvider
{
internal static IReadOnlyList<string> IgnoredAnnotations { get; } = new List<string>
{
Expand All @@ -30,18 +31,31 @@ public abstract class RelationalMetadataModelProvider : MetadataModelProvider
private readonly Table _nullTable = new Table { };
private CSharpUniqueNamer<Table> _tableNamer;
private readonly IRelationalTypeMapper _typeMapper;
private readonly IMetadataReader _metadataReader;

protected RelationalMetadataModelProvider(
public RelationalMetadataModelProvider(
[NotNull] ILoggerFactory loggerFactory,
[NotNull] IRelationalTypeMapper typeMapper)
[NotNull] IRelationalTypeMapper typeMapper,
[NotNull] IMetadataReader metadataReader)
: base(loggerFactory)
{
Check.NotNull(typeMapper, nameof(typeMapper));
Check.NotNull(metadataReader, nameof(metadataReader));

_typeMapper = typeMapper;
_metadataReader = metadataReader;
}

protected virtual IModel GetModel([NotNull] SchemaInfo schemaInfo)
public override IModel GetModel([NotNull] string connectionString, [CanBeNull] TableSelectionSet tableSelectionSet)
{
Check.NotEmpty(connectionString, nameof(connectionString));

var schemaInfo = _metadataReader.GetSchema(connectionString, tableSelectionSet ?? TableSelectionSet.InclusiveAll);

return GetModelFromSchema(schemaInfo);
}

protected virtual IModel GetModelFromSchema([NotNull] SchemaInfo schemaInfo)
{
var modelBuilder = new ModelBuilder(new ConventionSet());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
<Compile Include="ReverseEngineering\TableSelectionSetSqliteExtensions.cs" />
<Compile Include="SqliteDesignTimeServices.cs" />
<Compile Include="ReverseEngineering\SqliteDmlParser.cs" />
<Compile Include="ReverseEngineering\SqliteMetadataModelProvider.cs" />
<Compile Include="ReverseEngineering\SqliteMetadataReader.cs" />
<None Include="project.json" />
</ItemGroup>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class SqliteDesignTimeServices
public virtual void ConfigureDesignTimeServices([NotNull] IServiceCollection serviceCollection)
{
serviceCollection
.AddSingleton<MetadataModelProvider, SqliteMetadataModelProvider>()
.AddSingleton<MetadataModelProvider, RelationalMetadataModelProvider>()
.AddSingleton<IRelationalTypeMapper, SqliteTypeMapper>()
.AddSingleton<IRelationalAnnotationProvider, SqliteAnnotationProvider>()
.AddSingleton<ConfigurationFactory, SqliteConfigurationFactory>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,18 +558,22 @@ public void Unique_names()

public class FakeMetadataModelProvider : RelationalMetadataModelProvider
{
public new IModel GetModel(SchemaInfo schemaInfo) => base.GetModel(schemaInfo);

public override IModel GetModel([NotNull] string connectionString, [CanBeNull] TableSelectionSet tableSelectionSet)
{
throw new NotImplementedException();
}
public IModel GetModel(SchemaInfo schemaInfo) => base.GetModelFromSchema(schemaInfo);

public FakeMetadataModelProvider(
[NotNull] ILoggerFactory loggerFactory)
: base(loggerFactory,
new TestTypeMapper())
new TestTypeMapper(),
new FakeMetadataReader())
{
}
}

public class FakeMetadataReader : IMetadataReader
{
public virtual SchemaInfo GetSchema([NotNull] string connectionString, [NotNull] TableSelectionSet tableSelectionSet)
{
throw new NotImplementedException();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using Microsoft.Data.Entity.Relational.Design.ReverseEngineering.Internal;
using Microsoft.Data.Entity.Relational.Design.Utilities;
using Microsoft.Data.Entity.Sqlite.Design;
using Microsoft.Data.Entity.Sqlite.Design.ReverseEngineering;
using Microsoft.Data.Entity.Sqlite.FunctionalTests;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
Expand All @@ -23,7 +22,7 @@ namespace EntityFramework.Sqlite.Design.FunctionalTests
{
public class SqliteMetadataModelProviderTest
{
private readonly SqliteMetadataModelProvider _metadataModelProvider;
private readonly RelationalMetadataModelProvider _metadataModelProvider;
private readonly SqliteTestStore _testStore;
private readonly TestLogger _logger;

Expand All @@ -44,7 +43,7 @@ public SqliteMetadataModelProviderTest()
serviceProvider.GetService<ILoggerFactory>().AddProvider(new TestLoggerProvider(_logger));

_metadataModelProvider = serviceProvider
.GetService<MetadataModelProvider>() as SqliteMetadataModelProvider;
.GetService<MetadataModelProvider>() as RelationalMetadataModelProvider;
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ namespace Microsoft.Data.Entity.Sqlite.Design
{
public class ApiConsistencyTest : ApiConsistencyTestBase
{
protected override Assembly TargetAssembly => typeof(SqliteMetadataModelProvider).Assembly;
protected override Assembly TargetAssembly => typeof(SqliteMetadataReader).Assembly;
}
}

0 comments on commit 7d512b9

Please sign in to comment.