Skip to content

Commit

Permalink
feat: renamed PriceInnerRecordHandling FIRST_OCCURENCE to LOWEST_PRIC…
Browse files Browse the repository at this point in the history
…E, adapted to new way of handling transactions in proto files, refactored schema methods that were causing IDE errors
  • Loading branch information
tpz committed May 9, 2024
1 parent decd40c commit c6c3a05
Show file tree
Hide file tree
Showing 88 changed files with 521 additions and 503 deletions.
4 changes: 2 additions & 2 deletions EvitaDB.Client/Converters/Models/EvitaEnumConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public static PriceInnerRecordHandling ToPriceInnerRecordHandling(
return grpcPriceInnerRecordHandling switch
{
GrpcPriceInnerRecordHandling.None => PriceInnerRecordHandling.None,
GrpcPriceInnerRecordHandling.FirstOccurrence => PriceInnerRecordHandling.FirstOccurrence,
GrpcPriceInnerRecordHandling.LowestPrice => PriceInnerRecordHandling.LowestPrice,
GrpcPriceInnerRecordHandling.Sum => PriceInnerRecordHandling.Sum,
GrpcPriceInnerRecordHandling.Unknown => PriceInnerRecordHandling.Unknown,
_ => throw new EvitaInternalError(
Expand All @@ -264,7 +264,7 @@ public static GrpcPriceInnerRecordHandling ToGrpcPriceInnerRecordHandling(
return priceInnerRecordHandling switch
{
PriceInnerRecordHandling.None => GrpcPriceInnerRecordHandling.None,
PriceInnerRecordHandling.FirstOccurrence => GrpcPriceInnerRecordHandling.FirstOccurrence,
PriceInnerRecordHandling.LowestPrice => GrpcPriceInnerRecordHandling.LowestPrice,
PriceInnerRecordHandling.Sum => GrpcPriceInnerRecordHandling.Sum,
PriceInnerRecordHandling.Unknown => GrpcPriceInnerRecordHandling.Unknown,
_ => throw new ArgumentOutOfRangeException(nameof(priceInnerRecordHandling), priceInnerRecordHandling, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ private static GrpcGlobalAttributeSchema ToGrpcGlobalAttributeSchema(
Name = attributeSchema.Name,
Unique = EvitaEnumConverter.ToGrpcAttributeUniquenessType(attributeSchema.UniquenessType),
UniqueGlobally = EvitaEnumConverter.ToGrpcGlobalAttributeUniquenessType(attributeSchema.GlobalUniquenessType),
Filterable = attributeSchema.Filterable,
Sortable = attributeSchema.Sortable,
Localized = attributeSchema.Localized,
Nullable = attributeSchema.Nullable,
Filterable = attributeSchema.Filterable(),
Sortable = attributeSchema.Sortable(),
Localized = attributeSchema.Localized(),
Nullable = attributeSchema.Nullable(),
Type = EvitaDataTypesConverter.ToGrpcEvitaDataType(attributeSchema.Type),
IndexedDecimalPlaces = attributeSchema.IndexedDecimalPlaces,
DefaultValue = attributeSchema.DefaultValue is null
Expand Down
18 changes: 9 additions & 9 deletions EvitaDB.Client/Converters/Models/Schema/EntitySchemaConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public static GrpcEntitySchema Convert(IEntitySchema entitySchema)
Name = entitySchema.Name,
Description = entitySchema.Description,
DeprecationNotice = entitySchema.DeprecationNotice,
WithGeneratedPrimaryKey = entitySchema.WithGeneratedPrimaryKey,
WithHierarchy = entitySchema.WithHierarchy,
WithPrice = entitySchema.WithPrice,
WithGeneratedPrimaryKey = entitySchema.WithGeneratedPrimaryKey(),
WithHierarchy = entitySchema.WithHierarchy(),
WithPrice = entitySchema.WithPrice(),
IndexedPricePlaces = entitySchema.IndexedPricePlaces,
Locales = { entitySchema.Locales.Select(EvitaDataTypesConverter.ToGrpcLocale) },
Currencies = { entitySchema.Currencies.Select(EvitaDataTypesConverter.ToGrpcCurrency) },
Expand Down Expand Up @@ -266,10 +266,10 @@ private static GrpcAttributeSchema ToGrpcAttributeSchema(IAttributeSchema attrib
{
Name = attributeSchema.Name,
Unique = EvitaEnumConverter.ToGrpcAttributeUniquenessType(attributeSchema.UniquenessType),
Filterable = attributeSchema.Filterable,
Sortable = attributeSchema.Sortable,
Localized = attributeSchema.Localized,
Nullable = attributeSchema.Nullable,
Filterable = attributeSchema.Filterable(),
Sortable = attributeSchema.Sortable(),
Localized = attributeSchema.Localized(),
Nullable = attributeSchema.Nullable(),
Type = EvitaDataTypesConverter.ToGrpcEvitaDataType(attributeSchema.Type),
IndexedDecimalPlaces = attributeSchema.IndexedDecimalPlaces,
DefaultValue = attributeSchema.DefaultValue is null
Expand Down Expand Up @@ -315,8 +315,8 @@ private static GrpcAssociatedDataSchema ToGrpcAssociatedDataSchema(IAssociatedDa
{
Name = associatedDataSchema.Name,
Type = EvitaDataTypesConverter.ToGrpcEvitaAssociatedDataDataType(associatedDataSchema.Type),
Localized = associatedDataSchema.Localized,
Nullable = associatedDataSchema.Nullable,
Localized = associatedDataSchema.Localized(),
Nullable = associatedDataSchema.Nullable(),
Description = associatedDataSchema.Description,
DeprecationNotice = associatedDataSchema.DeprecationNotice
};
Expand Down
36 changes: 3 additions & 33 deletions EvitaDB.Client/EvitaClientSession.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.RegularExpressions;
using EvitaDB.Client.Converters.DataTypes;
using EvitaDB.Client.Converters.Models;
using EvitaDB.Client.Converters.Models.Data;
using EvitaDB.Client.Converters.Models.Data.Mutations;
Expand Down Expand Up @@ -893,37 +894,6 @@ public ISealedEntitySchema UpdateAndFetchEntitySchema(ModifyEntitySchemaMutation
});
}

/// <summary>
/// Terminates opened transaction - either by rollback or commit depending on <see cref="EvitaClientTransaction.RollbackOnly"/>.
/// This method throws exception only when transaction hasn't been opened.
/// </summary>
public void CloseTransaction()
{
AssertActive();
var transaction = _transactionAccessor.Value;
if (transaction is null)
throw new UnexpectedTransactionStateException("No transaction has been opened!");
DestroyTransaction();
transaction.Close();
}

/// <summary>
/// Destroys transaction reference.
/// </summary>
private void DestroyTransaction()
{
_transactionAccessor.GetAndSet(transaction =>
{
Assert.IsTrue(transaction is not null, "Transaction unexpectedly not present!");
ExecuteWithEvitaSessionService(session =>
{
session.CloseTransaction(new GrpcCloseTransactionRequest { Rollback = transaction!.RollbackOnly });
return true;
});
return null;
});
}

/// <summary>
/// Switches catalog to the <see cref="Session.CatalogState.Alive"/> state and terminates the Evita session so that next session is
/// operating in the new catalog state.
Expand Down Expand Up @@ -1307,10 +1277,10 @@ private EvitaClientTransaction CreateAndInitTransaction()
}

var grpcResponse = ExecuteWithEvitaSessionService(evitaSessionService =>
evitaSessionService.OpenTransaction(new Empty())
evitaSessionService.GetTransactionId(new Empty())
);

var tx = new EvitaClientTransaction(this, grpcResponse.TransactionId);
var tx = new EvitaClientTransaction(EvitaDataTypesConverter.ToGuid(grpcResponse.TransactionId), grpcResponse.CatalogVersion);
_transactionAccessor.GetAndSet(transaction =>
{
Assert.IsPremiseValid(transaction == null, "Transaction unexpectedly found!");
Expand Down
13 changes: 6 additions & 7 deletions EvitaDB.Client/EvitaClientTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

public class EvitaClientTransaction : IDisposable
{
private readonly EvitaClientSession _session;
private readonly long _id;
private readonly Guid _transactionId;
private readonly long _catalogVersion;
public bool RollbackOnly { get; private set; }
public bool Closed { get; private set; }

public EvitaClientTransaction(EvitaClientSession session, long id)
public EvitaClientTransaction(Guid transactionId, long catalogVersion)
{
_session = session;
_id = id;
_transactionId = transactionId;
_catalogVersion = catalogVersion;
}

public void SetRollbackOnly()
Expand All @@ -25,11 +25,10 @@ public void Close()
return;
}
Closed = true;
_session.CloseTransaction();
}

public void Dispose()
{
Close();
}
}
}
4 changes: 2 additions & 2 deletions EvitaDB.Client/Models/Data/PriceInnerRecordHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public enum PriceInnerRecordHandling
{
None,
FirstOccurrence,
LowestPrice,
Sum,
Unknown
}
}
18 changes: 9 additions & 9 deletions EvitaDB.Client/Models/Data/Structure/AssociatedData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public AssociatedData(IEntitySchema entitySchema)
throw new AttributeNotFoundException(associatedDataName, EntitySchema);
}

Assert.IsTrue(!associatedDataSchema.Localized,
Assert.IsTrue(!associatedDataSchema.Localized(),
() => ContextMissingException.LocaleForAssociatedDataContextMissing(associatedDataName));
return AssociatedDataValues.TryGetValue(new AssociatedDataKey(associatedDataName),
out AssociatedDataValue? associatedDataValue)
Expand All @@ -92,7 +92,7 @@ public AssociatedData(IEntitySchema entitySchema)
? schema
: throw new AssociatedDataNotFoundException(associatedDataName, EntitySchema);
Assert.IsTrue(
!associatedDataSchema.Localized,
!associatedDataSchema.Localized(),
() => ContextMissingException.LocaleForAssociatedDataContextMissing(associatedDataName)
);
AssociatedDataValue? associatedDataValue =
Expand Down Expand Up @@ -120,7 +120,7 @@ public AssociatedData(IEntitySchema entitySchema)
? schema
: throw new AssociatedDataNotFoundException(associatedDataName, EntitySchema);

AssociatedDataKey associatedDataKey = associatedDataSchema.Localized ?
AssociatedDataKey associatedDataKey = associatedDataSchema.Localized() ?
new AssociatedDataKey(associatedDataName, locale) :
new AssociatedDataKey(associatedDataName);

Expand Down Expand Up @@ -149,7 +149,7 @@ public AssociatedData(IEntitySchema entitySchema)
throw new AttributeNotFoundException(associatedDataName, EntitySchema);
}

Assert.IsTrue(!associatedDataSchema.Localized,
Assert.IsTrue(!associatedDataSchema.Localized(),
() => ContextMissingException.LocaleForAttributeContextMissing(associatedDataName));
return AssociatedDataValues.TryGetValue(new AssociatedDataKey(associatedDataName), out var attributeValue)
? (object[]?) attributeValue.Value
Expand All @@ -163,7 +163,7 @@ public AssociatedData(IEntitySchema entitySchema)
throw new AttributeNotFoundException(associatedDataName, EntitySchema);
}

return associatedDataSchema.Localized
return associatedDataSchema.Localized()
? null
: AssociatedDataValues.TryGetValue(new AssociatedDataKey(associatedDataName), out var associatedDataValue)
? associatedDataValue
Expand All @@ -177,7 +177,7 @@ public AssociatedData(IEntitySchema entitySchema)
throw new AttributeNotFoundException(associatedDataName, EntitySchema);
}

AssociatedDataKey associatedDataKey = associatedDataSchema.Localized
AssociatedDataKey associatedDataKey = associatedDataSchema.Localized()
? new AssociatedDataKey(associatedDataName, locale)
: new AssociatedDataKey(associatedDataName);
return AssociatedDataValues.TryGetValue(associatedDataKey, out var associatedDataValue)
Expand All @@ -192,7 +192,7 @@ public AssociatedData(IEntitySchema entitySchema)
throw new AttributeNotFoundException(associatedDataName, EntitySchema);
}

AssociatedDataKey associatedDataKey = associatedDataSchema.Localized
AssociatedDataKey associatedDataKey = associatedDataSchema.Localized()
? new AssociatedDataKey(associatedDataName, locale)
: new AssociatedDataKey(associatedDataName);
return AssociatedDataValues.TryGetValue(associatedDataKey, out var associatedDataValue)
Expand All @@ -207,7 +207,7 @@ public AssociatedData(IEntitySchema entitySchema)
throw new AttributeNotFoundException(associatedDataName, EntitySchema);
}

AssociatedDataKey associatedDataKey = associatedDataSchema.Localized
AssociatedDataKey associatedDataKey = associatedDataSchema.Localized()
? new AssociatedDataKey(associatedDataName, locale)
: new AssociatedDataKey(associatedDataName);
return AssociatedDataValues.TryGetValue(associatedDataKey, out var associatedDataValue)
Expand Down Expand Up @@ -263,7 +263,7 @@ public ISet<CultureInfo> GetAssociatedDataLocales()
throw new AttributeNotFoundException(attributeName, EntitySchema);
}

AssociatedDataKey associatedDataKeyToUse = associatedDataSchema.Localized
AssociatedDataKey associatedDataKeyToUse = associatedDataSchema.Localized()
? associatedDataKey
: associatedDataKey.Localized
? new AssociatedDataKey(attributeName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Func<string> locationResolver
attributeSchema.Type, type
)
);
if (attributeSchema.Sortable)
if (attributeSchema.Sortable())
{
Assert.IsTrue(!type.IsArray,
() => new InvalidDataTypeMutationException(
Expand All @@ -73,7 +73,7 @@ Func<string> locationResolver
if (locale == null)
{
Assert.IsTrue(
!attributeSchema.Localized,
!attributeSchema.Localized(),
() => new InvalidMutationException(
"Attribute `" + attributeName + "` in entity " + locationResolver.Invoke() +
" schema is localized and doesn't accept non-localized attributes!"
Expand All @@ -83,7 +83,7 @@ Func<string> locationResolver
else
{
Assert.IsTrue(
attributeSchema.Localized,
attributeSchema.Localized(),
() => new InvalidMutationException(
"Attribute `" + attributeName + "` in entity " + locationResolver.Invoke() +
" schema is not localized and doesn't accept localized attributes!"
Expand Down Expand Up @@ -143,4 +143,4 @@ Func<string> locationSupplier
entitySchema, attributeName, type, locale, attributeSchema, locationSupplier
);
}
}
}
14 changes: 7 additions & 7 deletions EvitaDB.Client/Models/Data/Structure/Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ IDictionary<string, TS> attributeTypes
}
}

Assert.IsTrue(!attributeSchema!.Localized,
Assert.IsTrue(!attributeSchema!.Localized(),
() => ContextMissingException.LocaleForAttributeContextMissing(attributeName));
return AttributeValues.TryGetValue(new AttributeKey(attributeName), out AttributeValue? attributeValue)
? attributeValue.Value
Expand All @@ -84,7 +84,7 @@ IDictionary<string, TS> attributeTypes
}
}

Assert.IsTrue(!attributeSchema!.Localized,
Assert.IsTrue(!attributeSchema!.Localized(),
() => ContextMissingException.LocaleForAttributeContextMissing(attributeName));
if (AttributeValues.TryGetValue(new AttributeKey(attributeName), out AttributeValue? attributeValue))
{
Expand Down Expand Up @@ -119,7 +119,7 @@ IDictionary<string, TS> attributeTypes
}
}

return attributeSchema!.Localized ? null :
return attributeSchema!.Localized() ? null :
AttributeValues.TryGetValue(new AttributeKey(attributeName), out AttributeValue? attributeValue) ? attributeValue :
null;
}
Expand All @@ -134,7 +134,7 @@ IDictionary<string, TS> attributeTypes
}
}

AttributeKey attributeKey = attributeSchema!.Localized
AttributeKey attributeKey = attributeSchema!.Localized()
? new AttributeKey(attributeName, locale)
: new AttributeKey(attributeName);

Expand All @@ -153,7 +153,7 @@ IDictionary<string, TS> attributeTypes
}
}

AttributeKey attributeKey = attributeSchema!.Localized
AttributeKey attributeKey = attributeSchema!.Localized()
? new AttributeKey(attributeName, locale)
: new AttributeKey(attributeName);
return AttributeValues.TryGetValue(attributeKey, out AttributeValue? attributeValue)
Expand All @@ -168,7 +168,7 @@ IDictionary<string, TS> attributeTypes
CreateAttributeNotFoundException(attributeName);
}

AttributeKey attributeKey = attributeSchema!.Localized
AttributeKey attributeKey = attributeSchema!.Localized()
? new AttributeKey(attributeName, locale)
: new AttributeKey(attributeName);
return AttributeValues.TryGetValue(attributeKey, out AttributeValue? attributeValue) ? attributeValue : null;
Expand Down Expand Up @@ -222,7 +222,7 @@ public ISet<CultureInfo> GetAttributeLocales()
}
}

AttributeKey attributeKeyToUse = attributeSchema!.Localized
AttributeKey attributeKeyToUse = attributeSchema!.Localized()
? attributeKey
: attributeKey.Localized ? new AttributeKey(attributeName) : attributeKey;
return AttributeValues.TryGetValue(attributeKeyToUse, out AttributeValue? attributeValue) ? attributeValue : null;
Expand Down
Loading

0 comments on commit c6c3a05

Please sign in to comment.