Package com.pyranid

Interface InstanceProvider

All Known Implementing Classes:
DefaultInstanceProvider

public 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.

Since:
1.0.0
Author:
Mark Allen
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    provide(StatementContext<T> statementContext, Class<T> instanceType)
    Provides an instance of the given instanceType.
    default <T extends Record>
    T
    provideRecord(StatementContext<T> statementContext, Class<T> recordType, Object... initargs)
    Provides an instance of the given recordType.
  • Method Details

    • provide

      @Nonnull <T> T provide(@Nonnull StatementContext<T> statementContext, @Nonnull Class<T> instanceType)
      Provides an instance of the given instanceType.

      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 given recordType.

      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