Class SimpleRepositoryMethodFindByHandler

java.lang.Object
io.github.blyznytsiaorg.bibernate.dao.method.handler.SimpleRepositoryMethodFindByHandler
All Implemented Interfaces:
SimpleRepositoryMethodHandler

public class SimpleRepositoryMethodFindByHandler extends Object implements SimpleRepositoryMethodHandler
Handler for executing the findBy methods in a simple repository. Implements the SimpleRepositoryMethodHandler interface.
Since:
1.0
Author:
Blyzhnytsia Team
  • Field Details

  • Constructor Details

    • SimpleRepositoryMethodFindByHandler

      public SimpleRepositoryMethodFindByHandler()
  • Method Details

    • isMethodHandle

      public boolean isMethodHandle(Method method)
      Checks if the given method is a findBy method.
      Specified by:
      isMethodHandle in interface SimpleRepositoryMethodHandler
      Parameters:
      method - The method to check.
      Returns:
      true if the method is a findBy method, false otherwise.
    • execute

      public Object execute(Method method, Object[] parameters, RepositoryDetails repositoryDetails, MethodMetadata methodMetadata)
      Executes the findBy method in the simple repository.
      Specified by:
      execute in interface SimpleRepositoryMethodHandler
      Parameters:
      method - The findBy method to execute.
      parameters - The parameters for the findBy method invocation.
      repositoryDetails - Details about the repository, including its name, primary key type, entity type, etc.
      methodMetadata - Metadata for the repository method, including its name, return type, and parameters.
      Returns:
      The result of the findBy method execution, a list of entities, a single entity, or an empty list based on the return type and method invocation.
    • itemsIsEmpty

      private static void itemsIsEmpty(List<?> items, String entityClass, String methodName, Object[] parameters)
      Checks if the list of items is empty and throws an exception if no results are found.
      Parameters:
      items - The list of items to check.
      entityClass - The name of the entity class.
      methodName - The name of the method.
      parameters - The parameters used in the method invocation.
      Throws:
      EntityNotFoundException - if the list of items is empty.