List of usage examples for org.springframework.dao DataIntegrityViolationException getMessage
@Override
@Nullable
public String getMessage()
From source file:com.gst.accounting.journalentry.service.JournalEntryWritePlatformServiceJpaRepositoryImpl.java
private void handleJournalEntryDataIntegrityIssues(final DataIntegrityViolationException dve) { final Throwable realCause = dve.getMostSpecificCause(); logger.error(dve.getMessage(), dve); throw new PlatformDataIntegrityException("error.msg.glJournalEntry.unknown.data.integrity.issue", "Unknown data integrity issue with resource Journal Entry: " + realCause.getMessage()); }
From source file:org.openmrs.web.controller.person.PersonAttributeTypeFormController.java
/** * The onSubmit function receives the form/command object that was modified by the input form * and saves it to the db/*from ww w . j a v a2 s.co m*/ * * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse, java.lang.Object, * org.springframework.validation.BindException) */ protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object obj, BindException errors) throws Exception { HttpSession httpSession = request.getSession(); String view = getFormView(); if (Context.isAuthenticated()) { PersonAttributeType attrType = (PersonAttributeType) obj; PersonService ps = Context.getPersonService(); try { if (request.getParameter("save") != null) { ps.savePersonAttributeType(attrType); view = getSuccessView(); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "PersonAttributeType.saved"); } // if the user is retiring out the personAttributeType else if (request.getParameter("retire") != null) { String retireReason = request.getParameter("retireReason"); if (attrType.getPersonAttributeTypeId() != null && !(StringUtils.hasText(retireReason))) { errors.reject("retireReason", "general.retiredReason.empty"); return showForm(request, response, errors); } ps.retirePersonAttributeType(attrType, retireReason); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "PersonAttributeType.retiredSuccessfully"); view = getSuccessView(); } // if the user is purging the personAttributeType else if (request.getParameter("purge") != null) { try { ps.purgePersonAttributeType(attrType); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "PersonAttributeType.purgedSuccessfully"); view = getSuccessView(); } catch (DataIntegrityViolationException e) { httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "error.object.inuse.cannot.purge"); view = "personAttributeType.form?personAttributeTypeId=" + attrType.getPersonAttributeTypeId(); } } else if (request.getParameter("unretire") != null) { ps.unretirePersonAttributeType(attrType); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "PersonAttributeType.unretiredSuccessfully"); view = getSuccessView(); } } catch (PersonAttributeTypeLockedException e) { log.error("PersonAttributeType.locked", e); errors.reject(e.getMessage()); httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "PersonAttributeType.locked"); return showForm(request, response, errors); } catch (APIException e) { httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "error.general: " + e.getLocalizedMessage()); view = "personAttributeType.form?personAttributeTypeId=" + attrType.getPersonAttributeTypeId(); } } return new ModelAndView(new RedirectView(view)); }
From source file:com.gst.infrastructure.reportmailingjob.service.ReportMailingJobWritePlatformServiceImpl.java
/** * Handle any SQL data integrity issue //from ww w . j a v a 2s . c o m * * @param jsonCommand -- JsonCommand object * @param dve -- data integrity exception object * @return None **/ private void handleDataIntegrityIssues(final JsonCommand jsonCommand, final DataIntegrityViolationException dve) { final Throwable realCause = dve.getMostSpecificCause(); if (realCause.getMessage().contains(ReportMailingJobConstants.NAME_PARAM_NAME)) { final String name = jsonCommand.stringValueOfParameterNamed(ReportMailingJobConstants.NAME_PARAM_NAME); throw new PlatformDataIntegrityException("error.msg.report.mailing.job.duplicate.name", "Report mailing job with name `" + name + "` already exists", ReportMailingJobConstants.NAME_PARAM_NAME, name); } logger.error(dve.getMessage(), dve); throw new PlatformDataIntegrityException("error.msg.charge.unknown.data.integrity.issue", "Unknown data integrity issue with resource: " + realCause.getMessage()); }
From source file:org.openmrs.web.controller.patient.PatientIdentifierTypeFormController.java
/** * The onSubmit function receives the form/command object that was modified by the input form * and saves it to the db//from w w w . j a v a2 s . c om * * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse, java.lang.Object, * org.springframework.validation.BindException) */ protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object obj, BindException errors) throws Exception { HttpSession httpSession = request.getSession(); String view = getFormView(); ModelAndView toReturn = new ModelAndView(new RedirectView(view)); if (Context.isAuthenticated()) { PatientIdentifierType identifierType = (PatientIdentifierType) obj; PatientService ps = Context.getPatientService(); //to save the patient identifier type try { if (request.getParameter("save") != null) { ps.savePatientIdentifierType(identifierType); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "PatientIdentifierType.saved"); toReturn = new ModelAndView(new RedirectView(getSuccessView())); } // if the user is retiring the identifierType else if (request.getParameter("retire") != null) { String retireReason = request.getParameter("retireReason"); if (identifierType.getPatientIdentifierTypeId() != null && !(StringUtils.hasText(retireReason))) { errors.reject("retireReason", "general.retiredReason.empty"); return showForm(request, response, errors); } ps.retirePatientIdentifierType(identifierType, retireReason); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "PatientIdentifierType.retiredSuccessfully"); toReturn = new ModelAndView(new RedirectView(getSuccessView())); } // if the user is purging the identifierType else if (request.getParameter("purge") != null) { try { ps.purgePatientIdentifierType(identifierType); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "PatientIdentifierType.purgedSuccessfully"); toReturn = new ModelAndView(new RedirectView(getSuccessView())); } catch (DataIntegrityViolationException e) { httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "error.object.inuse.cannot.purge"); return showForm(request, response, errors); } } // if the user unretiring patient identifier type else if (request.getParameter("unretire") != null) { ps.unretirePatientIdentifierType(identifierType); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "PatientIdentifierType.unretiredSuccessfully"); toReturn = new ModelAndView(new RedirectView(getSuccessView())); } } catch (PatientIdentifierTypeLockedException e) { log.error("PatientIdentifierType.locked", e); errors.reject(e.getMessage()); httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "PatientIdentifierType.locked"); return showForm(request, response, errors); } catch (APIException e) { httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "error.general: " + e.getLocalizedMessage()); return showForm(request, response, errors); } } return toReturn; }
From source file:com.oneops.transistor.ws.rest.TransistorRestController.java
@RequestMapping(value = "/assemblies/{assemblyId}/platforms", method = RequestMethod.POST) @ResponseBody/*from w ww. j a va 2 s .com*/ public Map<String, Long> generateDesign(@PathVariable long assemblyId, @RequestBody CmsRfcCISimple platRfcSimple, @RequestHeader(value = "X-Cms-User", required = false) String userId, @RequestHeader(value = "X-Cms-Scope", required = false) String scope) { if (userId == null) userId = "oneops-system"; long startTime = System.currentTimeMillis(); CmsRfcCI platRfc = util.custRfcCISimple2RfcCI(platRfcSimple); try { long platformCiId = dManager.generatePlatform(platRfc, assemblyId, userId, scope); Map<String, Long> result = new HashMap<>(1); result.put("platformCiId", platformCiId); long tookTime = System.currentTimeMillis() - startTime; logger.debug("Time to generate Design - " + tookTime); return result; } catch (DataIntegrityViolationException dive) { if (dive instanceof DuplicateKeyException) { throw new CIValidationException(CmsError.CMS_DUPCI_NAME_ERROR, dive.getMessage()); } else { throw new TransistorException(CmsError.CMS_EXCEPTION, dive.getMessage()); } } catch (CmsBaseException te) { logger.error(te); te.printStackTrace(); throw te; } }
From source file:com.oneops.transistor.ws.rest.TransistorRestController.java
@RequestMapping(value = "/platforms/{fromPlatformId}/clone", method = RequestMethod.POST) @ResponseBody//from w w w . j ava 2s.c o m public Map<String, Long> clonePlatform(@PathVariable long fromPlatformId, @RequestBody CmsRfcCISimple platRfcSimple, @RequestHeader(value = "X-Cms-User", required = false) String userId, @RequestHeader(value = "X-Cms-Scope", required = false) String scope) { if (userId == null) userId = "oneops-system"; try { long startTime = System.currentTimeMillis(); CmsRfcCI platRfc = util.custRfcCISimple2RfcCI(platRfcSimple); long platformId = dManager.clonePlatform(platRfc, null, fromPlatformId, userId, scope); Map<String, Long> result = new HashMap<>(1); result.put("platformCiId", platformId); long tookTime = System.currentTimeMillis() - startTime; logger.debug("Time to generate Design - " + tookTime); return result; } catch (DataIntegrityViolationException dive) { if (dive instanceof DuplicateKeyException) { throw new CIValidationException(CmsError.CMS_DUPCI_NAME_ERROR, dive.getMessage()); } else { throw new TransistorException(CmsError.CMS_EXCEPTION, dive.getMessage()); } } catch (CmsBaseException te) { logger.error(te); te.printStackTrace(); throw te; } }
From source file:org.atomserver.core.dbstore.DBBasedAtomCollection.java
/** * This method handles BOTH inserts and updates * <p/>/*w ww . ja v a2 s . c o m*/ * NOTE: A PUT will receive an EntryTarget which points at the NEXT revision */ protected EntryMetaDataStatus modifyEntry(Object internalId, EntryTarget entryTarget, boolean mustAlreadyExist) throws AtomServerException { String workspace = entryTarget.getWorkspace(); String collection = entryTarget.getCollection(); Locale locale = entryTarget.getLocale(); String entryId = entryTarget.getEntryId(); int revision = entryTarget.getRevision(); log.debug("DBBasedAtomCollection.(MODIFY) [" + workspace + ", " + collection + ", " + locale + ", " + entryId + ", " + revision + "]" + "Id= " + internalId); boolean isNewEntry = (internalId == null); boolean writeFailed = true; if (!isNewEntry) { // if this isn't a new Entry and revision ==0 , then we know we have an error if (revision == 0) { // SELECT -- we do this select to know what revision we actually had, // so we can create the proper editURI EntryMetaData metaData = getWriteEntriesDAO().selectEntryByInternalId(internalId); int rev = metaData.getRevision(); String msg = "Entry [" + workspace + ", " + collection + ", " + entryId + ", " + locale + "] You requested a write at revision 0, but this has already been written" + " It should be " + (rev + 1) + ")"; throwOptimisticConcurrencyException(msg, workspace, collection, entryId, locale, (rev + 1)); } if (this.alwaysUpdateEntry()) { // update entry regardless of its content. int numRowsModified = getWriteEntriesDAO().updateEntry(entryTarget, false); if (numRowsModified > 0) { writeFailed = false; } log.debug("AFTER UPDATE:: [" + entryTarget.getEntryId() + "] numRowsModified= " + numRowsModified); } else { // Don't update entry if the content are the same. // SELECT -- we do this select to know what revision we actually had and its content hash code. EntryMetaData metaData = getWriteEntriesDAO().selectEntryByInternalId(internalId); // check revision compatibility boolean revisionError = (revision >= 0) && (metaData.getRevision() >= revision); // if the entry is deleted or the content has changed, proceed with update. if (!revisionError && !metaData.getDeleted() && !isContentChanged(entryTarget, metaData)) { log.debug(" CONTENT Hash is the same: [" + entryTarget.getEntryId() + "]"); metaData.setNewlyCreated(false); // If content has not changed, do not update the Entry (unless the categories are changed). return new EntryMetaDataStatus(metaData, false); } if (!revisionError) { int numRowsModified = getWriteEntriesDAO().updateEntry(entryTarget, false); if (numRowsModified > 0) { writeFailed = false; } log.debug("AFTER UPDATE:: [" + entryTarget.getEntryId() + "] numRowsModified= " + numRowsModified); } else { writeFailed = true; } } } else { if (mustAlreadyExist) { String msg = "Entry [" + workspace + ", " + collection + ", " + entryId + ", " + locale + "] does NOT already exist, and MUST in this case (most likely for a Categories PUT)"; log.error(msg); throw new BadRequestException(msg); } if (revision != 0 && revision != URIHandler.REVISION_OVERRIDE) { String msg = "Entry [" + workspace + ", " + collection + ", " + entryId + ", " + locale + "] does NOT exist, but you requested it to be created at revision= " + revision + "\nNOTE: only /0, /*, or nothing is acceptable for initial creation"; throwOptimisticConcurrencyException(msg, workspace, collection, entryId, locale, 0); } try { internalId = getWriteEntriesDAO().insertEntry(entryTarget); log.debug("AFTER INSERT :: [" + entryTarget.getEntryId() + "] internalId= " + internalId); if (internalId != null) { writeFailed = false; } } catch (DataIntegrityViolationException ee) { // SELECT -- we do this select to know what revision we actually had, // so we can create the proper editURI EntryMetaData entryMetaData = getWriteEntriesDAO().selectEntryByInternalId(internalId); String msg; if (revision == URIHandler.REVISION_OVERRIDE) { msg = "Entry [" + workspace + ", " + collection + ", " + entryId + ", " + locale + "] threw a DataIntegrityViolationException during an INSERT." + "\nThis is because someone else was inserting this record at exactly the same time" + "\nThus, you lost the race, and must attempt your INSERT again" + "\nException = " + ee.getMessage(); } else { msg = "Entry [" + workspace + ", " + collection + ", " + entryId + ", " + locale + "] edit revision does NOT match the revision requested (requested= " + revision + " actual= " + (entryMetaData == null ? 0 : (entryMetaData.getRevision() + 1)) + ")"; } if (entryMetaData == null) { throwOptimisticConcurrencyException(msg, null, null, null, null, 0, ee); } else { throwOptimisticConcurrencyException(msg, workspace, entryMetaData.getCollection(), entryMetaData.getEntryId(), entryMetaData.getLocale(), (entryMetaData.getRevision() + 1), ee); } } } return postModifyEntry(internalId, entryTarget, isNewEntry, writeFailed); }
From source file:com.oneops.transistor.ws.rest.TransistorRestController.java
@RequestMapping(value = "/assemblies/{fromAssemblyId}/clone", method = RequestMethod.POST) @ResponseBody//www .ja v a 2 s . co m public Map<String, Long> cloneAssembly(@PathVariable long fromAssemblyId, @RequestBody CmsCISimple targetCISimple, @RequestHeader(value = "X-Cms-User", required = false) String userId, @RequestHeader(value = "X-Cms-Scope", required = false) String scope) { if (userId == null) userId = "oneops-system"; try { long startTime = System.currentTimeMillis(); if (targetCISimple.getCiAttributes().get("description") == null) { targetCISimple.addCiAttribute("description", null); } CmsCI targetCI = util.custCISimple2CI(targetCISimple, null); long resultCiId; if ("account.Assembly".equals(targetCI.getCiClassName())) { resultCiId = dManager.cloneAssembly(targetCI, fromAssemblyId, userId, scope); } else if ("account.Design".equals(targetCI.getCiClassName())) { resultCiId = dManager.saveAssemblyAsCatalog(targetCI, fromAssemblyId, userId, scope); } else { throw new TransistorException(CmsError.TRANSISTOR_BAD_CLASS_NAME, "Bad class name"); } Map<String, Long> result = new HashMap<>(1); result.put("resultCiId", resultCiId); long tookTime = System.currentTimeMillis() - startTime; logger.debug("Time to generate Assembly/Catalog - " + tookTime); return result; } catch (DataIntegrityViolationException dive) { if (dive instanceof DuplicateKeyException) { throw new CIValidationException(CmsError.CMS_DUPCI_NAME_ERROR, dive.getMessage()); } else { throw new TransistorException(CmsError.CMS_EXCEPTION, dive.getMessage()); } } catch (CmsBaseException te) { logger.error(te); te.printStackTrace(); throw te; } }
From source file:org.androidpn.server.dao.UserDaoTest.java
public void testUpdateUser() throws Exception { User user = dao.getUser(1L);// w w w . j ava 2s .co m dao.saveUser(user); user = dao.getUser(1L); user.setId(null); endTransaction(); try { dao.saveUser(user); fail("saveUser didn't throw DataIntegrityViolationException"); } catch (DataIntegrityViolationException e) { assertNotNull(e); log.debug("expected exception: " + e.getMessage()); } }