use of org.hibernate.exception.ConstraintViolationException in project openmrs-core by openmrs.
the class FormServiceImpl method saveFormResource.
/**
* @see org.openmrs.api.FormService#saveFormResource(org.openmrs.FormResource)
*/
@Override
public FormResource saveFormResource(FormResource formResource) throws APIException {
if (formResource == null) {
return null;
}
// If a form resource with same name exists, replace it with current value
FormResource toPersist = formResource;
FormResource original = Context.getFormService().getFormResource(formResource.getForm(), formResource.getName());
if (original != null) {
original.setName(formResource.getName());
original.setValue(formResource.getValue());
original.setDatatypeClassname(formResource.getDatatypeClassname());
original.setDatatypeConfig(formResource.getDatatypeConfig());
original.setPreferredHandlerClassname(formResource.getPreferredHandlerClassname());
toPersist = original;
}
try {
CustomDatatypeUtil.saveIfDirty(toPersist);
} catch (ConstraintViolationException ex) {
throw new InvalidFileTypeException(ex.getMessage(), ex);
}
return dao.saveFormResource(toPersist);
}
use of org.hibernate.exception.ConstraintViolationException in project herd by FINRAOS.
the class HerdErrorInformationExceptionHandlerTest method testConstraintViolationException.
@Test
public void testConstraintViolationException() throws Exception {
validateErrorInformation(exceptionHandler.handlePersistenceException(getPersistenceException(new ConstraintViolationException(MESSAGE, null, "testConstraint")), new MockHttpServletResponse()), HttpStatus.BAD_REQUEST, false);
validateErrorInformation(exceptionHandler.handlePersistenceException(getPersistenceException(new SQLException(MESSAGE, HerdErrorInformationExceptionHandler.POSTGRES_SQL_STATE_CODE_FOREIGN_KEY_VIOLATION, 0)), new MockHttpServletResponse()), HttpStatus.BAD_REQUEST, false);
}
use of org.hibernate.exception.ConstraintViolationException in project crnk-framework by crnk-project.
the class HibernateConstraintViolationExceptionMapper method fromErrorResponse.
@Override
public ConstraintViolationException fromErrorResponse(ErrorResponse errorResponse) {
Iterable<ErrorData> errors = errorResponse.getErrors();
ErrorData error = errors.iterator().next();
String msg = error.getDetail();
String constraintName = error.getCode();
return new ConstraintViolationException(msg, null, constraintName);
}
use of org.hibernate.exception.ConstraintViolationException in project candlepin by candlepin.
the class RdbmsExceptionTranslator method isConstraintViolationDuplicateEntry.
public boolean isConstraintViolationDuplicateEntry(PersistenceException pe) {
log.debug("Translating {}", pe);
if (pe.getCause() != null && pe.getCause() instanceof ConstraintViolationException) {
ConstraintViolationException cve = (ConstraintViolationException) pe.getCause();
log.info("ConstraintViolationException error code:" + cve.getErrorCode());
// http://dev.mysql.com/doc/refman/5.7/en/error-messages-server.html
if (cve.getSQLState() != null && cve.getSQLState().equals("23000") && cve.getErrorCode() == 1062) {
return true;
}
// https://www.postgresql.org/docs/8.3/static/errcodes-appendix.html
if (cve.getSQLState() != null && cve.getSQLState().equals("23505")) {
return true;
}
// TODO add Oracle
}
return false;
}
use of org.hibernate.exception.ConstraintViolationException in project candlepin by candlepin.
the class OwnerResource method deleteOwner.
/**
* Removes an Owner
*
* @httpcode 404
* @httpcode 200
*/
@DELETE
@Path("/{owner_key}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(notes = "Removes an Owner", value = "Delete Owner")
@ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") })
public void deleteOwner(@PathParam("owner_key") String ownerKey, @QueryParam("revoke") @DefaultValue("true") boolean revoke, @QueryParam("force") @DefaultValue("false") boolean force) {
Owner owner = findOwnerByKey(ownerKey);
Event event = eventFactory.ownerDeleted(owner);
if (!force && consumerCurator.doesShareConsumerExist(owner)) {
throw new BadRequestException(i18n.tr("owner \"{0}\" cannot be deleted while there is a share consumer. " + "You may use \"force\" to bypass.", owner.getKey()));
}
try {
ownerManager.cleanupAndDelete(owner, revoke);
} catch (PersistenceException e) {
if (e.getCause() instanceof ConstraintViolationException) {
throw new ConflictException(e.getMessage(), e);
} else {
throw e;
}
}
sink.queueEvent(event);
}
Aggregations