Example usage for javax.persistence StoredProcedureQuery getSingleResult

List of usage examples for javax.persistence StoredProcedureQuery getSingleResult

Introduction

In this page you can find the example usage for javax.persistence StoredProcedureQuery getSingleResult.

Prototype

Object getSingleResult();

Source Link

Document

Retrieve a single result from the next result set.

Usage

From source file:gov.opm.scrd.batchprocessing.jobs.BatchProcessingJob.java

/**
 * Checks whether the current day is a holiday.
 *
 * @param now The current day.//from   w  w  w . j av  a2 s.c o m
 * @return True if the current date is a holiday, false otherwise.
 * @throws BatchProcessingException If major error occurred.
 */
protected boolean isNowHoliday(Date now) throws BatchProcessingException {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(now);
    int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);

    if (dayOfWeek == Calendar.SUNDAY || dayOfWeek == Calendar.SATURDAY) {
        return true; // Sunday for 0 and Saturday for 6 are holidays
    }

    try {
        startTransaction();

        StoredProcedureQuery sp = entityManager.createNamedStoredProcedureQuery("IsThisHoliday");
        sp.setParameter("pDate2Test", now, TemporalType.DATE);

        Boolean result = (Boolean) sp.getSingleResult();

        commitTransaction();

        return result;
    } catch (PersistenceException pe) {
        throw new BatchProcessingException("Database error checking holiday.", pe);
    }
}

From source file:gov.opm.scrd.batchprocessing.jobs.BatchProcessingJob.java

/**
 * Batch daily account update./*  ww w  . j a v  a  2  s  . co  m*/
 * <p/>
 * This method does not throw any exception.
 *
 * @param procMessage The process message. Used to build the mail message.
 * @return true if execution is successful; false otherwise.
 */
private boolean batchDailyAccountUpdate(StringBuilder procMessage) {
    try {
        startTransaction();

        StoredProcedureQuery sp = entityManager.createNamedStoredProcedureQuery("BatchDailyAccountUpdate");
        sp.setParameter("pAuditBatchIDLog", todayAuditBatch.getId());

        Integer count = (Integer) sp.getSingleResult();

        commitTransaction();

        String msg = "Updated " + count + " master records to history or ACH Stop status.";
        logger.info(msg);
        procMessage.append(CRLF).append(CRLF).append(msg);

        return true;
    } catch (PersistenceException pe) {
        logger.error("ERROR: Updating master records to history or ACH Stop status failed.", pe);
        procMessage.append(CRLF).append(CRLF)
                .append("ERROR: Updating master records to history or ACH Stop status failed. ");
        return false;
    }
}