Example usage for org.springframework.dao EmptyResultDataAccessException getMessage

List of usage examples for org.springframework.dao EmptyResultDataAccessException getMessage

Introduction

In this page you can find the example usage for org.springframework.dao EmptyResultDataAccessException getMessage.

Prototype

@Override
@Nullable
public String getMessage() 

Source Link

Document

Return the detail message, including the message from the nested exception if there is one.

Usage

From source file:in.mycp.service.MycpAuthService.java

@Override
protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication)
        throws AuthenticationException {
    String password = (String) authentication.getCredentials();
    if (StringUtils.isBlank(password)) {
        throw new BadCredentialsException("Please enter password");
    }// w w w .j a v  a  2 s  . c o m
    List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
    in.mycp.domain.User mycpUser = null;
    try {
        ShaPasswordEncoder passEncoder = new ShaPasswordEncoder(256);
        String encodedPass = passEncoder.encodePassword(password, username);
        mycpUser = in.mycp.domain.User
                .findUsersByEmailEqualsAndPasswordEqualsAndActiveNot(username, encodedPass, false)
                .getSingleResult();
        mycpUser.setLoggedInDate(new Date());
        mycpUser = mycpUser.merge();
        List<Role> roles = Role.findRolesByIntvalLessThan(mycpUser.getRole().getIntval() + 1).getResultList();
        //everybody gets role_user
        //authorities.add(new GrantedAuthorityImpl("ROLE_USER"));
        for (Iterator iterator = roles.iterator(); iterator.hasNext();) {
            Role role = (Role) iterator.next();
            authorities.add(new GrantedAuthorityImpl(role.getName()));
        }

    } catch (EmptyResultDataAccessException e) {
        log.error(e.getMessage());//e.printStackTrace();
        throw new BadCredentialsException("Invalid username or password");
    } catch (EntityNotFoundException e) {
        log.error(e.getMessage());//e.printStackTrace();
        throw new BadCredentialsException("Invalid user");
    } catch (NonUniqueResultException e) {
        throw new BadCredentialsException("Non-unique user, contact administrator");
    } catch (Exception e) {
        throw new BadCredentialsException("Invalid username or password");
    }

    return new User(mycpUser.getEmail(), mycpUser.getPassword(), mycpUser.getActive(), // enabled
            true, // account not expired
            true, // credentials not expired
            true, // account not locked
            authorities);
}

From source file:net.noday.core.web.BaseController.java

@ExceptionHandler
public ModelAndView resolveException(EmptyResultDataAccessException e, WebRequest req) {
    log.error(e.getMessage(), e);
    ModelAndView m = new ModelAndView("error/404");
    responseMsg(m, false, e.getMessage());
    return m;//from   w  w w .j  a  v a  2 s. c o m
}

From source file:com.sr.model.dao.IMahasiswaDAOImpl.java

@Override
public Blob getFotoByNim(String nim) {
    try {/*from ww  w .  j  av a 2 s  .  c  o  m*/
        return getJdbcTemplate().queryForObject(GET_FOTO_MAHASISWA_BY_NIM, new Object[] { nim },
                new FotoMahasiswaRowMapper());
    } catch (EmptyResultDataAccessException er) {
        System.out.println("EmptyResultDataAccess " + er.getMessage());
        return null;
    }
}

From source file:com.alibaba.cobar.manager.dao.delegate.CobarAdapter.java

@Override
public String getVersion() {
    try {//from  w  w  w .j av  a2  s .  c o m
        return (String) getJdbcTemplate().queryForObject(SHOW_VERSION, new RowMapper() {

            @Override
            public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
                String version = rs.getString(VERSION);
                return version;
            }

        });
    } catch (EmptyResultDataAccessException e) {
        logger.error(e.getMessage(), e);
        return null;
    }
}

From source file:om.edu.squ.squportal.portlet.dps.dao.db.DpsDbImpl.java

/**
 * /*from w w w.  j a v  a 2s.c o m*/
 * method name  : getStudentAcademicDetail
 * @param studentId
 * @param locale
 * @return
 * @throws NoDBRecordException
 * DpsDbImpl
 * return type  : AcademicDetail
 * 
 * purpose      :
 *
 * Date          :   Jan 9, 2017 11:22:11 AM
 */
public AcademicDetail getStudentAcademicDetail(String studentId, String studentNo, Locale locale)
        throws NoDBRecordException, NotCorrectDBRecordException {
    String SQL_ACADEMIC_DETAIL_STUDENT = queryProps.getProperty(Constants.SQL_ACADEMIC_DETAIL_STUDENT);
    RowMapper<AcademicDetail> mapper = new RowMapper<AcademicDetail>() {

        public AcademicDetail mapRow(ResultSet rs, int rowNum) throws SQLException {
            AcademicDetail academicDetail = new AcademicDetail();
            academicDetail.setId(rs.getString(Constants.CONST_COLMN_STUDENT_ID));
            academicDetail.setStudentNo(rs.getString(Constants.CONST_COLMN_STUDENT_NO));
            academicDetail.setStdStatCode(rs.getString(Constants.CONST_COLMN_STDSTATCD));
            academicDetail.setCollege(rs.getString(Constants.CONST_COLMN_COLLEGE_NAME));
            academicDetail.setMajor(rs.getString(Constants.CONST_COLMN_MAJOR_NAME));
            academicDetail.setAdvisorId(rs.getString(Constants.CONST_COLMN_ADVISOR_ID));
            academicDetail.setSupervisorId(rs.getString(Constants.CONST_COLMN_SUPERVISOR_ID));
            academicDetail.setDegree(rs.getString(Constants.CONST_COLMN_DEGREE_NAME));
            academicDetail.setStatus(rs.getString(Constants.CONST_COLMN_STATUS_NAME));

            return academicDetail;
        }
    };

    Map<String, String> namedParameterMap = new HashMap<String, String>();
    namedParameterMap.put("paramLocale", locale.getLanguage());
    namedParameterMap.put("paramStudentId", studentId);
    namedParameterMap.put("paramStudentNo", studentNo);

    try {
        return nPJdbcTemplDps.queryForObject(SQL_ACADEMIC_DETAIL_STUDENT, namedParameterMap, mapper);
    } catch (EmptyResultDataAccessException ex) {
        throw new NoDBRecordException(ex.getMessage());
    } catch (IncorrectResultSizeDataAccessException exNotCorrectResultSize) {
        logger.error("DB Error : Error Thrown and to be catched in Service layer");
        throw new NotCorrectDBRecordException(exNotCorrectResultSize.getMessage());
    }
}

From source file:om.edu.squ.squportal.portlet.dps.dao.db.DpsDbImpl.java

/**
 * //from  ww w .  j  a v  a 2s.c  o  m
 * method name  : getStudentPersonalDetail
 * @param studentId
 * @param locale
 * @return
 * @throws NoDBRecordException
 * DpsDbImpl
 * return type  : PersonalDetail
 * 
 * purpose      :
 *
 * Date          :   Jan 9, 2017 11:21:56 AM
 */
public PersonalDetail getStudentPersonalDetail(String studentId, String studentNo, Locale locale)
        throws NoDBRecordException {

    String SQL_PERSONAL_DETAIL_STUDENT = queryProps.getProperty(Constants.SQL_PERSONAL_DETAIL_STUDENT);

    RowMapper<PersonalDetail> mapper = new RowMapper<PersonalDetail>() {

        public PersonalDetail mapRow(ResultSet rs, int rowNum) throws SQLException {
            PersonalDetail personalDetail = new PersonalDetail();

            personalDetail.setId(rs.getString(Constants.CONST_COLMN_STUDENT_ID));
            personalDetail.setName(rs.getString(Constants.CONST_COLMN_STUDENT_NAME));
            personalDetail.setPhone(rs.getString(Constants.CONST_COLMN_STUDENT_PHONE));
            personalDetail.setEmail(rs.getString(Constants.CONST_COLMN_STUDENT_EMAIL));
            personalDetail.setRegion(rs.getString(Constants.CONST_COLMN_STUDENT_HOME_REGION));
            personalDetail.setWillayat(rs.getString(Constants.CONST_COLMN_STUDENT_HOME_WILAYAT));
            personalDetail.setTown(rs.getString(Constants.CONST_COLMN_STUDENT_TOWN_VILLAGE));
            personalDetail.setPoBox(rs.getString(Constants.CONST_COLMN_STUDENT_HOME_POBOX));
            personalDetail.setPostalCode(rs.getString(Constants.CONST_COLMN_STUDENT_HOME_POSTALCD));

            return personalDetail;
        }
    };
    Map<String, String> namedParameterMap = new HashMap<String, String>();
    namedParameterMap.put("paramLocale", locale.getLanguage());
    namedParameterMap.put("paramStudentId", studentId);
    namedParameterMap.put("paramStudentNo", studentNo);
    try {
        return nPJdbcTemplDps.queryForObject(SQL_PERSONAL_DETAIL_STUDENT, namedParameterMap, mapper);
    } catch (EmptyResultDataAccessException ex) {

        throw new NoDBRecordException(ex.getMessage());
    }

}

From source file:om.edu.squ.squportal.portlet.dps.dao.db.DpsDbImpl.java

/**
 * //from w ww.  j a  v a 2 s .  c  o m
 * method name  : getEmployee
 * @param empNumber
 * @return
 * DpsDbImpl
 * return type  : Employee
 * 
 * purpose      :
 *
 * Date          :   Jan 8, 2017 3:42:44 PM
 * @throws ExceptionEmptyResultset 
 */
public Employee getEmployee(String empNumber) throws ExceptionEmptyResultset {
    String SQL_DPS_EMPLOYEE_DETAIL = queryProps.getProperty(Constants.COST_SQL_DPS_EMPLOYEE_DETAIL);

    RowMapper<Employee> mapper = new RowMapper<Employee>() {

        public Employee mapRow(ResultSet rs, int rowNum) throws SQLException {
            Employee employee = new Employee();
            Branch branch = new Branch();
            Department department = new Department();

            employee.setEmpNumber(rs.getString(Constants.COST_COL_DPS_EMP_NO));
            department.setDeptCode(rs.getString(Constants.COST_COL_DPS_DEPT_CODE));
            branch.setBranchCode(rs.getString(Constants.COST_COL_DPS_BRANCH_CODE));
            employee.setDepartment(department);
            employee.setBranch(branch);
            employee.setEmail(Constants.COST_COL_DPS_EMP_EMAIL);

            return employee;
        }
    };

    Map<String, String> mapParamsDPS = new HashMap<String, String>();
    mapParamsDPS.put("paramEmpNumber", empNumber);

    try {
        return nPJdbcTemplDps.queryForObject(SQL_DPS_EMPLOYEE_DETAIL, mapParamsDPS, mapper);
    } catch (EmptyResultDataAccessException ex) {
        logger.error("Empty resultset error. Details : " + ex.getMessage());
        throw new ExceptionEmptyResultset(ex.getMessage());
    }

}

From source file:com.carfinance.module.vehicleservicemanage.dao.VehicleServiceManageDao.java

public VehicleReservationInfo getVehicleReservationInfoById(long reservation_id) {
    try {//from www. jav  a  2 s  .  c o  m
        String sql = "select * from vehicle_reservation where id = ?";
        Object[] o = new Object[] { reservation_id };
        logger.info(sql.replaceAll("\\?", "{}"), o);
        return this.getJdbcTemplate().queryForObject(sql, o, new VehicleReservationInfoRowMapper());
    } catch (EmptyResultDataAccessException e) {
        logger.error(e.getMessage(), e);
        return null;
    }
}

From source file:com.carfinance.module.vehicleservicemanage.dao.VehicleServiceManageDao.java

public VehicleContraceInfo getVehicleContraceInfoById(long contrace_id) {
    try {// w  w w  .  j  a  v a2 s.  com
        String sql = "select * from vehicle_contrace where id = ?";
        Object[] o = new Object[] { contrace_id };
        logger.info(sql.replaceAll("\\?", "{}"), o);
        return this.getJdbcTemplate().queryForObject(sql, o, new VehicleContraceInfoRowMapper());
    } catch (EmptyResultDataAccessException e) {
        logger.error(e.getMessage(), e);
        return null;
    }
}

From source file:com.carfinance.module.vehicleservicemanage.dao.VehicleServiceManageDao.java

public PropertyContraceInfo getPropertyContraceInfoByreservationid(long reservation_id) {
    try {/* w w  w.  ja va  2s  .  c o  m*/
        String sql = "select * from property_contrace where reservation_id = ?";
        Object[] o = new Object[] { reservation_id };
        logger.info(sql.replaceAll("\\?", "{}"), o);
        return this.getJdbcTemplate().queryForObject(sql, o, new PropertyContraceInfoRowMapper());
    } catch (EmptyResultDataAccessException e) {
        logger.error(e.getMessage(), e);
        return null;
    }
}