Skip to content

Commit

Permalink
Merge pull request #29 from deveel/28-entity-key-type-in-repository-g…
Browse files Browse the repository at this point in the history
…eneric-type-specification

Supporting the Specification of Key Types in Repositories
  • Loading branch information
tsutomi authored Nov 2, 2023
2 parents d6c2f0d + 859754a commit 851f273
Show file tree
Hide file tree
Showing 48 changed files with 2,839 additions and 1,388 deletions.
81 changes: 2 additions & 79 deletions src/Deveel.Repository.Core/Data/IFilterableRepository_T.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,84 +22,7 @@ namespace Deveel.Data {
/// <typeparam name="TEntity">
/// The strongly typed entity that is stored in the repository
/// </typeparam>
public interface IFilterableRepository<TEntity> : IRepository<TEntity> where TEntity : class {
/// <summary>
/// Determines if at least one item in the repository exists for the
/// given filtering conditions
/// </summary>
/// <param name="filter">The filter used to identify the items</param>
/// <param name="cancellationToken"></param>
/// <returns>
/// Returns <c>true</c> if at least one item in the inventory matches the given
/// filter, otherwise returns <c>false</c>
/// </returns>
/// <exception cref="NotSupportedException">
/// Thrown if the repository does not support filtering
/// </exception>
/// <exception cref="ArgumentException">
/// Throw if the <paramref name="filter"/> is not supported by the repository
/// </exception>
Task<bool> ExistsAsync(IQueryFilter filter, CancellationToken cancellationToken = default);

/// <summary>
/// Counts the number of items in the repository matching the given
/// filtering conditions
/// </summary>
/// <param name="filter">The filter used to identify the items</param>
/// <param name="cancellationToken"></param>
/// <remarks>
/// Passing a <c>null</c> filter or passing <see cref="QueryFilter.Empty"/> as
/// argument is equivalent to ask the repository not to use any filter, returning the
/// total count of all items int the inventory.
/// </remarks>
/// <returns>
/// Returns the total count of items matching the given filtering conditions
/// </returns>
/// <exception cref="NotSupportedException">
/// Thrown if the repository does not support filtering
/// </exception>
/// <exception cref="ArgumentException">
/// Throw if the <paramref name="filter"/> is not supported by the repository
/// </exception>
Task<long> CountAsync(IQueryFilter filter, CancellationToken cancellationToken = default);

/// <summary>
/// Finds the first item in the repository that matches the given query
/// </summary>
/// <param name="query">
/// The query definition used to identify the item to return
/// and eventually sort the results.
/// </param>
/// <param name="cancellationToken">
/// A token used to cancel the operation
/// </param>
/// <returns>
/// Returns the first item in the repository that matches the given filtering condition,
/// or <c>null</c> if none of the items matches the condition.
/// </returns>
/// <exception cref="NotSupportedException">
/// Thrown if the repository does not support filtering
/// </exception>
/// <exception cref="ArgumentException">
/// Throw if the <paramref name="query"/> defines a filter or a sort rule
/// that is not supported by the repository
/// </exception>
Task<TEntity?> FindAsync(IQuery query, CancellationToken cancellationToken = default);

/// <summary>
/// Finds all the items in the repository that match the given filtering condition
/// </summary>
/// <param name="query">
/// The query definition used to identify the item to return
/// and eventually sort the results.
/// </param>
/// <param name="cancellationToken">
/// A token used to cancel the operation
/// </param>
/// <returns>
/// Returns a list of items in the repository that match the given query,
/// or an empty list if none of the items matches the condition.
/// </returns>
Task<IList<TEntity>> FindAllAsync(IQuery query, CancellationToken cancellationToken = default);
/// <seealso cref="IFilterableRepository{TEntity, TKey}"/>
public interface IFilterableRepository<TEntity> : IFilterableRepository<TEntity, object> where TEntity : class {
}
}
108 changes: 108 additions & 0 deletions src/Deveel.Repository.Core/Data/IFilterableRepository_T2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Copyright 2023 Deveel AS
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;

namespace Deveel.Data {
/// <summary>
/// Represents a repository that can be filtered to retrieve a subset of
/// the entities it contains.
/// </summary>
/// <typeparam name="TEntity">
/// The strongly typed entity that is stored in the repository
/// </typeparam>
/// <typeparam name="TKey">
/// The type of key used to identify the entity in the repository
/// </typeparam>
public interface IFilterableRepository<TEntity, TKey> : IRepository<TEntity, TKey> where TEntity : class {
/// <summary>
/// Determines if at least one item in the repository exists for the
/// given filtering conditions
/// </summary>
/// <param name="filter">The filter used to identify the items</param>
/// <param name="cancellationToken"></param>
/// <returns>
/// Returns <c>true</c> if at least one item in the inventory matches the given
/// filter, otherwise returns <c>false</c>
/// </returns>
/// <exception cref="NotSupportedException">
/// Thrown if the repository does not support filtering
/// </exception>
/// <exception cref="ArgumentException">
/// Throw if the <paramref name="filter"/> is not supported by the repository
/// </exception>
Task<bool> ExistsAsync(IQueryFilter filter, CancellationToken cancellationToken = default);

/// <summary>
/// Counts the number of items in the repository matching the given
/// filtering conditions
/// </summary>
/// <param name="filter">The filter used to identify the items</param>
/// <param name="cancellationToken"></param>
/// <remarks>
/// Passing a <c>null</c> filter or passing <see cref="QueryFilter.Empty"/> as
/// argument is equivalent to ask the repository not to use any filter, returning the
/// total count of all items int the inventory.
/// </remarks>
/// <returns>
/// Returns the total count of items matching the given filtering conditions
/// </returns>
/// <exception cref="NotSupportedException">
/// Thrown if the repository does not support filtering
/// </exception>
/// <exception cref="ArgumentException">
/// Throw if the <paramref name="filter"/> is not supported by the repository
/// </exception>
Task<long> CountAsync(IQueryFilter filter, CancellationToken cancellationToken = default);

/// <summary>
/// Finds the first item in the repository that matches the given query
/// </summary>
/// <param name="query">
/// The query definition used to identify the item to return
/// and eventually sort the results.
/// </param>
/// <param name="cancellationToken">
/// A token used to cancel the operation
/// </param>
/// <returns>
/// Returns the first item in the repository that matches the given filtering condition,
/// or <c>null</c> if none of the items matches the condition.
/// </returns>
/// <exception cref="NotSupportedException">
/// Thrown if the repository does not support filtering
/// </exception>
/// <exception cref="ArgumentException">
/// Throw if the <paramref name="query"/> defines a filter or a sort rule
/// that is not supported by the repository
/// </exception>
Task<TEntity?> FindAsync(IQuery query, CancellationToken cancellationToken = default);

/// <summary>
/// Finds all the items in the repository that match the given filtering condition
/// </summary>
/// <param name="query">
/// The query definition used to identify the item to return
/// and eventually sort the results.
/// </param>
/// <param name="cancellationToken">
/// A token used to cancel the operation
/// </param>
/// <returns>
/// Returns a list of items in the repository that match the given query,
/// or an empty list if none of the items matches the condition.
/// </returns>
Task<IList<TEntity>> FindAllAsync(IQuery query, CancellationToken cancellationToken = default);
}
}
24 changes: 24 additions & 0 deletions src/Deveel.Repository.Core/Data/IMultiTenantRepository_T.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2023 Deveel AS
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;

namespace Deveel.Data {
/// <summary>
/// Represents a repository that is capable of segregating the
/// data by the tenant that owns it.
/// </summary>
public interface IMultiTenantRepository<TEntity> : IMultiTenantRepository<TEntity, object> where TEntity : class {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ namespace Deveel.Data {
/// Represents a repository that is capable of segregating the
/// data by the tenant that owns it.
/// </summary>
public interface IMultiTenantRepository<TEntity> : IRepository<TEntity> where TEntity : class {
public interface IMultiTenantRepository<TEntity, TKey> : IRepository<TEntity, TKey> where TEntity : class {
/// <summary>
/// Gets the identifier of the tenant that owns the data
/// </summary>
string? TenantId { get; }
}
string? TenantId { get; }
}
}
22 changes: 1 addition & 21 deletions src/Deveel.Repository.Core/Data/IPageableRepository_T.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,6 @@ namespace Deveel.Data {
/// <typeparam name="TEntity">
/// The strongly typed entity that is stored in the repository
/// </typeparam>
public interface IPageableRepository<TEntity> : IRepository<TEntity> where TEntity : class {
/// <summary>
/// Gets a page of items from the repository
/// </summary>
/// <param name="request">The request to obtain a given page from the repository. This
/// object provides the number of the page, the size of the items to return, filters and
/// sorting order.</param>
/// <param name="cancellationToken"></param>
/// <returns>
/// Returns an instance of <see cref="PageResult{TEntity}"/> that provides the
/// page items and a count of total items.
/// </returns>
/// <exception cref="RepositoryException">
/// Thrown if an error occurred while retrieving the page
/// </exception>
/// <exception cref="NotSupportedException">
/// Thrown if the filters or the sorting capabilities are not provided by the
/// implementation of the repository
/// </exception>
/// <seealso cref="PageResult{TEntity}"/>
Task<PageResult<TEntity>> GetPageAsync(PageQuery<TEntity> request, CancellationToken cancellationToken = default);
public interface IPageableRepository<TEntity> : IPageableRepository<TEntity, object> where TEntity : class {
}
}
50 changes: 50 additions & 0 deletions src/Deveel.Repository.Core/Data/IPageableRepository_T2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2023 Deveel AS
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;

namespace Deveel.Data {
/// <summary>
/// Represents a repository that is capable of returning a page of items
/// of the given type contained in the underlying storage.
/// </summary>
/// <typeparam name="TEntity">
/// The strongly typed entity that is stored in the repository
/// </typeparam>
/// <typeparam name="TKey">
/// The type of the key that uniquely identifies the entity
/// </typeparam>
public interface IPageableRepository<TEntity, TKey> : IRepository<TEntity, TKey> where TEntity : class {
/// <summary>
/// Gets a page of items from the repository
/// </summary>
/// <param name="request">The request to obtain a given page from the repository. This
/// object provides the number of the page, the size of the items to return, filters and
/// sorting order.</param>
/// <param name="cancellationToken"></param>
/// <returns>
/// Returns an instance of <see cref="PageResult{TEntity}"/> that provides the
/// page items and a count of total items.
/// </returns>
/// <exception cref="RepositoryException">
/// Thrown if an error occurred while retrieving the page
/// </exception>
/// <exception cref="NotSupportedException">
/// Thrown if the filters or the sorting capabilities are not provided by the
/// implementation of the repository
/// </exception>
/// <seealso cref="PageResult{TEntity}"/>
Task<PageResult<TEntity>> GetPageAsync(PageQuery<TEntity> request, CancellationToken cancellationToken = default);
}
}
27 changes: 27 additions & 0 deletions src/Deveel.Repository.Core/Data/IQueryableRepository_T.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2023 Deveel AS
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;

namespace Deveel.Data {
/// <summary>
/// Represents a repository that is capable of being queried
/// </summary>
/// <typeparam name="TEntity">
/// The strongly typed entity that is stored in the repository
/// </typeparam>
/// <seealso cref="IQueryableRepository{TEntity, TKey}"/>
public interface IQueryableRepository<TEntity> : IQueryableRepository<TEntity, object> where TEntity : class {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ namespace Deveel.Data {
/// <typeparam name="TEntity">
/// The strongly typed entity that is stored in the repository
/// </typeparam>
public interface IQueryableRepository<TEntity> : IRepository<TEntity> where TEntity : class {
/// <typeparam name="TKey">
/// The type of the key used to uniquely identify the entity.
/// </typeparam>
public interface IQueryableRepository<TEntity, TKey> : IRepository<TEntity, TKey> where TEntity : class {
/// <summary>
/// Gets a queryable object that can be used to query the repository
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Deveel.Repository.Core/Data/IRepositoryProvider_T.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Deveel.Data {
/// <typeparam name="TEntity">
/// The type of entity handled by the repository instances
/// </typeparam>
public interface IRepositoryProvider<TEntity> where TEntity : class {
public interface IRepositoryProvider<TEntity> : IRepositoryProvider<TEntity, object> where TEntity : class {
/// <summary>
/// Gets a repository instance that is isolating the entities
/// for a tenant.
Expand All @@ -35,6 +35,6 @@ public interface IRepositoryProvider<TEntity> where TEntity : class {
/// Returns an instance of <see cref="IRepository{TEntity}"/> that
/// is isolating the entities for the given tenant.
/// </returns>
Task<IRepository<TEntity>> GetRepositoryAsync(string tenantId, CancellationToken cancellationToken = default);
new Task<IRepository<TEntity>> GetRepositoryAsync(string tenantId, CancellationToken cancellationToken = default);
}
}
Loading

0 comments on commit 851f273

Please sign in to comment.