Example usage for org.springframework.transaction.support DefaultTransactionDefinition DefaultTransactionDefinition

List of usage examples for org.springframework.transaction.support DefaultTransactionDefinition DefaultTransactionDefinition

Introduction

In this page you can find the example usage for org.springframework.transaction.support DefaultTransactionDefinition DefaultTransactionDefinition.

Prototype

public DefaultTransactionDefinition() 

Source Link

Document

Create a new DefaultTransactionDefinition, with default settings.

Usage

From source file:com.krawler.spring.common.CommonFnController.java

public ModelAndView changeUserPassword(HttpServletRequest request, HttpServletResponse response) {
    JSONObject jobj = new JSONObject();
    KwlReturnObject kmsg = null;/* w w  w.j av  a  2s  . c om*/
    //Create transaction
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("CF_Tx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);

    TransactionStatus status = txnManager.getTransaction(def);
    try {
        String platformURL = this.getServletContext().getInitParameter("platformURL");

        HashMap<String, Object> requestParams = new HashMap<String, Object>();
        requestParams.put("currentpassword", StringUtil.checkForNull(request.getParameter("currentpassword")));
        requestParams.put("changepassword", StringUtil.checkForNull(request.getParameter("changepassword")));
        requestParams.put("userid", sessionHandlerImpl.getUserid(request));
        requestParams.put("companyid", sessionHandlerImpl.getCompanyid(request));
        requestParams.put("remoteapikey", ConfigReader.getinstance().get("remoteapikey"));

        kmsg = profileHandlerDAOObj.changeUserPassword(platformURL, requestParams);
        jobj = (JSONObject) kmsg.getEntityList().get(0);
        txnManager.commit(status);
        jobj.put("success", true);
    } catch (Exception e) {
        System.out.println(e.getMessage());
        txnManager.rollback(status);
    }
    return new ModelAndView("jsonView", "model", jobj.toString());
}

From source file:com.krawler.spring.crm.caseModule.CrmCustomerCaseController.java

public ModelAndView saveCustomerCases(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, ServiceException {
    JSONObject myjobj = new JSONObject();
    KwlReturnObject kmsg = null;/*from  w w  w . j  ava  2  s .  c o  m*/
    CrmCase cases = null;
    String responseMessage = "";
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("JE_Tx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED);
    TransactionStatus status = txnManager.getTransaction(def);
    FileUploadHandler uh = new FileUploadHandler();
    HashMap hm = uh.getItems(request);
    Map model = new HashMap();

    try {

        String companyid = sessionHandlerImpl.getCompanyid(request);
        String customerId = (String) request.getSession().getAttribute("customerid");
        String contactId = (String) request.getSession().getAttribute("contactid");
        String caseOwnerID = crmCustomerCaseService.getCompanyCaseDefaultOwnerID(companyid);
        Integer operationCode = CrmPublisherHandler.ADDRECORDCODE;
        JSONObject jobj = new JSONObject();
        JSONObject jobj1 = new JSONObject();
        String id = java.util.UUID.randomUUID().toString();

        jobj.put("caseid", id);
        jobj.put("contactnameid", contactId);
        jobj.put("userid", caseOwnerID);
        jobj.put("caseownerid", caseOwnerID);
        jobj.put("subject", hm.get("subject"));
        jobj.put("description", hm.get("description"));
        jobj.put("companyid", companyid);
        jobj.put("createdon", System.currentTimeMillis());
        jobj.put("updatedon", System.currentTimeMillis());
        jobj.put("casecreatedby", contactId);
        jobj.put("createdbyflag", "1");

        kmsg = crmCustomerCaseService.addCases(jobj);
        cases = (CrmCase) kmsg.getEntityList().get(0);

        try {
            FileItem fileItem = (FileItem) hm.get("attachment");
            String filename = fileItem.getName();
            String docID = "";
            if (filename != null && filename != "") {
                if (fileItem.getSize() <= 10485760) { //limit 10 mb
                    kmsg = crmCustomerCaseService.uploadFile(fileItem, null, companyid, getServletContext());//Since document is uploaded by customer ,userid is null for uploadfile function
                    Docs doc = (Docs) kmsg.getEntityList().get(0);
                    docID = doc.getDocid();
                    jobj1.put("docid", docID);
                    jobj1.put("companyid", companyid);
                    jobj1.put("id", id);
                    jobj1.put("map", "6");
                    jobj1.put("refid", id);
                    crmCustomerCaseService.saveDocumentMapping(jobj1);
                    crmCustomerCaseService.saveCustomerDocs(customerId, docID, id);
                }
            }
        } catch (Exception e) {
            logger.warn("Attachment upload failed with Customer case :" + e.getMessage());
        }

        myjobj.put("success", true);
        myjobj.put("ID", cases.getCaseid());
        myjobj.put("createdon", jobj.optLong("createdon"));
        txnManager.commit(status);

        JSONObject cometObj = jobj;
        if (!StringUtil.isNullObject(cases)) {
            if (!StringUtil.isNullObject(cases.getCreatedon())) {
                cometObj.put("createdon", cases.getCreatedonGMT());
            }
        }
        //publishCasesModuleInformation(request, cometObj, operationCode, companyid, caseOwnerID);
        request.setAttribute("caselist", "true");
        responseMessage = "usercases/redirect";

    } catch (Exception e) {
        logger.warn(e.getMessage(), e);
        txnManager.rollback(status);
    }
    return new ModelAndView(responseMessage, "model", model);
}

From source file:es.tid.fiware.rss.expenditureLimit.processing.test.ProcessingLimitServiceTest.java

/**
 * Update control dates//from   www. j a  va  2  s. c o  m
 * 
 * @param controls
 */
private void updateDate(List<DbeExpendControl> controls) {
    GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance();
    cal.setTime(new Date());
    cal.add(Calendar.DAY_OF_MONTH, 1);
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
    TransactionStatus status = transactionManager.getTransaction(def);
    for (DbeExpendControl control : controls) {
        control.setDtNextPeriodStart(cal.getTime());
        controlService.createOrUpdate(control);
    }
    transactionManager.commit(status);

}

From source file:com.bleum.canton.jms.dao.impl.JMSTaskDao.java

@Override
public void updateTaskProcessed(JMSTask task, int maxRetry) {
    DefaultTransactionDefinition paramTransactionDefinition = new DefaultTransactionDefinition();
    TransactionStatus tstatus = platformTransactionManager.getTransaction(paramTransactionDefinition);
    try {//  ww  w  .  ja v  a  2 s  .c  o  m
        if (task.getRetry() >= maxRetry) {
            this.jdbcTemplate.update(UPDATE_TASK_COMPLETE, new Date(), task.getId());
        } else {
            this.jdbcTemplate.update(UPDATE_TASK_PROCESSED, task.getRetry() + 1, new Date(), task.getId());
        }
        platformTransactionManager.commit(tstatus);
    } catch (Exception e) {
        platformTransactionManager.rollback(tstatus);
    }
}

From source file:alfio.manager.AdminReservationManager.java

public Result<Boolean> updateReservation(String eventName, String reservationId,
        AdminReservationModification adminReservationModification, String username) {
    DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
    TransactionTemplate template = new TransactionTemplate(transactionManager, definition);
    return template.execute(status -> {
        try {//from  w  w w . j a  v a2 s.  c  om
            Result<Boolean> result = eventRepository.findOptionalByShortName(eventName)
                    .flatMap(e -> optionally(() -> {
                        eventManager.checkOwnership(e, username, e.getOrganizationId());
                        return e;
                    }))
                    .map(event -> ticketReservationRepository.findOptionalReservationById(reservationId)
                            .map(r -> performUpdate(reservationId, event, r, adminReservationModification))
                            .orElseGet(() -> Result.error(ErrorCode.ReservationError.UPDATE_FAILED)))
                    .orElseGet(() -> Result.error(ErrorCode.ReservationError.NOT_FOUND));
            if (!result.isSuccess()) {
                log.debug(
                        "Application error detected eventName: {} reservationId: {}, username: {}, reservation: {}",
                        eventName, reservationId, username,
                        AdminReservationModification.summary(adminReservationModification));
                status.setRollbackOnly();
            }
            return result;
        } catch (Exception e) {
            log.error(
                    "Error during update of reservation eventName: {} reservationId: {}, username: {}, reservation: {}",
                    eventName, reservationId, username,
                    AdminReservationModification.summary(adminReservationModification));
            status.setRollbackOnly();
            return Result.error(singletonList(ErrorCode.custom("", e.getMessage())));
        }
    });
}

From source file:org.openvpms.component.business.service.archetype.rule.ArchetypeRuleServiceTestCase.java

/**
 * Verifies that if a rule throws an exception, all changes are rolled
 * back./*  ww  w.ja  v  a  2s .  c  o m*/
 */
@Test
public void testTransactionRollbackOnException() {
    Party person = createPerson("MR", "T", "Anderson");
    Act act = (Act) service.create("act.simple");
    service.save(person);
    service.save(act);

    // start a new transaction
    TransactionStatus status = txnManager.getTransaction(new DefaultTransactionDefinition());

    // change some details
    person.getDetails().put("lastName", "Foo");

    service.save(person);

    try {
        // make the act.simple.after save rule throw an exception
        act.setStatus("EXCEPTION_AFTER");
        service.save(act);
        fail("Expected save to fail");
    } catch (Exception expected) {
        // expected
    }
    try {
        txnManager.commit(status);
        fail("Expected commit to fail");
    } catch (TransactionException expected) {
        // verify that no changes are made persistent
        person = reload(person);
        act = reload(act);
        assertEquals(person.getName(), "Anderson,T");
        assertNull(act.getStatus());
    }
}

From source file:es.tid.fiware.rss.expenditureLimit.dao.impl.tests.DbeExpendControlDaoTest.java

@Test
public void testNewExpendLimitDataForaUser() {

    BmService bmService = new BmService();
    bmService.setNuServiceId(1);//from   w w  w. ja  v a 2  s.  c  o m
    BmCurrency bmCurrency = new BmCurrency();
    bmCurrency.setNuCurrencyId(1);
    BmObCountry bmObCountry = new BmObCountry();
    bmObCountry.setId(new BmObCountryId(1, 1));
    List<DbeExpendControl> l = expLimitDao.getExpendDataForUserAppProvCurrencyObCountry("userId01", bmService,
            "app123456", bmCurrency, bmObCountry);

    Assert.assertTrue("Elements founds", l != null && l.size() == 3);
    Iterator<DbeExpendControl> it = l.iterator();
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(Propagation.REQUIRES_NEW.value());
    TransactionStatus status = transactionManager.getTransaction(def);
    while (it.hasNext()) {
        DbeExpendControl el = it.next();
        DbeExpendControl neoEc = new DbeExpendControl();
        neoEc.setId(new DbeExpendLimitPK());
        neoEc.getId().setNuCountryId(el.getId().getNuCountryId());
        neoEc.getId().setNuCurrencyId(el.getId().getNuCountryId());
        neoEc.getId().setNuObId(el.getId().getNuCountryId());
        neoEc.getId().setNuServiceId(el.getId().getNuCountryId());
        neoEc.getId().setTxAppProviderId("123456");
        neoEc.getId().setTxElType(el.getId().getTxElType());
        neoEc.getId().setTxEndUserId("userId101");
        neoEc.setDtNextPeriodStart(el.getDtNextPeriodStart());
        neoEc.setTxNotifications(el.getTxNotifications());
        neoEc.setFtExpensedAmount(el.getFtExpensedAmount());
        expLimitDao.saveDbeExpendControl(neoEc);
    }
    transactionManager.commit(status);
    l = expLimitDao.getExpendDataForUserAppProvCurrencyObCountry("userId101", bmService, "123456", bmCurrency,
            bmObCountry);

    Assert.assertTrue("Elements founds", l != null && l.size() == 3);
    it = l.iterator();
    while (it.hasNext()) {
        DbeExpendControl el = it.next();
        if (!el.getId().getTxAppProviderId().equalsIgnoreCase("123456")) {
            Assert.fail("Application provider invalid: " + el.getId().getTxAppProviderId());
        }
        if (!el.getId().getTxEndUserId().equalsIgnoreCase("userId101")) {
            Assert.fail("User invalid: " + el.getId().getTxEndUserId());
        }
    }
}

From source file:org.dbflute.utflute.spring.SpringTestCase.java

protected SpringTransactionResource xregisterTransaction(SpringTransactionResource resource,
        final String managerKey) {
    final PlatformTransactionManager manager = getComponent(managerKey);
    final DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
    final TransactionStatus status = manager.getTransaction(def);
    resource.registerTransaction(manager, status);
    return resource;
}

From source file:com.krawler.spring.crm.common.commentController.java

public ModelAndView addComments(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    JSONObject jobj = new JSONObject();
    JSONObject myjobj = new JSONObject();
    KwlReturnObject kmsg = null;//from  w  ww  .  j a  v  a 2s . c  o m
    Object c;
    String details = "";
    String auditAction = "";
    String id = java.util.UUID.randomUUID().toString();
    String randomnumber = request.getParameter("randomnumber");
    String moduleName = request.getParameter("modulename");
    String jsondata = request.getParameter("jsondata");
    String map = "";
    String refid = "";
    //Create transaction
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("JE_Tx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED);
    TransactionStatus status = txnManager.getTransaction(def);
    try {
        String userid = sessionHandlerImpl.getUserid(request);
        String companyid = sessionHandlerImpl.getCompanyid(request);
        JSONArray jarr = new JSONArray("[" + jsondata + "]");
        for (int i = 0; i < jarr.length(); i++) {
            jobj = jarr.getJSONObject(i);
            map = jobj.getString("mapid");
            refid = jobj.getString("leadid");
            String commStrAudit = StringUtil.serverHTMLStripper(jobj.getString("comment"));
            commStrAudit = commStrAudit.replaceAll("&nbsp;", "");
            String cid = java.util.UUID.randomUUID().toString();
            String commentid = jobj.getString("commentid");
            jobj.put("userid", userid);
            jobj.put("companyid", companyid);
            jobj.put("cid", cid);
            jobj.put("refid", refid);
            if (StringUtil.isNullOrEmpty(commentid)) { // Add Mode
                jobj.put("id", id);
                if (moduleName.equals(Constants.Case)) {//Case                                      
                    crmCommentDAOObj.addCaseComments(jobj);
                } else {
                    kmsg = crmCommentDAOObj.addComments(jobj);
                }
            } else { // Edit Mode

                jobj.put("id", commentid.trim());
                if (moduleName.equals(Constants.Case)) {
                    kmsg = crmCommentDAOObj.editCaseComments(jobj);
                } else {
                    kmsg = crmCommentDAOObj.editComments(jobj);
                }
            }

            //@@@ - Need to restructure this code
            if (map.equals("0")) {
                c = hibernateTemplate.get("com.krawler.crm.database.tables.CrmCampaign", refid);
                details = " Campaign - ";
                details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "campaignname")) ? ""
                        : BeanUtils.getProperty(c, "campaignname");
                auditAction = AuditAction.CAMPAIGN_ADD_COMMENTS;
            } else if (map.equals("1")) {
                c = hibernateTemplate.get("com.krawler.crm.database.tables.CrmLead", refid);
                details = " Lead - ";
                details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "firstname")) ? ""
                        : BeanUtils.getProperty(c, "firstname") + " ";
                details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "lastname")) ? ""
                        : BeanUtils.getProperty(c, "lastname");
                auditAction = AuditAction.LEAD_ADD_COMMENTS;
            } else if (map.equals("2")) {
                c = hibernateTemplate.get("com.krawler.crm.database.tables.CrmContact", refid);
                details = " Contact - ";
                details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "firstname")) ? ""
                        : BeanUtils.getProperty(c, "firstname");
                details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "lastname")) ? ""
                        : BeanUtils.getProperty(c, "lastname");
                auditAction = AuditAction.CONTACT_ADD_COMMENTS;
            } else if (map.equals("3")) {
                c = hibernateTemplate.get("com.krawler.crm.database.tables.CrmProduct", refid);
                details = " Product - ";
                details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "productname")) ? ""
                        : BeanUtils.getProperty(c, "productname");
                auditAction = AuditAction.PRODUCT_ADD_COMMENTS;
            } else if (map.equals("4")) {
                c = hibernateTemplate.get("com.krawler.crm.database.tables.CrmAccount", refid);
                details = " Account - ";
                details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "accountname")) ? ""
                        : BeanUtils.getProperty(c, "accountname");
                auditAction = AuditAction.ACCOUNT_ADD_COMMENTS;
            } else if (map.equals("5")) {
                c = hibernateTemplate.get("com.krawler.crm.database.tables.CrmOpportunity", refid);
                details = " Opportunity - ";
                details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "oppname")) ? ""
                        : BeanUtils.getProperty(c, "oppname");
                auditAction = AuditAction.OPPORTUNITY_ADD_COMMENTS;
            } else if (map.equals("6")) {
                c = hibernateTemplate.get("com.krawler.crm.database.tables.CrmCase", refid);
                details = " Case - ";
                details += StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "subject")) ? ""
                        : BeanUtils.getProperty(c, "subject");
                auditAction = AuditAction.CASE_ADD_COMMENTS;
            } else if (map.equals("7")) {
                c = hibernateTemplate.get("com.krawler.crm.database.tables.CrmActivityMaster", refid);
                String subject = StringUtil.isNullOrEmpty(BeanUtils.getProperty(c, "subject")) ? ""
                        : "(" + BeanUtils.getProperty(c, "subject") + ")";
                //                      String aname = BeanUtils.getProperty(c,"crmCombodataByStatusid.aliasName");
                //                    if(!StringUtil.isNullOrEmpty(aname)){
                //                        comboStatus=aname;
                //                    }
                details = " Activity - " + BeanUtils.getProperty(c, "flag") + " " + subject;
                auditAction = AuditAction.ACTIVITY_ADD_COMMENTS;
            }
            auditTrailDAOObj.insertAuditLog(auditAction,
                    " Comment: '" + commStrAudit + "' , added for " + details, request, refid, id);
        }
        myjobj.put("ID", id);
        txnManager.commit(status);

        // add comment on other logins for same user
        try {
            JSONObject commetMap = new JSONObject();
            boolean isCommentAdded = kmsg.isSuccessFlag();
            int operationCode = CrmPublisherHandler.ADDCOMMENT;
            commetMap.put("isCommentAdded", isCommentAdded);
            commetMap.put("recid", refid);
            commetMap.put("modulename", moduleName);
            cometManagementService.publishModuleInformation(companyid, userid, randomnumber, moduleName, refid,
                    operationCode, commetMap, CometConstants.CRMUPDATES);
        } catch (Exception e) {
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
        txnManager.rollback(status);
    }
    return new ModelAndView("jsonView", "model", myjobj.toString());
}

From source file:org.ohmage.query.impl.SurveyUploadQuery.java

@Override
public List<Integer> insertSurveys(final String username, final String client, final String campaignUrn,
        final List<SurveyResponse> surveyUploadList, final Map<UUID, Image> bufferedImageMap,
        final Map<String, Video> videoContentsMap, final Map<String, Audio> audioContentsMap)
        throws DataAccessException {

    List<Integer> duplicateIndexList = new ArrayList<Integer>();
    int numberOfSurveys = surveyUploadList.size();

    // The following variables are used in logging messages when errors occur
    SurveyResponse currentSurveyResponse = null;
    PromptResponse currentPromptResponse = null;
    String currentSql = null;//from  ww  w  .j a  v  a  2 s. co  m

    List<File> fileList = new LinkedList<File>();

    // Wrap all of the inserts in a transaction 
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("survey upload");
    DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(getDataSource());
    TransactionStatus status = transactionManager.getTransaction(def); // begin transaction

    // Use a savepoint to handle nested rollbacks if duplicates are found
    Object savepoint = status.createSavepoint();

    try { // handle TransactionExceptions

        for (int surveyIndex = 0; surveyIndex < numberOfSurveys; surveyIndex++) {

            try { // handle DataAccessExceptions

                final SurveyResponse surveyUpload = surveyUploadList.get(surveyIndex);
                currentSurveyResponse = surveyUpload;
                currentSql = SQL_INSERT_SURVEY_RESPONSE;

                KeyHolder idKeyHolder = new GeneratedKeyHolder();

                // First, insert the survey
                getJdbcTemplate().update(new PreparedStatementCreator() {
                    public PreparedStatement createPreparedStatement(Connection connection)
                            throws SQLException {
                        PreparedStatement ps = connection.prepareStatement(SQL_INSERT_SURVEY_RESPONSE,
                                Statement.RETURN_GENERATED_KEYS);

                        String locationString = null;
                        Location location = surveyUpload.getLocation();
                        if (location != null) {
                            try {
                                locationString = location.toJson(false, LocationColumnKey.ALL_COLUMNS)
                                        .toString();
                            } catch (JSONException e) {
                                throw new SQLException(e);
                            } catch (DomainException e) {
                                throw new SQLException(e);
                            }
                        }

                        ps.setString(1, surveyUpload.getSurveyResponseId().toString());
                        ps.setString(2, username);
                        ps.setString(3, campaignUrn);
                        ps.setLong(4, surveyUpload.getTime());
                        ps.setString(5, surveyUpload.getTimezone().getID());
                        ps.setString(6, surveyUpload.getLocationStatus().toString());
                        ps.setString(7, locationString);
                        ps.setString(8, surveyUpload.getSurvey().getId());
                        try {
                            ps.setString(9,
                                    surveyUpload
                                            .toJson(false, false, false, false, true, true, true, true, true,
                                                    false, false, true, true, true, true, false, false)
                                            .toString());
                        } catch (JSONException e) {
                            throw new SQLException("Couldn't create the JSON.", e);
                        } catch (DomainException e) {
                            throw new SQLException("Couldn't create the JSON.", e);
                        }
                        ps.setString(10, client);
                        ps.setTimestamp(11, new Timestamp(System.currentTimeMillis()));
                        try {
                            ps.setString(12, surveyUpload.getLaunchContext().toJson(true).toString());
                        } catch (JSONException e) {
                            throw new SQLException("Couldn't create the JSON.", e);
                        }
                        try {
                            ps.setString(13, PreferenceCache.instance()
                                    .lookup(PreferenceCache.KEY_DEFAULT_SURVEY_RESPONSE_SHARING_STATE));
                        } catch (CacheMissException e) {
                            throw new SQLException("Error reading from the cache.", e);
                        }
                        return ps;
                    }
                }, idKeyHolder);

                savepoint = status.createSavepoint();

                final Number surveyResponseId = idKeyHolder.getKey(); // the primary key on the survey_response table for the 
                                                                      // just-inserted survey
                currentSql = SQL_INSERT_PROMPT_RESPONSE;

                // Now insert each prompt response from the survey
                Collection<Response> promptUploadList = surveyUpload.getResponses().values();

                createPromptResponse(username, client, surveyResponseId, fileList, promptUploadList, null,
                        bufferedImageMap, videoContentsMap, audioContentsMap, transactionManager, status);

            } catch (DataIntegrityViolationException dive) { // a unique index exists only on the survey_response table

                if (isDuplicate(dive)) {

                    LOGGER.debug("Found a duplicate survey upload message for user " + username);

                    duplicateIndexList.add(surveyIndex);
                    status.rollbackToSavepoint(savepoint);

                } else {

                    // Some other integrity violation occurred - bad!! All 
                    // of the data to be inserted must be validated before 
                    // this query runs so there is either missing validation 
                    // or somehow an auto_incremented key has been duplicated.

                    LOGGER.error("Caught DataAccessException", dive);
                    logErrorDetails(currentSurveyResponse, currentPromptResponse, currentSql, username,
                            campaignUrn);
                    for (File f : fileList) {
                        f.delete();
                    }
                    rollback(transactionManager, status);
                    throw new DataAccessException(dive);
                }

            } catch (org.springframework.dao.DataAccessException dae) {

                // Some other database problem happened that prevented
                // the SQL from completing normally.

                LOGGER.error("caught DataAccessException", dae);
                logErrorDetails(currentSurveyResponse, currentPromptResponse, currentSql, username,
                        campaignUrn);
                for (File f : fileList) {
                    f.delete();
                }
                rollback(transactionManager, status);
                throw new DataAccessException(dae);
            }

        }

        // Finally, commit the transaction
        transactionManager.commit(status);
        LOGGER.info("Completed survey message persistence");
    }

    catch (TransactionException te) {

        LOGGER.error("failed to commit survey upload transaction, attempting to rollback", te);
        rollback(transactionManager, status);
        for (File f : fileList) {
            f.delete();
        }
        logErrorDetails(currentSurveyResponse, currentPromptResponse, currentSql, username, campaignUrn);
        throw new DataAccessException(te);
    }

    LOGGER.info(
            "Finished inserting survey responses and any associated images into the database and the filesystem.");
    return duplicateIndexList;
}