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 Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringThe prefix for the handled method (findBy).Fields inherited from interface io.github.blyznytsiaorg.bibernate.dao.method.handler.SimpleRepositoryMethodHandler
CANNOT_FIND_RESULT_FOR_S_IN_METHOD_S, CANNOT_RETURN_S_SHOULD_BE_OPTIONAL_S_OR_S, EXPECTED_SINGLE_RESULT, HANDLE_METHOD, LOOKS_LIKE_METHOD_WITHOUT_REQUIRED_PARAMETER_ID, NOT_SUPPORTED_RETURN_TYPE_FOR_METHOD_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionexecute(Method method, Object[] parameters, RepositoryDetails repositoryDetails, MethodMetadata methodMetadata) Executes the findBy method in the simple repository.booleanisMethodHandle(Method method) Checks if the given method is a findBy method.private static voiditemsIsEmpty(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.
-
Field Details
-
METHOD_NAME
The prefix for the handled method (findBy).- See Also:
-
-
Constructor Details
-
SimpleRepositoryMethodFindByHandler
public SimpleRepositoryMethodFindByHandler()
-
-
Method Details
-
isMethodHandle
Checks if the given method is a findBy method.- Specified by:
isMethodHandlein interfaceSimpleRepositoryMethodHandler- Parameters:
method- The method to check.- Returns:
trueif the method is a findBy method,falseotherwise.
-
execute
public Object execute(Method method, Object[] parameters, RepositoryDetails repositoryDetails, MethodMetadata methodMetadata) Executes the findBy method in the simple repository.- Specified by:
executein interfaceSimpleRepositoryMethodHandler- 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.
-