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

Add support for new custom row-mapping projections in QueryDSL 2.2.0 [DATAJDBC-12] #269

Closed
spring-projects-issues opened this issue Jul 18, 2011 · 2 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link

Thomas Risberg opened DATAJDBC-12 and commented

Add support for new custom row-mapping projections in QueryDSL 2.2.0

https://bugs.launchpad.net/querydsl/+bug/809289


No further details from DATAJDBC-12

@spring-projects-issues
Copy link
Author

Alex Soto commented

This improvement is already implemented in current version of Spring-Data. Because MappingProjection class extends from ExpressionBase you can use QueryDslJdbcTemplate methods that also accepts Expression as parameter. For example:

public Customer findCustomerById(Long id) {
SQLQuery sqlQuery = template.newSqlQuery().from(qCustomer)
.where(qCustomer.id.eq(id));
return template.queryForObject(sqlQuery,new MappingProjection<Customer>(Customer.class, qCustomer.all()) {

		/**
		 * 
		 */
		private static final long serialVersionUID = 6080677802308908210L;

		@Override
		protected Customer map(Tuple tuple) {
			Customer customer = new Customer();
			customer.setId(tuple.get(qCustomer.id));
			customer.setFirstName(tuple.get(qCustomer.firstName));
			customer.setLastName(tuple.get(qCustomer.lastName).replace(',', '#'));
			return customer;
		}
	});
}

This afternoon I will upload full code in my github.

@spring-projects-issues
Copy link
Author

Thomas Risberg commented

Thanks Alex, you're right, works with the current implementation. That was easy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants