List of usage examples for org.springframework.jdbc.support JdbcUtils lookupColumnName
public static String lookupColumnName(ResultSetMetaData resultSetMetaData, int columnIndex) throws SQLException
From source file:io.pivotal.dataflow.task.app.jdbcgemfire.common.JdbcColumnToPojoRowMapper.java
@Override public Map<String, Object> mapRow(ResultSet rs, int arg1) throws SQLException { Map<String, Object> builder = new HashMap<>(); Map<String, Object> processed = new HashMap<>(); ColumnStandardMapper mapper = new ColumnStandardMapper(); ResultSetMetaData metaData = rs.getMetaData(); for (int i = 1; i <= metaData.getColumnCount(); i++) { builder.put(JdbcUtils.lookupColumnName(metaData, i), JdbcUtils.getResultSetValue(rs, i)); }//w ww.java 2s . c o m // send map to groovyColumnProcessor.process() processed = mapper.process(builder); return processed; }
From source file:org.apereo.services.persondir.support.jdbc.ColumnMapParameterizedRowMapper.java
@Override public final Map<String, Object> mapRow(final ResultSet rs, final int rowNum) throws SQLException { final ResultSetMetaData rsmd = rs.getMetaData(); final int columnCount = rsmd.getColumnCount(); final Map<String, Object> mapOfColValues = this.createColumnMap(columnCount); for (int i = 1; i <= columnCount; i++) { final String columnName = JdbcUtils.lookupColumnName(rsmd, i); final Object obj = this.getColumnValue(rs, i); if (!this.ignoreNull || obj != null) { final String key = this.getColumnKey(columnName); mapOfColValues.put(key, obj); }// w ww . ja v a 2 s .co m } return mapOfColValues; }
From source file:org.jasig.services.persondir.support.jdbc.ColumnMapParameterizedRowMapper.java
public final Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException { final ResultSetMetaData rsmd = rs.getMetaData(); final int columnCount = rsmd.getColumnCount(); final Map<String, Object> mapOfColValues = this.createColumnMap(columnCount); for (int i = 1; i <= columnCount; i++) { final String columnName = JdbcUtils.lookupColumnName(rsmd, i); final Object obj = this.getColumnValue(rs, i); if (!this.ignoreNull || obj != null) { final String key = this.getColumnKey(columnName); mapOfColValues.put(key, obj); }/*from w w w . ja v a2s.co m*/ } return mapOfColValues; }
From source file:com.krawler.workflow.module.dao.DataObjectRowMapper.java
public Object mapRow(ResultSet rs, int rowNumber) throws SQLException { Map<String, Object> mappedObject = new HashMap<String, Object>(); ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); for (int index = 1; index <= columnCount; index++) { String column = columnMap.get(index); if (column == null) { column = JdbcUtils.lookupColumnName(rsmd, index).toLowerCase(); columnMap.put(index, column); }//from ww w.j ava 2 s .co m Object value = rs.getObject(index); if (formatter != null && value != null && value instanceof Date) value = formatter.format(value); mappedObject.put(column, value); } return mappedObject; }
From source file:io.github.huherto.springyRecords.PrintRowCallbackHandler.java
@Override public void processRow(ResultSet rs) throws SQLException { if (rsmd == null) { rsmd = rs.getMetaData();// w ww .j a va 2 s . c om } if (format != null) { Object args[] = new Object[rsmd.getColumnCount()]; for (int index = 1; index <= rsmd.getColumnCount(); index++) { Object obj = JdbcUtils.getResultSetValue(rs, index); args[index - 1] = obj; } writer.println(String.format(format, args)); } else { StringBuilder sb = new StringBuilder(); for (int index = 1; index <= rsmd.getColumnCount(); index++) { Object obj = JdbcUtils.getResultSetValue(rs, index); if (index > 1) { sb.append(", "); } sb.append(JdbcUtils.lookupColumnName(rsmd, index)); sb.append("="); sb.append(obj); } writer.println(sb.toString()); } writer.flush(); }
From source file:io.github.huherto.springyRecords.RecordMapper.java
/** * Extract the values for all columns in the current row. * <p>Utilizes public setters and result set metadata. * @see java.sql.ResultSetMetaData/* www.jav a 2s .c o m*/ */ @Override public T mapRow(ResultSet rs, int rowNumber) throws SQLException { Assert.state(this.mappedClass != null, "Mapped class was not specified"); T mappedObject; try { mappedObject = mappedClass.newInstance(); } catch (Exception ex) { throw new RuntimeException(ex); } ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); for (int index = 1; index <= columnCount; index++) { String column = JdbcUtils.lookupColumnName(rsmd, index); Field field = this.mappedFields.get(column.replaceAll(" ", "")); if (field != null) { Object value = getColumnValue(rs, index, field); if (logger.isTraceEnabled() && rowNumber == 0) { logger.trace("Mapping column '" + column + "' to property '" + field.getName() + "' of type " + field.getType()); } try { field.set(mappedObject, value); } catch (IllegalArgumentException e) { if (value == null && primitivesDefaultedForNullValue) { logger.debug("Intercepted IllegalArgumentException for row " + rowNumber + " and column '" + column + "' with value " + value + " when setting property '" + field.getName() + "' of type " + field.getType() + " on object: " + mappedObject); } else { throw e; } } catch (IllegalAccessException e) { e.printStackTrace(); } } } return mappedObject; }
From source file:com.clican.pluto.common.support.spring.BeanPropertyRowMapper.java
/** * Extract the values for all columns in the current row. * <p>//from w ww . j a v a 2s .c om * Utilizes public setters and result set metadata. * * @see java.sql.ResultSetMetaData */ public Object mapRow(ResultSet rs, int rowNumber) throws SQLException { Assert.state(this.mappedClass != null, "Mapped class was not specified"); Object mappedObject = BeanUtils.instantiateClass(this.mappedClass); BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(mappedObject); initBeanWrapper(bw); ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); Set<String> populatedProperties = (isCheckFullyPopulated() ? new HashSet<String>() : null); for (int index = 1; index <= columnCount; index++) { String column = JdbcUtils.lookupColumnName(rsmd, index).toLowerCase(); PropertyDescriptor pd = (PropertyDescriptor) this.mappedFields.get(column); if (pd != null) { try { Object value = getColumnValue(rs, index, pd); if (logger.isDebugEnabled() && rowNumber == 0) { logger.debug("Mapping column '" + column + "' to property '" + pd.getName() + "' of type " + pd.getPropertyType()); } bw.setPropertyValue(pd.getName(), value); if (populatedProperties != null) { populatedProperties.add(pd.getName()); } } catch (NotWritablePropertyException ex) { throw new DataRetrievalFailureException( "Unable to map column " + column + " to property " + pd.getName(), ex); } } } if (populatedProperties != null && !populatedProperties.equals(this.mappedProperties)) { throw new InvalidDataAccessApiUsageException("Given ResultSet does not contain all fields " + "necessary to populate object of class [" + this.mappedClass + "]: " + this.mappedProperties); } return mappedObject; }
From source file:com.gzj.tulip.jade.rowmapper.BeanPropertyRowMapper.java
/** * Extract the values for all columns in the current row. * <p>/*w w w . j a v a 2 s . co m*/ * Utilizes public setters and result set metadata. * * @see java.sql.ResultSetMetaData */ public Object mapRow(ResultSet rs, int rowNumber) throws SQLException { // spring's : Object mappedObject = BeanUtils.instantiateClass(this.mappedClass); // jade's : private Object instantiateClass(this.mappedClass); // why: ??mappedClass.newInstranceBeanUtils.instantiateClass(mappedClass)1? Object mappedObject = instantiateClass(this.mappedClass); BeanWrapper bw = new BeanWrapperImpl(mappedObject); ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); boolean warnEnabled = logger.isWarnEnabled(); boolean debugEnabled = logger.isDebugEnabled(); Set<String> populatedProperties = (checkProperties ? new HashSet<String>() : null); for (int index = 1; index <= columnCount; index++) { String column = JdbcUtils.lookupColumnName(rsmd, index).toLowerCase(); PropertyDescriptor pd = this.mappedFields.get(column); if (pd != null) { try { Object value = JdbcUtils.getResultSetValue(rs, index, pd.getPropertyType()); if (debugEnabled && rowNumber == 0) { logger.debug("Mapping column '" + column + "' to property '" + pd.getName() + "' of type " + pd.getPropertyType()); } bw.setPropertyValue(pd.getName(), value); if (populatedProperties != null) { populatedProperties.add(pd.getName()); } } catch (NotWritablePropertyException ex) { throw new DataRetrievalFailureException( "Unable to map column " + column + " to property " + pd.getName(), ex); } } else { if (checkColumns) { throw new InvalidDataAccessApiUsageException("Unable to map column '" + column + "' to any properties of bean " + this.mappedClass.getName()); } if (warnEnabled && rowNumber == 0) { logger.warn("Unable to map column '" + column + "' to any properties of bean " + this.mappedClass.getName()); } } } if (populatedProperties != null && !populatedProperties.equals(this.mappedProperties)) { throw new InvalidDataAccessApiUsageException("Given ResultSet does not contain all fields " + "necessary to populate object of class [" + this.mappedClass + "]: " + this.mappedProperties); } return mappedObject; }
From source file:com.sinosoft.one.data.jade.rowmapper.BeanPropertyRowMapper.java
/** * Extract the values for all columns in the current row. * <p>//w w w. ja v a2s .c o m * Utilizes public setters and result set metadata. * * @see java.sql.ResultSetMetaData */ public Object mapRow(ResultSet rs, int rowNumber) throws SQLException { // spring's : Object mappedObject = BeanUtils.instantiateClass(this.mappedClass); // jade's : private Object instantiateClass(this.mappedClass); // why: ??mappedClass.newInstranceBeanUtils.instantiateClass(mappedClass)1? Object mappedObject = instantiateClass(this.mappedClass); BeanWrapper bw = new BeanWrapperImpl(mappedObject); bw.setConversionService(this.conversionService); ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); boolean warnEnabled = logger.isWarnEnabled(); boolean debugEnabled = logger.isDebugEnabled(); Set<String> populatedProperties = (checkProperties ? new HashSet<String>() : null); for (int index = 1; index <= columnCount; index++) { String column = JdbcUtils.lookupColumnName(rsmd, index).toLowerCase(); PropertyDescriptor pd = this.mappedFields.get(column); if (pd != null) { try { Object value = JdbcUtils.getResultSetValue(rs, index, pd.getPropertyType()); if (debugEnabled && rowNumber == 0) { logger.debug("Mapping column '" + column + "' to property '" + pd.getName() + "' of type " + pd.getPropertyType()); } bw.setPropertyValue(pd.getName(), value); if (populatedProperties != null) { populatedProperties.add(pd.getName()); } } catch (NotWritablePropertyException ex) { throw new DataRetrievalFailureException( "Unable to map column " + column + " to property " + pd.getName(), ex); } } else { if (checkColumns) { throw new InvalidDataAccessApiUsageException("Unable to map column '" + column + "' to any properties of bean " + this.mappedClass.getName()); } if (warnEnabled && rowNumber == 0) { logger.warn("Unable to map column '" + column + "' to any properties of bean " + this.mappedClass.getName()); } } } if (populatedProperties != null && !populatedProperties.equals(this.mappedProperties)) { throw new InvalidDataAccessApiUsageException("Given ResultSet does not contain all fields " + "necessary to populate object of class [" + this.mappedClass + "]: " + this.mappedProperties); } return mappedObject; }