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:edu.jhuapl.openessence.datasource.jdbc.entry.JdbcOeDataEntrySource.java

public void deleteQueryRecords(String tablename, List<DbKeyValMap> keysForDeletion)
        throws OeDataSourceAccessException {
    if (tablename == null) {
        throw new OeDataSourceAccessException(
                "Records were not deleted. No target table was specified to perform the deletion.");
    }//from   www. j  a  v a 2s .  com

    TransactionDefinition def = new DefaultTransactionDefinition();
    TransactionStatus status = getTransactionManager().getTransaction(def);
    try {
        keysForDeletion = (keysForDeletion == null) ? new ArrayList<DbKeyValMap>() : keysForDeletion;
        for (DbKeyValMap dbKeys : keysForDeletion) {
            editableDeleteStatement(tablename, dbKeys);
        }
        getTransactionManager().commit(status);
    } catch (DataAccessException de) {
        getTransactionManager().rollback(status);
        throw new OeDataSourceAccessException(
                "Records were not deleted. DataAccessException occured while deleting record.", de);
    }

}

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

public ModelAndView addTag(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    JSONObject jobj = new JSONObject();
    KwlReturnObject kmsg = null;/*from w ww.  j  a v  a2 s  .  com*/
    //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 tag = request.getParameter("tag");
        String newTag = request.getParameter("newTag");
        HashMap<String, Object> requestParams = new HashMap<String, Object>();
        requestParams.put("tag", StringUtil.checkForNull(tag));

        kmsg = crmDocumentDAOObj.addTag(requestParams);
        Docs d = (Docs) kmsg.getEntityList().get(0);
        auditTrailDAOObj.insertAuditLog(com.krawler.common.admin.AuditAction.DOC_TAG_ADDED,
                " Document - '" + newTag + "' tag added for " + d.getDocname(), request, d.getDocid());
        txnManager.commit(status);
    } catch (Exception e) {
        logger.warn(e.getMessage(), e);
        txnManager.rollback(status);
    }
    return new ModelAndView("jsonView", "model", jobj.toString());
}

From source file:com.krawler.spring.hrms.common.hrmsCommonController.java

public ModelAndView terminateEmp(HttpServletRequest request, HttpServletResponse response) {
    String hql = "";
    SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
    SimpleDateFormat sdf = new SimpleDateFormat("dd-mm-yyyy");
    JSONObject msg = 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 ww .  ja  v a 2 s  .  com*/
        boolean isCompanySuperAdmin = false;
        Empprofile e = null;
        String ids[] = request.getParameterValues("ids");
        String masterid = request.getParameter("tercause");
        String desc = ((StringUtil.isNullOrEmpty(request.getParameter("terdesc"))) ? ""
                : request.getParameter("terdesc"));
        String reldate = request.getParameter("relievedate");
        Date rvdate = fmt.parse(reldate);
        Empprofile emp = null;
        UserLogin usl = null;
        User usr = null;
        Date now = new Date();
        //           User updatedby=(User)session.get(User.class,sessionHandlerImplObj.getUserid(request));
        // User updatedby=(User)kwlCommonTablesDAOObj.getObject("com.krawler.common.admin.User", sessionHandlerImplObj.getUserid(request));
        String updatedby = sessionHandlerImplObj.getUserid(request);

        String companyid = sessionHandlerImplObj.getCompanyid(request);
        for (int i = 0; i < ids.length; i++) {
            if (hrmsCommonDAOObj.isCompanySuperAdmin(ids[i], companyid)) {
                isCompanySuperAdmin = true;
                break;
            }
        }
        if (isCompanySuperAdmin) {
            msg.put("msg", "adminerror");
            msg.put("success", true);
            txnManager.commit(status);
            return new ModelAndView("jsonView", "model", msg.toString());
        }

        for (int i = 0; i < ids.length; i++) {
            e = (Empprofile) kwlCommonTablesDAOObj.getObject("com.krawler.hrms.ess.Empprofile", ids[i]);
            if (e != null) {
                if (e.getJoindate() != null) {
                    if (e.getJoindate().after(rvdate)) {
                        msg.put("msg", "invalidterminatedate");
                        msg.put("success", true);
                        txnManager.commit(status);
                        return new ModelAndView("jsonView", "model", msg.toString());
                    }
                }
            }
            //                hql = "from Empprofile where userLogin.userID=?";
            //                List lst = HibernateUtil.executeQuery(session, hql, new Object[]{ids[i]});
            ////                usl=(UserLogin)session.get(UserLogin.class,ids[i]);
            //                usl=(UserLogin)HibernateUtil.getPrimary("com.krawler.common.admin.UserLogin", "userID");
            ////                usr=(User)session.get(User.class,ids[i]);
            //                usr=(User)HibernateUtil.getPrimary("com.krawler.common.admin.User", "userID");
            //                if(lst.isEmpty()){
            //                          emp=new Empprofile();
            //                          emp.setUserLogin(usl);
            //                }else{
            //                  emp=(Empprofile)session.get(Empprofile.class,ids[i]);
            //                }
            //                 Emphistory ehst=new Emphistory();
            //                 ehst.setUserid(usr);
            //                 ehst.setDepartment(usr.getDepartment());
            //                 ehst.setDesignation(usr.getDesignationid());
            //                 ehst.setSalary(usr.getSalary());
            //                 ehst.setEmpid(usr.getEmployeeid());
            //                 ehst.setUpdatedon(rvdate);
            //                 ehst.setJoindate(emp.getJoindate());
            //                 ehst.setEnddate(rvdate);
            //                 ehst.setUpdatedby(updatedby);
            //                 ehst.setCategory(Emphistory.Emp_Desg_change);
            //                 emp.setTerminatedby(updatedby);
            //                 emp.setTercause((MasterData)session.get(MasterData.class,masterid));
            //                 emp.setRelievedate(rvdate);
            //                 emp.setTerReason(desc);
            //                 emp.setTermnd(true);
            //                 usr.setDeleted(true);
            //                 session.saveOrUpdate(ehst);
            //                 session.saveOrUpdate(emp);
            //                 session.saveOrUpdate(usr);
            //                 //@@ProfileHandler.insertAuditLog(session, AuditAction.EMPLOYEE_TERMINATED, "Employee " + sessionHandlerImplObj.getFullName(usr) + " terminated by " + sessionHandlerImplObj.getFullName(session, sessionHandlerImplObj.getUserid(request)),request);
            HashMap<String, Object> requestParams = new HashMap<String, Object>();
            if (rvdate.before(now) || rvdate.equals(now)) {
                requestParams.put("termnd", true);
            }
            requestParams.put("userid", ids[i]);
            requestParams.put("terminatedby", updatedby);
            requestParams.put("tercause", masterid);
            requestParams.put("terReason", desc);
            requestParams.put("relievedate", reldate);
            KwlReturnObject result = hrmsCommonDAOObj.addEmpprofile(requestParams);

            HashMap<String, Object> deleteJobj = organizationService.deleteNode(ids[i]);

            if (rvdate.before(now) || rvdate.equals(now)) {
                requestParams.clear();
                requestParams.put("UserID", ids[i]);
                requestParams.put("Deleteflag", 1);
                hrmsCommonDAOObj.adduser(requestParams);
            }
        }
        msg.put("success", true);
        txnManager.commit(status);
    } catch (Exception e) {
        e.printStackTrace();
        txnManager.rollback(status);
    } finally {
        return new ModelAndView("jsonView", "model", msg.toString());
    }
}

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

@Override
public void deleteClass(String classId) throws DataAccessException {
    // Create the transaction.
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("Deleting a class.");

    try {/*from w w  w .  ja va2  s . co m*/
        // Begin the transaction.
        PlatformTransactionManager transactionManager = new DataSourceTransactionManager(getDataSource());
        TransactionStatus status = transactionManager.getTransaction(def);

        try {
            getJdbcTemplate().update(SQL_DELETE_CLASS, new Object[] { classId });
        } catch (org.springframework.dao.DataAccessException e) {
            transactionManager.rollback(status);
            throw new DataAccessException(
                    "Error while executing SQL '" + SQL_DELETE_CLASS + "' with parameter: " + classId, 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.poscoict.license.service.ManagementService.java

public void upload(String folder, String packageVersion, MultipartFile file, String comment, String mode,
        HttpSession session) throws Exception {
    TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
    try {//from www  . ja  v a 2 s  . c o m
        String folderPath = getFolderPath(folder);
        String objectId = "";
        if (mode.equals("package")) {
            if (packageVersion != null && packageVersion != "") {
                folderPath += packageVersion + File.separator;
                objectId = "pk_" + attachFileDateFormat()
                        + UUID.randomUUID().toString().replaceAll("-", "").substring(0, 12);
            }
        } else {
            folderPath += packageVersion + File.separator + "patch" + File.separator;
            objectId = "pt_" + attachFileDateFormat()
                    + UUID.randomUUID().toString().replaceAll("-", "").substring(0, 12);
            ;
        }

        MultipartFile upFile = file;
        String fileName = null;
        if (upFile != null) {
            fileName = upFile.getOriginalFilename();
            System.out.println("up: fileName: " + fileName + " " + folderPath);
            if (mode.equals("package")) {
                managementDao.addFileInfo(objectId, folder, folder.equals("etc") ? fileName : packageVersion,
                        fileName, comment.replaceAll("\n", "<br>"), folderPath + fileName,
                        (String) session.getAttribute("USER_NO"));
            } else {
                String pObjectId = managementDao.getProductKey(folder, packageVersion);
                managementDao.addPatchFileInfo(objectId, pObjectId, folder, packageVersion, fileName,
                        comment.replaceAll("\n", "<br>"), folderPath + fileName,
                        (String) session.getAttribute("USER_NO"));
            }
            try {
                File ufile = new File(folderPath + fileName);

                if (ufile.isFile()) {
                    logger.error("upload- Duplicate FileName: " + folderPath + fileName);
                    throw new UserException(
                            "???? . ??  .");
                }

                if (!ufile.exists()) {
                    ufile.mkdirs();
                }
                upFile.transferTo(ufile);
            } catch (IOException e) {
                e.printStackTrace();
                logger.error("packageUpload/patchUpload(File Upload Error): ", e);
                throw new IOException();
            }
        }
        this.transactionManager.commit(status);
    } catch (DuplicateKeyException e) {
        this.transactionManager.rollback(status);
        logger.error("packageUpload/patchUpload(File Upload Error): ", e);
        throw new DuplicateKeyException(
                " ?. ?? ? .");
    } catch (Exception e) {
        this.transactionManager.rollback(status);
        logger.error("packageUpload/patchUpload(File Upload Error): ", e);
        throw new Exception(e);
    }
}

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

public ModelAndView deletedocument(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    JSONObject jobj = new JSONObject();
    KwlReturnObject kmsg = null;/*from w  w w . ja v  a  2 s  . com*/
    //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);
    String docid = "";
    if (request.getParameter("docid") != null)
        docid = request.getParameter("docid");
    try {
        crmDocumentDAOObj.deletedocument(docid);
        //            auditTrailDAOObj.insertAuditLog(AuditAction.DOC_TAG_ADDED,
        //                    " Document - '" + newTag + "' tag added for "+d.getDocname(),
        //                    request, d.getDocid());
        txnManager.commit(status);
    } catch (Exception e) {
        logger.warn(e.getMessage(), e);
        txnManager.rollback(status);
    }
    return new ModelAndView("jsonView", "model", jobj.toString());
}

From source file:com.krawler.spring.hrms.rec.job.hrmsRecJobController.java

public ModelAndView DeleteInternalJobs(HttpServletRequest request, HttpServletResponse response) {
    List tabledata = null;//ww w. ja va  2 s  .  c  om
    JSONObject jobj = new JSONObject();
    JSONObject jobj1 = new JSONObject();
    String hql = null;
    boolean flag = true;
    ArrayList<String> name = new ArrayList<String>();
    ArrayList<Object> value = new ArrayList<Object>();
    KwlReturnObject result = null;
    //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);
    String title = "Success";
    try {
        String delids[] = request.getParameterValues("delid");
        for (int i = 0; i < delids.length; i++) {
            name.clear();
            value.clear();
            //                hql = "from Allapplications where position.positionid=? and company.companyID=? and delflag=0";
            //                tabledata = HibernateUtil.executeQuery(session, hql, new Object[]{delids[i], AuthHandler.getCompanyid(request)});
            name.add("position.positionid");
            value.add(delids[i]);
            name.add("company.companyID");
            value.add(sessionHandlerImplObj.getCompanyid(request));
            name.add("delflag");
            value.add(0);
            result = hrmsRecJobDAOObj.getPositionstatus(name, value);
            tabledata = result.getEntityList();
            if (tabledata.isEmpty()) {
                HashMap<String, Object> requestParams = new HashMap<String, Object>();

                requestParams.put("filter_names", Arrays.asList("applypos"));
                requestParams.put("filter_values", Arrays.asList((Positionmain) kwlCommonTablesDAOObj
                        .getObject("com.krawler.hrms.recruitment.Positionmain", delids[i])));
                result = hrmsRecAgencyDAOObj.getApplyagency(requestParams);
                if (result.getEntityList().isEmpty()) {
                    name.clear();
                    value.clear();
                    name.add("positionid");
                    value.add(delids[i]);

                    //                    hql = "from Positionmain where positionid=?";
                    //                    tabledata = HibernateUtil.executeQuery(session, hql, delids[i]);
                    requestParams.clear();
                    requestParams.put("filter_names", name);
                    requestParams.put("filter_values", value);
                    result = hrmsRecJobDAOObj.getPositionmain(requestParams);
                    tabledata = result.getEntityList();
                    if (!tabledata.isEmpty()) {
                        requestParams = new HashMap<String, Object>();
                        requestParams.put("delflag", 1);
                        requestParams.put("positionid", delids[i]);
                        result = hrmsRecJobDAOObj.updatePositionmain(requestParams);
                        //                        Positionmain log = (Positionmain) tabledata.get(0);
                        //                        log.setDelflag(1);
                        //                        session.update(log);

                    }
                } else {
                    flag = false;
                }
            } else {
                flag = false;
            }
        }
        if (flag) {
            jobj.put("message",
                    messageSource.getMessage("hrms.recruitment.SelectedJobPositionsuccessfullydeleted", null,
                            "Selected Job Position(s) successfully deleted.",
                            RequestContextUtils.getLocale(request)));
        } else {
            jobj.put("message", messageSource.getMessage("hrms.recruitment.SomejobscannotbedeletedBeacause",
                    null,
                    "Some jobs have assigned applicants or are assigned to agencies and hence cannot be deleted.",
                    RequestContextUtils.getLocale(request)));
        }
        jobj1.put("valid", true);
        jobj.put("title", title);
        jobj1.put("data", jobj.toString());
        txnManager.commit(status);
    } catch (Exception ex) {
        ex.printStackTrace();
        txnManager.rollback(status);
    } finally {
        return new ModelAndView("jsonView", "model", jobj1.toString());
    }
}

From source file:com.poscoict.license.service.ManagementService.java

public void addCustomUser(HttpSession session, ContractPersonInfo userInfo, UserPermission userPermission)
        throws UserException {
    TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
    try {// w  w  w .j ava2  s .co  m
        userInfo.setPROJECT_NAME("CUSTOM USER");
        managementDao.addOrderCompanyInfo(userInfo, passwordEncoder(userInfo.getUSER_NO()),
                Consts.USERLV_CUSTOM_USER, (String) session.getAttribute("USER_NO"));

        Map<String, Object> map = setPermissionCode(userPermission);
        String codes = (String) map.get("codes");
        String codeTypes = (String) map.get("codeTypes");
        int size = (Integer) map.get("size");
        managementDao.insert_user_permission(codes, codeTypes, userInfo.getUSER_NO(), size);

        this.transactionManager.commit(status);
    } catch (NullPointerException e) {
        this.transactionManager.rollback(status);
        logger.error("addCustomUser: ", e);
        throw new UserException("  ? ");
    } catch (Exception e) {
        this.transactionManager.rollback(status);
        logger.error("addCustomUser: ", e);
        throw new UserException("  ? ");
    }
}

From source file:com.krawler.spring.hrms.rec.job.hrmsRecJobController.java

public ModelAndView addjobprofile(HttpServletRequest request, HttpServletResponse response) {
    String id = "";
    KwlReturnObject result = null;/*from www . ja  v  a 2 s.c o  m*/
    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 {
        String jsondata1 = request.getParameter("jsondataresp");
        String jsondata2 = request.getParameter("jsondataskill");
        String jsondata3 = request.getParameter("jsondataqual");
        ArrayList name = new ArrayList();
        ArrayList value = new ArrayList();
        name.add("positionid");
        value.add(request.getParameter("position"));
        HashMap<String, Object> requestParams = new HashMap<String, Object>();
        requestParams.put("filter_names", name);
        requestParams.put("filter_values", value);
        result = hrmsRecJobDAOObj.getPositionmain(requestParams);
        Positionmain pos = null;
        if (result.getEntityList() != null && result.getEntityList().size() > 0)
            pos = (Positionmain) result.getEntityList().get(0);

        requestParams = new HashMap<String, Object>();
        JSONArray jarr = new JSONArray("[" + jsondata1 + "]");
        for (int i = 0; i < jarr.length(); i++) {
            JSONObject jobj = jarr.getJSONObject(i);
            if (!StringUtil.isNullOrEmpty(jobj.getString("id"))) {
                id = jobj.getString("id");
                requestParams.put("id", id);
            }
            requestParams.put("responsibility", jobj.getString("responsibility"));
            requestParams.put("position", pos);
            requestParams.put("type", jobj.getString("type"));
            hrmsRecJobDAOObj.addJobProfile(requestParams);
            requestParams.clear();
        }

        requestParams.clear();
        jarr = new JSONArray("[" + jsondata2 + "]");
        for (int j = 0; j < jarr.length(); j++) {
            JSONObject jobj = jarr.getJSONObject(j);
            if (!StringUtil.isNullOrEmpty(jobj.getString("id"))) {
                id = jobj.getString("id");
                requestParams.put("id", id);
            }
            requestParams.put("skill", jobj.getString("skill"));
            requestParams.put("skilldesc", jobj.getString("skilldesc"));
            requestParams.put("type", jobj.getString("type"));
            requestParams.put("position", pos);
            hrmsRecJobDAOObj.addJobProfile(requestParams);
            requestParams.clear();
        }

        requestParams.clear();
        jarr = new JSONArray("[" + jsondata3 + "]");
        for (int j = 0; j < jarr.length(); j++) {
            JSONObject jobj = jarr.getJSONObject(j);
            if (!StringUtil.isNullOrEmpty(jobj.getString("id"))) {
                id = jobj.getString("id");
                requestParams.put("id", id);
            }
            requestParams.put("qualification", jobj.getString("qualification"));
            requestParams.put("qualificationdesc", jobj.getString("qualificationdesc"));
            requestParams.put("type", jobj.getString("type"));
            requestParams.put("position", pos);
            hrmsRecJobDAOObj.addJobProfile(requestParams);
            requestParams.clear();
        }
        jobj1.put("valid", true);
        jobj1.put("data", "success");
        txnManager.commit(status);
    } catch (Exception ex) {
        ex.printStackTrace();
        txnManager.rollback(status);
    } finally {
        return new ModelAndView("jsonView", "model", jobj1.toString());
    }
}

From source file:com.siblinks.ws.service.impl.PostServiceImpl.java

/**
 * {@inheritDoc}/*from   w  w  w.ja v a 2s .  c o m*/
 */
@Override
@RequestMapping(value = "/removeAnswer", method = RequestMethod.POST)
public ResponseEntity<Response> removeAnswer(@RequestBody final RequestData request) {

    SimpleResponse simpleResponse = null;
    TransactionStatus statusDB = null;
    boolean status = true;
    try {
        if (!AuthenticationFilter.isAuthed(context)) {
            simpleResponse = new SimpleResponse(SibConstants.FAILURE, "Authentication required.");
            return new ResponseEntity<Response>(simpleResponse, HttpStatus.FORBIDDEN);
        }

        Object[] queryParams = { request.getRequest_data().getAid() };
        TransactionDefinition def = new DefaultTransactionDefinition();
        statusDB = transactionManager.getTransaction(def);

        status = dao.insertUpdateObject(SibConstants.SqlMapper.SQL_SIB_NUM_REPLIES_UPDATE_DELETE, queryParams);

        status = dao.insertUpdateObject(SibConstants.SqlMapper.SQL_REMOVE_ANSWER, queryParams);
        dao.insertUpdateObject(SibConstants.SqlMapper.SQL_REMOVE_ANSWER_LIKE, queryParams);

        transactionManager.commit(statusDB);
        simpleResponse = new SimpleResponse("" + status, request.getRequest_data_type(),
                request.getRequest_data_method(), request.getRequest_data().getAid());
    } catch (Exception e) {
        transactionManager.rollback(statusDB);
        logger.info("Delete answer Error:" + e.getMessage());
        e.printStackTrace();
        simpleResponse = new SimpleResponse(SibConstants.FAILURE, "Post", "editAnswer", e.getMessage());
    }
    return new ResponseEntity<Response>(simpleResponse, HttpStatus.OK);
}