Interface ProjectionRepository<P extends Record & Projection<ID>,ID>
- Type Parameters:
P- the type of projection managed by this repository.ID- the type of the primary key of the projection, orVoidif the projection has no primary key.
- All Superinterfaces:
Repository
- All Known Implementing Classes:
ProjectionRepositoryImpl
ProjectionRepository relies on preview features of the Java platform:
ProjectionRepositoryrefers to one or more preview APIs:StringTemplate.
Projection repositories provide a high-level abstraction for reading projections in the database. They offer a
set of methods for reading projections, as well as querying and filtering entities based on specific criteria. The
repository interface is designed to work with entity records that implement the Projection interface,
providing a consistent and type-safe way to interact with the database.
- Since:
- 1.1
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionlongcount()Returns the number of projections in the database of the projection type supported by this repository.longCounts the number of projections identified by the provided stream of IDs using the default batch size.longCounts the number of projections identified by the provided stream of IDs, with the counting process divided into batches of the specified size.longcountByRef(Stream<Ref<P>> refs) Counts the number of projections identified by the provided stream of refs using the default batch size.longcountByRef(Stream<Ref<P>> refs, int batchSize) Counts the number of projections identified by the provided stream of refs, with the counting process divided into batches of the specified size.booleanexistsById(ID id) Checks if a projection with the specified primary key exists in the database.booleanexistsByRef(Ref<P> ref) Checks if a projection with the specified primary key exists in the database.findAll()Returns a list of all projections of the type supported by this repository.findAllById(Iterable<ID> ids) Retrieves a list of projections based on their primary keys.findAllByRef(Iterable<Ref<P>> refs) Retrieves a list of projections based on their primary keys.Retrieves a projection based on its primary key.Retrieves a projection based on its primary key.Retrieves a projection based on its primary key.Retrieves a projection based on its primary key.model()Returns the projection model associated with this repository.Creates a new ref projection instance with the specified primary key.Creates a new ref projection instance with the specified projection.QueryBuilder<P, P, ID> select()Creates a new query builder for the projection type managed by this repository.<R> QueryBuilder<P, R, ID> Creates a new query builder for the customselectType.<R> QueryBuilder<P, R, ID> select(Class<R> selectType, StringTemplatePREVIEW template) Creates a new query builder for the customselectTypeand customtemplatefor the select clause.Returns a stream of all projections of the type supported by this repository.default <R> RselectAll(ResultCallback<P, R> callback) Processes a stream of all projections of the type supported by this repository using the specified callback.selectAllById(Stream<ID> ids) Retrieves a stream of projections based on their primary keys.selectAllById(Stream<ID> ids, int batchSize) Retrieves a stream of projections based on their primary keys.default <R> RselectAllById(Stream<ID> ids, int batchSize, ResultCallback<P, R> callback) Retrieves a stream of projections based on their primary keys.default <R> RselectAllById(Stream<ID> ids, ResultCallback<P, R> callback) Processes a stream of projections corresponding to the provided IDs using the specified callback.selectAllByRef(Stream<Ref<P>> refs) Retrieves a stream of projections based on their primary keys.selectAllByRef(Stream<Ref<P>> refs, int batchSize) Retrieves a stream of projections based on their primary keys.default <R> RselectAllByRef(Stream<Ref<P>> refs, int batchSize, ResultCallback<P, R> callback) Retrieves a stream of projections based on their primary keys.default <R> RselectAllByRef(Stream<Ref<P>> refs, ResultCallback<P, R> callback) Processes a stream of projections corresponding to the provided IDs using the specified callback.Creates a new query builder for the projection type managed by this repository.Methods inherited from interface st.orm.repository.Repository
orm
-
Method Details
-
model
Returns the projection model associated with this repository.- Returns:
- the projection model.
-
ref
Creates a new ref projection instance with the specified primary key.- Parameters:
id- the primary key of the projection.- Returns:
- a ref projection instance.
-
ref
Creates a new ref projection instance with the specified projection.- Parameters:
projection- the projection.- Returns:
- a ref projection instance.
-
select
QueryBuilder<P,P, select()ID> Creates a new query builder for the projection type managed by this repository.- Returns:
- a new query builder for the projection type.
-
selectCount
QueryBuilder<P,Long, selectCount()ID> Creates a new query builder for the projection type managed by this repository.- Returns:
- a new query builder for the projection type.
-
select
Creates a new query builder for the customselectType.- Type Parameters:
R- the result type of the query.- Parameters:
selectType- the result type of the query.- Returns:
- a new query builder for the custom
selectType.
-
select
<R> QueryBuilder<P,R, selectID> (@Nonnull Class<R> selectType, @Nonnull StringTemplatePREVIEW template) Creates a new query builder for the customselectTypeand customtemplatefor the select clause.- Type Parameters:
R- the result type of the query.- Parameters:
selectType- the result type of the query.template- the custom template for the select clause.- Returns:
- a new query builder for the custom
selectType.
-
count
long count()Returns the number of projections in the database of the projection type supported by this repository.- Returns:
- the total number of projections in the database as a long value.
- Throws:
PersistenceException- if the count operation fails due to underlying database issues, such as connectivity.
-
existsById
Checks if a projection with the specified primary key exists in the database.This method determines the presence of a projection by checking if the count of projections with the given primary key is greater than zero. It leverages the
selectCountmethod, which performs a count operation on the database.- Parameters:
id- the primary key of the projection to check for existence.- Returns:
- true if a projection with the specified primary key exists, false otherwise.
- Throws:
PersistenceException- if there is an underlying database issue during the count operation.
-
existsByRef
Checks if a projection with the specified primary key exists in the database.This method determines the presence of a projection by checking if the count of projections with the given primary key is greater than zero. It leverages the
selectCountmethod, which performs a count operation on the database.- Parameters:
ref- the primary key of the projection to check for existence.- Returns:
- true if a projection with the specified primary key exists, false otherwise.
- Throws:
PersistenceException- if there is an underlying database issue during the count operation.
-
findById
Retrieves a projection based on its primary key.This method performs a lookup in the database, returning the corresponding projection if it exists.
- Parameters:
id- the primary key of the projection to retrieve.- Returns:
- the projection associated with the provided primary key. The returned projection encapsulates all relevant data as mapped by the projection model.
- Throws:
PersistenceException- if the retrieval operation fails due to underlying database issues, such as connectivity problems or query execution errors.
-
findByRef
Retrieves a projection based on its primary key.This method performs a lookup in the database, returning the corresponding projection if it exists.
- Parameters:
ref- the ref to match.- Returns:
- the projection associated with the provided primary key. The returned projection encapsulates all relevant data as mapped by the projection model.
- Throws:
PersistenceException- if the retrieval operation fails due to underlying database issues, such as connectivity problems or query execution errors.
-
getById
Retrieves a projection based on its primary key.This method performs a lookup in the database, returning the corresponding projection if it exists.
- Parameters:
id- the primary key of the projection to retrieve.- Returns:
- the projection associated with the provided primary key. The returned projection encapsulates all relevant data as mapped by the projection model.
- Throws:
NoResultException- if no projection is found matching the given primary key, indicating that there's no corresponding data in the database.PersistenceException- if the retrieval operation fails due to underlying database issues, such as connectivity problems or query execution errors.
-
getByRef
Retrieves a projection based on its primary key.This method performs a lookup in the database, returning the corresponding projection if it exists.
- Parameters:
ref- the ref to match.- Returns:
- the projection associated with the provided primary key. The returned projection encapsulates all relevant data as mapped by the projection model.
- Throws:
NoResultException- if no projection is found matching the given primary key, indicating that there's no corresponding data in the database.PersistenceException- if the retrieval operation fails due to underlying database issues, such as connectivity problems or query execution errors.
-
findAll
Returns a list of all projections of the type supported by this repository. Each element in the list represents a projection in the database, encapsulating all relevant data as mapped by the projection model.Please note: loading all projections into memory at once can be very memory-intensive if your table is large.
- Returns:
- a stream of all entities of the type supported by this repository.
- Throws:
PersistenceException- if the selection operation fails due to underlying database issues, such as connectivity.
-
findAllById
Retrieves a list of projections based on their primary keys.This method retrieves projections matching the provided IDs in batches, consolidating them into a single list. The batch-based retrieval minimizes database overhead, allowing efficient handling of larger collections of IDs. Note that the order of projections in the returned list is not guaranteed to match the order of IDs in the input collection, as the database may not preserve insertion order during retrieval.
- Parameters:
ids- the primary keys of the projections to retrieve, represented as an iterable collection.- Returns:
- a list of projections corresponding to the provided primary keys. Projections are returned without any guarantee of order alignment with the input list. If an ID does not correspond to any projection in the database, no corresponding projection will be included in the returned list.
- Throws:
PersistenceException- if the selection operation fails due to database issues, such as connectivity problems or invalid input parameters.
-
findAllByRef
Retrieves a list of projections based on their primary keys.This method retrieves projections matching the provided IDs in batches, consolidating them into a single list. The batch-based retrieval minimizes database overhead, allowing efficient handling of larger collections of IDs. Note that the order of projections in the returned list is not guaranteed to match the order of IDs in the input collection, as the database may not preserve insertion order during retrieval.
- Parameters:
refs- the primary keys of the projections to retrieve, represented as an iterable collection.- Returns:
- a list of projections corresponding to the provided primary keys. Projections are returned without any guarantee of order alignment with the input list. If an ID does not correspond to any projection in the database, no corresponding projection will be included in the returned list.
- Throws:
PersistenceException- if the selection operation fails due to database issues, such as connectivity problems or invalid input parameters.
-
selectAll
Returns a stream of all projections of the type supported by this repository. Each element in the stream represents a projection in the database, encapsulating all relevant data as mapped by the projection model.The resulting stream is lazily loaded, meaning that the projections are only retrieved from the database as they are consumed by the stream. This approach is efficient and minimizes the memory footprint, especially when dealing with large volumes of projections.
Note that calling this method does trigger the execution of the underlying query, so it should only be invoked when the query is intended to run. Since the stream holds resources open while in use, it must be closed after usage to prevent resource leaks. As the stream is AutoCloseable, it is recommended to use it within a try-with-resources block.
- Returns:
- a stream of all projections of the type supported by this repository.
- Throws:
PersistenceException- if the selection operation fails due to underlying database issues, such as connectivity.
-
selectAll
Processes a stream of all projections of the type supported by this repository using the specified callback. This method retrieves the projections and applies the provided callback to process them, returning the result produced by the callback.This method ensures efficient handling of large data sets by loading projections only as needed. It also manages lifecycle of the callback stream, automatically closing the stream after processing to prevent resource leaks.
- Type Parameters:
R- the type of result produced by the callback after processing the projections.- Parameters:
callback- aResultCallbackdefining how to process the stream of projections and produce a result.- Returns:
- the result produced by the callback's processing of the projection stream.
- Throws:
PersistenceException- if the operation fails due to underlying database issues, such as connectivity.
-
selectAllById
Retrieves a stream of projections based on their primary keys.This method executes queries in batches, depending on the number of primary keys in the specified ids stream. This optimization aims to reduce the overhead of executing multiple queries and efficiently retrieve projections. The batching strategy enhances performance, particularly when dealing with large sets of primary keys.
The resulting stream is lazily loaded, meaning that the projections are only retrieved from the database as they are consumed by the stream. This approach is efficient and minimizes the memory footprint, especially when dealing with large volumes of projections.
Note that calling this method does trigger the execution of the underlying query, so it should only be invoked when the query is intended to run. Since the stream holds resources open while in use, it must be closed after usage to prevent resource leaks. As the stream is AutoCloseable, it is recommended to use it within a try-with-resources block.
- Parameters:
ids- a stream of projection IDs to retrieve from the repository.- Returns:
- a stream of projections corresponding to the provided primary keys. The order of projections in the stream is not guaranteed to match the order of ids in the input stream. If an id does not correspond to any projection in the database, it will simply be skipped, and no corresponding projection will be included in the returned stream. If the same projection is requested multiple times, it may be included in the stream multiple times if it is part of a separate batch.
- Throws:
PersistenceException- if the selection operation fails due to underlying database issues, such as connectivity.
-
selectAllById
Processes a stream of projections corresponding to the provided IDs using the specified callback. This method retrieves projections matching the given IDs and applies the callback to process the results, returning the outcome produced by the callback.This method is designed for efficient data handling by only retrieving specified projections as needed. It also manages the lifecycle of the callback stream, automatically closing the stream after processing to prevent resource leaks.
- Type Parameters:
R- the type of result produced by the callback after processing the projections.- Parameters:
ids- a stream of projection IDs to retrieve from the repository.callback- aResultCallbackdefining how to process the stream of projections and produce a result.- Returns:
- the result produced by the callback's processing of the projection stream.
- Throws:
PersistenceException- if the operation fails due to underlying database issues, such as connectivity.
-
selectAllByRef
Retrieves a stream of projections based on their primary keys.This method executes queries in batches, depending on the number of primary keys in the specified ids stream. This optimization aims to reduce the overhead of executing multiple queries and efficiently retrieve projections. The batching strategy enhances performance, particularly when dealing with large sets of primary keys.
The resulting stream is lazily loaded, meaning that the projections are only retrieved from the database as they are consumed by the stream. This approach is efficient and minimizes the memory footprint, especially when dealing with large volumes of projections.
Note that calling this method does trigger the execution of the underlying query, so it should only be invoked when the query is intended to run. Since the stream holds resources open while in use, it must be closed after usage to prevent resource leaks. As the stream is AutoCloseable, it is recommended to use it within a try-with-resources block.
- Parameters:
refs- a stream of refs to retrieve from the repository.- Returns:
- a stream of projections corresponding to the provided primary keys. The order of projections in the stream is not guaranteed to match the order of ids in the input stream. If an id does not correspond to any projection in the database, it will simply be skipped, and no corresponding projection will be included in the returned stream. If the same projection is requested multiple times, it may be included in the stream multiple times if it is part of a separate batch.
- Throws:
PersistenceException- if the selection operation fails due to underlying database issues, such as connectivity.
-
selectAllByRef
Processes a stream of projections corresponding to the provided IDs using the specified callback. This method retrieves projections matching the given IDs and applies the callback to process the results, returning the outcome produced by the callback.This method is designed for efficient data handling by only retrieving specified projections as needed. It also manages the lifecycle of the callback stream, automatically closing the stream after processing to prevent resource leaks.
- Type Parameters:
R- the type of result produced by the callback after processing the projections.- Parameters:
refs- a stream of refs to retrieve from the repository.callback- aResultCallbackdefining how to process the stream of projections and produce a result.- Returns:
- the result produced by the callback's processing of the projection stream.
- Throws:
PersistenceException- if the operation fails due to underlying database issues, such as connectivity.
-
selectAllById
Retrieves a stream of projections based on their primary keys.This method executes queries in batches, with the batch size determined by the provided parameter. This optimization aims to reduce the overhead of executing multiple queries and efficiently retrieve projections. The batching strategy enhances performance, particularly when dealing with large sets of primary keys.
The resulting stream is lazily loaded, meaning that the projections are only retrieved from the database as they are consumed by the stream. This approach is efficient and minimizes the memory footprint, especially when dealing with large volumes of projections.
Note that calling this method does trigger the execution of the underlying query, so it should only be invoked when the query is intended to run. Since the stream holds resources open while in use, it must be closed after usage to prevent resource leaks. As the stream is AutoCloseable, it is recommended to use it within a try-with-resources block.
- Parameters:
ids- a stream of projection IDs to retrieve from the repository.batchSize- the number of primary keys to include in each batch. This parameter determines the size of the batches used to execute the selection operation. A larger batch size can improve performance, especially when dealing with large sets of primary keys.- Returns:
- a stream of projections corresponding to the provided primary keys. The order of projections in the stream is not guaranteed to match the order of ids in the input stream. If an id does not correspond to any projection in the database, it will simply be skipped, and no corresponding projection will be included in the returned stream. If the same projection is requested multiple times, it may be included in the stream multiple times if it is part of a separate batch.
- Throws:
PersistenceException- if the selection operation fails due to underlying database issues, such as connectivity.
-
selectAllById
default <R> R selectAllById(@Nonnull Stream<ID> ids, int batchSize, @Nonnull ResultCallback<P, R> callback) Retrieves a stream of projections based on their primary keys.This method executes queries in batches, with the batch size determined by the provided parameter. This optimization aims to reduce the overhead of executing multiple queries and efficiently retrieve projections. The batching strategy enhances performance, particularly when dealing with large sets of primary keys.
The resulting stream is lazily loaded, meaning that the projections are only retrieved from the database as they are consumed by the stream. This approach is efficient and minimizes the memory footprint, especially when dealing with large volumes of projections.
Note that calling this method does trigger the execution of the underlying query, so it should only be invoked when the query is intended to run. Since the stream holds resources open while in use, it must be closed after usage to prevent resource leaks. As the stream is AutoCloseable, it is recommended to use it within a try-with-resources block.
- Parameters:
batchSize- the number of primary keys to include in each batch. This parameter determines the size of the batches used to execute the selection operation. A larger batch size can improve performance, especially when dealing with large sets of primary keys.- Returns:
- a stream of projections corresponding to the provided primary keys. The order of projections in the stream is not guaranteed to match the order of ids in the input stream. If an id does not correspond to any projection in the database, it will simply be skipped, and no corresponding projection will be included in the returned stream. If the same projection is requested multiple times, it may be included in the stream multiple times if it is part of a separate batch.
- Throws:
PersistenceException- if the selection operation fails due to underlying database issues, such as connectivity.
-
selectAllByRef
Retrieves a stream of projections based on their primary keys.This method executes queries in batches, with the batch size determined by the provided parameter. This optimization aims to reduce the overhead of executing multiple queries and efficiently retrieve projections. The batching strategy enhances performance, particularly when dealing with large sets of primary keys.
The resulting stream is lazily loaded, meaning that the projections are only retrieved from the database as they are consumed by the stream. This approach is efficient and minimizes the memory footprint, especially when dealing with large volumes of projections.
Note that calling this method does trigger the execution of the underlying query, so it should only be invoked when the query is intended to run. Since the stream holds resources open while in use, it must be closed after usage to prevent resource leaks. As the stream is AutoCloseable, it is recommended to use it within a try-with-resources block.
- Parameters:
refs- a stream of refs to retrieve from the repository.batchSize- the number of primary keys to include in each batch. This parameter determines the size of the batches used to execute the selection operation. A larger batch size can improve performance, especially when dealing with large sets of primary keys.- Returns:
- a stream of projections corresponding to the provided primary keys. The order of projections in the stream is not guaranteed to match the order of refs in the input stream. If an id does not correspond to any projection in the database, it will simply be skipped, and no corresponding projection will be included in the returned stream. If the same projection is requested multiple times, it may be included in the stream multiple times if it is part of a separate batch.
- Throws:
PersistenceException- if the selection operation fails due to underlying database issues, such as connectivity.
-
selectAllByRef
default <R> R selectAllByRef(@Nonnull Stream<Ref<P>> refs, int batchSize, @Nonnull ResultCallback<P, R> callback) Retrieves a stream of projections based on their primary keys.This method executes queries in batches, with the batch size determined by the provided parameter. This optimization aims to reduce the overhead of executing multiple queries and efficiently retrieve projections. The batching strategy enhances performance, particularly when dealing with large sets of primary keys.
The resulting stream is lazily loaded, meaning that the projections are only retrieved from the database as they are consumed by the stream. This approach is efficient and minimizes the memory footprint, especially when dealing with large volumes of projections.
Note that calling this method does trigger the execution of the underlying query, so it should only be invoked when the query is intended to run. Since the stream holds resources open while in use, it must be closed after usage to prevent resource leaks. As the stream is AutoCloseable, it is recommended to use it within a try-with-resources block.
- Parameters:
batchSize- the number of primary keys to include in each batch. This parameter determines the size of the batches used to execute the selection operation. A larger batch size can improve performance, especially when dealing with large sets of primary keys.- Returns:
- a stream of projections corresponding to the provided primary keys. The order of projections in the stream is not guaranteed to match the order of refs in the input stream. If an id does not correspond to any projection in the database, it will simply be skipped, and no corresponding projection will be included in the returned stream. If the same projection is requested multiple times, it may be included in the stream multiple times if it is part of a separate batch.
- Throws:
PersistenceException- if the selection operation fails due to underlying database issues, such as connectivity.
-
countById
Counts the number of projections identified by the provided stream of IDs using the default batch size.This method calculates the total number of projections that match the provided primary keys. The counting is performed in batches, which helps optimize performance and manage database load when dealing with large sets of IDs.
- Parameters:
ids- a stream of IDs for which to count matching projections.- Returns:
- the total count of projections matching the provided IDs.
- Throws:
PersistenceException- if there is an error during the counting operation, such as connectivity issues.
-
countById
Counts the number of projections identified by the provided stream of IDs, with the counting process divided into batches of the specified size.This method performs the counting operation in batches, specified by the
batchSizeparameter. This batching approach is particularly useful for efficiently handling large volumes of IDs, reducing the overhead on the database and improving performance.- Parameters:
ids- a stream of IDs for which to count matching projections.batchSize- the size of the batches to use for the counting operation. A larger batch size can improve performance but may also increase the load on the database.- Returns:
- the total count of projections matching the provided IDs.
- Throws:
PersistenceException- if there is an error during the counting operation, such as connectivity issues.
-
countByRef
Counts the number of projections identified by the provided stream of refs using the default batch size.This method calculates the total number of projections that match the provided primary keys. The counting is performed in batches, which helps optimize performance and manage database load when dealing with large sets of IDs.
- Parameters:
refs- a stream of refs for which to count matching projections.- Returns:
- the total count of projections matching the provided IDs.
- Throws:
PersistenceException- if there is an error during the counting operation, such as connectivity issues.
-
countByRef
Counts the number of projections identified by the provided stream of refs, with the counting process divided into batches of the specified size.This method performs the counting operation in batches, specified by the
batchSizeparameter. This batching approach is particularly useful for efficiently handling large volumes of IDs, reducing the overhead on the database and improving performance.- Parameters:
refs- a stream of refs for which to count matching projections.batchSize- the size of the batches to use for the counting operation. A larger batch size can improve performance but may also increase the load on the database.- Returns:
- the total count of projections matching the provided IDs.
- Throws:
PersistenceException- if there is an error during the counting operation, such as connectivity issues.
-
ProjectionRepositorywhen preview features are enabled.