Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
warning-explosive committed May 13, 2024
1 parent 21ba8f5 commit 3c207fd
Show file tree
Hide file tree
Showing 95 changed files with 2,528 additions and 1,531 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ private static async Task MarkInboxAsFailed(
.ReadRequiredHeader<Id>()
.Value;

/* TODO: #205 - test it
update "Deduplication"."InboxMessage" a
set "State" = 'failed'::"Deduplication"."EnInboxMessageState"
from "Deduplication"."IntegrationMessage" b
where a."Message" = b."PrimaryKey"
and b."PrimaryKey" = '502a235e-82b3-432e-9fe0-f7f2b1bb545e'
*/

await transaction
.Update<InboxMessage>()
.Set(inbox => inbox.State.Assign(EnInboxMessageState.Failed))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,9 @@ public string Translate(QuerySourceExpression expression, int depth)
}
else
{
sb.Append('"');
sb.Append(_modelProvider.SchemaName(expression.ItemType));
sb.Append('"');
sb.Append('.');
sb.Append('"');
sb.Append(_modelProvider.TableName(expression.ItemType));
sb.Append('"');
var table = _modelProvider.Tables[expression.ItemType];

sb.Append($@"""{table.Schema}"".""{table.Name}""");
}

return sb.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ protected override async Task Commit(
IAdvancedIntegrationContext context,
CancellationToken token)
{
// TODO: #205 - test it
await (Inbox == null
? PersistInbox(context, _transaction, _endpointIdentity, EnInboxMessageState.Handled, token)
: MarkInboxAsHandled(_transaction, Inbox.PrimaryKey, token)).ConfigureAwait(false);
Expand All @@ -82,6 +83,15 @@ protected override async Task Rollback(
CancellationToken token)
{
await _transaction.Close(false, token).ConfigureAwait(false);

// TODO: #205 - test it
if (Inbox == null)
{
await using (await _transaction.OpenScope(true, token).ConfigureAwait(false))
{
await PersistInbox(context, _transaction, _endpointIdentity, EnInboxMessageState.Processing, token).ConfigureAwait(false);
}
}
}

private static Task<InboxMessage?> ReadInbox(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using AutoRegistration.Api.Attributes;
using AutoRegistration.Api.Enumerations;
using SpaceEngineers.Core.DataAccess.Orm.Sql.Migrations.Model;
using SpaceEngineers.Core.DataAccess.Orm.Sql.Model;
using Translation;

[Component(EnLifestyle.Singleton)]
internal class DatabaseColumnConstraintViewQueryProvider : ISqlViewQueryProvider<DatabaseColumnConstraint, Guid>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace SpaceEngineers.Core.DataAccess.Orm.Sql.Migrations.Postgres.Model
using AutoRegistration.Api.Attributes;
using AutoRegistration.Api.Enumerations;
using SpaceEngineers.Core.DataAccess.Orm.Sql.Migrations.Model;
using SpaceEngineers.Core.DataAccess.Orm.Sql.Model;
using Translation;

[Component(EnLifestyle.Singleton)]
internal class DatabaseColumnViewQueryProvider : ISqlViewQueryProvider<DatabaseColumn, Guid>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace SpaceEngineers.Core.DataAccess.Orm.Sql.Migrations.Postgres.Model
using AutoRegistration.Api.Attributes;
using AutoRegistration.Api.Enumerations;
using SpaceEngineers.Core.DataAccess.Orm.Sql.Migrations.Model;
using SpaceEngineers.Core.DataAccess.Orm.Sql.Model;
using Translation;

[Component(EnLifestyle.Singleton)]
internal class DatabaseEnumTypeViewQueryProvider : ISqlViewQueryProvider<DatabaseEnumType, Guid>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace SpaceEngineers.Core.DataAccess.Orm.Sql.Migrations.Postgres.Model
using AutoRegistration.Api.Attributes;
using AutoRegistration.Api.Enumerations;
using SpaceEngineers.Core.DataAccess.Orm.Sql.Migrations.Model;
using SpaceEngineers.Core.DataAccess.Orm.Sql.Model;
using Translation;

[Component(EnLifestyle.Singleton)]
internal class DatabaseFunctionViewQueryProvider : ISqlViewQueryProvider<DatabaseFunction, Guid>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using AutoRegistration.Api.Attributes;
using AutoRegistration.Api.Enumerations;
using SpaceEngineers.Core.DataAccess.Orm.Sql.Migrations.Model;
using SpaceEngineers.Core.DataAccess.Orm.Sql.Model;
using Translation;

[Component(EnLifestyle.Singleton)]
internal class DatabaseIndexViewQueryProvider : ISqlViewQueryProvider<DatabaseIndexColumn, Guid>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using AutoRegistration.Api.Attributes;
using AutoRegistration.Api.Enumerations;
using SpaceEngineers.Core.DataAccess.Orm.Sql.Migrations.Model;
using SpaceEngineers.Core.DataAccess.Orm.Sql.Model;
using Translation;

[Component(EnLifestyle.Singleton)]
internal class DatabaseSchemaViewQueryProvider : ISqlViewQueryProvider<DatabaseSchema, Guid>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace SpaceEngineers.Core.DataAccess.Orm.Sql.Migrations.Postgres.Model
using AutoRegistration.Api.Attributes;
using AutoRegistration.Api.Enumerations;
using SpaceEngineers.Core.DataAccess.Orm.Sql.Migrations.Model;
using SpaceEngineers.Core.DataAccess.Orm.Sql.Model;
using Translation;

[Component(EnLifestyle.Singleton)]
internal class DatabaseTriggerViewQueryProvider : ISqlViewQueryProvider<DatabaseTrigger, Guid>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace SpaceEngineers.Core.DataAccess.Orm.Sql.Migrations.Postgres.Model
using AutoRegistration.Api.Attributes;
using AutoRegistration.Api.Enumerations;
using SpaceEngineers.Core.DataAccess.Orm.Sql.Migrations.Model;
using SpaceEngineers.Core.DataAccess.Orm.Sql.Model;
using Translation;

[Component(EnLifestyle.Singleton)]
internal class DatabaseViewViewQueryProvider : ISqlViewQueryProvider<DatabaseView, Guid>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,11 @@ public string Translate(BinaryExpression expression, int depth)
{
sb.Append(_translator.Translate(expression.Left, depth));
sb.Append(" = ANY");
sb.Append('(');
sb.Append(_translator.Translate(expression.Right, depth + 1));
sb.Append(')');
}
else if (FunctionalOperators.ContainsKey(expression.Operator))
else if (FunctionalOperators.TryGetValue(expression.Operator, out var @operator))
{
sb.Append(FunctionalOperators[expression.Operator]);
sb.Append(@operator);
sb.Append('(');
sb.Append(_translator.Translate(expression.Left, depth));
sb.Append(", ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public string Translate(ColumnExpression expression, int depth)
{
var sb = new StringBuilder();

if (expression.Source != null)
if (expression.Source is not ParameterExpression { SkipInSql: true })
{
sb.Append(_translator.Translate(expression.Source, depth));
sb.Append('.');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
namespace SpaceEngineers.Core.DataAccess.Orm.Sql.Postgres.Translation
{
using System;
using System.Text;
using AutoRegistration.Api.Abstractions;
using AutoRegistration.Api.Attributes;
using AutoRegistration.Api.Enumerations;
using SpaceEngineers.Core.DataAccess.Orm.Sql.Translation;
using SpaceEngineers.Core.DataAccess.Orm.Sql.Translation.Expressions;

[Component(EnLifestyle.Singleton)]
internal class ColumnsChainExpressionTranslator : ISqlExpressionTranslator<ColumnsChainExpression>,
IResolvable<ISqlExpressionTranslator<ColumnsChainExpression>>,
ICollectionResolvable<ISqlExpressionTranslator>
{
private readonly ISqlExpressionTranslatorComposite _translator;

public ColumnsChainExpressionTranslator(ISqlExpressionTranslatorComposite translator)
{
_translator = translator;
}

public string Translate(ISqlExpression expression, int depth)
{
return expression is ColumnsChainExpression columnsChainExpression
? Translate(columnsChainExpression, depth)
: throw new NotSupportedException($"Unsupported sql expression type {expression.GetType()}");
}

public string Translate(ColumnsChainExpression expression, int depth)
{
var sb = new StringBuilder();

if (expression.Source is not ParameterExpression { SkipInSql: true })
{
sb.Append(_translator.Translate(expression.Source, depth));
sb.Append('.');
}

sb.Append('"');
sb.Append(expression.Name);
sb.Append('"');

return sb.ToString();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace SpaceEngineers.Core.DataAccess.Orm.Sql.Postgres.Translation
{
using System;
using System.Text;
using AutoRegistration.Api.Abstractions;
using AutoRegistration.Api.Attributes;
using AutoRegistration.Api.Enumerations;
Expand All @@ -14,10 +15,14 @@ internal class DeleteExpressionTranslator : ISqlExpressionTranslator<DeleteExpre
ICollectionResolvable<ISqlExpressionTranslator>
{
private readonly IModelProvider _modelProvider;
private readonly ISqlExpressionTranslatorComposite _translator;

public DeleteExpressionTranslator(IModelProvider modelProvider)
public DeleteExpressionTranslator(
IModelProvider modelProvider,
ISqlExpressionTranslatorComposite translator)
{
_modelProvider = modelProvider;
_translator = translator;
}

public string Translate(ISqlExpression expression, int depth)
Expand All @@ -29,9 +34,23 @@ public string Translate(ISqlExpression expression, int depth)

public string Translate(DeleteExpression expression, int depth)
{
var table = _modelProvider.Tables[expression.Type];
var sb = new StringBuilder();

return $@"DELETE FROM ""{table.Schema}"".""{table.Name}""";
var table = _modelProvider.Tables[expression.ItemType];

sb.Append(new string('\t', depth));

if (expression.FilterExpression != null)
{
sb.AppendLine($@"DELETE FROM ""{table.Schema}"".""{table.Name}""");
sb.Append(_translator.Translate(expression.FilterExpression, depth));
}
else
{
sb.Append($@"DELETE FROM ""{table.Schema}"".""{table.Name}""");
}

return sb.ToString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public string Translate(FilterExpression expression, int depth)
{
var sb = new StringBuilder();

sb.AppendLine(_translator.Translate(expression.Source, depth));
sb.Append(new string('\t', depth));
sb.AppendLine("WHERE");
sb.Append(new string('\t', depth + 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public string Translate(InsertExpression expression, int depth)
{
var sb = new StringBuilder();

var table = _modelProvider.Tables[expression.Type];
var table = _modelProvider.Tables[expression.ItemType];

sb.Append(CultureInfo.InvariantCulture, $@"INSERT INTO ""{table.Schema}"".""{table.Name}"" ");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public string Translate(OrderByExpression expression, int depth)
{
var sb = new StringBuilder();

sb.AppendLine(_translator.Translate(expression.Source, depth));
sb.Append(new string('\t', depth));
sb.AppendLine("ORDER BY");
sb.Append(new string('\t', depth + 1));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public string Translate(ISqlExpression expression, int depth)

public string Translate(ParameterExpression expression, int depth)
{
if (expression.SkipInSql)
{
return string.Empty;
}

return expression.Name;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,37 @@ public string Translate(ProjectionExpression expression, int depth)
sb.Append(new string('\t', depth));
sb.AppendLine("FROM");
sb.Append(new string('\t', depth + 1));
sb.Append(_translator.Translate(expression.Source, depth + 1));

var sourceExpression = _translator.Translate(expression.Source, depth + 1);

if (expression.FilterExpression != null
|| expression.OrderByExpression != null)
{
sb.AppendLine(sourceExpression);
}
else
{
sb.Append(sourceExpression);
}

if (expression.FilterExpression != null)
{
var filterExpression = _translator.Translate(expression.FilterExpression, depth);

if (expression.OrderByExpression != null)
{
sb.AppendLine(filterExpression);
}
else
{
sb.Append(filterExpression);
}
}

if (expression.OrderByExpression != null)
{
sb.Append(_translator.Translate(expression.OrderByExpression, depth));
}

return sb.ToString();
}
Expand Down

This file was deleted.

Loading

0 comments on commit 3c207fd

Please sign in to comment.