Example usage for org.springframework.dao IncorrectResultSizeDataAccessException getMessage

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

Introduction

In this page you can find the example usage for org.springframework.dao IncorrectResultSizeDataAccessException 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:com.sfs.whichdoctor.dao.AddressDAOImpl.java

/**
 * Update postcode and geocode./*from w  w  w  . jav a  2 s  .c o m*/
 *
 * @param countryVal the country
 * @param user the user
 * @param privileges the privileges
 * @return the hash map
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
@SuppressWarnings("unchecked")
public final HashMap<String, Collection<Integer>> updatePostcodeAndGeocode(final String countryVal,
        final UserBean user, final PrivilegesBean privileges) throws WhichDoctorDaoException {
    /**
     * Load the addresses based on the country and update their postcode.
     * Returns a hashmap containing the GUIDs of addresses 'updated' and
     * 'not updated'
     **/
    HashMap<String, Collection<Integer>> results = new HashMap<String, Collection<Integer>>();

    Collection<Integer> updated = new ArrayList<Integer>();
    Collection<Integer> notUpdated = new ArrayList<Integer>();

    String country = "";
    if (StringUtils.isNotBlank(countryVal)) {
        country = countryVal;
    }

    Collection<AddressBean> addresses = new ArrayList<AddressBean>();

    final String loadCountrySQL = getSQL().getValue("address/load")
            + " WHERE address.Active = true AND loc_state.Class = ?";

    try {
        addresses = this.getJdbcTemplateReader().query(loadCountrySQL, new Object[] { country },
                new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadAddress(rs);
                    }
                });

    } catch (IncorrectResultSizeDataAccessException ie) {
        dataLogger.debug("No results found for this search: " + ie.getMessage());
    }

    for (AddressBean address : addresses) {

        try {
            String existingPostcode = address.getPostCode();
            String existingGeocode = address.getGeocode();
            if (existingPostcode == null) {
                existingPostcode = "";
            }
            if (existingGeocode == null) {
                existingGeocode = "";
            }

            String newPostcode = this.getPostcode(address);
            String newGeocode = this.getGeocode(address);
            if (newPostcode == null) {
                newPostcode = "";
            }
            if (newGeocode == null) {
                newGeocode = "";
            }

            boolean updateAddress = false;

            if (newPostcode.compareTo("") != 0) {
                if (newPostcode.compareTo(existingPostcode) != 0) {
                    // A postcode was found update
                    address.setPostCode(newPostcode);
                    updateAddress = true;
                }
            }
            if (newGeocode.compareTo("") != 0) {
                if (newGeocode.compareTo(existingGeocode) != 0) {
                    // A geocode was found update
                    address.setGeocode(newGeocode);
                    updateAddress = true;
                }
            }
            if (updateAddress) {
                address.setLogMessage("Refreshed postcode/geocode");

                modify(address, user, privileges);
                updated.add(address.getGUID());
                dataLogger.error("Updated postcode/geocode for address GUID: " + address.getGUID());
            } else {
                dataLogger.error("Postcode/geocode not updated for address GUID: " + address.getGUID());
                notUpdated.add(address.getGUID());
            }
        } catch (Exception e) {
            dataLogger.error("Error updating postcode/geocode for address GUID " + address.getGUID() + ": "
                    + e.getMessage());
            notUpdated.add(address.getGUID());
        }
    }
    dataLogger.error("Postcode/geocode update process complete, " + updated.size() + " addresses changed, "
            + notUpdated.size() + " not updated");

    results.put("updated", updated);
    results.put("not updated", notUpdated);

    return results;
}

From source file:com.sfs.whichdoctor.dao.MembershipDAOImpl.java

/**
 * Used to get an ArrayList of MembershipBean details for a specified GUID
 * number.//from  w  w w .  j a  v a2  s . c o  m
 *
 * @param guid the guid
 * @param allMembership the all membership
 * @param membershipClass the membership class
 * @param membershipType the membership type
 *
 * @return the collection< membership bean>
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
@SuppressWarnings("unchecked")
public final Collection<MembershipBean> load(final int guid, final boolean allMembership,
        final String membershipClass, final String membershipType) throws WhichDoctorDaoException {

    dataLogger.info("Membership details for GUID: " + guid + " requested");

    // Do check whether required results are light (only primary)
    // or full (all memberships)
    boolean specificMembership = false;

    StringBuffer sql = new StringBuffer();
    sql.append(getSQL().getValue("membership/load"));
    sql.append(" WHERE membership.Active = true" + " AND membership.ReferenceGUID = ?");

    Collection<Object> parameters = new ArrayList<Object>();
    parameters.add(guid);

    if (StringUtils.isNotBlank(membershipClass)) {
        if (!StringUtils.equals(membershipClass, "Preferred")) {
            sql.append(" AND membershiptype.Class = ?");
            parameters.add(membershipClass);
            specificMembership = true;
        }
    }
    if (StringUtils.isNotBlank(membershipType)) {
        if (!StringUtils.equals(membershipType, "Preferred")) {
            sql.append(" AND membershiptype.Name = ?");
            parameters.add(membershipType);
            specificMembership = true;
        }
    }
    sql.append(" ORDER BY PrimaryMembership DESC, membership.GUID ASC");
    if (!allMembership) {
        sql.append(" LIMIT 1");
    }

    Collection<MembershipBean> memberships = new ArrayList<MembershipBean>();
    try {
        memberships = this.getJdbcTemplateReader().query(sql.toString(), parameters.toArray(), new RowMapper() {
            public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                return loadMembership(rs);
            }
        });

    } catch (IncorrectResultSizeDataAccessException ie) {
        dataLogger.debug("No results found for search: " + ie.getMessage());
    }

    if (specificMembership) {
        // Specific membership field set, check to see if result
        // If not load more generic
        if (memberships.size() == 0) {
            if (StringUtils.isNotBlank(membershipType)) {
                /* MembershipType set, load just membership class */
                memberships = load(guid, allMembership, membershipClass, null);
            }
            if (memberships.size() == 0) {
                if (StringUtils.isNotBlank(membershipClass)) {
                    /* MembershipClass set, load just membership */
                    memberships = load(guid, allMembership, null, null);
                }
            }
        }
    }
    return memberships;
}

From source file:com.sfs.whichdoctor.dao.RotationDAOImpl.java

/**
 * Load a RotationBean for a specified GUID and supplied load details.
 *
 * @param guid the guid// w  w w.j av a 2 s  .com
 * @param loadDetails the load details
 *
 * @return the rotation bean
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
@SuppressWarnings("unchecked")
public final RotationBean loadGUID(final int guid, final BuilderBean loadDetails)
        throws WhichDoctorDaoException {

    final String loadGUID = getSQL().getValue("rotation/load")
            + " AND rotation.Active = true AND people.Active = true " + "AND rotation.GUID = ?";

    RotationBean rotation = null;

    try {
        rotation = (RotationBean) this.getJdbcTemplateReader().queryForObject(loadGUID, new Object[] { guid },
                new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadRotation(rs, loadDetails);
                    }
                });

    } catch (IncorrectResultSizeDataAccessException ie) {
        dataLogger.debug("No results found for search: " + ie.getMessage());
    }
    return rotation;
}

From source file:com.sfs.whichdoctor.dao.RotationDAOImpl.java

/**
 * Load the current rotations for the supplied person GUID.
 *
 * @param personGUID the person guid//from w ww .  j  a va 2 s. c o m
 * @param loadDetails the load details
 * @return the collection
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
@SuppressWarnings("unchecked")
public final Collection<RotationBean> loadCurrentForPerson(final int personGUID, final BuilderBean loadDetails)
        throws WhichDoctorDaoException {

    Collection<RotationBean> rotations = new ArrayList<RotationBean>();

    Date currentTime = new Date(Calendar.getInstance().getTimeInMillis());

    final String loadCurrent = getSQL().getValue("rotation/load")
            + " AND rotation.Active = true AND people.Active = true "
            + " AND people.GUID = ? AND rotation.StartDate < ? AND rotation.EndDate > ?";

    try {
        rotations = this.getJdbcTemplateReader().query(loadCurrent,
                new Object[] { personGUID, currentTime, currentTime }, new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadRotation(rs, loadDetails);
                    }
                });

    } catch (IncorrectResultSizeDataAccessException ie) {
        dataLogger.debug("No results found for search: " + ie.getMessage());
    }

    return rotations;
}

From source file:com.sfs.whichdoctor.dao.RotationDAOImpl.java

/**
 * Load a RotationBean for a specified rotationId and supplied load details.
 * A boolean parameter identifies whether to use the default reader
 * connection or optional writer connection datasource.
 *
 * @param rotationId the rotation id/*  w  w  w.  j  ava2s  .co  m*/
 * @param loadDetails the load details
 * @param useWriterConn the use writer conn
 *
 * @return the rotation bean
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
@SuppressWarnings("unchecked")
private RotationBean load(final int rotationId, final BuilderBean loadDetails, final boolean useWriterConn)
        throws WhichDoctorDaoException {

    RotationBean rotation = null;

    final String loadRotationId = getSQL().getValue("rotation/load") + " AND rotation.RotationId = ?";

    JdbcTemplate jdbcTemplate = this.getJdbcTemplateReader();
    if (useWriterConn) {
        jdbcTemplate = this.getJdbcTemplateWriter();
    }

    try {
        rotation = (RotationBean) jdbcTemplate.queryForObject(loadRotationId, new Object[] { rotationId },
                new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadRotation(rs, loadDetails);
                    }
                });

    } catch (IncorrectResultSizeDataAccessException ie) {
        dataLogger.debug("No results found for the search: " + ie.getMessage());
    }
    return rotation;
}

From source file:com.sfs.whichdoctor.dao.RotationDAOImpl.java

/**
 * Builds the accreditation summary./*from ww w .j  a  va 2 s  .c o  m*/
 *
 * @param personGUID the person guid
 * @param type the type
 * @return the collection
 */
@SuppressWarnings("unchecked")
private Collection<HashMap<String, Integer>> buildAccreditationSummary(final int personGUID,
        final String type) {

    // Build a map to hold the accreditation summary
    Collection<HashMap<String, Integer>> accreditationSummary = new ArrayList<HashMap<String, Integer>>();

    try {
        accreditationSummary = this.getJdbcTemplateWriter().query(
                this.getSQL().getValue("rotation/accreditationSummary"), new Object[] { personGUID, type },
                new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        HashMap<String, Integer> summary = new HashMap<String, Integer>();

                        summary.put("Accreditation", rs.getInt("Accreditation"));
                        summary.put("GUID", rs.getInt("GUID"));
                        summary.put("AccreditationTypeId", rs.getInt("AccreditationTypeId"));
                        summary.put("SpecialtyId", rs.getInt("SpecialtyId"));

                        int trainingId = DEFAULT_ROTATION;
                        String type = rs.getString("TrainingClass");

                        if (StringUtils.contains(type, "ontinuing")) {
                            trainingId = CONTINUING_ROTATION;
                        }
                        if (StringUtils.contains(type, "nterrupt")) {
                            trainingId = INTERRUPTED_ROTATION;
                        }
                        summary.put("TrainingId", trainingId);

                        return summary;
                    }
                });

    } catch (IncorrectResultSizeDataAccessException ie) {
        dataLogger.debug("No results found for this search: " + ie.getMessage());
    }

    return accreditationSummary;
}

From source file:com.sfs.whichdoctor.dao.PersonDAOImpl.java

/**
 * Load a PersonBean for a specified GUID and the load options provided.
 *
 * @param guid the guid//from  ww w .ja  v a 2s.co m
 * @param loadDetails the load details
 *
 * @return the person bean
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
@SuppressWarnings("unchecked")
public final PersonBean loadGUID(final int guid, final BuilderBean loadDetails) throws WhichDoctorDaoException {

    PersonBean person = null;

    final String loadGUID = getSQL().getValue("person/load") + " AND people.Active = true AND people.GUID = ?";

    try {
        person = (PersonBean) this.getJdbcTemplateReader().queryForObject(loadGUID, new Object[] { guid },
                new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadPerson(rs, loadDetails);
                    }
                });

    } catch (IncorrectResultSizeDataAccessException ie) {
        dataLogger.debug("No results found for search: " + ie.getMessage());
    }

    return person;
}

From source file:com.sfs.whichdoctor.dao.PersonDAOImpl.java

/**
 * Load a PersonBean for a specified identifier using the load options
 * provided./*w  ww .  j av a 2  s . c om*/
 *
 * @param identifier the identifier
 * @param loadDetails the load details
 *
 * @return the person bean
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
@SuppressWarnings("unchecked")
public final PersonBean loadIdentifier(final int identifier, final BuilderBean loadDetails)
        throws WhichDoctorDaoException {

    PersonBean person = null;

    final String loadIdentifier = getSQL().getValue("person/load")
            + " AND people.Active = true AND people.PersonIdentifier = ?";

    try {
        person = (PersonBean) this.getJdbcTemplateReader().queryForObject(loadIdentifier,
                new Object[] { identifier }, new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadPerson(rs, loadDetails);
                    }
                });

    } catch (IncorrectResultSizeDataAccessException ie) {
        dataLogger.debug("No results found for search: " + ie.getMessage());
    }

    return person;
}

From source file:com.sfs.whichdoctor.dao.PersonDAOImpl.java

/**
 * Update the region index for this person.
 *
 * @param guid the guid//from  ww w . j  ava  2  s.c o m
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final void updateRegion(final int guid) throws WhichDoctorDaoException {

    int regionId = 0;

    try {
        final Date currentDate = new Date(Calendar.getInstance().getTimeInMillis());

        regionId = this.getJdbcTemplateReader().queryForInt(this.getSQL().getValue("person/loadEmployerRegion"),
                new Object[] { currentDate, currentDate, guid });

    } catch (IncorrectResultSizeDataAccessException ie) {
        dataLogger.debug("No results found for search: " + ie.getMessage());
    }

    // If no region id found, search to get the region for the person's address
    if (regionId == 0) {
        regionId = this.getAddressDAO().getRegionId(guid);
    }

    try {
        this.getSearchIndexDAO().update(guid, "Region", 0, 0, regionId);
    } catch (Exception e) {
        dataLogger.error("Error updating region index: " + e.getMessage());
    }
}

From source file:com.sfs.whichdoctor.dao.PersonDAOImpl.java

/**
 * Update the resident country index for this person.
 *
 * @param guid the guid//from w w w .j  a v a  2 s . com
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final void updateResidentCountry(final int guid) throws WhichDoctorDaoException {

    int stateCountryId = 0;

    try {
        final Date currentDate = new Date(Calendar.getInstance().getTimeInMillis());

        stateCountryId = this.getJdbcTemplateReader().queryForInt(
                this.getSQL().getValue("person/loadEmployerCountry"),
                new Object[] { currentDate, currentDate, guid });

    } catch (IncorrectResultSizeDataAccessException ie) {
        dataLogger.debug("No results found for search: " + ie.getMessage());
    }

    // If no state/country id found, search to get the id for the person's address
    if (stateCountryId == 0) {
        stateCountryId = this.getAddressDAO().getStateCountryId(guid);
    }

    try {
        this.getSearchIndexDAO().update(guid, "Resident Country", 0, 0, stateCountryId);
    } catch (Exception e) {
        dataLogger.error("Error updating resident country index: " + e.getMessage());
    }
}