Permalink
Browse files

Removing IDocumentStorage

  • Loading branch information...
sebastienros committed May 18, 2017
1 parent 2861793 commit fb010154d34e3a0ce3d0d5fca1e3c146cc9931a1
Showing with 257 additions and 371 deletions.
  1. +0 −19 YesSql.sln
  2. +0 −1 samples/YesSql.Samples.Performance/YesSql.Samples.Performance.csproj
  3. +8 −9 src/YesSql.Abstractions/IConfiguration.cs
  4. +11 −0 src/YesSql.Abstractions/IContentSerializer.cs
  5. +1 −1 src/YesSql.Abstractions/ISession.cs
  6. +0 −78 src/YesSql.Abstractions/Storage/IDocumentStorage.cs
  7. +0 −24 src/YesSql.Abstractions/Storage/IDocumentStorageFactory.cs
  8. +3 −0 src/YesSql.Abstractions/YesSql.Abstractions.csproj
  9. +3 −34 src/YesSql.Core/Configuration.cs
  10. +25 −0 src/YesSql.Core/Serialization/JsonContentSerializer.cs
  11. +1 −1 src/YesSql.Core/Services/DefaultQuery.cs
  12. +151 −9 src/YesSql.Core/Session.cs
  13. +30 −18 src/YesSql.Core/Store.cs
  14. +2 −0 src/YesSql.Core/YesSql.Core.csproj
  15. +1 −3 src/YesSql.Provider.MySql/MySqlDbProviderOptionsExtensions.cs
  16. +1 −2 src/YesSql.Provider.MySql/YesSql.Provider.MySql.csproj
  17. +2 −4 src/YesSql.Provider.PostgreSql/PostgreSqlDbProviderOptionsExtensions.cs
  18. +1 −2 src/YesSql.Provider.PostgreSql/YesSql.Provider.PostgreSql.csproj
  19. +1 −3 src/YesSql.Provider.SqlServer/SqlServerDbProviderOptionsExtensions.cs
  20. +1 −2 src/YesSql.Provider.SqlServer/YesSql.Provider.SqlServer.csproj
  21. +2 −4 src/YesSql.Provider.Sqlite/SqliteDbProviderOptionsExtensions.cs
  22. +1 −2 src/YesSql.Provider.Sqlite/YesSql.Provider.Sqlite.csproj
  23. +2 −143 src/YesSql.Storage.Sql/SqlDocumentStorage.cs
  24. +1 −1 src/YesSql.Storage.Sql/SqlDocumentStorageFactory.cs
  25. +3 −4 test/YesSql.Tests/CoreTests.cs
  26. +3 −5 test/YesSql.Tests/ProviderTests.cs
  27. +3 −1 test/YesSql.Tests/SqlServerTests.cs
  28. +0 −1 test/YesSql.Tests/YesSql.Tests.csproj
View
@@ -24,8 +24,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YesSql.Tests", "test\YesSql
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YesSql.Bench", "samples\YesSql.Bench\YesSql.Bench.csproj", "{54213D0E-F9D8-4293-AD78-852FC72423F9}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YesSql.Storage.Sql", "src\YesSql.Storage.Sql\YesSql.Storage.Sql.csproj", "{2BEB1EEC-2FC4-42CA-A410-5C7C6AF721B4}"
-EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YesSql.Samples.Hi", "samples\YesSql.Samples.Hi\YesSql.Samples.Hi.csproj", "{2F005B29-D46A-441F-933D-CD25A0235074}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YesSql.Samples.FullText", "samples\YesSql.Samples.FullText\YesSql.Samples.FullText.csproj", "{DC85F009-6C82-4829-9764-E328C04F023F}"
@@ -120,22 +118,6 @@ Global
{54213D0E-F9D8-4293-AD78-852FC72423F9}.Release|x64.Build.0 = Release|Any CPU
{54213D0E-F9D8-4293-AD78-852FC72423F9}.Release|x86.ActiveCfg = Release|Any CPU
{54213D0E-F9D8-4293-AD78-852FC72423F9}.Release|x86.Build.0 = Release|Any CPU
- {2BEB1EEC-2FC4-42CA-A410-5C7C6AF721B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {2BEB1EEC-2FC4-42CA-A410-5C7C6AF721B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {2BEB1EEC-2FC4-42CA-A410-5C7C6AF721B4}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
- {2BEB1EEC-2FC4-42CA-A410-5C7C6AF721B4}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
- {2BEB1EEC-2FC4-42CA-A410-5C7C6AF721B4}.Debug|x64.ActiveCfg = Debug|Any CPU
- {2BEB1EEC-2FC4-42CA-A410-5C7C6AF721B4}.Debug|x64.Build.0 = Debug|Any CPU
- {2BEB1EEC-2FC4-42CA-A410-5C7C6AF721B4}.Debug|x86.ActiveCfg = Debug|Any CPU
- {2BEB1EEC-2FC4-42CA-A410-5C7C6AF721B4}.Debug|x86.Build.0 = Debug|Any CPU
- {2BEB1EEC-2FC4-42CA-A410-5C7C6AF721B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {2BEB1EEC-2FC4-42CA-A410-5C7C6AF721B4}.Release|Any CPU.Build.0 = Release|Any CPU
- {2BEB1EEC-2FC4-42CA-A410-5C7C6AF721B4}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
- {2BEB1EEC-2FC4-42CA-A410-5C7C6AF721B4}.Release|Mixed Platforms.Build.0 = Release|Any CPU
- {2BEB1EEC-2FC4-42CA-A410-5C7C6AF721B4}.Release|x64.ActiveCfg = Release|Any CPU
- {2BEB1EEC-2FC4-42CA-A410-5C7C6AF721B4}.Release|x64.Build.0 = Release|Any CPU
- {2BEB1EEC-2FC4-42CA-A410-5C7C6AF721B4}.Release|x86.ActiveCfg = Release|Any CPU
- {2BEB1EEC-2FC4-42CA-A410-5C7C6AF721B4}.Release|x86.Build.0 = Release|Any CPU
{2F005B29-D46A-441F-933D-CD25A0235074}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2F005B29-D46A-441F-933D-CD25A0235074}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F005B29-D46A-441F-933D-CD25A0235074}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@@ -289,7 +271,6 @@ Global
{F2C23E01-C045-4D8E-997F-A9110DA5E041} = {0882456B-4A70-4895-A3AE-39B9D30A1B31}
{2E2082CC-BB43-4971-A419-3F5CE5BD2CD7} = {90072A27-51D8-4043-B4D2-940088010E69}
{54213D0E-F9D8-4293-AD78-852FC72423F9} = {0882456B-4A70-4895-A3AE-39B9D30A1B31}
- {2BEB1EEC-2FC4-42CA-A410-5C7C6AF721B4} = {0C294EC4-E6EF-4839-AD34-335C1A5112F9}
{2F005B29-D46A-441F-933D-CD25A0235074} = {0882456B-4A70-4895-A3AE-39B9D30A1B31}
{DC85F009-6C82-4829-9764-E328C04F023F} = {0882456B-4A70-4895-A3AE-39B9D30A1B31}
{975E2E2B-FFA6-4FE0-A97B-DFBD0489D5BA} = {0882456B-4A70-4895-A3AE-39B9D30A1B31}
@@ -33,6 +33,5 @@
<ItemGroup>
<ProjectReference Include="..\..\src\YesSql.Core\YesSql.Core.csproj" />
<ProjectReference Include="..\..\src\YesSql.Provider.SqlServer\YesSql.Provider.SqlServer.csproj" />
- <ProjectReference Include="..\..\src\YesSql.Storage.Sql\YesSql.Storage.Sql.csproj" />
</ItemGroup>
</Project>
@@ -1,15 +1,14 @@
-using System.Data;
+using System.Data;
using System.Data.Common;
-using YesSql.Storage;
namespace YesSql
{
public interface IConfiguration
{
IIdentifierFactory IdentifierFactory { get; set; }
- IDocumentStorageFactory DocumentStorageFactory { get; set; }
IsolationLevel IsolationLevel { get; set; }
IConnectionFactory ConnectionFactory { get; set; }
+ IContentSerializer ContentSerializer { get; set; }
string TablePrefix { get; set; }
}
@@ -21,12 +20,6 @@ public static IConfiguration SetIdentifierFactory(this IConfiguration configurat
return configuration;
}
- public static IConfiguration SetDocumentStorageFactory(this IConfiguration configuration, IDocumentStorageFactory documentStorageFactory)
- {
- configuration.DocumentStorageFactory = documentStorageFactory;
- return configuration;
- }
-
public static IConfiguration SetIsolationLevel(this IConfiguration configuration, IsolationLevel isolationLevel)
{
configuration.IsolationLevel = isolationLevel;
@@ -44,6 +37,12 @@ public static IConfiguration SetTablePrefix(this IConfiguration configuration, s
configuration.TablePrefix = tablePrefix;
return configuration;
}
+
+ public static IConfiguration SetContentSerializer(this IConfiguration configuration, IContentSerializer contentSerializer)
+ {
+ configuration.ContentSerializer = contentSerializer;
+ return configuration;
+ }
}
public class DbConnectionFactory<TDbConnection> : IConnectionFactory
@@ -0,0 +1,11 @@
+using System;
+
+namespace YesSql
+{
+ public interface IContentSerializer
+ {
+ string Serialize(object item);
+ object Deserialize(string content, Type type);
+ dynamic DeserializeDynamic(string content);
+ }
+}
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
@@ -1,78 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-
-namespace YesSql.Storage
-{
- /// <summary>
- /// Reprensents a component responsible for storing <see cref="Document"/>
- /// instances in a persistent medium.
- /// </summary>
- public interface IDocumentStorage
- {
- /// <summary>
- /// Creates a document in the store.
- /// </summary>
- Task CreateAsync(params IIdentityEntity[] documents);
-
- /// <summary>
- /// Updates a document in the store.
- /// </summary>
- Task UpdateAsync(params IIdentityEntity[] documents);
-
- /// <summary>
- /// Deletes a document from the store.
- /// </summary>
- Task DeleteAsync(params IIdentityEntity[] documents);
-
- /// <summary>
- /// Loads documents by id.
- /// </summary>
- /// <returns></returns>
- Task<IEnumerable<T>> GetAsync<T>(params int[] ids);
-
- /// <summary>
- /// Loads documents by <see cref="IIdentityEntity"/>.
- /// </summary>
- /// <returns></returns>
- Task<IEnumerable<object>> GetAsync(params IIdentityEntity[] documents);
- }
-
- public static class StorageExtensions
- {
- public static async Task<object> GetAsync(this IDocumentStorage storage, int id, Type type)
- {
- return (await storage.GetAsync(new DocumentIdentity(id, type)))?.FirstOrDefault();
- }
-
- public static async Task<T> GetAsync<T>(this IDocumentStorage storage, int id) where T : class
- {
- return (await storage.GetAsync<T>(id))?.FirstOrDefault();
- }
-
- /// <summary>
- /// Creates a document in to the store.
- /// </summary>
- public static Task CreateAsync(this IDocumentStorage storage, int id, object item)
- {
- return storage.CreateAsync(new DocumentIdentity(id, item));
- }
-
- /// <summary>
- /// Updates a document in to the store.
- /// </summary>
- public static Task UpdateAsync(this IDocumentStorage storage, int id, object item)
- {
- return storage.UpdateAsync(new DocumentIdentity(id, item));
- }
-
- /// <summary>
- /// Deletes a document from the store.
- /// </summary>
- public static Task DeleteAsync(this IDocumentStorage storage, int id, Type type)
- {
- return storage.DeleteAsync(new DocumentIdentity(id, type));
- }
- }
-}
@@ -1,24 +0,0 @@
-using System.Threading.Tasks;
-using YesSql;
-
-namespace YesSql.Storage
-{
- public interface IDocumentStorageFactory
- {
- /// <summary>
- /// Creates a new storage instance that is not shared accross clients.
- /// </summary>
- IDocumentStorage CreateDocumentStorage(ISession session, IConfiguration configuration);
-
- /// <summary>
- /// Initializes the storage, for instance creating required SQL tables.
- /// </summary>
- Task InitializeAsync(IConfiguration configuration);
-
- /// <summary>
- /// Initializes the storage , for instance creating required SQL tables.
- /// </summary>
- Task InitializeCollectionAsync(IConfiguration configuration, string collectionName);
-
- }
-}
@@ -5,6 +5,9 @@
<RootNamespace>YesSql</RootNamespace>
<VersionPrefix>2.0.0</VersionPrefix>
</PropertyGroup>
+ <ItemGroup>
+ <PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
+ </ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
<Reference Include="System.Data" />
</ItemGroup>
@@ -1,8 +1,6 @@
-using System;
using System.Data;
-using System.Data.Common;
using YesSql.Data;
-using YesSql.Storage;
+using YesSql.Serialization;
namespace YesSql
{
@@ -11,44 +9,15 @@ public class Configuration : IConfiguration
public Configuration()
{
IdentifierFactory = new DefaultIdentifierFactory();
+ ContentSerializer = new JsonContentSerializer();
IsolationLevel = IsolationLevel.ReadCommitted;
TablePrefix = "";
}
public IIdentifierFactory IdentifierFactory { get; set; }
- public IDocumentStorageFactory DocumentStorageFactory { get; set; }
public IsolationLevel IsolationLevel { get; set; }
public IConnectionFactory ConnectionFactory { get; set; }
+ public IContentSerializer ContentSerializer { get; set; }
public string TablePrefix { get; set; }
-
- public Configuration SetIdentifierFactory(IIdentifierFactory identifierFactory)
- {
- IdentifierFactory = identifierFactory;
- return this;
- }
-
- public Configuration SetDocumentStorageFactory(IDocumentStorageFactory documentStorageFactory)
- {
- DocumentStorageFactory = documentStorageFactory;
- return this;
- }
-
- public Configuration SetIsolationLevel(IsolationLevel isolationLevel)
- {
- IsolationLevel = isolationLevel;
- return this;
- }
-
- public Configuration SetConnectionFactory(IConnectionFactory connectionFactory)
- {
- ConnectionFactory = connectionFactory;
- return this;
- }
-
- public Configuration SetTablePrefix(string tablePrefix)
- {
- TablePrefix = tablePrefix;
- return this;
- }
}
}
@@ -0,0 +1,25 @@
+using Newtonsoft.Json;
+using System;
+
+namespace YesSql.Serialization
+{
+ public class JsonContentSerializer : IContentSerializer
+ {
+ private readonly static JsonSerializerSettings _jsonSettings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto };
+
+ public object Deserialize(string content, Type type)
+ {
+ return JsonConvert.DeserializeObject(content, type, _jsonSettings);
+ }
+
+ public dynamic DeserializeDynamic(string content)
+ {
+ return JsonConvert.DeserializeObject<dynamic>(content, _jsonSettings);
+ }
+
+ public string Serialize(object item)
+ {
+ return JsonConvert.SerializeObject(item, _jsonSettings);
+ }
+ }
+}
@@ -478,7 +478,7 @@ public Task<T> FirstOrDefault()
return default(T);
}
- return await _query._session.GetAsync<T>(ids[0]);
+ return (await _query._session.GetAsync<T>(ids[0])).FirstOrDefault();
}
}
Oops, something went wrong.

0 comments on commit fb01015

Please sign in to comment.