Class SimpleRepositoryFactory

java.lang.Object
io.github.blyznytsiaorg.bibernate.dao.method.handler.SimpleRepositoryFactory

public class SimpleRepositoryFactory extends Object
Factory class for handling dynamic proxy creation and method invocations on repository interfaces. It registers repository details, collects custom repository implementations, and delegates method execution to appropriate handlers based on the repository interface and method metadata.
Since:
1.0
Author:
Blyzhnytsia Team
  • Field Details

    • CUSTOM_REPOSITORY_SHOULD_HAVE_DEFAULT_CONSTRUCTOR

      private static final String CUSTOM_REPOSITORY_SHOULD_HAVE_DEFAULT_CONSTRUCTOR
      Message for indicating that a custom repository should have a default constructor.
      See Also:
    • REPOSITORY_MEDATA

      private static final Map<String,RepositoryDetails> REPOSITORY_MEDATA
      Message for indicating a call to a method with specific details.
    • CUSTOM_REPOSITORY_IMPLEMENTATIONS

      private static final List<Object> CUSTOM_REPOSITORY_IMPLEMENTATIONS
      Message for indicating that an interface is not supported for a repository method.
    • CALL_METHOD_NAME_PARAMETERS_PARAMETER_NAMES_EXTENDS_INTERFACES

      private static final String CALL_METHOD_NAME_PARAMETERS_PARAMETER_NAMES_EXTENDS_INTERFACES
      Message for indicating a call to a method with specific details.
      See Also:
    • NOT_SUPPORTED_INTERFACE_FOR_REPOSITORY_WITH_METHOD

      private static final String NOT_SUPPORTED_INTERFACE_FOR_REPOSITORY_WITH_METHOD
      Message for indicating that an interface is not supported for a repository method.
      See Also:
    • RESOLVE_REPOSITORY_DETAILS

      private static final String RESOLVE_REPOSITORY_DETAILS
      Message for indicating the resolution of repository details for a method.
      See Also:
    • IMPLEMENTATION_FOR_METHOD_S_NOT_RESOLVED

      private static final String IMPLEMENTATION_FOR_METHOD_S_NOT_RESOLVED
      Message for indicating that an implementation for a method is not resolved.
      See Also:
    • LOOKS_LIKE_METHOD_METADATA_NOT_FOUND_FOR_METHOD

      private static final String LOOKS_LIKE_METHOD_METADATA_NOT_FOUND_FOR_METHOD
      Message for indicating that method metadata is not found for a method.
      See Also:
    • METHOD_HANDLER_CREATION

      private static final String METHOD_HANDLER_CREATION
      Message for indicating the creation of method handlers.
      See Also:
    • simpleRepositoryMethodHandlers

      private final List<SimpleRepositoryMethodHandler> simpleRepositoryMethodHandlers
  • Constructor Details

    • SimpleRepositoryFactory

      public SimpleRepositoryFactory()
      Constructs a SimpleRepositoryFactory and initializes the list of method handlers.
  • Method Details

    • registerRepository

      public <T> void registerRepository(Class<T> repositoryInterface)
      Registers a repository interface, collects custom repository implementations, and initializes repository metadata information.
      Type Parameters:
      T - The type of the repository interface.
      Parameters:
      repositoryInterface - The repository interface to be registered.
    • invoke

      public Object invoke(Object proxy, Method method, Object[] parameters)
      Invokes a method on the repository interface, delegates the execution to appropriate handlers, and returns the result.
      Parameters:
      proxy - The proxy object.
      method - The method being invoked.
      parameters - The parameters for the method invocation.
      Returns:
      The result of the method invocation.
    • collectCustomRepositoriesImplementation

      private <T> void collectCustomRepositoriesImplementation(Class<T> repositoryInterface)
      Collects implementations of custom repositories related to the provided repository interface and adds them to the list of custom repository implementations.
      Type Parameters:
      T - The type of the repository interface.
      Parameters:
      repositoryInterface - The repository interface to collect implementations for.
    • getMethodMetadataMap

      private <T> Map<String,MethodMetadata> getMethodMetadataMap(Class<T> repositoryInterface)
      Retrieves method metadata for all methods in the provided repository interface.
      Type Parameters:
      T - The type of the repository interface.
      Parameters:
      repositoryInterface - The repository interface to extract method metadata from.
      Returns:
      A map containing method names as keys and corresponding MethodMetadata instances as values.
    • getMethodMetadata

      private MethodMetadata getMethodMetadata(Method method)
      Retrieves method metadata, including return type and parameters, for the provided method.
      Parameters:
      method - The method to extract metadata from.
      Returns:
      The MethodMetadata instance representing the metadata of the given method.
    • getMethodMetadata

      private MethodMetadata getMethodMetadata(Method method, Type genericReturnType)
      Creates a MethodMetadata instance based on the provided Method and its generic return type.
      Parameters:
      method - The method for which metadata is being created.
      genericReturnType - The generic return type of the method.
      Returns:
      A MethodMetadata instance representing the metadata of the given method.