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

Provide a concrete implementation of MappingSqlQuery (say RowMappingSqlQuery) which can be injected a RowMapper, so that we can put it in a config file [SPR-3986] #8666

Closed
spring-projects-issues opened this issue Oct 18, 2007 · 2 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Celal Ziftci opened SPR-3986 and commented

MappingSqlQuery is an abstract class and expects concrete subclasses to implement mapRow(ResultSet, int). If we had a concrete implementation (say RowMappingSqlQuery), we could potentially put this RowMappingSqlQuery into a config file entirely.
Below is an example of how it would look:

<bean id="query_withParams" class="org.springframework.jdbc.object.RowMappingSqlQuery">
<property name="dataSource"><ref bean="someDataSource"/></property>
<property name="sql" value="select * from table where varchardata = ?"/>
<property name="parameters">
<list>
<bean class="org.springframework.jdbc.core.SqlParameter">
<constructor-arg index="0" value="varcharData"/>
<constructor-arg index="1"><util:constant static-field="java.sql.Types.VARCHAR"/></constructor-arg>
</bean>
</list>
</property>
<property name="rowMapper">
<bean class="some.package.IntegerRowMapper" />
</property>
</bean>

Note that we also provide a RowMapper to this RowMappingSqlQuery (so it will need to have a setter/getter for RowMapper).
Below is the sample implementation for this RowMappingSqlQuery class:

public class RowMappingSqlQuery extends MappingSqlQuery
{
RowMapper _rowMapper;

public RowMappingSqlQuery()
{
super();
}

public RowMappingSqlQuery( DataSource ds, String sql )
{
super( ds, sql );
}

/* This is the abstract method in MappingSqlQuery */
protected Object mapRow( ResultSet rs_, int rowNum_ ) throws SQLException
{
if( _rowMapper != null )
{
return rowMapper.mapRow( rs, rowNum_ );
}
else
{
return null;
}
}

public void setRowMapper( RowMapper rowMapper )
{
_rowMapper = rowMapper;
}

public RowMapper getRowMapper()
{
return _rowMapper;
}
}


Affects: 2.0.6, 2.1 M4, 2.5 RC1

Referenced from: commits 7ccb0b6, a3942c5

@spring-projects-issues
Copy link
Collaborator Author

Celal Ziftci commented

This is related to the JIRA here: http://opensource.atlassian.com/projects/spring/browse/SPR-3898
Since that one is fixed, this makes the usage of a query object in config very easy.

@spring-projects-issues
Copy link
Collaborator Author

Celal Ziftci commented

Has there been any progress on this?
Any comments on whether this can be added or not?

Thanks.

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0 M3 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant