Interface InstanceProvider
Contract for a factory that creates instances given a type.
Useful for resultset mapping, where each row in the resultset might require a new instance.
Implementors are suggested to employ application-specific strategies, such as having a DI container handle instance creation.
Implementations should be threadsafe.
- Since:
- 1.0.0
- Author:
- Mark Allen
-
Method Summary
Modifier and TypeMethodDescriptiondefault <T> Tprovide(StatementContext<T> statementContext, Class<T> instanceType) Provides an instance of the giveninstanceType.default <T extends Record>
TprovideRecord(StatementContext<T> statementContext, Class<T> recordType, Object... initargs) Provides an instance of the givenrecordType.
-
Method Details
-
provide
@Nonnull default <T> T provide(@Nonnull StatementContext<T> statementContext, @Nonnull Class<T> instanceType) Provides an instance of the giveninstanceType.Whether the instance is new every time or shared/reused is implementation-dependent.
- Type Parameters:
T- instance type token- Parameters:
instanceType- the type of instance to create- Returns:
- an instance of the given
instanceType
-
provideRecord
@Nonnull default <T extends Record> T provideRecord(@Nonnull StatementContext<T> statementContext, @Nonnull Class<T> recordType, @Nullable Object... initargs) Provides an instance of the givenrecordType.Whether the instance is new every time or shared/reused is implementation-dependent.
- Type Parameters:
T- instance type token- Parameters:
recordType- the type of instance to create (must be a record)initargs- values used to construct the record instance- Returns:
- an instance of the given
recordType - Since:
- 2.0.0
-