Java Code Examples for org.springframework.jdbc.support.JdbcUtils#lookupColumnName()
The following examples show how to use
org.springframework.jdbc.support.JdbcUtils#lookupColumnName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RowCountCallbackHandler.java From spring-analysis-note with MIT License | 6 votes |
/** * Implementation of ResultSetCallbackHandler. * Work out column size if this is the first row, otherwise just count rows. * <p>Subclasses can perform custom extraction or processing * by overriding the {@code processRow(ResultSet, int)} method. * @see #processRow(java.sql.ResultSet, int) */ @Override public final void processRow(ResultSet rs) throws SQLException { if (this.rowCount == 0) { ResultSetMetaData rsmd = rs.getMetaData(); this.columnCount = rsmd.getColumnCount(); this.columnTypes = new int[this.columnCount]; this.columnNames = new String[this.columnCount]; for (int i = 0; i < this.columnCount; i++) { this.columnTypes[i] = rsmd.getColumnType(i + 1); this.columnNames[i] = JdbcUtils.lookupColumnName(rsmd, i + 1); } // could also get column names } processRow(rs, this.rowCount++); }
Example 2
Source File: RowCountCallbackHandler.java From java-technology-stack with MIT License | 6 votes |
/** * Implementation of ResultSetCallbackHandler. * Work out column size if this is the first row, otherwise just count rows. * <p>Subclasses can perform custom extraction or processing * by overriding the {@code processRow(ResultSet, int)} method. * @see #processRow(java.sql.ResultSet, int) */ @Override public final void processRow(ResultSet rs) throws SQLException { if (this.rowCount == 0) { ResultSetMetaData rsmd = rs.getMetaData(); this.columnCount = rsmd.getColumnCount(); this.columnTypes = new int[this.columnCount]; this.columnNames = new String[this.columnCount]; for (int i = 0; i < this.columnCount; i++) { this.columnTypes[i] = rsmd.getColumnType(i + 1); this.columnNames[i] = JdbcUtils.lookupColumnName(rsmd, i + 1); } // could also get column names } processRow(rs, this.rowCount++); }
Example 3
Source File: RowCountCallbackHandler.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Work out column size if this is the first row, otherwise just count rows. * <p>Subclasses can perform custom extraction or processing * by overriding the {@code processRow(ResultSet, int)} method. * @see #processRow(java.sql.ResultSet, int) */ @Override public final void processRow(ResultSet rs) throws SQLException { if (this.rowCount == 0) { ResultSetMetaData rsmd = rs.getMetaData(); this.columnCount = rsmd.getColumnCount(); this.columnTypes = new int[this.columnCount]; this.columnNames = new String[this.columnCount]; for (int i = 0; i < this.columnCount; i++) { this.columnTypes[i] = rsmd.getColumnType(i + 1); this.columnNames[i] = JdbcUtils.lookupColumnName(rsmd, i + 1); } // could also get column names } processRow(rs, this.rowCount++); }
Example 4
Source File: RowCountCallbackHandler.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Implementation of ResultSetCallbackHandler. * Work out column size if this is the first row, otherwise just count rows. * <p>Subclasses can perform custom extraction or processing * by overriding the {@code processRow(ResultSet, int)} method. * @see #processRow(java.sql.ResultSet, int) */ @Override public final void processRow(ResultSet rs) throws SQLException { if (this.rowCount == 0) { ResultSetMetaData rsmd = rs.getMetaData(); this.columnCount = rsmd.getColumnCount(); this.columnTypes = new int[this.columnCount]; this.columnNames = new String[this.columnCount]; for (int i = 0; i < this.columnCount; i++) { this.columnTypes[i] = rsmd.getColumnType(i + 1); this.columnNames[i] = JdbcUtils.lookupColumnName(rsmd, i + 1); } // could also get column names } processRow(rs, this.rowCount++); }
Example 5
Source File: RowCountCallbackHandler.java From effectivejava with Apache License 2.0 | 6 votes |
/** * Implementation of ResultSetCallbackHandler. * Work out column size if this is the first row, otherwise just count rows. * <p>Subclasses can perform custom extraction or processing * by overriding the {@code processRow(ResultSet, int)} method. * @see #processRow(java.sql.ResultSet, int) */ @Override public final void processRow(ResultSet rs) throws SQLException { if (this.rowCount == 0) { ResultSetMetaData rsmd = rs.getMetaData(); this.columnCount = rsmd.getColumnCount(); this.columnTypes = new int[this.columnCount]; this.columnNames = new String[this.columnCount]; for (int i = 0; i < this.columnCount; i++) { this.columnTypes[i] = rsmd.getColumnType(i + 1); this.columnNames[i] = JdbcUtils.lookupColumnName(rsmd, i + 1); } // could also get column names } processRow(rs, this.rowCount++); }
Example 6
Source File: ColumnMapRowMapper.java From spring-analysis-note with MIT License | 5 votes |
@Override public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException { ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); Map<String, Object> mapOfColumnValues = createColumnMap(columnCount); for (int i = 1; i <= columnCount; i++) { String column = JdbcUtils.lookupColumnName(rsmd, i); mapOfColumnValues.putIfAbsent(getColumnKey(column), getColumnValue(rs, i)); } return mapOfColumnValues; }
Example 7
Source File: CamelCaseColumnMapRowMapper.java From Milkomeda with MIT License | 5 votes |
@Override public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException { ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); Map<String, Object> mapOfColumnValues = createColumnMap(columnCount); for (int i = 1; i <= columnCount; i++) { String column = JdbcUtils.lookupColumnName(rsmd, i); mapOfColumnValues.putIfAbsent(DataTypeConvertUtil.toCamelCase(getColumnKey(column)), getColumnValue(rs, i)); } return mapOfColumnValues; }
Example 8
Source File: ColumnMapRowMapper.java From java-technology-stack with MIT License | 5 votes |
@Override public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException { ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); Map<String, Object> mapOfColumnValues = createColumnMap(columnCount); for (int i = 1; i <= columnCount; i++) { String column = JdbcUtils.lookupColumnName(rsmd, i); mapOfColumnValues.putIfAbsent(getColumnKey(column), getColumnValue(rs, i)); } return mapOfColumnValues; }
Example 9
Source File: ObjectMapRowMapper.java From plumdo-work with Apache License 2.0 | 5 votes |
@Override public ObjectMap mapRow(ResultSet rs, int rowNum) throws SQLException { ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); ObjectMap mapOfColValues = new ObjectMap(); for (int i = 1; i <= columnCount; i++) { String key = JdbcUtils.lookupColumnName(rsmd, i); Object obj = JdbcUtils.getResultSetValue(rs, i, String.class); mapOfColValues.put(key, obj); } return mapOfColValues; }
Example 10
Source File: AggregationResultSetExtractor.java From compass with Apache License 2.0 | 5 votes |
private Map<String, Integer> createFieldIndex(ResultSet rs) throws SQLException { ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); Map<String, Integer> fieldIndex = new LinkedHashMap<String, Integer>(columnCount); for (int i = 1; i <= columnCount; i++) { String field = JdbcUtils.lookupColumnName(rsmd, i); fieldIndex.put(field, Integer.valueOf(i)); } return fieldIndex; }
Example 11
Source File: BeanPropertyRowMapper.java From effectivejava with Apache License 2.0 | 4 votes |
/** * Extract the values for all columns in the current row. * <p>Utilizes public setters and result set metadata. * @see java.sql.ResultSetMetaData */ @Override public T mapRow(ResultSet rs, int rowNumber) throws SQLException { Assert.state(this.mappedClass != null, "Mapped class was not specified"); T mappedObject = BeanUtils.instantiate(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); PropertyDescriptor pd = this.mappedFields.get(column.replaceAll(" ", "").toLowerCase()); 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()); } try { bw.setPropertyValue(pd.getName(), value); } catch (TypeMismatchException e) { if (value == null && primitivesDefaultedForNullValue) { logger.debug("Intercepted TypeMismatchException for row " + rowNumber + " and column '" + column + "' with value " + value + " when setting property '" + pd.getName() + "' of type " + pd.getPropertyType() + " on object: " + mappedObject); } else { throw e; } } 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; }