Class ReflectionMapperUtil


  • public final class ReflectionMapperUtil
    extends java.lang.Object
    Utilities for reflective mappers. This is an internal helper class that should have been package private but as the mappers are spread across the reflect and reflect.internal package, they are not. Any method in here may change at any time.
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static java.lang.String addPropertyNamePrefix​(java.lang.String prefix, java.lang.String name)
      Add a prefix separated with '.' to a java bean property name.
      static boolean anyColumnsStartWithPrefix​(java.util.Collection<java.lang.String> columnNames, java.lang.String prefix, java.util.List<ColumnNameMatcher> columnNameMatchers)
      Returns whether any of the given column names begin with the given prefix, according to the list of column name matchers.
      static java.util.OptionalInt findColumnIndex​(java.lang.String paramName, java.util.List<java.lang.String> columnNames, java.util.List<ColumnNameMatcher> columnNameMatchers, java.util.function.Supplier<java.lang.String> debugName)
      Attempts to find the index of a specified column's mapped parameter in a list of column names
      static java.util.List<java.lang.String> getColumnNames​(java.sql.ResultSet rs)
      Deprecated.
      Use getColumnNames(ResultSet, UnaryOperator) and CaseStrategy to control name capitalization
      static java.util.List<java.lang.String> getColumnNames​(java.sql.ResultSet rs, java.util.function.UnaryOperator<java.lang.String> caseStrategy)
      Returns the name of all the columns present in the specified ResultSet.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ReflectionMapperUtil

        private ReflectionMapperUtil()
    • Method Detail

      • getColumnNames

        @Deprecated
        public static java.util.List<java.lang.String> getColumnNames​(java.sql.ResultSet rs)
                                                               throws java.sql.SQLException
        Deprecated.
        Use getColumnNames(ResultSet, UnaryOperator) and CaseStrategy to control name capitalization
        Returns the name of all the columns present in the specified ResultSet. All column names are lowercased using the system locale.
        For new code, use the getColumnNames(ResultSet, UnaryOperator) method, which allows configuring the case modification strategy.
        Parameters:
        rs - the ResultSet to get the column names of
        Returns:
        list of all the column names in rs (will contain duplicates if multiple columns have the same name)
        Throws:
        java.sql.SQLException - See ResultSet.getMetaData(), ResultSetMetaData.getColumnCount(), and ResultSetMetaData.getColumnLabel(int)
        See Also:
        getColumnNames(ResultSet, UnaryOperator)
      • getColumnNames

        public static java.util.List<java.lang.String> getColumnNames​(java.sql.ResultSet rs,
                                                                      java.util.function.UnaryOperator<java.lang.String> caseStrategy)
                                                               throws java.sql.SQLException
        Returns the name of all the columns present in the specified ResultSet. The caseStrategy operator is applied to all column names to align upper/lower case etc.
        Parameters:
        rs - the ResultSet to get the column names of
        caseStrategy - Apply a specific case strategy to the column names.
        Returns:
        list of all the column names in rs (will contain duplicates if multiple columns have the same name)
        Throws:
        java.sql.SQLException - See ResultSet.getMetaData(), ResultSetMetaData.getColumnCount(), and ResultSetMetaData.getColumnLabel(int)
        See Also:
        CaseStrategy
      • findColumnIndex

        public static java.util.OptionalInt findColumnIndex​(java.lang.String paramName,
                                                            java.util.List<java.lang.String> columnNames,
                                                            java.util.List<ColumnNameMatcher> columnNameMatchers,
                                                            java.util.function.Supplier<java.lang.String> debugName)
        Attempts to find the index of a specified column's mapped parameter in a list of column names
        Parameters:
        paramName - the name of the parameter to search for
        columnNames - list of column names to search in
        columnNameMatchers - ColumnNameMatchers to map paramName to the column names
        debugName - name of the parameter to use for debugging purposes (ie: when throwing exceptions)
        Returns:
        OptionalInt with the found index, OptionalInt.empty() otherwise.
      • anyColumnsStartWithPrefix

        public static boolean anyColumnsStartWithPrefix​(java.util.Collection<java.lang.String> columnNames,
                                                        java.lang.String prefix,
                                                        java.util.List<ColumnNameMatcher> columnNameMatchers)
        Returns whether any of the given column names begin with the given prefix, according to the list of column name matchers.
        Parameters:
        columnNames - the column names to search
        prefix - the prefix to search for
        columnNameMatchers - list of column name matchers
        Returns:
        whether any of the column names begin with the prefix
        Since:
        3.5.0
      • addPropertyNamePrefix

        public static java.lang.String addPropertyNamePrefix​(java.lang.String prefix,
                                                             java.lang.String name)
        Add a prefix separated with '.' to a java bean property name. If the prefix is empty, return the name itself.
        Parameters:
        prefix - The prefix to add to the property name. The empty string is ignored.
        name - A property name.
        Returns:
        The prefixed name.