Java Code Examples for org.apache.ibatis.exceptions.PersistenceException#getCause()

The following examples show how to use org.apache.ibatis.exceptions.PersistenceException#getCause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AttachmentHandler.java    From taskana with Apache License 2.0 6 votes vote down vote up
void insertNewAttachmentOnTaskUpdate(TaskImpl newTaskImpl, Attachment attachment)
    throws AttachmentPersistenceException {
  LOGGER.debug("entry to insertNewAttachmentOnTaskUpdate()");
  AttachmentImpl attachmentImpl = (AttachmentImpl) attachment;
  initAttachment(attachmentImpl, newTaskImpl);

  try {
    attachmentMapper.insert(attachmentImpl);
    LOGGER.debug(
        "TaskService.updateTask() for TaskId={} INSERTED an Attachment={}.",
        newTaskImpl.getId(),
        attachmentImpl);
  } catch (PersistenceException e) {
    throw new AttachmentPersistenceException(
        String.format(
            "Cannot insert the Attachement %s for Task %s  because it already exists.",
            attachmentImpl.getId(), newTaskImpl.getId()),
        e.getCause());
  }
  LOGGER.debug("exit from insertNewAttachmentOnTaskUpdate(), returning");
}
 
Example 2
Source File: AttachmentHandler.java    From taskana with Apache License 2.0 6 votes vote down vote up
private void initializeAndInsertAttachment(TaskImpl task, AttachmentImpl attachmentImpl)
    throws AttachmentPersistenceException, InvalidArgumentException {
  LOGGER.debug("entry to initializeAndInsertAttachment()");
  initAttachment(attachmentImpl, task);
  ObjectReference objRef = attachmentImpl.getObjectReference();
  ObjectReference.validate(objRef, "ObjectReference", "Attachment");
  try {
    attachmentMapper.insert(attachmentImpl);
    LOGGER.debug(
        "TaskService.updateTask() for TaskId={} INSERTED an Attachment={}.",
        task.getId(),
        attachmentImpl);
  } catch (PersistenceException e) {
    throw new AttachmentPersistenceException(
        String.format(
            "Cannot insert the Attachement %s for Task %s  because it already exists.",
            attachmentImpl.getId(), task.getId()),
        e.getCause());
  }
  LOGGER.debug("exit from initializeAndInsertAttachment()");
}
 
Example 3
Source File: WorkbasketQueryImpl.java    From taskana with Apache License 2.0 5 votes vote down vote up
@Override
public List<WorkbasketSummary> list(int offset, int limit) {
  LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, this);
  List<WorkbasketSummary> workbaskets = new ArrayList<>();
  try {
    taskanaEngine.openConnection();
    RowBounds rowBounds = new RowBounds(offset, limit);
    handleCallerRolesAndAccessIds();
    workbaskets = taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
    return workbaskets;
  } catch (PersistenceException e) {
    if (e.getMessage().contains("ERRORCODE=-4470")) {
      TaskanaRuntimeException ex =
          new TaskanaRuntimeException(
              "The offset beginning was set over the amount of result-rows.", e.getCause());
      ex.setStackTrace(e.getStackTrace());
      throw ex;
    }
    throw e;
  } finally {
    taskanaEngine.returnConnection();
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug(
          "exit from list(offset,limit). Returning {} resulting Objects: {} ",
          workbaskets.size(),
          workbaskets);
    }
  }
}
 
Example 4
Source File: AbstractWorkbasketAccessItemQueryImpl.java    From taskana with Apache License 2.0 5 votes vote down vote up
@Override
public List<T> list(int offset, int limit) {
  LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, _this());
  List<T> result = new ArrayList<>();
  try {
    taskanaEngine.openConnection();
    RowBounds rowBounds = new RowBounds(offset, limit);
    List<T> foundAccessItms =
        taskanaEngine.getSqlSession().selectList(getLinkToMapper(), _this(), rowBounds);
    result.addAll(foundAccessItms);
    return result;
  } catch (PersistenceException e) {
    if (e.getMessage().contains("ERRORCODE=-4470")) {
      TaskanaRuntimeException ex =
          new TaskanaRuntimeException(
              "The offset beginning was set over the amount of result-rows.", e.getCause());
      ex.setStackTrace(e.getStackTrace());
      throw ex;
    }
    throw e;
  } finally {
    taskanaEngine.returnConnection();
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug(
          "exit from list(offset,limit). Returning {} resulting Objects: {} ",
          result.size(),
          result);
    }
  }
}
 
Example 5
Source File: WorkbasketAccessItemQueryImpl.java    From taskana with Apache License 2.0 5 votes vote down vote up
@Override
public List<WorkbasketAccessItem> list(int offset, int limit) {
  LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, this);
  List<WorkbasketAccessItem> result = new ArrayList<>();
  try {
    taskanaEngine.openConnection();
    RowBounds rowBounds = new RowBounds(offset, limit);
    List<WorkbasketAccessItemImpl> foundAccessItms =
        taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
    result.addAll(foundAccessItms);
    return result;
  } catch (PersistenceException e) {
    if (e.getMessage().contains("ERRORCODE=-4470")) {
      TaskanaRuntimeException ex =
          new TaskanaRuntimeException(
              "The offset beginning was set over the amount of result-rows.", e.getCause());
      ex.setStackTrace(e.getStackTrace());
      throw ex;
    }
    throw e;
  } finally {
    taskanaEngine.returnConnection();
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug(
          "exit from list(offset,limit). Returning {} resulting Objects: {} ",
          result.size(),
          result);
    }
  }
}
 
Example 6
Source File: TaskQueryImpl.java    From taskana with Apache License 2.0 5 votes vote down vote up
@Override
public List<TaskSummary> list(int offset, int limit) {
  LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, this);
  List<TaskSummary> result = new ArrayList<>();
  try {
    taskanaEngine.openConnection();
    checkForIllegalParamCombinations();
    checkOpenAndReadPermissionForSpecifiedWorkbaskets();
    setupAccessIds();
    setupJoinAndOrderParameters();
    RowBounds rowBounds = new RowBounds(offset, limit);
    List<TaskSummaryImpl> tasks =
        taskanaEngine.getSqlSession().selectList(getLinkToMapperScript(), this, rowBounds);
    result = taskService.augmentTaskSummariesByContainedSummaries(tasks);
    return result;
  } catch (PersistenceException e) {
    if (e.getMessage().contains("ERRORCODE=-4470")) {
      TaskanaRuntimeException ex =
          new TaskanaRuntimeException(
              "The offset beginning was set over the amount of result-rows.", e.getCause());
      ex.setStackTrace(e.getStackTrace());
      throw ex;
    }
    throw e;
  } finally {
    taskanaEngine.returnConnection();
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug(
          "exit from list(offset,limit). Returning {} resulting Objects: {} ",
          result.size(),
          result);
    }
  }
}
 
Example 7
Source File: MyBatisPersistenceExceptionMapper.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Response convert(final PersistenceException exception, final String id) {
  if (exception.getCause() instanceof FrozenException) {
    return Response.serverError()
        .status(SERVICE_UNAVAILABLE)
        .entity(String.format("Nexus Repository Manager is in read-only mode: (ID %s)", id))
        .type(TEXT_PLAIN)
        .build();
  }

  return unexpectedResponse(exception, id);
}
 
Example 8
Source File: ClassificationServiceImpl.java    From taskana with Apache License 2.0 4 votes vote down vote up
@Override
public void deleteClassification(String classificationId)
    throws ClassificationInUseException, ClassificationNotFoundException, NotAuthorizedException {
  LOGGER.debug("entry to deleteClassification(id = {})", classificationId);
  taskanaEngine.getEngine().checkRoleMembership(TaskanaRole.BUSINESS_ADMIN, TaskanaRole.ADMIN);
  try {
    taskanaEngine.openConnection();
    Classification classification = this.classificationMapper.findById(classificationId);
    if (classification == null) {
      throw new ClassificationNotFoundException(
          classificationId, "The classification \"" + classificationId + "\" wasn't found");
    }

    if (classification.getDomain().equals("")) {
      // master mode - delete all associated classifications in every domain.
      List<ClassificationSummary> classificationsInDomain =
          createClassificationQuery().keyIn(classification.getKey()).list();
      for (ClassificationSummary classificationInDomain : classificationsInDomain) {
        if (!"".equals(classificationInDomain.getDomain())) {
          deleteClassification(classificationInDomain.getId());
        }
      }
    }

    List<ClassificationSummary> childClassifications =
        createClassificationQuery().parentIdIn(classificationId).list();
    for (ClassificationSummary child : childClassifications) {
      this.deleteClassification(child.getId());
    }

    try {
      this.classificationMapper.deleteClassification(classificationId);
    } catch (PersistenceException e) {
      if (isReferentialIntegrityConstraintViolation(e)) {
        throw new ClassificationInUseException(
            String.format(
                "The classification id = \"%s\" and key = \"%s\" in domain = \"%s\" "
                    + "is in use and cannot be deleted. There are either tasks or "
                    + "attachments associated with the classification.",
                classificationId, classification.getKey(), classification.getDomain()),
            e.getCause());
      }
    }
  } finally {
    taskanaEngine.returnConnection();
    LOGGER.debug("exit from deleteClassification()");
  }
}
 
Example 9
Source File: ClassificationServiceImpl.java    From taskana with Apache License 2.0 4 votes vote down vote up
private boolean isDb2IntegrityConstraintViolation(PersistenceException e) {
  return e.getCause() instanceof SQLIntegrityConstraintViolationException
      && e.getMessage().contains("-532");
}
 
Example 10
Source File: ClassificationServiceImpl.java    From taskana with Apache License 2.0 4 votes vote down vote up
private boolean isH2OrPostgresIntegrityConstraintViolation(PersistenceException e) {
  return e.getCause() instanceof SQLException
      && ((SQLException) e.getCause()).getSQLState().equals("23503");
}