Example usage for javax.persistence StoredProcedureQuery getOutputParameterValue

List of usage examples for javax.persistence StoredProcedureQuery getOutputParameterValue

Introduction

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

Prototype

Object getOutputParameterValue(String parameterName);

Source Link

Document

Retrieve a value passed back from the procedure through an INOUT or OUT parameter.

Usage

From source file:example.springdata.jpa.storedprocedures.UserRepositoryIntegrationTests.java

@Test
public void plainJpa21_entityAnnotatedCustomNamedProcedurePlus1IO() {

    StoredProcedureQuery proc = em.createNamedStoredProcedureQuery("User.plus1");

    proc.setParameter("arg", 1);
    proc.execute();//from  w  ww . java2s .  c o  m

    assertThat(proc.getOutputParameterValue("res"), is((Object) 2));
}

From source file:example.springdata.jpa.storedprocedures.UserRepositoryIntegrationTests.java

@Test
public void plainJpa21() {

    StoredProcedureQuery proc = em.createStoredProcedureQuery("plus1inout");
    proc.registerStoredProcedureParameter(1, Integer.class, ParameterMode.IN);
    proc.registerStoredProcedureParameter(2, Integer.class, ParameterMode.OUT);

    proc.setParameter(1, 1);/*  w  w  w .  j  a v a 2 s  .  c om*/
    proc.execute();

    assertThat(proc.getOutputParameterValue(2), is((Object) 2));
}

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

/**
 * Collates new main frame payments.//from  w  w w. j a  v a2  s .  c  o m
 *
 * @param importStatus The import status.
 * @throws BatchProcessingException If major error occurred.
 */
private void collateNewMainframePayments(ImportStatus importStatus) throws BatchProcessingException {

    try {
        startTransaction();

        StoredProcedureQuery sp = entityManager.createNamedStoredProcedureQuery("BatchCollateNewPayments");

        sp.execute();

        Integer acceptedCount = (Integer) sp.getOutputParameterValue("pAcceptedCount");
        Integer unresolvedCount = (Integer) sp.getOutputParameterValue("pUnresolvedCount");
        Integer suspendedCount = (Integer) sp.getOutputParameterValue("pSuspendedCount");
        Integer acceptedACHCount = (Integer) sp.getOutputParameterValue("pAcceptedACHCount");
        Integer unresolvedACHCount = (Integer) sp.getOutputParameterValue("pUnresolvedACHCount");
        Integer suspendedACHCount = (Integer) sp.getOutputParameterValue("pSuspendedACHCount");

        commitTransaction();

        importStatus.setNumberAcceptedCheckPayments(acceptedCount);
        importStatus.setNumberUnresolvedCheckPayments(unresolvedCount);
        importStatus.setNumberSuspendedCheckPayments(suspendedCount);
        importStatus.setNumberAcceptedAchPayments(acceptedACHCount);
        importStatus.setNumberUnresolvedAchPayments(unresolvedACHCount);
        importStatus.setNumberSuspendedAchPayments(suspendedACHCount);
    } catch (PersistenceException pe) {
        throw new BatchProcessingException("Database Error: CollateNewMainframePayments", pe);
    }

    // Update audit batch log
    todayAuditBatch.setNumberAccepted(
            nullToZero(todayAuditBatch.getNumberAccepted()) + importStatus.getNumberAcceptedCheckPayments());
    todayAuditBatch.setNumberSuspended(
            nullToZero(todayAuditBatch.getNumberSuspended()) + importStatus.getNumberSuspendedCheckPayments());
    todayAuditBatch.setNumberUnresolved(nullToZero(todayAuditBatch.getNumberUnresolved())
            + importStatus.getNumberUnresolvedCheckPayments());
    todayAuditBatch.setNumberAchAccepted(
            nullToZero(todayAuditBatch.getNumberAchAccepted()) + importStatus.getNumberAcceptedAchPayments());
    todayAuditBatch.setNumberAchSuspended(
            nullToZero(todayAuditBatch.getNumberAchSuspended()) + importStatus.getNumberSuspendedAchPayments());
    todayAuditBatch.setNumberAchUnresolved(nullToZero(todayAuditBatch.getNumberAchUnresolved())
            + importStatus.getNumberUnresolvedAchPayments());

    try {
        todayAuditBatch = mergeEntity(todayAuditBatch);
    } catch (PersistenceException pe) {
        throw new BatchProcessingException(
                "Database error while updating audit batch log in collateNewMainframePayments", pe);
    }
}

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

/**
 * Process import record: R or C line.//from   ww  w .  j a  va  2 s. c  o  m
 *
 * @param mainFrame The MainframeImport record.
 * @param importStatus The import status.
 * @return The record type result.
 * @throws BatchProcessingException If major error occurred.
 */
private MainframeRecordType processImportRecord(MainframeImport mainFrame, ImportStatus importStatus)
        throws BatchProcessingException {

    String recordString = mainFrame.getRecordString();

    // Parse the record text
    rFile.parseFileLine(recordString);
    rFile.setAchPaymentFlag(
            rFile.getPaymentType() == LockboxPaymentType.ACH || mainFrame.getAchFlag() == Boolean.TRUE);

    String errorText = null;
    MainframeRecordType returnType = MainframeRecordType.NOT_A_RECORD;

    if (rFile.getValidFileRecord() == Boolean.TRUE) {

        if (rFile.getTransactionCode().equals("R")) {

            importStatus.setTransactionsTotal(importStatus.getTransactionsTotal().add(rFile.getAmount()));

            try {
                StoredProcedureQuery sp = entityManager
                        .createNamedStoredProcedureQuery("BatchInputBankPayments");
                sp.setParameter("pPayTransBatchNumber", rFile.getCdNumber());
                sp.setParameter("pPayTransBlockNumber", rFile.getBlockNumber());
                sp.setParameter("pPayTransSequenceNumber", rFile.getSequenceNumber());
                sp.setParameter("pSCMClaimNumber", rFile.getClaimNumber());
                sp.setParameter("pSCMDateOfBirth", rFile.getDateOfBirth(), TemporalType.DATE);
                sp.setParameter("pPayTransPaymentAmount", rFile.getAmount());
                sp.setParameter("pPayTransTransactionDate", rFile.getCdDate(), TemporalType.DATE);
                sp.setParameter("pACHPaymentFlag", rFile.getAchPaymentFlag());
                sp.setParameter("pNetworkId", batchProcessUser.getNetworkId());

                sp.execute();

                String returnCode = (String) sp.getOutputParameterValue("pReturn");
                Long paymentTransactionKey = (Long) sp.getOutputParameterValue("pPayTransactionKey");

                if ("0".equals(returnCode)) {
                    mainFrame.setPaymentTransactionId(paymentTransactionKey);
                    returnType = MainframeRecordType.VALID_R_TRANSACTION;
                } else if ("17".equals(returnCode)) {
                    returnType = MainframeRecordType.DUPLICATE_RECORD;
                    errorText = "Duplicate payment record based on year, batch, block, sequence, amount and date: "
                            + recordString;
                } else {
                    returnType = MainframeRecordType.BAD_R_TRANSACTION;
                    errorText = "Unknown R Transaction error (" + returnCode + "): " + recordString;
                }
            } catch (PersistenceException pe) {
                // Fill import status for logging
                fillImportStatus(importStatus, MainframeRecordType.BAD_R_TRANSACTION);
                errorText = "Database Error while inserting payment transaction record: " + recordString;
                throw new BatchProcessingException(errorText, pe);
            }
        } else {
            try {

                StoredProcedureQuery sp = entityManager
                        .createNamedStoredProcedureQuery("BatchPerformBankChanges");

                sp.setParameter("pSCMClaimnumber", rFile.getClaimNumber());
                sp.setParameter("pSCMDateOfBirth", rFile.getDateOfBirth(), TemporalType.DATE);
                sp.setParameter("pFieldNumber", rFile.getIndexOfAccountFieldToCorrect());
                sp.setParameter("pDataElement", rFile.getCorrectedData());

                String[] address = captureChanges(true, rFile.getCorrectedData());
                String[] name = captureChanges(false, rFile.getCorrectedData());

                sp.setParameter("pSCMCity", address[0]);
                sp.setParameter("pSCMState", address[1]);
                sp.setParameter("pSCMZipcode", address[2]);
                sp.setParameter("pSCMFName", name[0]);
                sp.setParameter("pSCMMInitial", name[1]);
                sp.setParameter("pSCMLastname", name[2]);
                sp.setParameter("pSCMSuffix", name[3]);

                sp.execute();

                Integer updatedCount = (Integer) sp.getOutputParameterValue("pUpdateCount");

                String returnCode = (String) sp.getOutputParameterValue("pErrorCode");

                if ("0".equals(returnCode)) {
                    if (updatedCount <= 0) {
                        returnType = MainframeRecordType.NOT_MATCH_C_TRANSACTION;
                        logger.warn("Change command did not update database for CSD #" + rFile.getClaimNumber()
                                + " Birthdate " + rFile.getDateOfBirth() + ": " + recordString);
                    } else {
                        returnType = MainframeRecordType.VALID_C_TRANSACTION;
                    }
                } else if ("-97".equals(returnCode)) {
                    returnType = MainframeRecordType.BAD_C_TRANSACTION;
                    errorText = "Invalid field number. The program does not accept changes to field # "
                            + rFile.getIndexOfAccountFieldToCorrect() + ": " + recordString;
                } else {
                    returnType = MainframeRecordType.BAD_C_TRANSACTION;
                    errorText = "Unknown C Transaction error (" + returnCode + "): " + recordString;
                }
            } catch (PersistenceException pe) {
                // Fill import status for logging
                fillImportStatus(importStatus, MainframeRecordType.BAD_C_TRANSACTION);
                errorText = "Database Error while changing the applicant record: " + recordString;
                throw new BatchProcessingException(errorText, pe);
            }
        }
    } else {
        if ("C".equals(rFile.getTransactionCode())) {
            returnType = MainframeRecordType.BAD_C_TRANSACTION;
        } else if ("R".equals(rFile.getTransactionCode())) {
            returnType = MainframeRecordType.BAD_R_TRANSACTION;
        } else {
            returnType = MainframeRecordType.NOT_A_RECORD;
        }
        errorText = "Text Line is not a valid Transaction Format [" + rFile.getRecordImportError() + "]: "
                + recordString;
    }

    if (errorText != null) {
        logger.error("Error importing the record from the MainframeImport table in"
                + " processImportRecord module: " + returnType + ". " + errorText);
    }

    return returnType;
}