public synchronized Object [ ] mapObjects ( ResultSet pRSet ) throws SQLException { Vector result = new Vector ( ) ; ResultSetMetaData meta = pRSet . getMetaData ( ) ; int cols = meta . getColumnCount ( ) ; // Get colum names String [ ] colNames = new String [ cols ] ; for ( int i = 0 ; i < cols ; i ++ ) { colNames [ i ] = meta . getColumnName ( i + 1 ) ; // JDBC cols start at 1... /* System.out.println(meta.getColumnLabel(i + 1)); System.out.println(meta.getColumnName(i + 1)); System.out.println(meta.getColumnType(i + 1)); System.out.println(meta.getColumnTypeName(i + 1)); // System.out.println(meta.getTableName(i + 1)); // System.out.println(meta.getCatalogName(i + 1)); // System.out.println(meta.getSchemaName(i + 1)); // Last three NOT IMPLEMENTED!! */ } // Loop through rows in resultset while ( pRSet . next ( ) ) { Object obj = null ; try { obj = mInstanceClass . newInstance ( ) ; // Asserts empty constructor! } catch ( IllegalAccessException iae ) { mLog . logError ( iae ) ; // iae.printStackTrace(); } catch ( InstantiationException ie ) { mLog . logError ( ie ) ; // ie.printStackTrace(); } // Read each colum from this row into object for ( int i = 0 ; i < cols ; i ++ ) { String property = ( String ) mColumnMap . get ( colNames [ i ] ) ; if ( property != null ) { // This column is mapped to a property mapColumnProperty ( pRSet , i + 1 , property , obj ) ; } } // Add object to the result Vector result . addElement ( obj ) ; } return result . toArray ( ( Object [ ] ) Array . newInstance ( mInstanceClass , result . size ( ) ) ) ; }
Maps each row of the given result set to an object ot this OM s type .