contact.setBirthDate(rs.getDate("birth_date"));
return contact;
}
}
In Listing 8-35, within the SelectAllContacts class, the SQL for selecting all contacts is declared. In
the class constructor, the super() method is called to construct the class, using the DataSource as well as
the SQL statement. Moreover, the MappingSqlQuery<T>.mapRow() method is implemented to provide the
mapping of the resultset to the Contact domain object.
Having the SelectAllContacts class in place, we can implement the findAll() method in the
JdbcContactDao class. Listing 8-36 shows the class.
Listing 8-36. Implementing the findAll() Method
package com.apress.prospring3.ch8.dao.jdbc.annotation;
import java.util.List;
import javax.annotation.Resource;
import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Repository;
import com.apress.prospring3.ch8.dao.ContactDao;
import com.apress.prospring3.ch8.domain.Contact;
@Repository("contactDao")
public class JdbcContactDao implements ContactDao {
private Log log = LogFactory.getLog(JdbcContactDao.class);
private DataSource dataSource;
private SelectAllContacts selectAllContacts;
@Resource(name="dataSource")
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
selectAllContacts = new SelectAllContacts(dataSource);
}
public DataSource getDataSource() {
return dataSource;
}
public List<Contact> findAll() {
return selectAllContacts.execute();
}
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home