Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make BeanPropertyRowMapper more extensible for override [SPR-15004] #19571

Open
spring-projects-issues opened this issue Dec 12, 2016 · 0 comments
Open
Labels
in: data type: enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Dec 12, 2016

Yanming Zhou opened SPR-15004 and commented

I'm writing my own RowMapper extends BeanPropertyRowMapper to supports nested property, for example:

public class Person{
   private Name name;
   //getter and setter;
}
public class Name{
   private String firstName;
   private String lastName;
   //getter and setter
}
select firstName as "name.firstName", lastName as "name.lastName" from person

I wish BeanPropertyRowMapper can expose such methods for overrides

	public T mapRow(ResultSet rs, int rowNumber) throws SQLException {
        ......
			boolean fromFind = false;
			if (pd == null) {
				pd = tryFindPropertyDescriptor(column, bw);
				fromFind = true;
			}
        ......
					try {
						if (fromFind) {
							bw.setPropertyValue(column, value);
						} else {
							bw.setPropertyValue(pd.getName(), value);
						}
					} catch (TypeMismatchException ex) {
        ......
					}
        ......
	}

	protected PropertyDescriptor tryFindPropertyDescriptor(String column, BeanWrapper bw) {
		return null;
	}

Subclass can override those methods:

@Override
protected PropertyDescriptor tryFindPropertyDescriptor(String column, BeanWrapper bw) {
     if (column.indexOf('.') > 0) 
          return bw.getPropertyDescriptor(column);
     return null;
}

And there is a fallback options, change field visibility of BeanPropertyRowMapper from private to protected, let subclass override mapRow entirely, I prefer to the first solution.


Affects: 4.3.4

@spring-projects-issues spring-projects-issues added in: data type: enhancement labels Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data type: enhancement
Projects
None yet
Development

No branches or pull requests

1 participant