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.dao.GadgetPreferencesDAOImpl.java

/**
 * Load a GadgetPreferencesBean for the supplied userDn.
 *
 * @param userDn the user dn// w w w. j  av  a 2  s .co m
 *
 * @return the gadgets preferences bean
 *
 * @throws SFSDaoException the SFS dao exception
 */
@SuppressWarnings("unchecked")
public final GadgetsPreferencesBean load(final String userDn) throws SFSDaoException {
    if (userDn == null) {
        throw new SFSDaoException("User DN cannot be null");
    }
    if (userDn.compareTo("") == 0) {
        throw new SFSDaoException("User DN cannot be an empty string");
    }

    GadgetsPreferencesBean gadgetsPreferences = new GadgetsPreferencesBean();
    gadgetsPreferences.setUserDn(userDn);

    dataLogger.debug("Load gadget preferences for: " + userDn);

    Collection<GadgetPreferencesBean> gadgetCollection = new ArrayList<GadgetPreferencesBean>();

    try {
        gadgetCollection = this.getJdbcTemplateReader().query(getSQL().getValue("gadget/preferences/load"),
                new Object[] { userDn }, new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadGadgetPreferences(rs);
                    }
                });

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

    for (GadgetPreferencesBean gadgetPreferences : gadgetCollection) {
        gadgetsPreferences.addGadgetPreference(gadgetPreferences);
        gadgetsPreferences.addGadgetPreferenceRef(gadgetPreferences.getId(), gadgetPreferences.getPosition());
    }
    return gadgetsPreferences;
}

From source file:com.sfs.dao.GadgetPreferencesDAOImpl.java

/**
 * Update the supplied GadgetPreferencesBean within the datastore.
 *
 * @param gadgetPreferences the gadget preferences
 *
 * @return true, if update//  w  w w  .  ja  v  a 2s .  c  om
 *
 * @throws SFSDaoException the SFS dao exception
 */
public final boolean update(final GadgetPreferencesBean gadgetPreferences) throws SFSDaoException {
    if (gadgetPreferences.getId() == 0) {
        throw new SFSDaoException("Gadget preference Id cannot be 0");
    }
    if (gadgetPreferences.getUrl().compareTo("") == 0) {
        throw new SFSDaoException("Gadget preferences URL cannot be an empty string");
    }
    if (gadgetPreferences.getUserDn() == null) {
        throw new SFSDaoException("User DN cannot be null");
    }
    if (gadgetPreferences.getUserDn().compareTo("") == 0) {
        throw new SFSDaoException("User DN cannot be an empty string");
    }

    boolean success = false;

    dataLogger.info(gadgetPreferences.getUserDn() + " attempting to update gadget preferences");

    int updateCount = 0;
    try {
        updateCount = this.getJdbcTemplateWriter().update(getSQL().getValue("gadget/preferences/update"),
                new Object[] { gadgetPreferences.getUrl(), gadgetPreferences.getUserDn(),
                        gadgetPreferences.getTitle(), writeGadgetPreferences(gadgetPreferences.getUserPrefs()),
                        gadgetPreferences.getPosition(), gadgetPreferences.getHeight(),
                        gadgetPreferences.getWidth(), gadgetPreferences.getId() });

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

    if (updateCount > 0) {
        dataLogger.info(gadgetPreferences.getUserDn() + " successfully updated gadget preference entry");
        success = true;
    }
    return success;
}

From source file:com.sfs.whichdoctor.analysis.FinancialSummaryAnalysisDAOImpl.java

/**
 * Perform a financial summary search using the given parameters.
 *
 * @param search the search//from   w ww.j  a va  2 s  .c  o m
 * @param loadDetails the load details
 *
 * @return the financial summary results
 *
 * @throws WhichDoctorAnalysisDaoException the which doctor analysis dao exception
 */
public final FinancialSummaryBean search(final FinancialSummaryBean search, final BuilderBean loadDetails)
        throws WhichDoctorAnalysisDaoException {

    Collection<PersonBean> people = new ArrayList<PersonBean>();
    Collection<OrganisationBean> organisations = new ArrayList<OrganisationBean>();

    for (int guid : search.getPeople().keySet()) {
        PersonBean person = search.getPeople().get(guid);
        people.add(person);
    }

    for (int guid : search.getOrganisations().keySet()) {
        OrganisationBean organisation = search.getOrganisations().get(guid);
        organisations.add(organisation);
    }

    /* With PersonBean build correctly formatted SQL WHERE statement */
    StringBuffer sqlWHERE = new StringBuffer();
    sqlWHERE.append(buildWHERE(people, organisations));
    Collection<Object> parameters = new ArrayList<Object>();

    if (StringUtils.isNotBlank(search.getSecurity())) {
        sqlWHERE.append(" AND financialtype.Security = ?");
        parameters.add(search.getSecurity());
    }

    /* Initalize the bean to hold the results */
    FinancialSummaryBean searchResults = new FinancialSummaryBean();

    /* Fill with values from SearchBean */
    searchResults.setRequestedPage(search.getRequestedPage());
    searchResults.setLimit(search.getLimit());
    searchResults.setPeople(people);
    searchResults.setOrganisations(organisations);
    searchResults.setOpeningDate(search.getOpeningDate());
    searchResults.setClosingDate(search.getClosingDate());

    /* If some constraints for the search exist, do search */
    if (people.size() > 0 || organisations.size() > 0) {

        /* Set Opening Balance */
        if (searchResults.getOpeningDate() != null) {
            try {
                final double balance = getBalance(sqlWHERE.toString(), parameters,
                        searchResults.getOpeningDate(), true);
                searchResults.setOpeningBalance(balance);
            } catch (Exception e) {
                throw new WhichDoctorAnalysisDaoException("Could not get opening balance: " + e.getMessage());
            }
        } else {
            searchResults.setOpeningBalance(0);
        }

        /* Set Closing Balance */
        try {
            final double balance = getBalance(sqlWHERE.toString(), parameters, searchResults.getClosingDate(),
                    false);
            searchResults.setClosingBalance(balance);
        } catch (Exception e) {
            throw new WhichDoctorAnalysisDaoException("Could not get closing balance: " + e.getMessage());
        }

        // Add Opening and Closing dates to the search if they exist
        if (search.getOpeningDate() != null) {
            if (search.getClosingDate() == null) {
                search.setClosingDate(new Date(Calendar.getInstance().getTimeInMillis()));
            }
            int larger = search.getOpeningDate().compareTo(search.getClosingDate());
            if (larger > 0) {
                // SearchCriteria date after SearchConstraint date
                String fieldA = df.format(search.getOpeningDate());
                String fieldB = df.format(search.getClosingDate());
                sqlWHERE.append(" AND financial_summary.Issued BETWEEN ? AND ?");
                parameters.add(fieldB);
                parameters.add(fieldA);
            }
            if (larger < 0) {
                // SearchCriteria date before SearchConstraint date
                String fieldA = df.format(search.getOpeningDate());
                String fieldB = df.format(search.getClosingDate());
                sqlWHERE.append(" AND financial_summary.Issued BETWEEN ? AND ?");
                parameters.add(fieldA);
                parameters.add(fieldB);

            }
            if (larger == 0) {
                // SearchCritier and SearchConstraint are equal
                String field = df.format(search.getOpeningDate());
                sqlWHERE.append(" AND financial_summary.Issued = ?");
                parameters.add(field);
            }
        }

        if (!loadDetails.getBoolean("SHOW_CANCELLED")) {
            sqlWHERE.append(" AND financial_summary.Cancelled = ?");
            parameters.add(false);
        }

        /* Set range of results required */
        StringBuffer sqlLIMIT = new StringBuffer();

        if (search.getLimit() != 0) {
            if (search.getRequestedPage() == 0) {
                search.setRequestedPage(1);
            }
            // Determine first and last record requested
            final int firstRecord = (search.getRequestedPage() - 1) * search.getLimit();

            sqlLIMIT.append(" LIMIT ");
            sqlLIMIT.append(firstRecord);
            sqlLIMIT.append(", ");
            sqlLIMIT.append(search.getLimit());
        }

        if (loadDetails.getBoolean("RESULT_COUNT")) {
            /* Load the result count for this search */
            final String countSQL = getSQL().getValue("financialSummary/count") + sqlWHERE.toString();
            dataLogger.info("SQL Query: " + countSQL);

            try {
                final int recordCount = this.getJdbcTemplateReader().queryForInt(countSQL,
                        parameters.toArray());

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

        if (loadDetails.getBoolean("LOAD_DETAILS")) {
            searchResults = loadTransactions(searchResults, loadDetails, sqlWHERE.toString(),
                    sqlLIMIT.toString(), parameters);
        }
    }
    if (searchResults.getTransactions() == null || searchResults.getTransactions().size() == 0) {
        searchResults.setBalanceBroughtForward(searchResults.getClosingBalance());
    }

    return searchResults;
}

From source file:com.sfs.dao.GadgetPreferencesDAOImpl.java

/**
 * Persist the supplied GadgetPreferencesBean object to the datastore.
 *
 * @param gadgetPreferences the gadget preferences
 *
 * @return the int/*from  w  w w  .j ava2  s  . c  o m*/
 *
 * @throws SFSDaoException the SFS dao exception
 */
public final int create(final GadgetPreferencesBean gadgetPreferences) throws SFSDaoException {
    if (gadgetPreferences.getUrl().compareTo("") == 0) {
        throw new SFSDaoException("Gadget preferences URL cannot be an empty string");
    }
    if (gadgetPreferences.getUserDn() == null) {
        throw new SFSDaoException("User DN cannot be null");
    }
    if (gadgetPreferences.getUserDn().compareTo("") == 0) {
        throw new SFSDaoException("User DN cannot be an empty string");
    }

    int gadgetPreferenceId = 0;

    dataLogger.info(gadgetPreferences.getUserDn() + " attempting to create gadget preferences");

    if (gadgetPreferences.getPosition() == 0) {
        // A gadget position has not been defined - get the last position

        int maxPosition = 0;
        try {
            maxPosition = this.getJdbcTemplateReader().queryForInt(
                    getSQL().getValue("gadget/preferences/maxPosition"),
                    new Object[] { gadgetPreferences.getUserDn() });

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

    int insertCount = 0;
    try {
        insertCount = this.getJdbcTemplateWriter().update(getSQL().getValue("gadget/preferences/create"),
                new Object[] { gadgetPreferences.getUrl(), gadgetPreferences.getUserDn(),
                        gadgetPreferences.getTitle(), writeGadgetPreferences(gadgetPreferences.getUserPrefs()),
                        gadgetPreferences.getPosition(), gadgetPreferences.getHeight(),
                        gadgetPreferences.getWidth() });

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

    if (insertCount > 0) {
        // Gadget preferences created - get id
        dataLogger.info(gadgetPreferences.getUserDn() + " successfully created gadget preference entry");
        try {
            // Use the TemplateWriter to read as the change may not have
            // reached slave yet
            gadgetPreferenceId = this.getJdbcTemplateWriter()
                    .queryForInt(getSQL().getValue("gadget/preferences/findMax"));

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

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

/**
 * Load the address verification bean based on the address guid.
 *
 * @param guid the guid//from   w  w  w.ja va  2 s .  c  om
 * @return the address verification bean
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
@SuppressWarnings("unchecked")
public final AddressVerificationBean load(final int addressVerificationId) throws WhichDoctorDaoException {

    AddressVerificationBean addressVerification = null;

    String loadGUID = this.getSQL().getValue("addressVerification/loadId");

    try {
        addressVerification = (AddressVerificationBean) this.getJdbcTemplateReader().queryForObject(loadGUID,
                new Object[] { addressVerificationId }, new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadAddressVerification(rs);
                    }
                });

    } catch (IncorrectResultSizeDataAccessException ie) {
        dataLogger.debug("Could not find an address verification record for " + " the AddressVerificationId "
                + addressVerificationId + ": " + ie.getMessage());
    }
    return addressVerification;
}

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

/**
 * Used to get a OrganisationBean for a specified guid with the load details
 * provided.//from  w  ww  . j a  va2 s . co  m
 *
 * @param guid the guid
 * @param loadDetails the load details
 *
 * @return the organisation bean
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final OrganisationBean loadGUID(final int guid, final BuilderBean loadDetails)
        throws WhichDoctorDaoException {

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

    OrganisationBean organisation = null;

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

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

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

/**
 * Used to get a OrganisationBean for a specified organisationId with the
 * load details provided. A boolean parameter identifies whether to use the
 * default reader connection or optional writer connection datasource
 *
 * @param organisationId the organisation id
 * @param loadDetails the load details/*ww  w .j a va  2 s.  c o m*/
 * @param useWriterConn the use writer conn
 *
 * @return the organisation bean
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
private OrganisationBean load(final int organisationId, final BuilderBean loadDetails,
        final boolean useWriterConn) throws WhichDoctorDaoException {

    OrganisationBean organisation = null;

    final String loadOrganisationId = getSQL().getValue("organisation/load")
            + " AND organisation.OrganisationId = ?";

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

    try {
        organisation = (OrganisationBean) jdbcTemplate.queryForObject(loadOrganisationId,
                new Object[] { organisationId }, new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadOrganisation(rs, loadDetails);
                    }
                });

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

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

/**
 * Load a DebitBean for a specified GUID and supplied load options.
 *
 * @param guid the guid// www . j a va2s  .c  o  m
 * @param loadDetails the load details
 *
 * @return the debit bean
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final DebitBean loadGUID(final int guid, final BuilderBean loadDetails) throws WhichDoctorDaoException {

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

    DebitBean debit = null;

    final String loadSQL = getSQL().getValue("debit/load") + " AND invoice.Active = true AND invoice.GUID = ?";

    try {
        debit = (DebitBean) this.getJdbcTemplateReader().queryForObject(loadSQL, new Object[] { guid },
                new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadDebit(rs, loadDetails);
                    }
                });

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

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

/**
 * Load a DebitBean for a specified debit name and supplied load options.
 *
 * @param strDebit the str debit/* www . ja  va2s  .  c om*/
 * @param loadDetails the load details
 *
 * @return the debit bean
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final DebitBean load(final String strDebit, final BuilderBean loadDetails)
        throws WhichDoctorDaoException {

    dataLogger.info("Debit Name: " + strDebit + " requested");

    int debitGUID = 0;

    final String loadSQL = getSQL().getValue("debit/loadName");

    try {
        debitGUID = this.getJdbcTemplateReader().queryForInt(loadSQL, new Object[] { strDebit });

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

    if (debitGUID > 0) {
        return loadGUID(debitGUID, loadDetails);
    } else {
        throw new WhichDoctorDaoException("Sorry no debit matching " + "those details could be identified");
    }
}

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

/**
 * Used to get a DebitBean for a specified debitId and supplied load
 * options. A boolean parameter identifies whether to use the default reader
 * connection or optional writer connection datasource.
 *
 * @param debitId the debit id/*w  ww  . j  a  va 2 s .c  o  m*/
 * @param loadDetails the load details
 * @param useWriterConn the use writer conn
 *
 * @return the debit bean
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
private DebitBean load(final int debitId, final BuilderBean loadDetails, final boolean useWriterConn)
        throws WhichDoctorDaoException {

    DebitBean debit = null;

    dataLogger.info("DebitId: " + debitId + " requested");

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

    final String loadSQL = getSQL().getValue("debit/load") + " AND invoice.InvoiceId = ?";

    try {
        debit = (DebitBean) jdbcTemplate.queryForObject(loadSQL, new Object[] { debitId }, new RowMapper() {
            public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                return loadDebit(rs, loadDetails);
            }
        });

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