Skip to content

Commit

Permalink
Fixed BeanPropertyRowMapper to only prefix actual upper-case letters …
Browse files Browse the repository at this point in the history
…with underscores

Issue: SPR-10547
  • Loading branch information
jhoeller authored and unknown committed May 16, 2013
1 parent cd3d0c3 commit c8b071c
Showing 1 changed file with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* 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.
Expand Down Expand Up @@ -37,6 +37,7 @@
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
Expand Down Expand Up @@ -163,18 +164,19 @@ protected void initialize(Class<T> mappedClass) {
* @return the converted name
*/
private String underscoreName(String name) {
if (!StringUtils.hasLength(name)) {
return "";
}
StringBuilder result = new StringBuilder();
if (name != null && name.length() > 0) {
result.append(name.substring(0, 1).toLowerCase());
for (int i = 1; i < name.length(); i++) {
String s = name.substring(i, i + 1);
if (s.equals(s.toUpperCase())) {
result.append("_");
result.append(s.toLowerCase());
}
else {
result.append(s);
}
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();
Expand Down

0 comments on commit c8b071c

Please sign in to comment.