本文整理汇总了Java中org.springframework.jdbc.core.simple.ParameterizedRowMapper类的典型用法代码示例。如果您正苦于以下问题:Java ParameterizedRowMapper类的具体用法?Java ParameterizedRowMapper怎么用?Java ParameterizedRowMapper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ParameterizedRowMapper类属于org.springframework.jdbc.core.simple包,在下文中一共展示了ParameterizedRowMapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fetchList
import org.springframework.jdbc.core.simple.ParameterizedRowMapper; //导入依赖的package包/类
/**
* 取分页
*
* @param jt
* jdbcTemplate
* @param sqlFetchRows
* 查询数据的sql
* @param args
* 查询参数
* @param size
* 大小
* @param rowMapper
* @return
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public List<E> fetchList(final JdbcTemplate jt, final String sqlFetchRows,
final Object args[], final int size, final ParameterizedRowMapper<E> rowMapper) {
if (size == 0) {
return null;
}
final Page<E> page = new Page<E>();
// TODO 在数据量很大时, limit效率很低
final String selectSQL = sqlFetchRows + " limit " + size;
jt.query(selectSQL, args, new ResultSetExtractor() {
public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
final List<E> pageItems = page.getPageItems();
int currentRow = 0;
while (rs.next()) {
pageItems.add(rowMapper.mapRow(rs, currentRow++));
}
return pageItems;
}
});
return page.getPageItems();
}
示例2: loadData
import org.springframework.jdbc.core.simple.ParameterizedRowMapper; //导入依赖的package包/类
protected FileInfo loadData(ServerRequest sr) throws IOException, DataAccessException {
if (!(sr instanceof TableServerRequest)) {
throw new IllegalArgumentException("FileInfoProcessor.loadData Requires an TableServerRequest");
}
TableServerRequest request= (TableServerRequest)sr;
SimpleJdbcTemplate jdbc = JdbcFactory.getSimpleTemplate(getDbInstance());
String sql = getSql(request);
Object[] params = getSqlParams(request);
final FileInfoRowMapper fim = makeRowMapper(request);
ParameterizedRowMapper<FileInfo> mapper = new ParameterizedRowMapper<FileInfo>() {
public FileInfo mapRow(ResultSet resultSet, int i) throws SQLException {
return fim.mapRow(resultSet, i);
}
};
LOGGER.info("Executing SQL query: " + sql,
" Parameters: " + "{" + CollectionUtil.toString(params) + "}");
FileInfo val = jdbc.queryForObject(sql, mapper, params);
return val;
}
示例3: getAttachments
import org.springframework.jdbc.core.simple.ParameterizedRowMapper; //导入依赖的package包/类
private List<DataSource> getAttachments(long messageId) throws DAOException
{
try
{
return simpleJdbcTemplate.query(
"select name, content_type, content" +
" from ebms_attachment" +
" where ebms_message_id = ?",
new ParameterizedRowMapper<DataSource>()
{
@Override
public DataSource mapRow(ResultSet rs, int rowNum) throws SQLException
{
ByteArrayDataSource result = new ByteArrayDataSource(rs.getBytes("content"),rs.getString("content_type"));
result.setName(rs.getString("name"));
return result;
}
},
messageId
);
}
catch (DataAccessException e)
{
throw new DAOException(e);
}
}
示例4: findByPetId
import org.springframework.jdbc.core.simple.ParameterizedRowMapper; //导入依赖的package包/类
@Override
public List<Visit> findByPetId(Integer petId) {
final List<Visit> visits = this.jdbcTemplate.query(
"SELECT id, visit_date, description FROM visits WHERE pet_id=?",
new ParameterizedRowMapper<Visit>() {
@Override
public Visit mapRow(ResultSet rs, int row) throws SQLException {
Visit visit = new Visit();
visit.setId(rs.getInt("id"));
Date visitDate = rs.getDate("visit_date");
visit.setDate(new DateTime(visitDate));
visit.setDescription(rs.getString("description"));
return visit;
}
},
petId);
return visits;
}
示例5: getSpitterById
import org.springframework.jdbc.core.simple.ParameterizedRowMapper; //导入依赖的package包/类
public Spitter getSpitterById(long id) {
return getSimpleJdbcTemplate().queryForObject(
SQL_SELECT_SPITTER_BY_ID,
new ParameterizedRowMapper<Spitter>() {
public Spitter mapRow(ResultSet rs, int rowNum)
throws SQLException {
Spitter spitter = new Spitter();
spitter.setId(rs.getLong(1));
spitter.setUsername(rs.getString(2));
spitter.setPassword(rs.getString(3));
spitter.setFullName(rs.getString(4));
spitter.setEmail(rs.getString(5));
return spitter;
}
}, id);
}
示例6: getSpitterById
import org.springframework.jdbc.core.simple.ParameterizedRowMapper; //导入依赖的package包/类
public Spitter getSpitterById(long id) {
return jdbcTemplate.queryForObject(//<co id="co_query"/>
SQL_SELECT_SPITTER_BY_ID,
new ParameterizedRowMapper<Spitter>() {
public Spitter mapRow(ResultSet rs, int rowNum)
throws SQLException {
Spitter spitter = new Spitter();//<co id="co_map"/>
spitter.setId(rs.getLong(1));
spitter.setUsername(rs.getString(2));
spitter.setPassword(rs.getString(3));
spitter.setFullName(rs.getString(4));
return spitter;
}
},
id //<co id="co_bind"/>
);
}
示例7: getRecentSpittle
import org.springframework.jdbc.core.simple.ParameterizedRowMapper; //导入依赖的package包/类
public List<Spittle> getRecentSpittle() {
DateTime dt = new DateTime().minusDays(1);
return getSimpleJdbcTemplate().query(SQL_SELECT_RECENT_SPITTLE,
new ParameterizedRowMapper<Spittle>() {
public Spittle mapRow(ResultSet rs, int rowNum) throws SQLException {
Spittle spittle = new Spittle();
spittle.setId(rs.getLong(1));
spittle.setSpitter(getSpitterById(rs.getLong(2)));
spittle.setText(rs.getString(3));
spittle.setWhen(rs.getDate(4));
return spittle;
}
}, dt.toDate());
}
示例8: findAdjusted
import org.springframework.jdbc.core.simple.ParameterizedRowMapper; //导入依赖的package包/类
public String findAdjusted(String date, int b) {
String productCode = "";
switch(b) {
case 1: {
productCode = "FISH_MEAL";
} break;
case 2: {
productCode = "FISH_OIL";
} break;
}
List<String> ls = jdbcTemplate.query("SELECT log FROM stock_inventory_log WHERE product_code = ? AND created_date = ?", new ParameterizedRowMapper<String>() {
public String mapRow(ResultSet rs, int i) throws SQLException {
return rs.getString(1);
}
}, productCode, date);
return ls.isEmpty() ? null : ls.get(0);
}
示例9: findAdjusted
import org.springframework.jdbc.core.simple.ParameterizedRowMapper; //导入依赖的package包/类
public String findAdjusted(String date, int b) {
String productCode = "";
switch (b) {
case 1: {
productCode = "FISH_MEAL";
}
break;
case 2: {
productCode = "FISH_OIL";
}
break;
}
List<String> ls = jdbcTemplate.query("SELECT log FROM stock_inventory_log WHERE product_code = ? AND created_date = ?", new ParameterizedRowMapper<String>() {
public String mapRow(ResultSet rs, int i) throws SQLException {
return rs.getString(1);
}
}, productCode, date);
return ls.isEmpty() ? null : ls.get(0);
}
示例10: getDataReviewStatusRowMapper
import org.springframework.jdbc.core.simple.ParameterizedRowMapper; //导入依赖的package包/类
public ParameterizedRowMapper<DataReviewStatusBean> getDataReviewStatusRowMapper()
throws SQLException {
dataReviewStatusRowMapper = new ParameterizedRowMapper<DataReviewStatusBean>() {
public DataReviewStatusBean mapRow(ResultSet rs, int rowNum)
throws SQLException {
DataReviewStatusBean dataStatusBean = new DataReviewStatusBean();
dataStatusBean.setDataId(rs
.getString(REVIEW_STATUS_TABLE_DATA_ID_COL));
dataStatusBean.setDataName(rs
.getString(REVIEW_STATUS_TABLE_DATA_NAME_COL));
dataStatusBean.setDataType(rs
.getString(REVIEW_STATUS_TABLE_DATA_TYPE_COL));
dataStatusBean.setReviewStatus(rs
.getString(REVIEW_STATUS_TABLE_STATUS_COL));
dataStatusBean.setSubmittedBy(rs
.getString(REVIEW_STATUS_TABLE_SUBMITTED_BY_COL));
dataStatusBean.setSubmittedDate(rs
.getDate(REVIEW_STATUS_TABLE_SUBMITTED_DATE_COL));
return dataStatusBean;
}
};
return dataReviewStatusRowMapper;
}
示例11: queryForObject
import org.springframework.jdbc.core.simple.ParameterizedRowMapper; //导入依赖的package包/类
public T queryForObject(String sql, ParameterizedRowMapper mapper,
Object... args) {
try {
T t = (T) this.simpleJdbcTemplate.queryForObject(sql, mapper, args);
return t;
} catch (RuntimeException e) {
return null;
}
}
示例12: fetchPage
import org.springframework.jdbc.core.simple.ParameterizedRowMapper; //导入依赖的package包/类
/**
* 取分页
*
* @param jt
* jdbcTemplate
* @param sqlCountRows
* 查询总数的SQL
* @param sqlFetchRows
* 查询数据的sql
* @param args
* 查询参数
* @param pageNo
* 页数
* @param pageSize
* 每页大小
* @param rowMapper
* @return
*/
public Page<E> fetchPage(final JdbcTemplate jt, final String sqlCountRows, final String sqlFetchRows,
final Object args[], final int pageNo, final int pageSize, final ParameterizedRowMapper<E> rowMapper) {
if (pageSize == 0) {
return null;
}
// 查询当前记录总数
final int rowCount = jt.queryForInt(sqlCountRows, args);
// 计算页数
int pageCount = rowCount / pageSize;
if (rowCount > pageSize * pageCount) {
pageCount++;
}
// 创建Page对象
final Page<E> page = new Page<E>();
page.setPageNumber(pageNo);
page.setPagesAvailable(pageCount);
page.setTotalCount(rowCount);
if (pageNo > pageCount)
return null;
// 取单页数据,计算起始位置
final int startRow = (pageNo - 1) * pageSize;
// TODO 在数据量很大时, limit效率很低
final String selectSQL = sqlFetchRows + " limit " + startRow + "," + pageSize;
jt.query(selectSQL, args, new ResultSetExtractor() {
public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
final List<E> pageItems = page.getPageItems();
int currentRow = 0;
while (rs.next()) {
pageItems.add(rowMapper.mapRow(rs, currentRow++));
}
return page;
}
});
return page;
}
示例13: refreshVetsCache
import org.springframework.jdbc.core.simple.ParameterizedRowMapper; //导入依赖的package包/类
/**
* Refresh the cache of Vets that the Clinic is holding.
* @see org.springframework.samples.petclinic.Clinic#getVets()
*/
@ManagedOperation
@Transactional(readOnly = true)
public void refreshVetsCache() throws DataAccessException {
synchronized (this.vets) {
this.logger.info("Refreshing vets cache");
// Retrieve the list of all vets.
this.vets.clear();
this.vets.addAll(this.simpleJdbcTemplate.query(
"SELECT id, first_name, last_name FROM vets ORDER BY last_name,first_name",
ParameterizedBeanPropertyRowMapper.newInstance(Vet.class)));
// Retrieve the list of all possible specialties.
final List<Specialty> specialties = this.simpleJdbcTemplate.query(
"SELECT id, name FROM specialties",
ParameterizedBeanPropertyRowMapper.newInstance(Specialty.class));
// Build each vet's list of specialties.
for (Vet vet : this.vets) {
final List<Integer> vetSpecialtiesIds = this.simpleJdbcTemplate.query(
"SELECT specialty_id FROM vet_specialties WHERE vet_id=?",
new ParameterizedRowMapper<Integer>() {
public Integer mapRow(ResultSet rs, int row) throws SQLException {
return Integer.valueOf(rs.getInt(1));
}},
vet.getId().intValue());
for (int specialtyId : vetSpecialtiesIds) {
Specialty specialty = EntityUtils.getById(specialties, Specialty.class, specialtyId);
vet.addSpecialty(specialty);
}
}
}
}
示例14: getImages
import org.springframework.jdbc.core.simple.ParameterizedRowMapper; //导入依赖的package包/类
@Transactional(readOnly=true)
public List<ImageDescriptor> getImages() throws DataAccessException {
return getSimpleJdbcTemplate().query(
"SELECT image_name, description FROM imagedb",
new ParameterizedRowMapper<ImageDescriptor>() {
public ImageDescriptor mapRow(ResultSet rs, int rowNum) throws SQLException {
String name = rs.getString(1);
String description = lobHandler.getClobAsString(rs, 2);
return new ImageDescriptor(name, description);
}
});
}
示例15: findAll
import org.springframework.jdbc.core.simple.ParameterizedRowMapper; //导入依赖的package包/类
/**
* Refresh the cache of Vets that the ClinicService is holding.
*
* @see org.springframework.samples.petclinic.model.service.ClinicService#findVets()
*/
@Override
public Collection<Vet> findAll() throws DataAccessException {
List<Vet> vets = new ArrayList<Vet>();
// Retrieve the list of all vets.
vets.addAll(this.jdbcTemplate.query(
"SELECT id, first_name, last_name FROM vets ORDER BY last_name,first_name",
ParameterizedBeanPropertyRowMapper.newInstance(Vet.class)));
// Retrieve the list of all possible specialties.
final List<Specialty> specialties = this.jdbcTemplate.query(
"SELECT id, name FROM specialties",
ParameterizedBeanPropertyRowMapper.newInstance(Specialty.class));
// Build each vet's list of specialties.
for (Vet vet : vets) {
final List<Integer> vetSpecialtiesIds = this.jdbcTemplate.query(
"SELECT specialty_id FROM vet_specialties WHERE vet_id=?",
new ParameterizedRowMapper<Integer>() {
@Override
public Integer mapRow(ResultSet rs, int row) throws SQLException {
return Integer.valueOf(rs.getInt(1));
}
},
vet.getId().intValue());
for (int specialtyId : vetSpecialtiesIds) {
Specialty specialty = EntityUtils.getById(specialties, Specialty.class, specialtyId);
vet.addSpecialty(specialty);
}
}
return vets;
}