Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oracle support #440

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions YesSql.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29123.88
# Visual Studio Version 17
VisualStudioVersion = 17.1.32414.318
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{0882456B-4A70-4895-A3AE-39B9D30A1B31}"
EndProject
Expand Down Expand Up @@ -45,9 +45,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YesSql.Provider.PostgreSql"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YesSql", "src\YesSql\YesSql.csproj", "{6BAC7887-02FB-4B6F-BB5C-D6DEF9646CC6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YesSql.Filters.Abstractions", "src\YesSql.Filters.Abstractions\YesSql.Filters.Abstractions.csproj", "{348B307C-66F0-4DBE-BA96-5D9DFAB5588E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YesSql.Filters.Abstractions", "src\YesSql.Filters.Abstractions\YesSql.Filters.Abstractions.csproj", "{348B307C-66F0-4DBE-BA96-5D9DFAB5588E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YesSql.Filters.Query", "src\YesSql.Filters.Query\YesSql.Filters.Query.csproj", "{86C3967F-B817-4119-B354-B6EB1AC1F237}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YesSql.Filters.Query", "src\YesSql.Filters.Query\YesSql.Filters.Query.csproj", "{86C3967F-B817-4119-B354-B6EB1AC1F237}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YesSql.Provider.Oracle", "src\YesSql.Provider.Oracle\YesSql.Provider.Oracle.csproj", "{97F56727-60FC-406D-9EF8-3456A78CFB9D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -301,6 +303,22 @@ Global
{86C3967F-B817-4119-B354-B6EB1AC1F237}.Release|x64.Build.0 = Release|Any CPU
{86C3967F-B817-4119-B354-B6EB1AC1F237}.Release|x86.ActiveCfg = Release|Any CPU
{86C3967F-B817-4119-B354-B6EB1AC1F237}.Release|x86.Build.0 = Release|Any CPU
{97F56727-60FC-406D-9EF8-3456A78CFB9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{97F56727-60FC-406D-9EF8-3456A78CFB9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{97F56727-60FC-406D-9EF8-3456A78CFB9D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{97F56727-60FC-406D-9EF8-3456A78CFB9D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{97F56727-60FC-406D-9EF8-3456A78CFB9D}.Debug|x64.ActiveCfg = Debug|Any CPU
{97F56727-60FC-406D-9EF8-3456A78CFB9D}.Debug|x64.Build.0 = Debug|Any CPU
{97F56727-60FC-406D-9EF8-3456A78CFB9D}.Debug|x86.ActiveCfg = Debug|Any CPU
{97F56727-60FC-406D-9EF8-3456A78CFB9D}.Debug|x86.Build.0 = Debug|Any CPU
{97F56727-60FC-406D-9EF8-3456A78CFB9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{97F56727-60FC-406D-9EF8-3456A78CFB9D}.Release|Any CPU.Build.0 = Release|Any CPU
{97F56727-60FC-406D-9EF8-3456A78CFB9D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{97F56727-60FC-406D-9EF8-3456A78CFB9D}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{97F56727-60FC-406D-9EF8-3456A78CFB9D}.Release|x64.ActiveCfg = Release|Any CPU
{97F56727-60FC-406D-9EF8-3456A78CFB9D}.Release|x64.Build.0 = Release|Any CPU
{97F56727-60FC-406D-9EF8-3456A78CFB9D}.Release|x86.ActiveCfg = Release|Any CPU
{97F56727-60FC-406D-9EF8-3456A78CFB9D}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -321,6 +339,7 @@ Global
{6BAC7887-02FB-4B6F-BB5C-D6DEF9646CC6} = {0C294EC4-E6EF-4839-AD34-335C1A5112F9}
{348B307C-66F0-4DBE-BA96-5D9DFAB5588E} = {0C294EC4-E6EF-4839-AD34-335C1A5112F9}
{86C3967F-B817-4119-B354-B6EB1AC1F237} = {0C294EC4-E6EF-4839-AD34-335C1A5112F9}
{97F56727-60FC-406D-9EF8-3456A78CFB9D} = {0C294EC4-E6EF-4839-AD34-335C1A5112F9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A6AB2945-2138-42B9-8F82-FCCF4DFC8F55}
Expand Down
10 changes: 10 additions & 0 deletions pack.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
param (
[string]$solutionPath = ".\YesSql.sln",
[string]$destinationLocalNuget = "..\localNugets"
)

Remove-Item .\nupkgs -Recurse -ErrorAction Ignore
dotnet pack $solutionPath -c release -o $pwd\nupkgs --nologo --version-suffix "tpc-portal-ymaz1" -v q
Remove-Item $destinationLocalNuget -Recurse -ErrorAction Ignore
nuget init .\nupkgs $destinationLocalNuget

23 changes: 22 additions & 1 deletion src/YesSql.Abstractions/Document.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;

namespace YesSql
{
/// <summary>
/// The class stored in the Document table of a collection.
/// </summary>
public class Document
public class Document : IEquatable<Document>
{
/// <summary>
/// The unique identifier of the document in the database.
Expand All @@ -27,5 +29,24 @@ public class Document
/// This property is used to track updates, and optionally detect concurrency violations.
/// </remarks>
public long Version { get; set; }
public bool Equals(Document other)
{
if (other == null)
{
return false;
}
return Id == other.Id && Type == other.Type && Content == other.Content && Version == other.Version;
}

public override int GetHashCode()
{
var hashCode = 13;
hashCode = (hashCode * 397) ^ Id;
hashCode = (hashCode * 397) ^ (!string.IsNullOrEmpty(Type) ? Type.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (!string.IsNullOrEmpty(Content) ? Content.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (int)Version;

return hashCode;
}
}
}
2 changes: 1 addition & 1 deletion src/YesSql.Abstractions/ISession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public static class SessionExtensions
/// Loads an object by its id.
/// </summary>
/// <returns>The object or <c>null</c>.</returns>
public async static Task<T> GetAsync<T>(this ISession session, int id, string collection = null) where T : class
public static async Task<T> GetAsync<T>(this ISession session, int id, string collection = null) where T : class
{
return (await session.GetAsync<T>(new[] { id }, collection)).FirstOrDefault();
}
Expand Down
17 changes: 17 additions & 0 deletions src/YesSql.Abstractions/ISqlDialect.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Text;
using System.Threading.Tasks;
using YesSql.Indexes;

namespace YesSql
{
Expand Down Expand Up @@ -209,5 +212,19 @@ public interface ISqlDialect
/// Create a <see cref="ISqlBuilder" /> instance.
/// </summary>
ISqlBuilder CreateBuilder(string tablePrefix);

string QuoteForParameter(string parameterName);
string ParameterNamePrefix { get; }
string StatementEnd { get; }
string BatchStatementEnd { get; }
string NullString { get; }
bool IsSpecialDistinctRequired { get; }
string GetParameterName(string parameterName);
IDbCommand ConfigureCommand(IDbCommand command);
Task<int> InsertReturningReduceIndexAsync(DbConnection connection, IIndex index, string insertSql, DbTransaction transaction);
void PrepareReturningMapIndexCommand(DbCommand command);
object GetDynamicParameters(DbConnection connection, object parameters, string tableName);
object GetSafeIndexParameters(IIndex index);
string AliasKeyword { get; }
}
}
4 changes: 1 addition & 3 deletions src/YesSql.Abstractions/Indexes/DescribeContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ public IMapFor<T, TIndex> For<TIndex>() where TIndex : IIndex

public IMapFor<T, TIndex> For<TIndex, TKey>() where TIndex : IIndex
{
List<IDescribeFor> descriptors;

if (!_describes.TryGetValue(typeof(T), out descriptors))
if (!_describes.TryGetValue(typeof(T), out var descriptors))
{
descriptors = _describes[typeof(T)] = new List<IDescribeFor>();
}
Expand Down
13 changes: 5 additions & 8 deletions src/YesSql.Abstractions/Indexes/DescribeFor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class IndexDescriptor<T, TIndex, TKey> : IDescribeFor, IMapFor<T, TIndex>
private Func<object, bool> _filter;

public PropertyInfo GroupProperty { get; set; }
public Type IndexType { get { return typeof(TIndex); } }
public Type IndexType => typeof(TIndex);

public Func<object, bool> Filter => _filter;

Expand All @@ -62,13 +62,13 @@ public IGroupFor<TIndex> Map(Func<T, IEnumerable<TIndex>> map)

public IMapFor<T, TIndex> When(Func<T, bool> predicate)
{
_filter = x => predicate((T) x);
_filter = x => predicate((T)x);
return this;
}

public IGroupFor<TIndex> Map(Func<T, TIndex> map)
{
_map = x => Task.FromResult((IEnumerable<TIndex>) new[] { map(x) });
_map = x => Task.FromResult((IEnumerable<TIndex>)new[] { map(x) });
return this;
}

Expand Down Expand Up @@ -166,10 +166,7 @@ public GroupedEnumerable(object key, IEnumerable<IIndex> enumerable)
_enumerable = enumerable;
}

public TKey Key
{
get { return (TKey)_key; }
}
public TKey Key => (TKey)_key;

public IEnumerator<TIndex> GetEnumerator()
{
Expand All @@ -181,4 +178,4 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
return GetEnumerator();
}
}
}
}
6 changes: 1 addition & 5 deletions src/YesSql.Abstractions/Storage/IIdentityEntity.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System;

namespace YesSql.Storage
{
Expand Down
18 changes: 12 additions & 6 deletions src/YesSql.Core/Commands/CreateDocumentCommand.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Dapper;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Threading.Tasks;
using Dapper;
using Microsoft.Extensions.Logging;

namespace YesSql.Commands
{
Expand All @@ -24,28 +24,34 @@ public override Task ExecuteAsync(DbConnection connection, DbTransaction transac
{
var documentTable = _tableNameConvention.GetDocumentTable(Collection);

var insertCmd = $"insert into {dialect.QuoteForTableName(_tablePrefix + documentTable)} ({dialect.QuoteForColumnName("Id")}, {dialect.QuoteForColumnName("Type")}, {dialect.QuoteForColumnName("Content")}, {dialect.QuoteForColumnName("Version")}) values (@Id, @Type, @Content, @Version);";
var tableName = _tablePrefix + documentTable;
var insertCmd = "insert into " + dialect.QuoteForTableName(tableName) + " (" + dialect.QuoteForColumnName("Id") + ", " + dialect.QuoteForColumnName("Type") + ", " + dialect.QuoteForColumnName("Content") + ", " + dialect.QuoteForColumnName("Version") + ") " +
"values (" + dialect.QuoteForParameter("Id") + ", " + dialect.QuoteForParameter("Type") + ", " + dialect.QuoteForParameter("Content") + ", " + dialect.QuoteForParameter("Version") + ")" + dialect.StatementEnd;

if (logger.IsEnabled(LogLevel.Trace))
{
logger.LogTrace(insertCmd);
}

return connection.ExecuteAsync(insertCmd, Document, transaction);
var parameters = dialect.GetDynamicParameters(connection, Document, tableName);
return connection.ExecuteScalarAsync<int>(insertCmd, parameters, transaction);
}

public override bool AddToBatch(ISqlDialect dialect, List<string> queries, DbCommand batchCommand, List<Action<DbDataReader>> actions, int index)
{
var documentTable = _tableNameConvention.GetDocumentTable(Collection);
var insertCmd = $"insert into {dialect.QuoteForTableName(_tablePrefix + documentTable)} ({dialect.QuoteForColumnName("Id")}, {dialect.QuoteForColumnName("Type")}, {dialect.QuoteForColumnName("Content")}, {dialect.QuoteForColumnName("Version")}) values (@Id_{index}, @Type_{index}, @Content_{index}, @Version_{index});";
var tableName = _tablePrefix + documentTable;
var insertCmd = $"insert into {dialect.QuoteForTableName(tableName)} ({dialect.QuoteForColumnName("Id")}, " +
$"{dialect.QuoteForColumnName("Type")}, {dialect.QuoteForColumnName("Content")}, {dialect.QuoteForColumnName("Version")}) " +
$"values ({dialect.QuoteForParameter("Id")}_{index}, {dialect.QuoteForParameter("Type")}_{index}, {dialect.QuoteForParameter("Content")}_{index}, {dialect.QuoteForParameter("Version")}_{index})" + dialect.BatchStatementEnd;

queries.Add(insertCmd);

batchCommand
.AddParameter("Id_" + index, Document.Id)
.AddParameter("Type_" + index, Document.Type)
.AddParameter("Content_" + index, Document.Content)
.AddParameter("Version_" + index, Document.Version);
.AddParameter(dialect.GetParameterName("Version") + "_" + index, Document.Version);

return true;
}
Expand Down
13 changes: 5 additions & 8 deletions src/YesSql.Core/Commands/CreateIndexCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,18 @@ public override async Task ExecuteAsync(DbConnection connection, DbTransaction t
{
var command = connection.CreateCommand();
command.Transaction = transaction;
command.CommandText = sql;
command.CommandText = sql; //"update " + dialect.QuoteForTableName(_store.Configuration.TablePrefix + type.Name) + " set " + dialect.QuoteForColumnName("DocumentId") + " =" + dialect.QuoteForParameter("mapid") + " where " + dialect.QuoteForColumnName("Id") + " = " + dialect.QuoteForParameter("Id");
GetProperties(command, Index, "", dialect);
command.AddParameter($"DocumentId", Index.GetAddedDocuments().Single().Id);
dialect.PrepareReturningMapIndexCommand(command);
Index.Id = Convert.ToInt32(await command.ExecuteScalarAsync());
}
else
{
Index.Id = await connection.ExecuteScalarAsync<int>(sql, Index, transaction);

var reduceIndex = Index as ReduceIndex;
Index.Id = await dialect.InsertReturningReduceIndexAsync(connection, Index, sql, transaction);
var bridgeTableName = _store.Configuration.TableNameConvention.GetIndexTable(type, Collection) + "_" + documentTable;
var columnList = dialect.QuoteForColumnName(type.Name + "Id") + ", " + dialect.QuoteForColumnName("DocumentId");
var bridgeSql = "insert into " + dialect.QuoteForTableName(_store.Configuration.TablePrefix + bridgeTableName) + " (" + columnList + ") values (@Id, @DocumentId);";
var bridgeSql = "insert into " + dialect.QuoteForTableName(_store.Configuration.TablePrefix + bridgeTableName) + " (" + columnList + ") values (" + dialect.QuoteForParameter("Id") + ", " + dialect.QuoteForParameter("DocumentId") + ")" + dialect.StatementEnd;

if (logger.IsEnabled(LogLevel.Trace))
{
Expand Down Expand Up @@ -107,11 +106,9 @@ public override bool AddToBatch(ISqlDialect dialect, List<string> queries, DbCom
}
else
{
var reduceIndex = Index as ReduceIndex;

var bridgeTableName = _store.Configuration.TablePrefix + _store.Configuration.TableNameConvention.GetIndexTable(type, Collection) + "_" + documentTable;
var columnList = dialect.QuoteForColumnName(type.Name + "Id") + ", " + dialect.QuoteForColumnName("DocumentId");
queries.Add($"insert into {dialect.QuoteForTableName(bridgeTableName)} ({columnList}) values ({dialect.IdentityLastId}, @DocumentId_{index});");
queries.Add($"insert into {dialect.QuoteForTableName(bridgeTableName)} ({columnList}) values ({dialect.IdentityLastId}, {dialect.QuoteForParameter("DocumentId")}_{index})"+ dialect.BatchStatementEnd);
batchCommand.AddParameter($"DocumentId_{index}", _addedDocumentIds[0]);
}

Expand Down
7 changes: 5 additions & 2 deletions src/YesSql.Core/Commands/DeleteDocumentCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public DeleteDocumentCommand(Document document, IStore store, string collection)
public override Task ExecuteAsync(DbConnection connection, DbTransaction transaction, ISqlDialect dialect, ILogger logger)
{
var documentTable = _store.Configuration.TableNameConvention.GetDocumentTable(Collection);
var deleteCmd = $"delete from {dialect.QuoteForTableName(_store.Configuration.TablePrefix + documentTable)} where {dialect.QuoteForColumnName("Id")} = @Id;";
var deleteCmd = "delete from " + dialect.QuoteForTableName(_store.Configuration.TablePrefix + documentTable) + " where " + dialect.QuoteForColumnName("Id")
+ " = " + dialect.QuoteForParameter("Id") + dialect.StatementEnd;


if (logger.IsEnabled(LogLevel.Trace))
{
Expand All @@ -35,7 +37,8 @@ public override bool AddToBatch(ISqlDialect dialect, List<string> queries, DbCom
{
var documentTable = _store.Configuration.TableNameConvention.GetDocumentTable(Collection);

var deleteCmd = $"delete from {dialect.QuoteForTableName(_store.Configuration.TablePrefix + documentTable)} where {dialect.QuoteForColumnName("Id")} = @Id_{index};";
var deleteCmd = $"delete from {dialect.QuoteForTableName(_store.Configuration.TablePrefix + documentTable)} where {dialect.QuoteForColumnName("Id")} " +
$"= {dialect.QuoteForParameter("Id")}_{index}"+ dialect.BatchStatementEnd;
queries.Add(deleteCmd);
command.AddParameter($"Id_{index}", Document.Id, DbType.Int32);

Expand Down
4 changes: 2 additions & 2 deletions src/YesSql.Core/Commands/DeleteMapIndexCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public DeleteMapIndexCommand(Type indexType, int documentId, IStore store, strin

public Task ExecuteAsync(DbConnection connection, DbTransaction transaction, ISqlDialect dialect, ILogger logger )
{
var command = $"delete from {dialect.QuoteForTableName(_store.Configuration.TablePrefix + _store.Configuration.TableNameConvention.GetIndexTable(IndexType, Collection))} where {dialect.QuoteForColumnName("DocumentId")} = @Id;";
var command = $"delete from {dialect.QuoteForTableName(_store.Configuration.TablePrefix + _store.Configuration.TableNameConvention.GetIndexTable(IndexType, Collection))} where {dialect.QuoteForColumnName("DocumentId")} = " + dialect.QuoteForParameter("Id") + dialect.StatementEnd;

if (logger.IsEnabled(LogLevel.Trace))
{
Expand All @@ -39,7 +39,7 @@ public Task ExecuteAsync(DbConnection connection, DbTransaction transaction, ISq

public bool AddToBatch(ISqlDialect dialect, List<string> queries, DbCommand command, List<Action<DbDataReader>> actions, int index)
{
var sql = $"delete from {dialect.QuoteForTableName(_store.Configuration.TablePrefix + _store.Configuration.TableNameConvention.GetIndexTable(IndexType, Collection))} where {dialect.QuoteForColumnName("DocumentId")} = @Id_{index};";
var sql = $"delete from {dialect.QuoteForTableName(_store.Configuration.TablePrefix + _store.Configuration.TableNameConvention.GetIndexTable(IndexType, Collection))} where {dialect.QuoteForColumnName("DocumentId")} = {dialect.QuoteForParameter("Id")}_{index}"+ dialect.BatchStatementEnd;

queries.Add(sql);

Expand Down
Loading