gt: 		T mappedObject = BeanUtils.instantiate(this.mappedClass);
context: /*
   * Copyright 2002-2013 the original author or authors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.springframework.jdbc.core;
  
  import java.beans.PropertyDescriptor;
  import java.sql.ResultSet;
  import java.sql.ResultSetMetaData;
  import java.sql.SQLException;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Map;
  import java.util.Set;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  import org.springframework.beans.BeanUtils;
  import org.springframework.beans.BeanWrapper;
  import org.springframework.beans.NotWritablePropertyException;
  import org.springframework.beans.PropertyAccessorFactory;
  import org.springframework.beans.TypeMismatchException;
  import org.springframework.dao.DataRetrievalFailureException;
  import org.springframework.dao.InvalidDataAccessApiUsageException;
  import org.springframework.jdbc.support.JdbcUtils;
  import org.springframework.util.Assert;
  import org.springframework.util.StringUtils;
  
  /**
   * {@link RowMapper} implementation that converts a row into a new instance
   * of the specified mapped target class. The mapped target class must be a
   * top-level class and it must have a default or no-arg constructor.
   *
   * <p>Column values are mapped based on matching the column name as obtained from result set
   * metadata to public setters for the corresponding properties. The names are matched either
   * directly or by transforming a name separating the parts with underscores to the same name
   * using "camel" case.
   *
   * <p>Mapping is provided for fields in the target class for many common types, e.g.:
   * String, boolean, Boolean, byte, Byte, short, Short, int, Integer, long, Long,
   * float, Float, double, Double, BigDecimal, {@code java.util.Date}, etc.
   *
   * <p>To facilitate mapping between columns and fields that don't have matching names,
   * try using column aliases in the SQL statement like "select fname as first_name from customer".
   *
   * <p>For 'null' values read from the databasem, we will attempt to call the setter, but in the case of
   * Java primitives, this causes a TypeMismatchException. This class can be configured (using the
   * primitivesDefaultedForNullValue property) to trap this exception and use the primitives default value.
   * Be aware that if you use the values from the generated bean to update the database the primitive value
   * will have been set to the primitive's default value instead of null.
   *
   * <p>Please note that this class is designed to provide convenience rather than high performance.
   * For best performance consider using a custom RowMapper.
   *
   * @author Thomas Risberg
   * @author Juergen Hoeller
   * @since 2.5
   */
  public class BeanPropertyRowMapper<T> implements RowMapper<T> {
  
  	/** Logger available to subclasses */
  	protected final Log logger = LogFactory.getLog(getClass());
  
  	/** The class we are mapping to */
  	private Class<T> mappedClass;
  
  	/** Whether we're strictly validating */
  	private boolean checkFullyPopulated = false;
  
  	/** Whether we're defaulting primitives when mapping a null value */
  	private boolean primitivesDefaultedForNullValue = false;
  
  	/** Map of the fields we provide mapping for */
  	private Map<String, PropertyDescriptor> mappedFields;
  
  	/** Set of bean properties we provide mapping for */
  	private Set<String> mappedProperties;
  
  
  	/**
  	 * Create a new BeanPropertyRowMapper for bean-style configuration.
  	 * @see #setMappedClass
  	 * @see #setCheckFullyPopulated
  	 */
  	public BeanPropertyRowMapper() {
  	}
  
  	/**
  	 * Create a new BeanPropertyRowMapper, accepting unpopulated properties
  	 * in the target bean.
  	 * <p>Consider using the {@link #newInstance} factory method instead,
  	 * which allows for specifying the mapped type once only.
  	 * @param mappedClass the class that each row should be mapped to
  	 */
  	public BeanPropertyRowMapper(Class<T> mappedClass) {
  		initialize(mappedClass);
  	}
  
  	/**
  	 * Create a new BeanPropertyRowMapper.
  	 * @param mappedClass the class that each row should be mapped to
  	 * @param checkFullyPopulated whether we're strictly validating that
  	 * all bean properties have been mapped from corresponding database fields
  	 */
  	public BeanPropertyRowMapper(Class<T> mappedClass, boolean checkFullyPopulated) {
  		initialize(mappedClass);
  		this.checkFullyPopulated = checkFullyPopulated;
  	}
  
  
  	/**
  	 * Set the class that each row should be mapped to.
  	 */
  	public void setMappedClass(Class<T> mappedClass) {
  		if (this.mappedClass == null) {
  			initialize(mappedClass);
  		}
  		else {
  			if (!this.mappedClass.equals(mappedClass)) {
  				throw new InvalidDataAccessApiUsageException("The mapped class can not be reassigned to map to " +
  						mappedClass + " since it is already providing mapping for " + this.mappedClass);
  			}
  		}
  	}
  
  	/**
  	 * Initialize the mapping metadata for the given class.
  	 * @param mappedClass the mapped class.
  	 */
  	protected void initialize(Class<T> mappedClass) {
  		this.mappedClass = mappedClass;
  		this.mappedFields = new HashMap<String, PropertyDescriptor>();
  		this.mappedProperties = new HashSet<String>();
  		PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(mappedClass);
  		for (PropertyDescriptor pd : pds) {
  			if (pd.getWriteMethod() != null) {
  				this.mappedFields.put(pd.getName().toLowerCase(), pd);
  				String underscoredName = underscoreName(pd.getName());
  				if (!pd.getName().toLowerCase().equals(underscoredName)) {
  					this.mappedFields.put(underscoredName, pd);
  				}
  				this.mappedProperties.add(pd.getName());
  			}
  		}
  	}
  
  	/**
  	 * Convert a name in camelCase to an underscored name in lower case.
  	 * Any upper case letters are converted to lower case with a preceding underscore.
  	 * @param name the string containing original name
  	 * @return the converted name
  	 */
  	private String underscoreName(String name) {
  		if (!StringUtils.hasLength(name)) {
  			return "";
  		}
  		StringBuilder result = new StringBuilder();
  		result.append(name.substring(0, 1).toLowerCase());
  		for (int i = 1; i < name.length(); i++) {
  			String s = name.substring(i, i + 1);
  			String slc = s.toLowerCase();
  			if (!s.equals(slc)) {
  				result.append("_").append(slc);
  			}
  			else {
  				result.append(s);
  			}
  		}
  		return result.toString();
  	}
  
  	/**
  	 * Get the class that we are mapping to.
  	 */
  	public final Class<T> getMappedClass() {
  		return this.mappedClass;
  	}
  
  	/**
  	 * Set whether we're strictly validating that all bean properties have been
  	 * mapped from corresponding database fields.
  	 * <p>Default is {@code false}, accepting unpopulated properties in the
  	 * target bean.
  	 */
  	public void setCheckFullyPopulated(boolean checkFullyPopulated) {
  		this.checkFullyPopulated = checkFullyPopulated;
  	}
  
  	/**
  	 * Return whether we're strictly validating that all bean properties have been
  	 * mapped from corresponding database fields.
  	 */
  	public boolean isCheckFullyPopulated() {
  		return this.checkFullyPopulated;
  	}
  
  	/**
  	 * Set whether we're defaulting Java primitives in the case of mapping a null value
  	 * from corresponding database fields.
  	 * <p>Default is {@code false}, throwing an exception when nulls are mapped to Java primitives.
  	 */
  	public void setPrimitivesDefaultedForNullValue(boolean primitivesDefaultedForNullValue) {
  		this.primitivesDefaultedForNullValue = primitivesDefaultedForNullValue;
  	}
  
  	/**
  	 * Return whether we're defaulting Java primitives in the case of mapping a null value
  	 * from corresponding database fields.
  	 */
  	public boolean isPrimitivesDefaultedForNullValue() {
  		return primitivesDefaultedForNullValue;
  	}
  
  
  	/**
  	 * Extract the values for all columns in the current row.
  	 * <p>Utilizes public setters and result set metadata.
  	 * @see java.sql.ResultSetMetaData
  	 */
  	public T mapRow(ResultSet rs, int rowNumber) throws SQLException {
  		Assert.state(this.mappedClass != null, "Mapped class was not specified");
  