Package com.opencsv

Class ResultSetHelperService

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.lang.String applyFormatter​(java.text.NumberFormat formatter, java.lang.Number value)  
      java.lang.String[] getColumnNames​(java.sql.ResultSet rs)
      Returns the column names from the ResultSet.
      private java.lang.String getColumnValue​(java.sql.ResultSet rs, int colType, int colIndex, boolean trim, java.lang.String dateFormatString, java.lang.String timestampFormatString)  
      java.lang.String[] getColumnValues​(java.sql.ResultSet rs)
      Returns the column values from the result set.
      java.lang.String[] getColumnValues​(java.sql.ResultSet rs, boolean trim)
      Returns the column values from the result set with the values trimmed if desired.
      java.lang.String[] getColumnValues​(java.sql.ResultSet rs, boolean trim, java.lang.String dateFormatString, java.lang.String timeFormatString)
      Returns the column values from the result set with the values trimmed if desired.
      protected java.lang.String handleClob​(java.sql.ResultSet rs, int colIndex)
      retrieves the data out of a CLOB
      protected java.lang.String handleDate​(java.sql.ResultSet rs, int colIndex, java.lang.String dateFormatString)
      retrieves an date from a result set
      protected java.lang.String handleNClob​(java.sql.ResultSet rs, int colIndex)
      retrieves the data out of a NCLOB
      protected java.lang.String handleNVarChar​(java.sql.ResultSet rs, int colIndex, boolean trim)
      retrieves the data from an NVarChar in a result set
      protected java.lang.String handleTimestamp​(java.sql.Timestamp timestamp, java.lang.String timestampFormatString)
      The formatted timestamp.
      protected java.lang.String handleVarChar​(java.sql.ResultSet rs, int colIndex, boolean trim)
      retrieves the data from an VarChar in a result set
      void setDateFormat​(java.lang.String dateFormat)
      Set a default date format pattern that will be used by the service.
      void setDateTimeFormat​(java.lang.String dateTimeFormat)
      Set a default date time format pattern that will be used by the service.
      void setFloatingPointFormat​(java.text.NumberFormat format)
      Set a default number formatter for integer numbers that will be used by the service.
      void setIntegerFormat​(java.text.NumberFormat format)
      Set a default number formatter for floating point numbers that will be used by the service.
      • Methods inherited from class java.lang.Object

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

      • DEFAULT_TIMESTAMP_FORMAT

        static final java.lang.String DEFAULT_TIMESTAMP_FORMAT
        See Also:
        Constant Field Values
      • dateFormat

        protected java.lang.String dateFormat
      • dateTimeFormat

        protected java.lang.String dateTimeFormat
      • integerFormat

        protected java.text.NumberFormat integerFormat
      • floatingPointFormat

        protected java.text.NumberFormat floatingPointFormat
    • Constructor Detail

      • ResultSetHelperService

        public ResultSetHelperService()
        Default constructor.
    • Method Detail

      • setDateFormat

        public void setDateFormat​(java.lang.String dateFormat)
        Set a default date format pattern that will be used by the service.
        Parameters:
        dateFormat - Desired date format
      • setDateTimeFormat

        public void setDateTimeFormat​(java.lang.String dateTimeFormat)
        Set a default date time format pattern that will be used by the service.
        Parameters:
        dateTimeFormat - Desired date time format
      • setIntegerFormat

        public void setIntegerFormat​(java.text.NumberFormat format)
        Set a default number formatter for floating point numbers that will be used by the service.
        Parameters:
        format - Desired number format. Should not be null
      • setFloatingPointFormat

        public void setFloatingPointFormat​(java.text.NumberFormat format)
        Set a default number formatter for integer numbers that will be used by the service.
        Parameters:
        format - Desired number format. Should not be null
      • getColumnNames

        public java.lang.String[] getColumnNames​(java.sql.ResultSet rs)
                                          throws java.sql.SQLException
        Description copied from interface: ResultSetHelper
        Returns the column names from the ResultSet.
        Specified by:
        getColumnNames in interface ResultSetHelper
        Parameters:
        rs - ResultSet
        Returns:
        String array containing the column names.
        Throws:
        java.sql.SQLException - Thrown by the ResultSet.
      • getColumnValues

        public java.lang.String[] getColumnValues​(java.sql.ResultSet rs)
                                           throws java.sql.SQLException,
                                                  java.io.IOException
        Description copied from interface: ResultSetHelper
        Returns the column values from the result set.
        Specified by:
        getColumnValues in interface ResultSetHelper
        Parameters:
        rs - The ResultSet containing the values.
        Returns:
        String array containing the values.
        Throws:
        java.sql.SQLException - Thrown by the ResultSet.
        java.io.IOException - Thrown by the ResultSet.
      • getColumnValues

        public java.lang.String[] getColumnValues​(java.sql.ResultSet rs,
                                                  boolean trim)
                                           throws java.sql.SQLException,
                                                  java.io.IOException
        Description copied from interface: ResultSetHelper
        Returns the column values from the result set with the values trimmed if desired.
        Specified by:
        getColumnValues in interface ResultSetHelper
        Parameters:
        rs - The ResultSet containing the values.
        trim - Values should have white spaces trimmed.
        Returns:
        String array containing the values.
        Throws:
        java.sql.SQLException - Thrown by the ResultSet.
        java.io.IOException - Thrown by the ResultSet.
      • getColumnValues

        public java.lang.String[] getColumnValues​(java.sql.ResultSet rs,
                                                  boolean trim,
                                                  java.lang.String dateFormatString,
                                                  java.lang.String timeFormatString)
                                           throws java.sql.SQLException,
                                                  java.io.IOException
        Description copied from interface: ResultSetHelper
        Returns the column values from the result set with the values trimmed if desired. Also format the date and time columns based on the format strings passed in.
        Specified by:
        getColumnValues in interface ResultSetHelper
        Parameters:
        rs - The ResultSet containing the values.
        trim - Values should have white spaces trimmed.
        dateFormatString - Format string for dates.
        timeFormatString - Format string for timestamps.
        Returns:
        String array containing the values.
        Throws:
        java.sql.SQLException - Thrown by the ResultSet.
        java.io.IOException - Thrown by the ResultSet.
      • handleTimestamp

        protected java.lang.String handleTimestamp​(java.sql.Timestamp timestamp,
                                                   java.lang.String timestampFormatString)
        The formatted timestamp.
        Parameters:
        timestamp - Timestamp read from resultset
        timestampFormatString - Format string
        Returns:
        Formatted time stamp.
      • getColumnValue

        private java.lang.String getColumnValue​(java.sql.ResultSet rs,
                                                int colType,
                                                int colIndex,
                                                boolean trim,
                                                java.lang.String dateFormatString,
                                                java.lang.String timestampFormatString)
                                         throws java.sql.SQLException,
                                                java.io.IOException
        Throws:
        java.sql.SQLException
        java.io.IOException
      • applyFormatter

        private java.lang.String applyFormatter​(java.text.NumberFormat formatter,
                                                java.lang.Number value)
      • handleVarChar

        protected java.lang.String handleVarChar​(java.sql.ResultSet rs,
                                                 int colIndex,
                                                 boolean trim)
                                          throws java.sql.SQLException
        retrieves the data from an VarChar in a result set
        Parameters:
        rs - - result set
        colIndex - - column location of the data in the result set
        trim - - should the value be trimmed before being returned
        Returns:
        a string representing the VarChar from the result set
        Throws:
        java.sql.SQLException
      • handleNVarChar

        protected java.lang.String handleNVarChar​(java.sql.ResultSet rs,
                                                  int colIndex,
                                                  boolean trim)
                                           throws java.sql.SQLException
        retrieves the data from an NVarChar in a result set
        Parameters:
        rs - - result set
        colIndex - - column location of the data in the result set
        trim - - should the value be trimmed before being returned
        Returns:
        a string representing the NVarChar from the result set
        Throws:
        java.sql.SQLException
      • handleDate

        protected java.lang.String handleDate​(java.sql.ResultSet rs,
                                              int colIndex,
                                              java.lang.String dateFormatString)
                                       throws java.sql.SQLException
        retrieves an date from a result set
        Parameters:
        rs - - result set
        colIndex - - column location of the data in the result set
        dateFormatString - - desired format of the date
        Returns:
        - a string representing the data from the result set in the format set in dateFomratString.
        Throws:
        java.sql.SQLException
      • handleClob

        protected java.lang.String handleClob​(java.sql.ResultSet rs,
                                              int colIndex)
                                       throws java.sql.SQLException,
                                              java.io.IOException
        retrieves the data out of a CLOB
        Parameters:
        rs - - result set
        colIndex - - column location of the data in the result set
        Returns:
        the data in the Clob as a string.
        Throws:
        java.sql.SQLException
        java.io.IOException
      • handleNClob

        protected java.lang.String handleNClob​(java.sql.ResultSet rs,
                                               int colIndex)
                                        throws java.sql.SQLException,
                                               java.io.IOException
        retrieves the data out of a NCLOB
        Parameters:
        rs - - result set
        colIndex - - column location of the data in the result set
        Returns:
        the data in the NCLOB as a string.
        Throws:
        java.sql.SQLException
        java.io.IOException