Class RepositoryParserUtils
java.lang.Object
io.github.blyznytsiaorg.bibernate.dao.utils.RepositoryParserUtils
Utility class for parsing repository method names and building corresponding SQL WHERE queries.
- Since:
- 1.0
- Author:
- Blyzhnytsia Team
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classCustom implementation ofAnnotationParanamerto handle the @Param annotation. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringEmpty string constant.private static final StringString representing the equality operation in SQL.private static final StringLog message format for debug messages containing field and operation information.private static final StringPrefix indicating the start of a find-by method in the method name.private static final com.thoughtworks.paranamer.ParanamerParanamer instance for retrieving parameter names with consideration of annotations.private static final StringRegular expression for splitting method names based on camel case.Mapping of supported operations to their corresponding SQL conditions.private static final StringPlaceholder for parameter in SQL queries.Set of partial SQL conditions used in method name parsing.Set of supported operations for constructing SQL queries.private static final StringUnderscore character used for converting camel case to underscore format.private static final StringPrefix for log messages related to constructing WHERE queries.private static final StringMessage indicating that a method doesn't have parameters annotated with @Param. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidaddFieldAndOperation(Queue<String> fields, Queue<String> operations, StringBuilder field, StringBuilder operation, String partName) Adds the current field and operation to the corresponding queues and resets the StringBuilders.private static voidaddRemainingFieldsAndOperations(Queue<String> fields, Queue<String> operations, StringBuilder field, StringBuilder operation) Adds any remaining fields and operations to their respective queues.private static voidappendSqlOperation(StringBuilder whereQuery, String currentOperation) Appends the SQL operation to the given WHERE query based on the provided operation name.static StringbuildQueryByMethodName(String methodName) Builds a WHERE query based on the provided repository method name.private static StringbuildWhereQuery(Queue<String> fields, Queue<String> operations) Constructs a WHERE query based on the provided queues of fields and operations.private static StringconvertToUnderscore(String originalColumnName) Converts a given column name to underscore format.getParameterNames(AccessibleObject methodOrConstructor) Retrieves parameter names for a given method or constructor, considering the @Param annotation.
-
Field Details
-
info
private static final com.thoughtworks.paranamer.Paranamer infoParanamer instance for retrieving parameter names with consideration of annotations. -
SUPPORTED_OPERATIONS
Set of supported operations for constructing SQL queries. -
OPERATION_TO_SQL_CONDITIONS
Mapping of supported operations to their corresponding SQL conditions. -
PART_SQL_CONDITIONS
Set of partial SQL conditions used in method name parsing. -
EQ
String representing the equality operation in SQL.- See Also:
-
PARAMETER
Placeholder for parameter in SQL queries.- See Also:
-
UNDERSCORE
Underscore character used for converting camel case to underscore format.- See Also:
-
WILL_RESOLVE_AS_REGULAR_METHOD_PARAMETERS
Message indicating that a method doesn't have parameters annotated with @Param.- See Also:
-
EMPTY
Empty string constant.- See Also:
-
FIND_BY
Prefix indicating the start of a find-by method in the method name.- See Also:
-
NAME_SPLITERATOR
Regular expression for splitting method names based on camel case.- See Also:
-
WHERE
Prefix for log messages related to constructing WHERE queries.- See Also:
-
FIELDS_OPERATIONS
Log message format for debug messages containing field and operation information.- See Also:
-
-
Constructor Details
-
RepositoryParserUtils
public RepositoryParserUtils()
-
-
Method Details
-
buildQueryByMethodName
Builds a WHERE query based on the provided repository method name.- Parameters:
methodName- The repository method name.- Returns:
- The constructed WHERE query.
-
addFieldAndOperation
private static void addFieldAndOperation(Queue<String> fields, Queue<String> operations, StringBuilder field, StringBuilder operation, String partName) Adds the current field and operation to the corresponding queues and resets the StringBuilders. If the current operation is blank, uses the provided part name as the operation.- Parameters:
fields- The queue of field names.operations- The queue of SQL operations.field- The StringBuilder representing the current field name.operation- The StringBuilder representing the current SQL operation.partName- The part name to be considered as a field or operation.
-
addRemainingFieldsAndOperations
private static void addRemainingFieldsAndOperations(Queue<String> fields, Queue<String> operations, StringBuilder field, StringBuilder operation) Adds any remaining fields and operations to their respective queues. Checks if the field and operation StringBuilders are not empty before adding.- Parameters:
fields- The queue of field names.operations- The queue of SQL operations.field- The StringBuilder representing the current field name.operation- The StringBuilder representing the current SQL operation.
-
buildWhereQuery
Constructs a WHERE query based on the provided queues of fields and operations. Converts field names to underscore format and appends corresponding SQL operations. The constructed WHERE query is logged as debug information before being returned.- Parameters:
fields- The queue of field names to be included in the WHERE query.operations- The queue of SQL operations corresponding to the fields.- Returns:
- The constructed WHERE query.
-
appendSqlOperation
Appends the SQL operation to the given WHERE query based on the provided operation name. If the operation name is null, appends a default equality operation with a placeholder parameter.- Parameters:
whereQuery- The StringBuilder representing the WHERE query being constructed.currentOperation- The operation name to be appended to the WHERE query.
-
convertToUnderscore
Converts a given column name to underscore format.- Parameters:
originalColumnName- The original column name.- Returns:
- The column name in underscore format.
-
getParameterNames
Retrieves parameter names for a given method or constructor, considering the @Param annotation.- Parameters:
methodOrConstructor- The method or constructor for which to retrieve parameter names.- Returns:
- A list of parameter names.
-