List of usage examples for org.springframework.transaction.support DefaultTransactionDefinition setName
public final void setName(String name)
From source file:com.krawler.spring.hrms.common.hrmsDocumentController.java
public ModelAndView deleteDocuments(HttpServletRequest request, HttpServletResponse response) { KwlReturnObject result;//from w ww.j a v a2s . c o m 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 { HashMap<String, Object> requestParams = new HashMap<String, Object>(); requestParams.put("ids", request.getParameterValues("ids")); String applicant = request.getParameter("applicant"); applicant = StringUtil.checkForNull(applicant); if (applicant.equalsIgnoreCase("applicant")) { result = hrmsExtApplDocsDAOObj.deleteDocuments(requestParams); } else { result = documentDAOObj.deleteDocuments(requestParams); } if (result.isSuccessFlag()) { jobj.put("success", true); } else { jobj.put("success", false); } jobj1.put("data", jobj.toString()); jobj1.put("valid", true); txnManager.commit(status); } catch (Exception e) { System.out.println(e.getMessage()); txnManager.rollback(status); } finally { return new ModelAndView("jsonView", "model", jobj1.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 ww.j av a2s.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:com.krawler.spring.hrms.common.hrmsDocumentController.java
public ModelAndView addDocuments(HttpServletRequest request, HttpServletResponse response) throws ServletException { JSONObject jobj = new JSONObject(); JSONObject myjobj = new JSONObject(); List fileItems = null;/* w w w.jav a 2 s . c om*/ KwlReturnObject kmsg = null; String auditAction = ""; boolean applicant = false; String id = java.util.UUID.randomUUID().toString(); PrintWriter out = 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); try { response.setContentType("text/html;charset=UTF-8"); out = response.getWriter(); String userid = sessionHandlerImplObj.getUserid(request); String map = request.getParameter("mapid"); HashMap<String, String> arrParam = new HashMap<String, String>(); boolean fileUpload = false; String docdesc; ArrayList<FileItem> fi = new ArrayList<FileItem>(); if (request.getParameter("fileAdd") != null) { DiskFileUpload fu = new DiskFileUpload(); fileItems = fu.parseRequest(request); documentDAOObj.parseRequest(fileItems, arrParam, fi, fileUpload); arrParam.put("IsIE", request.getParameter("IsIE")); if (arrParam.get("applicantid").equalsIgnoreCase("applicant")) { applicant = true; userid = arrParam.get("refid"); } if (StringUtil.isNullOrEmpty((String) arrParam.get("docdesc")) == false) { docdesc = (String) arrParam.get("docdesc"); } } for (int cnt = 0; cnt < fi.size(); cnt++) { String docID; if (applicant) { kmsg = hrmsExtApplDocsDAOObj.uploadFile(fi.get(cnt), userid, arrParam, profileHandlerDAOObj.getUserFullName(sessionHandlerImplObj.getUserid(request))); HrmsDocs doc = (HrmsDocs) kmsg.getEntityList().get(0); docID = doc.getDocid(); } else { kmsg = documentDAOObj.uploadFile(fi.get(cnt), userid, arrParam); Docs doc = (Docs) kmsg.getEntityList().get(0); docID = doc.getDocid(); } String companyID = sessionHandlerImplObj.getCompanyid(request); String userID = sessionHandlerImplObj.getUserid(request); String refid = arrParam.get("refid"); jobj.put("userid", userID); jobj.put("docid", docID); jobj.put("companyid", companyID); jobj.put("id", id); jobj.put("map", map); jobj.put("refid", refid); if (arrParam.get("applicantid").equalsIgnoreCase("applicant")) { hrmsExtApplDocsDAOObj.saveDocumentMapping(jobj); } else { documentDAOObj.saveDocumentMapping(jobj); } } myjobj.put("ID", id); txnManager.commit(status); } catch (Exception e) { System.out.println(e.getMessage()); txnManager.rollback(status); } finally { out.close(); } return new ModelAndView("jsonView", "model", myjobj.toString()); }
From source file:org.ohmage.query.impl.AuditQueries.java
@Override public void createAudit(final RequestServlet.RequestType requestType, final String uri, final String client, final String requestId, final String deviceId, final Map<String, String[]> parameters, final Map<String, String[]> extras, final String response, final long receivedMillis, final long respondMillis) throws DataAccessException { if (requestType == null) { throw new IllegalArgumentException("The request type is required and cannot be null."); } else if (uri == null) { throw new IllegalArgumentException("The request URI is required and cannot be null."); } else if (response == null) { throw new IllegalArgumentException("The response is required and cannot be null."); }//from ww w . java 2 s .c o m // Create the transaction. DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("Creating a request audit."); try { // Begin the transaction. PlatformTransactionManager transactionManager = new DataSourceTransactionManager(getDataSource()); TransactionStatus status = transactionManager.getTransaction(def); // Create a key holder that will be responsible for referencing // which row was just inserted. KeyHolder keyHolder = new GeneratedKeyHolder(); // Insert the audit entry. try { getJdbcTemplate().update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement(SQL_INSERT_AUDIT, new String[] { "id" }); ps.setString(1, requestType.name().toLowerCase()); ps.setString(2, uri); ps.setString(3, client); ps.setString(4, requestId); ps.setString(5, deviceId); ps.setString(6, response); ps.setLong(7, receivedMillis); ps.setLong(8, respondMillis); return ps; } }, keyHolder); } catch (org.springframework.dao.DataAccessException e) { transactionManager.rollback(status); throw new DataAccessException("Error while executing SQL '" + SQL_INSERT_AUDIT + "' with parameters: " + requestType.name().toLowerCase() + ", " + uri + ", " + client + ", " + deviceId + ", " + response + ", " + receivedMillis + ", " + respondMillis, e); } // Add all of the parameters. if (parameters != null) { for (String key : parameters.keySet()) { for (String value : parameters.get(key)) { try { getJdbcTemplate().update(SQL_INSERT_PARAMETER, keyHolder.getKey().longValue(), key, value); } catch (org.springframework.dao.DataAccessException e) { transactionManager.rollback(status); throw new DataAccessException( "Error while executing SQL '" + SQL_INSERT_PARAMETER + "' with parameters: " + keyHolder.getKey().longValue() + ", " + key + ", " + value, e); } } } } // Add all of the extras. if (extras != null) { for (String key : extras.keySet()) { for (String value : extras.get(key)) { try { getJdbcTemplate().update(SQL_INSERT_EXTRA, keyHolder.getKey().longValue(), key, value); } catch (org.springframework.dao.DataAccessException e) { transactionManager.rollback(status); throw new DataAccessException( "Error while executing SQL '" + SQL_INSERT_EXTRA + "' with parameters: " + keyHolder.getKey().longValue() + ", " + key + ", " + value, 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.UserCampaignQueries.java
@Override public void createUserCampaignMask(final CampaignMask mask) throws DataAccessException { // Create the transaction. DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("Creating an observer."); try {//from w w w . jav a 2 s . com // Begin the transaction. PlatformTransactionManager transactionManager = new DataSourceTransactionManager(getDataSource()); TransactionStatus status = transactionManager.getTransaction(def); // Campaign mask creation SQL. final String campaignMaskSql = "INSERT INTO campaign_mask(" + "assigner_user_id, " + "assignee_user_id, " + "campaign_id, " + "mask_id, " + "creation_time) " + "VALUES (" + "(SELECT id FROM user WHERE username = ?), " + "(SELECT id FROM user WHERE username = ?), " + "(SELECT id FROM campaign WHERE urn = ?), " + "?, " + "?)"; // Campaign mask creation statement with parameters. PreparedStatementCreator maskCreator = new PreparedStatementCreator() { /* * (non-Javadoc) * @see org.springframework.jdbc.core.PreparedStatementCreator#createPreparedStatement(java.sql.Connection) */ @Override public PreparedStatement createPreparedStatement(final Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement(campaignMaskSql, new String[] { "id" }); ps.setString(1, mask.getAssignerUserId()); ps.setString(2, mask.getAssigneeUserId()); ps.setString(3, mask.getCampaignId()); ps.setString(4, mask.getId().toString()); ps.setLong(5, mask.getCreationTime().getMillis()); return ps; } }; // The auto-generated key for the observer. KeyHolder maskKeyHolder = new GeneratedKeyHolder(); // Create the observer. try { getJdbcTemplate().update(maskCreator, maskKeyHolder); } catch (org.springframework.dao.DataAccessException e) { transactionManager.rollback(status); throw new DataAccessException("Error executing SQL '" + campaignMaskSql + "' with parameters: " + mask.getAssignerUserId() + ", " + mask.getAssigneeUserId() + ", " + mask.getCampaignId() + ", " + mask.getId().toString() + ", " + mask.getCreationTime().getMillis(), e); } // Get the mask's DB ID. long key = maskKeyHolder.getKey().longValue(); // Create each of the masks. final String campaignMaskPromptIdSql = "INSERT INTO campaign_mask_survey_prompt_map(" + "campaign_mask_id, " + "survey_id, " + "prompt_id)" + "VALUES (?, ?, ?)"; // Get the survey IDs from the mask. Map<String, Set<String>> promptIds = mask.getSurveyPromptMap(); // Create the list of parameters for each of the survey IDs. List<Object[]> maskPromptIdParameters = new ArrayList<Object[]>(promptIds.size()); // Cycle through the survey IDs building the parameters list. for (String surveyId : promptIds.keySet()) { for (String promptId : promptIds.get(surveyId)) { maskPromptIdParameters.add(new Object[] { key, surveyId, promptId }); } } // Add the mask survey IDs. getJdbcTemplate().batchUpdate(campaignMaskPromptIdSql, maskPromptIdParameters); // 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:ru.apertum.qsystem.common.model.QCustomer.java
private void saveToSelfDB() { // ? ? // w w w. j a v a2 s .com final DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("SomeTxName"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus status = Spring.getInstance().getTxManager().getTransaction(def); try { if (input_data == null) { // ? ? , ? input_data = ""; } Spring.getInstance().getHt().saveOrUpdate(this); } catch (Exception ex) { Spring.getInstance().getTxManager().rollback(status); throw new ServerException(" ? \n" + ex.toString() + "\n" + Arrays.toString(ex.getStackTrace())); } Spring.getInstance().getTxManager().commit(status); QLog.l().logger().debug("."); }
From source file:com.krawler.spring.crm.activityModule.crmActivityController.java
public ModelAndView deleteActivity(HttpServletRequest request, HttpServletResponse response) throws ServletException { JSONObject myjobj = null;/*from w w w.j av a 2s . co m*/ KwlReturnObject kmsg = null; CrmActivityMaster activity = 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); try { String userid = sessionHandlerImpl.getUserid(request); ArrayList activityids = new ArrayList(); String timeZoneDiff = sessionHandlerImpl.getTimeZoneDifference(request); myjobj = new JSONObject(); myjobj.put("success", false); if (StringUtil.bNull(request.getParameter("jsondata"))) { String jsondata = request.getParameter("jsondata"); JSONArray jarr = new JSONArray("[" + jsondata + "]"); for (int i = 0; i < jarr.length(); i++) { JSONObject jobject = jarr.getJSONObject(i); activityids.add(jobject.getString("activityid").toString()); } String[] arrayid = (String[]) activityids.toArray(new String[] {}); JSONObject jobj = new JSONObject(); jobj.put("deleteflag", 1); jobj.put("activityid", arrayid); jobj.put("userid", userid); jobj.put("updatedon", new Date()); jobj.put("tzdiff", timeZoneDiff); kmsg = crmActivityDAOObj.updateMassActivity(jobj); List<CrmActivityMaster> ll = crmActivityDAOObj.getActivities(activityids); if (ll != null) { for (int i = 0; i < ll.size(); i++) { CrmActivityMaster activityaudit = (CrmActivityMaster) ll.get(i); if (activityaudit.getValidflag() == 1) { auditTrailDAOObj.insertAuditLog(AuditAction.ACTIVITY_DELETE, activityaudit.getFlag() + " - Activity deleted ", request, activityaudit.getActivityid()); } } } JSONObject cometObj = new JSONObject(); cometObj.put("ids", jarr); publishActivityModuleInformation(request, cometObj, CrmPublisherHandler.DELETERECORDCODE, sessionHandlerImpl.getCompanyid(request), userid); } myjobj.put("success", true); myjobj.put("ID", activityids.toArray()); txnManager.commit(status); } catch (JSONException e) { LOGGER.warn(e.getMessage(), e); txnManager.rollback(status); } catch (Exception e) { LOGGER.warn(e.getMessage(), e); txnManager.rollback(status); } return new ModelAndView("jsonView", "model", myjobj.toString()); }
From source file:org.ohmage.query.impl.UserMobilityQueries.java
@Override public void updateMobilityPoint(final UUID mobilityId, final MobilityPoint.PrivacyState privacyState) throws DataAccessException { // Create the transaction. DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("Updating a Mobility data point."); try {/*from ww w . j a v a2 s . c o m*/ // Begin the transaction. PlatformTransactionManager transactionManager = new DataSourceTransactionManager(getDataSource()); TransactionStatus status = transactionManager.getTransaction(def); if (privacyState != null) { String sql = "UPDATE mobility " + "SET privacy_state_id = (" + "SELECT id " + "FROM mobility_privacy_state " + "WHERE privacy_state = ?) " + "WHERE uuid = ?"; try { getJdbcTemplate().update(sql, new Object[] { privacyState.toString(), mobilityId.toString() }); } catch (org.springframework.dao.DataAccessException e) { transactionManager.rollback(status); throw new DataAccessException( "Error executing SQL '" + sql + "' with parameter: " + privacyState.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.profileHandler.profileHandlerController.java
public ModelAndView deleteUser(HttpServletRequest request, HttpServletResponse response) throws ServletException { JSONObject jobj = 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 {//from w ww . j a v a 2 s. c o m String[] ids = request.getParameterValues("userids"); for (int i = 0; i < ids.length; i++) { profileHandlerDAOObj.deleteUser(ids[i]); } jobj.put("msg", messageSource.getMessage("crm.userprofile.deleteusersuccessmsg", null, RequestContextUtils.getLocale(request)));//"User deleted successfully"); txnManager.commit(status); } catch (Exception e) { logger.warn("General exception in deleteUser()", e); txnManager.rollback(status); } return new ModelAndView("jsonView", "model", jobj.toString()); }
From source file:com.krawler.spring.profileHandler.profileHandlerController.java
public ModelAndView saveDateFormat(HttpServletRequest request, HttpServletResponse response) throws ServletException { JSONObject jobj = 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 {/*from w ww .j av a2 s . c o m*/ String dateid = request.getParameter("newformat"); HashMap<String, Object> requestParams = new HashMap<String, Object>(); requestParams.put("userid", sessionHandlerImpl.getUserid(request)); requestParams.put("dateformat", StringUtil.checkForNull(dateid)); requestParams.put("addUser", false); profileHandlerDAOObj.saveUser(requestParams); request.getSession().setAttribute("dateformatid", dateid); jobj.put("success", true); txnManager.commit(status); } catch (Exception e) { logger.warn("General exception in saveDateFormat()", e); txnManager.rollback(status); } return new ModelAndView("jsonView", "model", jobj.toString()); }