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

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

Introduction

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

Prototype

public final void setName(String name) 

Source Link

Document

Set the name of this transaction.

Usage

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

public void addUserToClassWithRole(final String username, final String classId, final Clazz.Role classRole)
        throws DataAccessException {

    // Create the transaction.
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("Adding a user to a class.");

    try {/* ww  w. ja  va  2s  .  c o  m*/
        // Begin the transaction.
        PlatformTransactionManager transactionManager = new DataSourceTransactionManager(getDataSource());
        TransactionStatus status = transactionManager.getTransaction(def);

        // Insert the new user.
        try {
            getJdbcTemplate().update(SQL_INSERT_USER_CLASS,
                    new Object[] { username, classId, classRole.toString() });
        } catch (org.springframework.dao.DataAccessException e) {
            transactionManager.rollback(status);
            throw new DataAccessException("Error while executing SQL '" + SQL_INSERT_USER_CLASS
                    + "' with parameters: " + username + ", " + classId + ", " + classRole.toString(), e);
        }

        // Commit the transaction.
        try {
            transactionManager.commit(status);
        } catch (TransactionException e) {
            transactionManager.rollback(status);
            throw new DataAccessException("Error while committing the transaction.", e);
        }
    } catch (TransactionException e) {
        throw new DataAccessException("Error while attempting to rollback the transaction.", e);
    }
}

From source file:org.bitsofinfo.util.address.usps.ais.store.jpa.JPAStore.java

private Copyright processCopyright(Copyright copyright) throws StoreException {
    Copyright c = this.entityMgr.find(Copyright.class, copyright.getIdentifier());

    if (c == null) {
        DefaultTransactionDefinition td = new DefaultTransactionDefinition();
        td.setName("Process copyright");
        td.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);

        TransactionStatus txs = this.transactionManager.getTransaction(td);

        try {/*from  ww w.j  a v a 2s.  c  o m*/
            this.saveRecord(copyright);
            this.transactionManager.commit(txs);

        } catch (DataIntegrityViolationException e) {
            if (!txs.isCompleted()) {
                this.transactionManager.rollback(txs);
            }

            // ignore this, it is fine, some other load beat us to it
            c = this.entityMgr.find(Copyright.class, copyright.getIdentifier());
        }

        c = copyright;
    }

    return c;
}

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

@Override
public void updateAnnotation(final UUID annotationId, final String annotationText, final String client,
        final long time, final DateTimeZone timezone) throws DataAccessException {

    // Create the transaction.
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("Updating an annotation.");

    try {/* w w  w.  j  ava2  s.  c o  m*/
        // Begin the transaction.
        PlatformTransactionManager transactionManager = new DataSourceTransactionManager(getDataSource());
        TransactionStatus status = transactionManager.getTransaction(def);

        try {
            getJdbcTemplate().update(SQL_UPDATE_ANNOTATION, time, timezone.getID(), client, annotationText,
                    annotationId.toString());
        } catch (org.springframework.dao.DataAccessException e) {

            transactionManager.rollback(status);
            throw new DataAccessException("Error executing SQL '" + SQL_UPDATE_ANNOTATION
                    + "' with parameters: " + time + ", " + timezone.getID() + ", " + client + ", "
                    + annotationText + ", " + annotationId.toString(), e);
        }

        // Commit the transaction.
        try {
            transactionManager.commit(status);
        } catch (TransactionException e) {
            transactionManager.rollback(status);
            throw new DataAccessException("Error while committing the transaction.", e);
        }
    } catch (TransactionException e) {
        throw new DataAccessException("Error while attempting to rollback the transaction.", e);
    }
}

From source file:com.krawler.spring.organizationChart.organizationChartController.java

public ModelAndView deleteNode(HttpServletRequest request, HttpServletResponse response) {
    JSONObject jobj = new JSONObject();
    JSONObject jobj1 = new JSONObject();
    //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 {/*w w  w . j  a v  a 2  s. c  om*/

        boolean success = false;
        String nodeid = request.getParameter("nodeId");

        if (!StringUtil.isNullOrEmpty(nodeid)) {
            HashMap<String, Object> deleteJobj = organizationService.deleteNode(nodeid);

            success = Boolean.parseBoolean(deleteJobj.get("success").toString());

            List<Empprofile> ll = (List<Empprofile>) deleteJobj.get("childList");
            Empprofile emp = null;

            if (deleteJobj.get("deletedEmployee") != null) {
                emp = (Empprofile) deleteJobj.get("deletedEmployee");
            }

            User parentEmp = null;

            if (deleteJobj.get("parentEmployee") != null) {
                parentEmp = (User) deleteJobj.get("parentEmployee");
            }

            if (parentEmp != null && emp != null) {

                if (emp != null) {

                    String details = emp.getUserLogin().getUserName() + " [ "
                            + emp.getUserLogin().getUser().getFirstName() + " "
                            + emp.getUserLogin().getUser().getLastName() + " ] Un-assigned from "
                            + parentEmp.getFirstName() + " " + parentEmp.getLastName()
                            + " , and removed from Organization.";
                    auditTrailDAOObj.insertAuditLog(AuditAction.ORGANIZATION_CHART_NODE_DELETED, details,
                            request, "0");
                }

                for (Empprofile e : ll) {
                    String details = e.getUserLogin().getUser().getFirstName() + " "
                            + e.getUserLogin().getUser().getLastName() + "  re-assigned to "
                            + parentEmp.getFirstName() + " " + parentEmp.getLastName() + "  ";

                    auditTrailDAOObj.insertAuditLog(AuditAction.ORGANIZATION_CHART_NODE_ASSIGNED, details,
                            request, "0");
                }
            }

        }

        jobj.put("data", "{success:" + success + "}");

        jobj1.put("valid", true);
        jobj1.put("data", jobj);
        jobj1.put("success", true);
        txnManager.commit(status);
    } catch (Exception e) {
        logger.warn("General exception in deleteNode()", e);
        txnManager.rollback(status);
    }
    return new ModelAndView("jsonView", "model", jobj1.toString());
}

From source file:org.bitsofinfo.util.address.usps.ais.store.jpa.JPAStore.java

private void processNonCopyrightRecords(List<USPSRecord> records, Copyright copyright) throws StoreException {

    DefaultTransactionDefinition td = new DefaultTransactionDefinition();
    td.setName("Process copyright");
    td.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);

    TransactionStatus txs = this.transactionManager.getTransaction(td);
    try {//www .  j  a  va2 s .co  m

        //copyright = this.entityMgr.merge(copyright);

        for (USPSRecord r : records) {

            // skip copyrights if it is the same one passed in above
            if (r instanceof Copyright) {
                if (r.getIdentifier().equals(copyright.getIdentifier())) {
                    // chuck it as it has already been processed
                    continue;
                }
            }

            // ensure the copyright is linked
            r.setCopyright(copyright);

            // if we use the action code, use that to
            // determine to save or delete.
            if (r.getActionCode() == ActionCode.D) {
                this.deleteRecord(r);
            } else {
                this.saveRecord(r);
            }
        }

        this.transactionManager.commit(txs);

    } catch (Exception e) {
        this.transactionManager.rollback(txs);
    }

}

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

@Override
public void createPromptResponseAnnotation(final UUID annotationId, final String client, final Long time,
        final DateTimeZone timezone, final String annotationText, Integer promptResponseId)
        throws DataAccessException {

    // Create the transaction.
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("Creating a new prompt response annotation.");

    try {/*from ww w  .  j  av  a  2  s  . c o m*/
        // Begin the transaction.
        PlatformTransactionManager transactionManager = new DataSourceTransactionManager(getDataSource());
        TransactionStatus status = transactionManager.getTransaction(def);
        long id = 0;

        try {
            id = insertAnnotation(annotationId, time, timezone, client, annotationText);
        } catch (org.springframework.dao.DataAccessException e) {

            transactionManager.rollback(status);
            throw new DataAccessException("Error while executing SQL '" + SQL_INSERT_ANNOTATION
                    + "' with parameters: " + annotationId + ", " + time + ", " + timezone.getID() + ", "
                    + client + ", " + ((annotationText.length() > 25) ? annotationText.substring(0, 25) + "..."
                            : annotationText),
                    e);
        }
        try {
            // Insert the link between the prompt_response and its annotation
            getJdbcTemplate().update(SQL_INSERT_PROMPT_RESPONSE_ANNOTATION, promptResponseId, id);

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

            transactionManager.rollback(status);
            throw new DataAccessException("Error while executing SQL '" + SQL_INSERT_PROMPT_RESPONSE_ANNOTATION
                    + "' with parameters: " + promptResponseId + ", " + id, e);
        }

        // Commit the transaction.
        try {
            transactionManager.commit(status);
        } catch (TransactionException e) {
            transactionManager.rollback(status);
            throw new DataAccessException("Error while committing the transaction.", e);
        }

    } catch (TransactionException e) {
        throw new DataAccessException("Error while attempting to rollback the transaction.", e);
    }
}

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

@Override
public void createSurveyResponseAnnotation(final UUID annotationId, final String client, final Long time,
        final DateTimeZone timezone, final String annotationText, final UUID surveyId)
        throws DataAccessException {

    // Create the transaction.
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("Creating a new survey response annotation.");

    try {/*from   www.jav a 2s .c o m*/
        // Begin the transaction.
        PlatformTransactionManager transactionManager = new DataSourceTransactionManager(getDataSource());
        TransactionStatus status = transactionManager.getTransaction(def);
        long id = 0;

        try {
            id = insertAnnotation(annotationId, time, timezone, client, annotationText);
        } catch (org.springframework.dao.DataAccessException e) {

            transactionManager.rollback(status);
            throw new DataAccessException("Error while executing SQL '" + SQL_INSERT_ANNOTATION
                    + "' with parameters: " + annotationId + ", " + time + ", " + timezone.getID() + ", "
                    + client + ", " + ((annotationText.length() > 25) ? annotationText.substring(0, 25) + "..."
                            : annotationText),
                    e);
        }

        try {
            // Insert the link between the survey_response and its annotation
            getJdbcTemplate().update(SQL_INSERT_SURVEY_RESPONSE_ANNOTATION, surveyId.toString(), id);

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

            transactionManager.rollback(status);
            throw new DataAccessException("Error while executing SQL '" + SQL_INSERT_SURVEY_RESPONSE_ANNOTATION
                    + "' with parameters: " + surveyId.toString() + ", " + id, e);
        }

        // Commit the transaction.
        try {
            transactionManager.commit(status);
        } catch (TransactionException e) {
            transactionManager.rollback(status);
            throw new DataAccessException("Error while committing the transaction.", e);
        }

    } catch (TransactionException e) {
        throw new DataAccessException("Error while attempting to rollback the transaction.", e);
    }
}

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

public ModelAndView addComment(HttpServletRequest request, HttpServletResponse response) {
    Map model = new HashMap();
    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);
    try {/*w w w . j ava2s  .c  o  m*/
        if ((String) request.getSession().getAttribute(Constants.SESSION_CUSTOMER_ID) != null) {
            String caseId = request.getParameter("caseid");
            String userId = (String) request.getSession().getAttribute("contactid");
            String comment = request.getParameter("addcomment");
            crmCustomerCaseService.addComment(caseId, userId, comment);
            txnManager.commit(status);
            request.setAttribute("casedetails", "true");
            request.setAttribute("caseid", caseId);
        } else {
            request.setAttribute("logout", "true");
        }
        responseMessage = "usercases/redirect";
    }

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

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;/*  w ww  .ja  v  a2  s.c om*/
    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:com.krawler.spring.crm.caseModule.CrmCustomerCaseController.java

public ModelAndView custPassword_Change(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {

    String newpass = request.getParameter("newpass");
    String currentpass = request.getParameter("curpass");
    String customerid = request.getParameter("customerid");
    String email = request.getParameter("email");
    Map model = new HashMap();
    // String replaceStr=request.getParameter("cdomain");
    String url = URLUtil.getRequestPageURL(request, Links.UnprotectedLoginPageFull);
    String loginurl = url.concat("caselogin.jsp");
    String name = request.getParameter("cname");
    boolean verify_pass = false;
    String responseMessage = "";
    if ((String) request.getSession().getAttribute(Constants.SESSION_CUSTOMER_ID) != null) {
        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 {//from   w  w w. j a  va 2  s. co  m

            verify_pass = contactManagementService.verifyCurrentPass(currentpass, customerid);
            if (verify_pass) {
                contactManagementService.custPassword_Change(newpass, customerid);
                txnManager.commit(status);
                request.setAttribute("homepage", "true");
                request.setAttribute("success", "true");
                responseMessage = "usercases/redirect";
                String partnerNames = sessionHandlerImplObj.getPartnerName();
                String sysEmailId = sessionHandlerImplObj.getSystemEmailId();
                String passwordString = "Username: " + email + " <br/><br/>Password: <b>" + newpass + "</b>";
                String htmlmsg = "Dear <b>" + name
                        + "</b>,<br/><br/> Your <b>password has been changed</b> for your account on "
                        + partnerNames + " CRM. <br/><br/>" + passwordString + "<br/><br/>You can log in at:\n"
                        + loginurl + "<br/><br/>See you on " + partnerNames + " CRM <br/><br/> -The "
                        + partnerNames + " CRM Team";
                try {
                    SendMailHandler.postMail(new String[] { email }, "[" + partnerNames + "] Password Changed",
                            htmlmsg, "", sysEmailId, partnerNames + " Admin");
                } catch (MessagingException e) {
                    e.printStackTrace();
                }

            } else {
                request.setAttribute("changepassword", "true");
                request.setAttribute("mis_pass", "true");
                txnManager.commit(status);
            }

        } catch (Exception e) {
            logger.warn("custPassword_change Error:", e);
            txnManager.rollback(status);
            responseMessage = "../../usercases/failure";
        }
    } else {
        request.setAttribute("logout", "true");
    }
    responseMessage = "usercases/redirect";
    return new ModelAndView(responseMessage, "model", model);
}