List of usage examples for org.springframework.transaction.support DefaultTransactionDefinition DefaultTransactionDefinition
public DefaultTransactionDefinition()
From source file:com.poscoict.license.service.ManagementService.java
public String modifyProfile(ContractPersonInfo info, String oldUserNo, String[] etcFile, HttpSession session) { logger.info("modifyProfile: oldUserNo= " + oldUserNo); logger.info("modifyProfile: etcFile= " + etcFile); TransactionStatus status = this.transactionManager.getTransaction(new DefaultTransactionDefinition()); try {//from w w w .j a v a 2s . c om managementDao.updateProductSetupDate(oldUserNo, info.getPRODUCT_SETUP_DATE().isEmpty() ? null : info.getPRODUCT_SETUP_DATE()); managementDao.updateProfileInfo(info, oldUserNo, (String) session.getAttribute("USER_NO")); if (!info.getUSER_NO().equals(oldUserNo)) { System.out.println("update USER_NO"); managementDao.updateLicenseUserNo(info.getUSER_NO(), oldUserNo, (String) session.getAttribute("USER_NO")); } managementDao.deleteUserEtcFileInfo(oldUserNo); if (etcFile != null) { for (int i = 0; i < etcFile.length; i++) { String objectId = etcFile[i]; managementDao.addUserEtcFileInfo(info.getUSER_NO(), objectId, (String) session.getAttribute("USER_NO")); } } this.transactionManager.commit(status); } catch (DuplicateKeyException e) { this.transactionManager.rollback(status); logger.error("plusProduct: ", e); throw new DuplicateKeyException( " ?. ?? ? ."); } catch (RuntimeException e) { this.transactionManager.rollback(status); logger.error("plusProduct: ", e); } return info.getUSER_NO(); }
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 w w w . ja v a 2s . 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:org.ohmage.query.impl.SurveyResponseQueries.java
public void updateSurveyResponsesPrivacyState(final Set<UUID> surveyResponseIds, final SurveyResponse.PrivacyState newPrivacyState) throws DataAccessException { StringBuilder sqlBuilder = new StringBuilder(SQL_UPDATE_SURVEY_RESPONSES_PRIVACY_STATE); sqlBuilder.append(StringUtils.generateStatementPList(surveyResponseIds.size())); List<Object> parameters = new ArrayList<Object>(surveyResponseIds.size() + 1); parameters.add(newPrivacyState.toString()); for (UUID surveyResponseId : surveyResponseIds) { parameters.add(surveyResponseId.toString()); }/*from ww w . j av a2 s .co m*/ // Create the transaction. DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("Updating a survey response."); try { // Begin the transaction. PlatformTransactionManager transactionManager = new DataSourceTransactionManager(getDataSource()); TransactionStatus status = transactionManager.getTransaction(def); try { getJdbcTemplate().update(sqlBuilder.toString(), parameters.toArray()); } catch (org.springframework.dao.DataAccessException e) { transactionManager.rollback(status); throw new DataAccessException("Error executing SQL '" + sqlBuilder.toString() + "' with parameters: " + parameters.toArray(), 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.crmCaseController.java
public ModelAndView updateMassCases(HttpServletRequest request, HttpServletResponse response) throws ServletException { JSONObject myjobj = new JSONObject(); KwlReturnObject kmsg = null;/*from www . jav a 2 s . c o m*/ CrmCase cases = 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 { JSONObject jobj = new JSONObject(request.getParameter("jsondata")); String companyid = sessionHandlerImpl.getCompanyid(request); String userid = sessionHandlerImpl.getUserid(request); Integer operationCode = CrmPublisherHandler.UPDATERECORDCODE; String caseIds = jobj.getString("caseid"); String arrayId[] = caseIds.split(","); jobj.put("userid", userid); jobj.put("companyid", companyid); if (jobj.has("updatedon") && !StringUtil.isNullOrEmpty(jobj.getString("updatedon"))) { jobj.put("updatedon", jobj.getLong("updatedon")); } else { jobj.put("updatedon", new Date().getTime()); } jobj.put("caseid", arrayId); jobj.put("tzdiff", sessionHandlerImpl.getTimeZoneDifference(request)); JSONArray jcustomarray = null; if (jobj.has("customfield")) { jcustomarray = jobj.getJSONArray("customfield"); } if (jobj.has("customfield")) { HashMap<String, Object> customrequestParams = new HashMap<String, Object>(); customrequestParams.put("customarray", jcustomarray); customrequestParams.put("modulename", Constants.Crm_Case_modulename); customrequestParams.put("moduleprimarykey", Constants.Crm_Caseid); customrequestParams.put("companyid", companyid); customrequestParams.put("customdataclasspath", Constants.Crm_case_custom_data_classpath); KwlReturnObject customDataresult = null; for (String id : arrayId) { customrequestParams.put("modulerecid", id); customDataresult = fieldDataManagercntrl.setCustomData(customrequestParams); } if (customDataresult != null && customDataresult.getEntityList().size() > 0) { jobj.put("CrmCaseCustomDataobj", true); } } if (jobj.has("createdon")) { jobj.put("createdon", jobj.getLong("createdon")); } kmsg = crmCaseDAOObj.updateMassCases(jobj); // TODO : How to insert audit log when mass update // cases = (CrmCase) kmsg.getEntityList().get(0); // if (cases.getValidflag() == 1) { // auditTrailDAOObj.insertAuditLog(AuditAction.CASE_UPDATE, // jobj.getString("auditstr") + " Case - " + ((acc.getCasename() == // null) ? "" : acc.getCasename()) + " ", // request, id); // } // } JSONObject cometObj = jobj; if (request.getParameter("massEdit") != null && Boolean.parseBoolean(request.getParameter("massEdit"))) { crmCommonService.validateMassupdate(arrayId, "Case", companyid); cometObj.put("caseid", caseIds); cometObj.put("ismassedit", true); } myjobj.put("success", true); myjobj.put("ID", caseIds); myjobj.put("createdon", jobj.has("createdon") ? jobj.getLong("createdon") : ""); if (!StringUtil.isNullObject(cases)) { if (cases.getCreatedOn() != null) { cometObj.put("createdon", cases.getCreatedonGMT()); } } publishCasesModuleInformation(request, cometObj, operationCode, companyid, userid); txnManager.commit(status); } catch (Exception e) { LOGGER.warn(e.getMessage(), e); txnManager.rollback(status); } return new ModelAndView("jsonView", "model", myjobj.toString()); }
From source file:edu.jhuapl.openessence.datasource.jdbc.entry.JdbcOeDataEntrySource.java
/** * ************************************************************************************************************** * CR[U]D - Update methods for Data Entry ************************************************************************************************************** *///from www .j a v a 2s . co m @Override public void updateCompleteRecord(final DbKeyValMap recordPks, final CompleteRecord replacementRecord) throws OeDataSourceAccessException { final TransactionDefinition def = new DefaultTransactionDefinition(); final TransactionStatus status = getTransactionManager().getTransaction(def); try { final CompleteRecord originalRecord = getCompleteRecord(recordPks, new ArrayList<String>(this.getChildTableMap().keySet())); if (originalRecord != null) { // update ParentRecord updateParentRecord(recordPks, replacementRecord.getParentRecord()); // update Child Record Sets -todo make use of refactor see ChildRecordSet final Map<String, ChildRecordSet> origRecordSetMap = new HashMap<String, ChildRecordSet>(); for (final ChildRecordSet recSet : originalRecord.getChildrenRecordSets()) { origRecordSetMap.put(recSet.getChildTableName(), recSet); } updateChildRecordSets(recordPks, origRecordSetMap, replacementRecord.getChildrenRecordSets()); } else { addCompleteRecord(replacementRecord, false); } getTransactionManager().commit(status); } catch (DataAccessException de) { getTransactionManager().rollback(status); throw new OeDataSourceAccessException( "No records were updated. DataAccessException occured while updating record.", de); } catch (OeDataSourceException e) { getTransactionManager().rollback(status); throw new OeDataSourceAccessException( "No records were updated. OeDataSourceException occured while updating record.", e); } }
From source file:com.krawler.spring.crm.leadModule.crmLeadCommonController.java
public ModelAndView convertLeads(HttpServletRequest request, HttpServletResponse response) throws ServletException { JSONObject myjobj = null;/*from w w w . java 2 s. co m*/ boolean refNotFoundFlag = false; String refNotFoundStr = ""; KwlReturnObject kmsg = null; CrmLead lead = null; CrmAccount acc = null; CrmOpportunity opp = null; String contactid = null; boolean b = false; //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); JSONObject accModulejObj = new JSONObject(); JSONObject oppModulejObj = new JSONObject(); JSONObject contactModulejObj = new JSONObject(); JSONObject resJson = new JSONObject(); try { Map<String, Object> moduleFields = new HashMap<String, Object>(); Map<String, Object> columnMappedList = new HashMap<String, Object>(); JSONArray moduleCustomfieldArray; myjobj = new JSONObject(); myjobj.put("success", false); String timeZoneDiff = sessionHandlerImpl.getTimeZoneDifference(request); String timeFormatId = sessionHandlerImpl.getUserTimeFormat(request); boolean convertedflag = true; boolean companyNotifyFlag = sessionHandlerImpl.getCompanyNotifyOnFlag(request); // extract ip address String ipAddress = SystemUtil.getIpAddress(request); String companyid = sessionHandlerImpl.getCompanyid(request); if (StringUtil.bNull(request.getParameter("jsondata"))) { String userid = sessionHandlerImpl.getUserid(request); String conversiontype = " "; String jsondata = request.getParameter("jsondata"); JSONArray jarr = new JSONArray("[" + jsondata + "]"); JSONObject jobj = jarr.getJSONObject(0); String leadid = jobj.getString("leadid"); CrmLead CrmLeadObj = crmLeadDAOObj.getLead(leadid); if (CrmLeadObj == null || CrmLeadObj.getIsconverted().equals("1")) { convertedflag = false; refNotFoundStr = " Selected lead already converted successfully."; } if (convertedflag) { String accflag = jobj.getString("accflag"); String conflag = jobj.optString("conflag"); String oppflag = jobj.getString("oppflag"); String taskflag = jobj.getString("taskflag"); Long closingdate = jobj.getLong("closingdate"); String lastname = jobj.getString("lastname"); String accountname = jobj.getString("accountname"); String oppParentaccountid = jobj.getString("oppparentaccountid"); String oppname = jobj.getString("oppname"); String oppstageid = jobj.getString("oppstageid"); String validflag = jobj.getString("validflag"); String leadType = jobj.getString("type"); boolean transfer = false; String details = ""; String accid = java.util.UUID.randomUUID().toString(); // check all mandatory column mapped resJson.put("success", true); if (accflag.equals("1")) { accModulejObj = getModuleRecord(request, Constants.MODULE_ACCOUNT, companyid, jobj, moduleFields, columnMappedList); checkManadatoryColumnMapped(resJson, Constants.MODULE_ACCOUNT, companyid, moduleFields, columnMappedList); } if (oppflag.equals("1")) { oppModulejObj = getModuleRecord(request, Constants.MODULE_OPPORTUNITY, companyid, jobj, moduleFields, columnMappedList); // check all mandatory column mapped checkManadatoryColumnMapped(resJson, Constants.MODULE_OPPORTUNITY, companyid, moduleFields, columnMappedList); } if (conflag.equals("1")) { contactModulejObj = getModuleRecord(request, Constants.MODULE_CONTACT, companyid, jobj, moduleFields, columnMappedList); // check all mandatory column mapped checkManadatoryColumnMapped(resJson, Constants.MODULE_CONTACT, companyid, moduleFields, columnMappedList); } if (!resJson.getBoolean("success")) { refNotFoundFlag = true; refNotFoundStr = resJson.getString("msg"); } if (!refNotFoundFlag) { // Convert into Account if (accflag.equals("1")) { conversiontype = "1"; refNotFoundStr = ""; if (accModulejObj.getBoolean("success")) { accModulejObj.put("accountname", accountname); accModulejObj.put("leadid", leadid); accModulejObj.put("companyid", companyid); accModulejObj.put("userid", userid); accModulejObj.put("updatedon", new Date()); accModulejObj.put("accountid", accid); accModulejObj.put("validflag", "0"); accModulejObj.put("tzdiff", timeZoneDiff); kmsg = crmAccountDAOObj.addAccounts(accModulejObj); moduleCustomfieldArray = accModulejObj.getJSONArray("customfield"); if (moduleCustomfieldArray.length() > 0) { KwlReturnObject customDataresult = fieldDataManagercntrl.setcustomdata( moduleCustomfieldArray, Constants.Crm_account_moduleid, accid, companyid, true); if (customDataresult != null && customDataresult.getEntityList().size() > 0) { JSONObject accJObj = new JSONObject(); accJObj.put("accountid", accid); accJObj.put("CrmAccountCustomDataobj", accid); accJObj.put("tzdiff", timeZoneDiff); kmsg = crmAccountDAOObj.editAccounts(accJObj); } // fieldManager.storeCustomFields(moduleCustomfieldArray,"account",true,accid,"1"); } crmCommentDAOObj.CreateDuplicateComments(leadid, accid); documentConversion(leadid, accid, "4"); auditTrailDAOObj.insertAuditLog(AuditAction.ACCOUNT_CREATE, accountname + " - Account created from Lead - " + lastname, request, accid); acc = (CrmAccount) kmsg.getEntityList().get(0); //Save Account Owner saveAccOwnersFromLead(leadid, accid); details += " Account - [ " + accountname + " ], "; if (oppflag.equals("1")) { transfer = false; } else { transfer = true; } if (leadType.equals("1")) { // checked for Lead Type - if Company then associated contacts must be linked with newly added Account linkLeadsContactsToAccount(leadid, accid, userid, companyid, timeZoneDiff, ipAddress); } } else { myjobj.put("success", false); refNotFoundStr += "Data not found in Account module for following fields - <BR /> " + accModulejObj.getString("msg") + "<BR /><BR />"; refNotFoundFlag = true; } // Add Activity if (taskflag.equals("1")) { if (StringUtil.bNull(request.getParameter("activitydata"))) { String activityjson = request.getParameter("activitydata"); JSONObject activityJSON = new JSONObject(activityjson); activityJSON.put("relatedtoid", Constants.MODULE_ACCOUNT); activityJSON.put("relatedtonameid", accid); String loginURL = URLUtil.getRequestPageURL(request, Links.loginpageFull); String partnerName = sessionHandlerImpl.getPartnerName(request); activityManagementService.saveActivity(companyid, userid, timeFormatId, timeZoneDiff, ipAddress, activityJSON, companyNotifyFlag, loginURL, partnerName); } } } String oppid = java.util.UUID.randomUUID().toString(); // Convert into Opportunity if (oppflag.equals("1")) { conversiontype = "2"; if (oppModulejObj.getBoolean("success")) { oppModulejObj.put("oppid", oppid); oppModulejObj.put("companyid", companyid); oppModulejObj.put("userid", userid); oppModulejObj.put("updatedon", new Date().getTime()); oppModulejObj.put("tzdiff", timeZoneDiff); // oppJObj.put("createdon", new Date()); oppModulejObj.put("leadid", leadid); if (accflag.equals("1")) { oppModulejObj.put("accountnameid", accid); } else { oppModulejObj.put("accountnameid", oppParentaccountid); } // String timeFormatId = sessionHandlerImpl.getUserTimeFormat(request); // String timeZoneDiff = sessionHandlerImpl.getTimeZoneDifference(request); if (jobj.has("closingdate")) { oppModulejObj.put("closingdate", jobj.getLong("closingdate")); } oppModulejObj.put("validflag", "0"); oppModulejObj.put("oppstageid", oppstageid); oppModulejObj.put("currencyid", "0"); oppModulejObj.put("oppname", oppname); kmsg = crmOpportunityDAOObj.addOpportunities(oppModulejObj); moduleCustomfieldArray = oppModulejObj.getJSONArray("customfield"); if (moduleCustomfieldArray.length() > 0) { // fieldManager.storeCustomFields(moduleCustomfieldArray,"opportunity",true,oppid,"5"); KwlReturnObject customDataresult = fieldDataManagercntrl.setcustomdata( moduleCustomfieldArray, Constants.Crm_opportunity_moduleid, oppid, companyid, true); if (customDataresult != null && customDataresult.getEntityList().size() > 0) { JSONObject oppJObj = new JSONObject(); oppJObj.put("oppid", oppid); oppJObj.put("CrmOpportunityCustomDataobj", oppid); oppJObj.put("tzdiff", timeZoneDiff); kmsg = crmOpportunityDAOObj.editOpportunities(oppJObj); } } opp = (CrmOpportunity) kmsg.getEntityList().get(0); //Save Opportunity Owner saveOppOwnersFromLead(leadid, oppid); crmCommentDAOObj.CreateDuplicateComments(leadid, oppid); documentConversion(leadid, oppid, "5"); auditTrailDAOObj.insertAuditLog(AuditAction.OPPORTUNITY_CREATE, oppname + " - Opportunity created from Lead - " + lastname, request, oppid); details += "Opportunity [ " + oppname + " ], "; if (accflag.equals("1")) { // transfer = true; } b = true; } else { myjobj.put("success", false); refNotFoundStr += "Data not found in Opportunity module for following fields - <BR /> " + oppModulejObj.getString("msg") + "<BR /><BR />"; refNotFoundFlag = true; } } // Convert into Contact if (conflag.equals("1")) { if (leadType.equals("0")) { // checked for Lead Type - if Company then don't convert to contact if (contactModulejObj.getBoolean("success")) { // conversiontype="3"; contactModulejObj.put("leadid", leadid); if (accflag.equals("1")) { contactModulejObj.put("accountid", accid); } else if (oppflag.equals("1")) { contactModulejObj.put("accountid", oppParentaccountid); } contactModulejObj.put("validflag", "0"); // add new contact JSONObject contactJson = contactManagementService.saveContact(companyid, userid, timeZoneDiff, ipAddress, contactModulejObj); contactid = contactJson.getString("ID"); moduleCustomfieldArray = contactModulejObj.getJSONArray("customfield"); if (moduleCustomfieldArray.length() > 0) { // fieldManager.storeCustomFields(moduleCustomfieldArray,"contact",true,conid,"6"); KwlReturnObject customDataresult = fieldDataManagercntrl.setcustomdata( moduleCustomfieldArray, Constants.Crm_contact_moduleid, contactid, companyid, true); if (customDataresult != null && customDataresult.getEntityList().size() > 0) { JSONObject contactJObj = new JSONObject(); contactJObj.put("contactid", contactid); contactJObj.put("CrmContactCustomDataobj", contactid); contactJObj.put("tzdiff", timeZoneDiff); contactJson = contactManagementService.saveContact(companyid, userid, timeZoneDiff, ipAddress, contactJObj); } } //Save Contact Owner saveContactOwnersFromLead(leadid, contactid); // auditTrailDAOObj.insertAuditLog(AuditAction.CONTACT_CREATE, // firstname + " " + lastname + " - Contact created from Lead - "+kmsg.getEntityList().getFirstname()+" "+leadd.getLastname(), // request, conid); String firstname = ""; String contactName = ""; String lName = ""; if (contactModulejObj.has("firstname")) { firstname = contactModulejObj.get("firstname").toString().trim(); } if (contactModulejObj.has("lastname")) { lName = contactModulejObj.get("lastname").toString().trim(); } contactName = (firstname + " " + lName).trim(); crmCommentDAOObj.CreateDuplicateComments(leadid, contactid); documentConversion(leadid, contactid, "2"); auditTrailDAOObj.insertAuditLog(AuditAction.CONTACT_CREATE, contactName + " - Contact created from Lead - " + lastname, request, contactid); if (oppflag.equals("1")) { transfer = false; } else { transfer = true; } b = true; } else { myjobj.put("success", false); refNotFoundStr += "Data not found in Contact module for following fields - <BR /> " + contactModulejObj.getString("msg") + "<BR /><BR />"; refNotFoundFlag = true; } } else { if (accflag.equals("1")) { accid = acc.getAccountid(); } else if (oppflag.equals("1")) { if (opp.getCrmAccount() != null) accid = opp.getCrmAccount().getAccountid(); else accid = ""; } else { accid = ""; } updateContacts(leadid, accid, timeZoneDiff, ipAddress); } } } if (!refNotFoundFlag) { kmsg = crmManagerDAOObj.getMasterIDCompany(companyid, Constants.LEADSTATUSID_QUALIFIED); DefaultMasterItem obj = (DefaultMasterItem) kmsg.getEntityList().get(0); JSONObject leadJObj = new JSONObject(); if (transfer) { leadJObj.put("istransfered", "1"); } leadJObj.put("leadid", leadid); leadJObj.put("leadstatusid", obj.getID()); leadJObj.put("conversiontype", conversiontype); leadJObj.put("leadconversiondate", conversiontype); leadJObj.put("isconverted", "1"); leadJObj.put("updatedon", new Date()); leadJObj.put("tzdiff", timeZoneDiff); kmsg = crmLeadDAOObj.editLeads(leadJObj); lead = (CrmLead) kmsg.getEntityList().get(0); auditTrailDAOObj.insertAuditLog(AuditAction.LEAD_CONVERT, details + " created by converting Lead - " + lead.getLastname(), request, leadid); b = true; myjobj.put("success", b); } } // end of if } if (!refNotFoundFlag && convertedflag) { txnManager.commit(status); if (acc != null) crmCommonDAOObj.validaterecorsingledHB("Account", acc.getAccountid(), companyid); if (opp != null) crmCommonDAOObj.validaterecorsingledHB("Opportunity", opp.getOppid(), companyid); if (contactid != null) crmCommonDAOObj.validaterecorsingledHB("Contact", contactid, companyid); } else { myjobj.put("msg", refNotFoundStr); txnManager.rollback(status); } } catch (JSONException e) { txnManager.rollback(status); logger.warn(e.getMessage(), e); } catch (Exception e) { txnManager.rollback(status); logger.warn(e.getMessage(), e); } return new ModelAndView(successView, "model", myjobj.toString()); }
From source file:com.poscoict.license.service.ManagementService.java
@SuppressWarnings("unchecked") public String plusProduct(ContractProductInfo info, String userNo, HttpSession session) throws UserException { logger.info("plusProduct: userNo= " + userNo); TransactionStatus status = this.transactionManager.getTransaction(new DefaultTransactionDefinition()); try {//www . ja va 2 s . com String licenseUpPath = Consts.LICENSE_FILE_HOME; if (info != null) { ArrayList<MultipartFile> upFileList = (ArrayList<MultipartFile>) info.getFile(); ArrayList<String> proIdList = (ArrayList<String>) info.getPRODUCT_FILE_ID(); ArrayList<String> licenseKeyList = (ArrayList<String>) info.getLICENSE_KEY(); ArrayList<String> quantityList = (ArrayList<String>) info.getLICENSE_QUANTITY(); ArrayList<String> fileCheckList = (ArrayList<String>) info.getCHECKBOX(); for (int i = 0; i < proIdList.size(); i++) { String path = ""; String licenseName = ""; // ??? String objectId = proIdList.get(i); String licenseKey = licenseKeyList.get(i); String quantity = quantityList.get(i); String fileCheck = fileCheckList.get(i); if (fileCheck.equals("false")) { try { MultipartFile upFile = upFileList.get(i); licenseName = upFile.getOriginalFilename(); // ??? File upfile = new File(licenseUpPath + userNo + File.separator + licenseName); if (upfile.isFile()) throw new UserException( "???? . ?? ."); if (!upfile.exists()) upfile.mkdirs(); upFile.transferTo(upfile); path = upfile.getAbsolutePath(); logger.info("plusProduct: upFileName= " + licenseName + " path= " + path); } catch (IOException e) { logger.error("plusProduct(File Upload Error): ", e); } } // ?? managementDao.addLicenseInfo(userNo, licenseKey, objectId, (String) session.getAttribute("USER_NO"), path, licenseName, quantity); } } this.transactionManager.commit(status); } catch (DuplicateKeyException e) { this.transactionManager.rollback(status); logger.error("plusProduct: ", e); throw new DuplicateKeyException( " ?. ?? ? ."); } catch (RuntimeException e) { this.transactionManager.rollback(status); logger.error("plusProduct: ", e); } return userNo; }
From source file:org.ohmage.query.impl.DocumentQueries.java
public void deleteDocument(String documentId) throws DataAccessException { // Begin transaction DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("Document delete."); try {//from ww w. ja v a 2s . c o m PlatformTransactionManager transactionManager = new DataSourceTransactionManager(getDataSource()); TransactionStatus status = transactionManager.getTransaction(def); String documentUrl = getDocumentUrl(documentId); try { getJdbcTemplate().update(SQL_DELETE_DOCUMENT, new Object[] { documentId }); } catch (org.springframework.dao.DataAccessException e) { transactionManager.rollback(status); throw new DataAccessException( "Error executing SQL '" + SQL_DELETE_DOCUMENT + "' with parameter: " + documentId, e); } try { if (!(new File((new URL(documentUrl)).getFile())).delete()) { LOGGER.warn( "The document no longer existed, so the deletion only removed the entry from the database."); } } catch (MalformedURLException e) { LOGGER.warn( "The URL was malformed, meaning that we couldn't have referenced the file anyway. Cannot delete the file.", e); } catch (SecurityException e) { LOGGER.warn( "Failed to delete the file because the security manager stopped us. Are we attempting to delete a file that isn't part of the heirarchy?", e); } // Commit 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 rolling back the transaction.", e); } }
From source file:org.ohmage.query.impl.SurveyResponseQueries.java
public void deleteSurveyResponse(final UUID surveyResponseId) throws DataAccessException { // Create the transaction. DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("Deleting a survey response."); try {/*from w w w .ja v a2 s .c o m*/ // Begin the transaction. PlatformTransactionManager transactionManager = new DataSourceTransactionManager(getDataSource()); TransactionStatus status = transactionManager.getTransaction(def); try { getJdbcTemplate().update(SQL_DELETE_SURVEY_RESPONSE, new Object[] { surveyResponseId.toString() }); } catch (org.springframework.dao.DataAccessException e) { transactionManager.rollback(status); throw new DataAccessException("Error executing SQL '" + SQL_DELETE_SURVEY_RESPONSE + "' with parameter: " + surveyResponseId.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.poscoict.license.service.BoardService.java
public int replyBoard(HttpSession session, String folder, String openFlag, String title, String content, String contentNo, String subCategory, MultipartFile[] boardAttach, String guestID, String guestPW) throws UserException { logger.info("replyBoard: folder= " + folder + " contentNo= " + contentNo); TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition()); CustomUserDetails userDetails = (CustomUserDetails) session.getAttribute("userDetails"); String userNo = userDetails.getUserNo(); boolean extraAccount = userDetails.getAuthorities().toString() .contains(Consts.rolePrefix + Consts.USERLV_GUEST); if (extraAccount) { guestID = guestID.trim();/*from w w w .j av a 2 s . c o m*/ guestPW = guestPW.trim(); if (guestID.isEmpty() || guestPW.isEmpty()) throw new UserException("guest ID ? PW ."); if (guestID.length() > 50 || guestPW.length() > 50) throw new UserException("ID ? PW ? 50? ."); } Board board = new Board(); // ? GRP, SEQ, LVL HashMap<String, Object> map = (HashMap<String, Object>) userDao.replyCheck(folder, Integer.parseInt(contentNo)); // int no = userDao.getBoardCount(folder) + 1; board.setCONTENT_NO(no); board.setFOLDER_ID(folder); board.setUSER_NO(userNo); board.setOPEN_FLAG(openFlag); board.setTITLE(title); board.setMAIN_CONTENT(content); board.setR_CREATION_USER(userNo); board.setR_CREATION_DATE(dateFormat()); board.setCONTENT_GRP((Integer) map.get("CONTENT_GRP")); board.setCONTENT_SEQ((Integer) map.get("CONTENT_SEQ") + 1); board.setSUBCATEGORY(subCategory); ArrayList<Map<String, Object>> attachList = new ArrayList<Map<String, Object>>(); if (boardAttach.length > 0) { for (int i = 0; i < boardAttach.length; i++) { Map<String, Object> attach = new HashMap<String, Object>(); String attachPath = Consts.BOARD_ATTACH_FILE_HOME; attachPath += folder + File.separator + attachDateFormat() + File.separator + attachFileDateFormat(); attach.put("fileName", boardAttach[i].getOriginalFilename()); int attachSize = (int) boardAttach[i].getSize(); if (attachSize == 0) continue; if (attachSize > 100 * 1024 * 1000) throw new UserException("? ? 100MB ."); attachPath += "(" + (i + 1) + ")_" + UUID.randomUUID().toString().replaceAll("-", "").substring(0, 12); if (boardAttach[i].getOriginalFilename().lastIndexOf(".") != -1) { attachPath += boardAttach[i].getOriginalFilename() .substring(boardAttach[i].getOriginalFilename().lastIndexOf(".")); } String objectId = "at_" + attachFileDateFormat() + i; objectId += UUID.randomUUID().toString().replaceAll("-", "").substring(0, 12); attach.put("filePath", attachPath); attach.put("fileSize", attachSize); attach.put("objectId", objectId); attachList.add(attach); System.out.println( "up: fileName: " + boardAttach[i].getOriginalFilename() + " attachPath: " + attachPath); try { File ufile = new File(attachPath); if (!ufile.exists()) { ufile.mkdirs(); } boardAttach[i].transferTo(ufile); } catch (IOException e) { e.printStackTrace(); try { throw new IOException("? ? "); } catch (IOException e1) { e1.printStackTrace(); } } } } try { if (attachList.size() > 0) { for (int i = 0; i < attachList.size(); i++) { userDao.setAttachFileInfo(no, folder, attachList.get(i).get("objectId").toString(), attachList.get(i).get("fileName").toString(), attachList.get(i).get("filePath").toString(), Integer.parseInt(attachList.get(i).get("fileSize").toString()), userNo); } } userDao.insertBoard(board); if (extraAccount) userDao.insertExtraAccounts(guestID, guestPW, no, folder); logger.info("replyBoard: extraAccount guestID : " + guestID); logger.info("replyBoard: extraAccount guestPW : " + guestPW); logger.info("replyBoard: extraAccount no : " + no); this.transactionManager.commit(status); } catch (Exception e) { this.transactionManager.rollback(status); logger.error("userDao.insertBoard: ", e); throw new UserException(" ? "); } logger.info("replyBoard: success "); return no; }