Class RepositoryParserUtils

java.lang.Object
io.github.blyznytsiaorg.bibernate.dao.utils.RepositoryParserUtils

public class RepositoryParserUtils extends Object
Utility class for parsing repository method names and building corresponding SQL WHERE queries.
Since:
1.0
Author:
Blyzhnytsia Team
  • Field Details

    • info

      private static final com.thoughtworks.paranamer.Paranamer info
      Paranamer instance for retrieving parameter names with consideration of annotations.
    • SUPPORTED_OPERATIONS

      private static final Set<String> SUPPORTED_OPERATIONS
      Set of supported operations for constructing SQL queries.
    • OPERATION_TO_SQL_CONDITIONS

      private static final Map<String,String> OPERATION_TO_SQL_CONDITIONS
      Mapping of supported operations to their corresponding SQL conditions.
    • PART_SQL_CONDITIONS

      private static final Set<String> PART_SQL_CONDITIONS
      Set of partial SQL conditions used in method name parsing.
    • EQ

      private static final String EQ
      String representing the equality operation in SQL.
      See Also:
    • PARAMETER

      private static final String PARAMETER
      Placeholder for parameter in SQL queries.
      See Also:
    • UNDERSCORE

      private static final String UNDERSCORE
      Underscore character used for converting camel case to underscore format.
      See Also:
    • WILL_RESOLVE_AS_REGULAR_METHOD_PARAMETERS

      private static final String WILL_RESOLVE_AS_REGULAR_METHOD_PARAMETERS
      Message indicating that a method doesn't have parameters annotated with @Param.
      See Also:
    • EMPTY

      private static final String EMPTY
      Empty string constant.
      See Also:
    • FIND_BY

      private static final String FIND_BY
      Prefix indicating the start of a find-by method in the method name.
      See Also:
    • NAME_SPLITERATOR

      private static final String NAME_SPLITERATOR
      Regular expression for splitting method names based on camel case.
      See Also:
    • WHERE

      private static final String WHERE
      Prefix for log messages related to constructing WHERE queries.
      See Also:
    • FIELDS_OPERATIONS

      private static final String FIELDS_OPERATIONS
      Log message format for debug messages containing field and operation information.
      See Also:
  • Constructor Details

    • RepositoryParserUtils

      public RepositoryParserUtils()
  • Method Details

    • buildQueryByMethodName

      public static String buildQueryByMethodName(String methodName)
      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

      private static String buildWhereQuery(Queue<String> fields, Queue<String> operations)
      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

      private static void appendSqlOperation(StringBuilder whereQuery, String currentOperation)
      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

      private static String convertToUnderscore(String originalColumnName)
      Converts a given column name to underscore format.
      Parameters:
      originalColumnName - The original column name.
      Returns:
      The column name in underscore format.
    • getParameterNames

      public static List<String> getParameterNames(AccessibleObject methodOrConstructor)
      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.