本文整理汇总了Java中org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper类的典型用法代码示例。如果您正苦于以下问题:Java ParameterizedBeanPropertyRowMapper类的具体用法?Java ParameterizedBeanPropertyRowMapper怎么用?Java ParameterizedBeanPropertyRowMapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParameterizedBeanPropertyRowMapper类属于org.springframework.jdbc.core.simple包,在下文中一共展示了ParameterizedBeanPropertyRowMapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getListRealType
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper; //导入依赖的package包/类
private RowMapper<?> getListRealType(Method method) {
ResultType resultType = method.getAnnotation(ResultType.class);
if (resultType != null) {
if (resultType.value().equals(Map.class)) {
return getColumnMapRowMapper();
}
return ParameterizedBeanPropertyRowMapper.newInstance(resultType.value());
}
String genericReturnType = method.getGenericReturnType().toString();
String realType = genericReturnType.replace("java.util.List", "").replace("<", "").replace(">", "");
if (realType.contains("java.util.Map")) {
return getColumnMapRowMapper();
} else if (realType.length() > 0) {
try {
return ParameterizedBeanPropertyRowMapper.newInstance(Class.forName(realType));
} catch (ClassNotFoundException e) {
LOGGER.error(e.getMessage(), e.fillInStackTrace());
throw new RuntimeException("dao get class error ,class name is:" + realType);
}
}
return getColumnMapRowMapper();
}
示例2: loadOwner
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper; //导入依赖的package包/类
/**
* Loads the {@link Owner} with the supplied <code>id</code>; also loads
* the {@link Pet Pets} and {@link Visit Visits} for the corresponding
* owner, if not already loaded.
*/
@Transactional(readOnly = true)
public Owner loadOwner(int id) throws DataAccessException {
Owner owner;
try {
owner = this.simpleJdbcTemplate.queryForObject(
"SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE id=?",
ParameterizedBeanPropertyRowMapper.newInstance(Owner.class),
id);
}
catch (EmptyResultDataAccessException ex) {
throw new ObjectRetrievalFailureException(Owner.class, new Integer(id));
}
loadPetsAndVisits(owner);
return owner;
}
示例3: findById
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper; //导入依赖的package包/类
/**
* Loads the {@link Owner} with the supplied <code>id</code>; also loads the {@link Pet Pets} and {@link Visit Visits}
* for the corresponding owner, if not already loaded.
*/
@Override
public Owner findById(int id) throws DataAccessException {
Owner owner;
try {
Map<String, Object> params = new HashMap<String, Object>();
params.put("id", id);
owner = this.namedParameterJdbcTemplate.queryForObject(
"SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE id= :id",
params,
ParameterizedBeanPropertyRowMapper.newInstance(Owner.class)
);
} catch (EmptyResultDataAccessException ex) {
throw new ObjectRetrievalFailureException(Owner.class, id);
}
loadPetsAndVisits(owner);
return owner;
}
示例4: queryForObject
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper; //导入依赖的package包/类
public T queryForObject(String sql, Class clazz, Object... args) {
try {
return (T) simpleJdbcTemplate
.queryForObject(sql, ParameterizedBeanPropertyRowMapper
.newInstance(clazz), args);
// return (T) this.jdbcTemplate.queryForObject(sql, args, clazz);
} catch (Exception ex) {
// ex.printStackTrace();
// throw new ObjectNotFoundException(ex, sql);
this.logger.error("查询出错", ex);
return null;
}
}
示例5: refreshVetsCache
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper; //导入依赖的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);
}
}
}
}
示例6: findOwners
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper; //导入依赖的package包/类
/**
* Loads {@link Owner Owners} from the data store by last name, returning
* all owners whose last name <i>starts</i> with the given name; also loads
* the {@link Pet Pets} and {@link Visit Visits} for the corresponding
* owners, if not already loaded.
*/
@Transactional(readOnly = true)
public Collection<Owner> findOwners(String lastName) throws DataAccessException {
List<Owner> owners = this.simpleJdbcTemplate.query(
"SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE last_name like ?",
ParameterizedBeanPropertyRowMapper.newInstance(Owner.class),
lastName + "%");
loadOwnersPetsAndVisits(owners);
return owners;
}
示例7: getProjectDescDetailList
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper; //导入依赖的package包/类
@Override
public List<ProjDescDetail> getProjectDescDetailList(Set<Integer> descItemIds, String descType) {
String sqlQuery = "select * from " + DescriptionType.getDescriptionTableName(descType) + " where ProjDescId in (:ids)";
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("ids", descItemIds);
List<ProjDescDetail> projDescDetails = namedParameterJdbcTemplate.query(sqlQuery, parameters, ParameterizedBeanPropertyRowMapper.newInstance(ProjDescDetail.class));
return projDescDetails;
}
示例8: QueryImpl
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper; //导入依赖的package包/类
/**
* <p> 构造函数初始化SQL,及相关参数 </p>
* @param sql
* @param params
*/
public QueryImpl(
Class<T> entity ,
JdbcTemplate jdbcTemplate,
SQLGenerator sqlGenerator,
String sql,
Object...params){
super(jdbcTemplate,sqlGenerator,sql,params);
this.mapper = ParameterizedBeanPropertyRowMapper.newInstance( entity );
}
示例9: findAll
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper; //导入依赖的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;
}
示例10: findByLastName
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper; //导入依赖的package包/类
/**
* Loads {@link Owner Owners} from the data store by last name, returning all owners whose last name <i>starts</i> with
* the given name; also loads the {@link Pet Pets} and {@link Visit Visits} for the corresponding owners, if not
* already loaded.
*/
@Override
public Collection<Owner> findByLastName(String lastName) throws DataAccessException {
Map<String, Object> params = new HashMap<String, Object>();
params.put("lastName", lastName + "%");
List<Owner> owners = this.namedParameterJdbcTemplate.query(
"SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE last_name like :lastName",
params,
ParameterizedBeanPropertyRowMapper.newInstance(Owner.class)
);
loadOwnersPetsAndVisits(owners);
return owners;
}
示例11: findPetTypes
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper; //导入依赖的package包/类
@Override
public List<PetType> findPetTypes() throws DataAccessException {
Map<String, Object> params = new HashMap<String, Object>();
return this.namedParameterJdbcTemplate.query(
"SELECT id, name FROM types ORDER BY name",
params,
ParameterizedBeanPropertyRowMapper.newInstance(PetType.class));
}
示例12: findById
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper; //导入依赖的package包/类
@Override
public SysUser findById(Integer id) {
try{
String sql = "SELECT * FROM sys_user WHERE id=?";
return this.jdbcTemplate.queryForObject(sql,
ParameterizedBeanPropertyRowMapper.newInstance(SysUser.class),id);
}catch(EmptyResultDataAccessException e){
e.printStackTrace();
return null;
}
}
示例13: findList
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper; //导入依赖的package包/类
@Override
public List<SysUser> findList(SysUser sysUser) {
logger.info("######info.....");
logger.debug("######debug.....");
logger.error("######error.....");
String sql = "SELECT * FROM sys_user";
return this.jdbcTemplate.query(sql, ParameterizedBeanPropertyRowMapper.newInstance(SysUser.class));
}
示例14: queryForList
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper; //导入依赖的package包/类
public List<T> queryForList(String sql, Class clazz, Object... args) {
return this.simpleJdbcTemplate.query(sql,
ParameterizedBeanPropertyRowMapper.newInstance(clazz), args);
}
示例15: getReturnDaoResult
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper; //导入依赖的package包/类
private Object getReturnDaoResult(String dbType, DaoPage pageSetting, Method method, String executeSql, Map<String, Object> paramMap) {
String methodName = method.getName();
if (checkActiveKey(methodName)) {
if (paramMap != null) {
return namedParameterJdbcTemplate.update(executeSql, paramMap);
} else {
return jdbcTemplate.update(executeSql);
}
} else if (checkBatchKey(methodName)) {
return batchUpdate(executeSql);
} else {
Class<?> returnType = method.getReturnType();
if(returnType.isPrimitive()){
Number number = jdbcTemplate.queryForObject(executeSql, BigDecimal.class);
if ("int".equals(returnType.getCanonicalName())) {
return number.intValue();
} else if ("long".equals(returnType.getCanonicalName())) {
return number.longValue();
} else if ("double".equals(returnType.getCanonicalName())) {
return number.doubleValue();
}
} else if(returnType.isAssignableFrom(List.class) || returnType.isAssignableFrom(DaoPage.class)){
int page = pageSetting.getPage();
int rows = pageSetting.getRows();
if (page != 0 && rows != 0) {
if(returnType.isAssignableFrom(DaoPage.class)){
if(paramMap != null){
pageSetting.setTotal(namedParameterJdbcTemplate.queryForObject(getCountSql(executeSql), paramMap, Integer.class));
} else{
pageSetting.setTotal(jdbcTemplate.queryForObject(getCountSql(executeSql), Integer.class));
}
}
executeSql = DaoUtil.createPageSql(dbType, executeSql, page, rows);
}
RowMapper resultType = getListRealType(method);
List list;
if (paramMap != null) {
list = namedParameterJdbcTemplate.query(executeSql, paramMap, resultType);
} else {
list = jdbcTemplate.query(executeSql, resultType);
}
if (returnType.isAssignableFrom(DaoPage.class)) {
pageSetting.setResults(list);
return pageSetting;
} else {
return list;
}
} else if (returnType.isAssignableFrom(Map.class)) {
// Map类型
if (paramMap != null) {
return namedParameterJdbcTemplate.queryForObject(executeSql, paramMap, getColumnMapRowMapper());
} else {
return jdbcTemplate.queryForObject(executeSql, getColumnMapRowMapper());
}
} else if (returnType.isAssignableFrom(String.class)) {
if (paramMap != null) {
return namedParameterJdbcTemplate.queryForObject(executeSql, paramMap, String.class);
} else {
return jdbcTemplate.queryForObject(executeSql, String.class);
}
} else if (DaoUtil.isWrapClass(returnType)) {
if (paramMap != null) {
return namedParameterJdbcTemplate.queryForObject(executeSql, paramMap, returnType);
} else {
return jdbcTemplate.queryForObject(executeSql, returnType);
}
} else {
// 对象类型
RowMapper<?> rm = ParameterizedBeanPropertyRowMapper.newInstance(returnType);
if (paramMap != null) {
return namedParameterJdbcTemplate.queryForObject(executeSql, paramMap, rm);
} else {
return jdbcTemplate.queryForObject(executeSql, rm);
}
}
}
return null;
}