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.ExamDAOImpl.java

/**
 * Used to get an ExamBean for a specified examId number.
 *
 * @param examId the exam id/*w w w.  jav  a  2s.  com*/
 * @return the exam bean
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
@SuppressWarnings("unchecked")
public final ExamBean load(final int examId) throws WhichDoctorDaoException {

    dataLogger.info("ExamId: " + examId + " requested");

    final String loadSQL = getSQL().getValue("exam/load") + " WHERE exam.ExamId = ?";

    ExamBean exam = null;

    try {
        exam = (ExamBean) this.getJdbcTemplateReader().queryForObject(loadSQL, new Object[] { examId },
                new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadExam(rs);
                    }
                });

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

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

/**
 * Used to get a Collection of ExamBeans for a specified GUID number.
 *
 * @param guid the guid//from   w  w  w.ja  va2 s  .  co m
 * @param fullResults the full results
 * @return the collection
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
@SuppressWarnings("unchecked")
public final Collection<ExamBean> load(final int guid, final boolean fullResults)
        throws WhichDoctorDaoException {

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

    final String loadExam = getSQL().getValue("exam/load")
            + " WHERE exam.Active = true AND exam.ReferenceGUID = ?" + " ORDER BY exam.DateSat";

    Collection<ExamBean> exams = new ArrayList<ExamBean>();

    try {
        exams = this.getJdbcTemplateReader().query(loadExam, new Object[] { guid }, new RowMapper() {
            public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                return loadExam(rs);
            }
        });

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

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

/**
 * Used to get a SearchBean for the specified SearchId number.
 *
 * @param searchId the search id//  www .  jav a  2 s.  c  o m
 * @return the search bean
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final SearchBean loadId(final int searchId) throws WhichDoctorDaoException {

    dataLogger.info("Search Id: " + searchId + " requested");

    SearchBean search = null;

    try {
        search = (SearchBean) this.getJdbcTemplateReader().queryForObject(
                this.getSQL().getValue("search/loadId"), new Object[] { searchId }, new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadSearch(rs);
                    }
                });

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

    return search;
}

From source file:com.sfs.whichdoctor.search.TagSearchDAOImpl.java

/**
 * Perform a search for tags.//ww  w  .j a  v a 2s  .c om
 *
 * @param objecttype the objecttype
 * @param order Order options are: alpha (alphabetical), count (tag count)
 * @param user the user
 *
 * @return the map< string, collection< tag bean>>
 *
 * @throws WhichDoctorSearchDaoException the which doctor search dao
 *             exception
 */
@SuppressWarnings("unchecked")
public final Map<String, Collection<TagBean>> search(final String objecttype, final String order,
        final UserBean user) throws WhichDoctorSearchDaoException {

    if (objecttype == null) {
        throw new WhichDoctorSearchDaoException("An object type must be " + "specified for a tag search");
    }

    Map<String, Collection<TagBean>> results = new HashMap<String, Collection<TagBean>>();

    // Holds a running total of the maximum tag count for each tag type
    HashMap<String, Integer> maxTagCount = new HashMap<String, Integer>();

    String searchSQL = this.getSQL().getValue("tag/search");

    /* Default order is alphabetical */
    if (StringUtils.equalsIgnoreCase(order, "count")) {
        searchSQL += " ORDER BY TagCount DESC";
    } else {
        searchSQL += " ORDER BY TagName ASC";
    }

    dataLogger.info("Performing tag search");

    Collection<TagBean> tagResults = new ArrayList<TagBean>();

    try {
        tagResults = this.getJdbcTemplateReader().query(searchSQL,
                new Object[] { objecttype, "Private", "Private", user.getDN() }, new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        TagBean tag = new TagBean();
                        tag.setTagName(rs.getString("TagName"));
                        tag.setTagType(rs.getString("TagType"));
                        tag.setTagCount(rs.getInt("TagCount"));

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

    for (TagBean tag : tagResults) {
        Collection<TagBean> tags = new ArrayList<TagBean>();
        if (results.containsKey(tag.getTagType())) {
            // Get existing array from
            tags = results.get(tag.getTagType());
        }

        if (maxTagCount.containsKey(tag.getTagType())) {
            Integer maxCount = maxTagCount.get(tag.getTagType());
            if (tag.getTagCount() > maxCount) {
                maxTagCount.put(tag.getTagType(), tag.getTagCount());
            }
        } else {
            maxTagCount.put(tag.getTagType(), new Integer(tag.getTagCount()));
        }
        tags.add(tag);

        results.put(tag.getTagType(), tags);
    }

    /* Iterate through results setting max tag count */
    for (String key : results.keySet()) {
        Integer maxCount = maxTagCount.get(key);

        Collection<TagBean> tempTags = results.get(key);
        Collection<TagBean> tags = new ArrayList<TagBean>();

        for (TagBean tag : tempTags) {
            tag.setMaxCount(maxCount);
            tags.add(tag);
        }
        results.put(key, tags);
    }

    /* Load all tags */
    String searchAllSQL = getSQL().getValue("tag/searchAll");

    if (order.compareToIgnoreCase("count") == 0) {
        searchAllSQL += " ORDER BY TagCount DESC";
    } else {
        searchAllSQL += " ORDER BY TagName ASC";
    }

    Collection<TagBean> allTagResults = new ArrayList<TagBean>();
    try {
        allTagResults = this.getJdbcTemplateReader().query(searchAllSQL,
                new Object[] { objecttype, "Private", "Private", user.getDN() }, new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        TagBean tag = new TagBean();
                        tag.setTagName(rs.getString("TagName"));
                        tag.setTagType("All");
                        tag.setTagCount(rs.getInt("TagCount"));

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

    int maxAllTagCount = 0;
    for (TagBean tag : allTagResults) {
        if (tag.getTagCount() > maxAllTagCount) {
            maxAllTagCount = tag.getTagCount();
        }
    }

    Collection<TagBean> allTags = new ArrayList<TagBean>();

    for (TagBean tag : allTagResults) {
        tag.setMaxCount(maxAllTagCount);
        allTags.add(tag);
    }

    if (allTags.size() > 0) {
        // At least one tag has been found, add it to results
        results.put("All", allTags);
    }
    return results;
}

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

/**
 * Load an EmailBean based on its id./*from  w  w  w .j  a  va2s.  c  o  m*/
 *
 * @param emailId the email id
 * @return the email bean
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final EmailBean load(final int emailId) throws WhichDoctorDaoException {

    dataLogger.info("Getting emailId:" + emailId);

    final String loadId = getSQL().getValue("email/load") + " " + getSQL().getValue("email/whereId");

    EmailBean email = null;
    try {
        email = (EmailBean) this.getJdbcTemplateReader().queryForObject(loadId, new Object[] { emailId },
                new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadEmail(rs);
                    }
                });

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

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

/**
 * Used to get a Collection of SearchBean details for a
 * specified search filter./*w ww .java 2s.  c om*/
 *
 * @param filter the filter
 * @param username or public saved searches
 * @param favourite load favourites or load everything
 * @return the collection
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
@SuppressWarnings("unchecked")
public final Collection<SearchBean> load(final String filter, final String username, final boolean favourite)
        throws WhichDoctorDaoException {

    dataLogger.info("Searches for: " + username + " requested");

    Collection<SearchBean> savedsearches = new ArrayList<SearchBean>();

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

    StringBuffer loadSearch = new StringBuffer();
    loadSearch.insert(0, this.getSQL().getValue("search/loadUser"));

    if (favourite) {
        loadSearch.append(" AND favourite = true");
    }
    if (StringUtils.isNotBlank(filter)) {
        loadSearch.append(" AND (Name LIKE ? OR Description LIKE ?)");
        parameters.add("%" + filter + "%");
        parameters.add("%" + filter + "%");
    }
    loadSearch.append(" ORDER BY savedsearch.Name");

    try {
        savedsearches = this.getJdbcTemplateReader().query(loadSearch.toString(), parameters.toArray(),
                new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadSearch(rs);
                    }
                });

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

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

/**
 * Used to get a ProjectBean for a specified ProjectId.
 *
 * @param projectId the project id//ww  w .  ja  v  a 2s  . com
 * @return the project bean
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
@SuppressWarnings("unchecked")
public final ProjectBean load(final int projectId) throws WhichDoctorDaoException {

    dataLogger.info("ProjectId: " + projectId + " requested");

    final String loadId = getSQL().getValue("project/load") + " WHERE project.ProjectId = ?";

    ProjectBean project = null;
    try {
        project = (ProjectBean) this.getJdbcTemplateReader().queryForObject(loadId, new Object[] { projectId },
                new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadProject(rs);
                    }
                });

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

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

/**
 * Used to get an Collection of ProjectBeans for a specified GUID number.
 *
 * @param guid the guid// ww w.  j av  a 2 s . c  o  m
 * @param fullResults the full results
 * @return the collection
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
@SuppressWarnings("unchecked")
public final Collection<ProjectBean> load(final int guid, final boolean fullResults)
        throws WhichDoctorDaoException {

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

    final String loadProject = getSQL().getValue("project/load")
            + " WHERE project.Active = true AND project.ReferenceGUID = ?"
            + " ORDER BY project.Year, guid.CreatedDate";

    Collection<ProjectBean> projects = new ArrayList<ProjectBean>();

    try {
        projects = this.getJdbcTemplateReader().query(loadProject, new Object[] { guid }, new RowMapper() {
            public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                return loadProject(rs);
            }
        });

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

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

/**
 * Used to get a IsbMessageBean for the the specified ISB Message Id.
 * Returns null if no isb message found/*from   ww  w .j a  va2s  .c o  m*/
 *
 * @param isbMessageId the isb message id
 *
 * @return the isb message bean
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final IsbMessageBean load(final int isbMessageId) throws WhichDoctorDaoException {

    dataLogger.info("ISB message id: " + isbMessageId + " requested");

    IsbMessageBean isbMessage = null;

    try {
        isbMessage = (IsbMessageBean) this.getIsbJdbcTemplate().queryForObject(
                this.getSQL().getValue("isbmessage/loadId"), new Object[] { isbMessageId }, new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadIsbMessageBean(rs);
                    }
                });

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

From source file:com.sfs.whichdoctor.search.SearchDAOImpl.java

/**
 * Search./*from w  w w. ja  v  a 2  s . co m*/
 *
 * @param search the search
 * @param loadDetails the load details
 *
 * @return the search results bean
 *
 * @throws WhichDoctorSearchDaoException the which doctor search dao
 *             exception
 */
@SuppressWarnings("unchecked")
public final SearchResultsBean search(final SearchBean search, final BuilderBean loadDetails)
        throws WhichDoctorSearchDaoException {

    if (this.sqlHandlers == null) {
        throw new WhichDoctorSearchDaoException("The search is not configured");
    }

    if (search.getType() == null) {
        /* Incorrect type set in SearchBean */
        dataLogger.error("No search type has been set");
        throw new WhichDoctorSearchDaoException("No search type has been set");
    }

    SqlHandler sqlHandler = null;
    if (this.sqlHandlers.containsKey(search.getType())) {
        sqlHandler = this.sqlHandlers.get(search.getType());
    }

    if (sqlHandler == null) {
        throw new WhichDoctorSearchDaoException("No SQL handler found for this search");
    }

    /* Build SQL WHERE statement */
    if (search.getSearchArray() != null) {
        search.setSQLWhereComponents(search.getSQLArrayStatement(sqlHandler.getIdentifierColumn()),
                search.getAction(), search.getSearchArray(), search.getSearchArrayDescription());
    } else {
        if (search.getSearchCriteria() != null && search.getSearchConstraints() != null) {
            Map<String[], Collection<Object>> fields = sqlHandler.construct(search.getSearchCriteria(),
                    search.getSearchConstraints());

            for (String[] key : fields.keySet()) {
                search.setSQLWhereComponents(key[0], search.getAction(), fields.get(key), key[1]);

            }
        }
    }

    final String sqlWHERE = search.getSearchSQL();

    // System.out.println("- SQL where: " + sqlWHERE);

    final Collection<Object> parameters = search.getSearchParameters();

    /* Set ordering system of returned results */
    if (search.getOrderColumn() == null) {
        search.setOrderColumn(sqlHandler.getDefaultOrder());
    }
    String sqlORDER = buildOrder(search);

    /* Set range of results */
    if (search.getRequestedPage() == 0) {
        search.setRequestedPage(1);
    }
    String sqlLIMIT = buildLimit(search);

    /* Initalize SearchResultsBean to hold result */
    SearchResultsBean searchResults = new SearchResultsBean();

    // Fill with values from SearchBean
    searchResults.setOrderAscending(search.getOrderAscending());
    searchResults.setOrderColumn(search.getOrderColumn());
    searchResults.setRequestedPage(search.getRequestedPage());
    searchResults.setType(search.getType());
    searchResults.setLimit(search.getLimit());
    searchResults.setSearchCriteria(search.getSearchCriteria());
    searchResults.setSearchVectors(search.getSearchVectors());

    if (loadDetails.getBoolean("RESULT_COUNT")) {
        /* Load the result count for this search */

        StringBuffer countSQL = new StringBuffer();
        countSQL.append(sqlHandler.getCountSql());
        countSQL.append(sqlWHERE);

        dataLogger.info("SQL Query: " + countSQL.toString());

        /* System.out.println("- SQL count: " + countSQL.toString()); */

        try {
            JdbcTemplate jdbcTemplate = this.getJdbcTemplateReader();
            if (!sqlHandler.getDefaultConnection()) {
                jdbcTemplate = this.getIsbJdbcTemplate();
            }
            final int totalResults = jdbcTemplate.queryForInt(countSQL.toString(), parameters.toArray());

            searchResults.setTotalResults(totalResults);
        } catch (DataAccessException de) {
            dataLogger.error("Error getting search result count: " + de.getMessage());
        }
    }

    // BUILD SQL Statement
    StringBuffer searchSQL = new StringBuffer();
    searchSQL.append(sqlHandler.getSelectSql());
    searchSQL.append(sqlWHERE);
    searchSQL.append(sqlHandler.getGroupBy());
    searchSQL.append(sqlORDER);
    searchSQL.append(sqlLIMIT);

    dataLogger.info("SQL Query: " + searchSQL.toString());

    /* System.out.println("- SQL search: " + searchSQL.toString()); */

    Collection<Integer> objects = null;

    try {
        JdbcTemplate jdbcTemplate = this.getJdbcTemplateReader();
        if (!sqlHandler.getDefaultConnection()) {
            jdbcTemplate = this.getIsbJdbcTemplate();
        }
        objects = jdbcTemplate.query(searchSQL.toString(), parameters.toArray(), new RowMapper() {
            public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                return rs.getInt(1);
            }
        });

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

    if (objects != null) {
        // Pass the results to the handler and load the referenced objects
        searchResults.setSearchResults(sqlHandler.load(objects, loadDetails));
    }
    return searchResults;
}