protected Object arrayFromResultSet ( ResultSet rs , int maxRows , Class arrayClass , Calendar cal ) throws SQLException { ArrayList < Object > list = new ArrayList < Object > ( ) ; Class componentType = arrayClass . getComponentType ( ) ; RowMapper rowMapper = RowMapperFactory . getRowMapper ( rs , componentType , cal ) ; // a value of zero indicates that all rows from the resultset should be included. if ( maxRows == 0 ) { maxRows = - 1 ; } int numRows ; boolean hasMoreRows = rs . next ( ) ; for ( numRows = 0 ; numRows != maxRows && hasMoreRows ; numRows ++ ) { list . add ( rowMapper . mapRowToReturnType ( ) ) ; hasMoreRows = rs . next ( ) ; } Object array = Array . newInstance ( componentType , numRows ) ; try { for ( int i = 0 ; i < numRows ; i ++ ) { Array . set ( array , i , list . get ( i ) ) ; } } catch ( IllegalArgumentException iae ) { ResultSetMetaData md = rs . getMetaData ( ) ; // assuming no errors in resultSetObject() this can only happen // for single column result sets. throw new ControlException ( "The declared Java type for array " + componentType . getName ( ) + "is incompatible with the SQL format of column " + md . getColumnName ( 1 ) + md . getColumnTypeName ( 1 ) + "which returns objects of type + " + list . get ( 0 ) . getClass ( ) . getName ( ) ) ; } return array ; }
Invoked when the return type of the method is an array type .