Search in sources :

Example 1 with PersistenceException

use of org.apache.ibatis.exceptions.PersistenceException in project taskana by Taskana.

the class ObjectReferenceQueryImpl method list.

@Override
public List<ObjectReference> list(int offset, int limit) {
    LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, this);
    List<ObjectReference> result = null;
    try {
        taskanaEngine.openConnection();
        RowBounds rowBounds = new RowBounds(offset, limit);
        result = taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
        return result;
    } catch (Exception e) {
        if (e instanceof PersistenceException) {
            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()) {
            int numberOfResultObjects = result == null ? 0 : result.size();
            LOGGER.debug("exit from list(offset,limit). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
        }
    }
}
Also used : PersistenceException(org.apache.ibatis.exceptions.PersistenceException) RowBounds(org.apache.ibatis.session.RowBounds) TaskanaRuntimeException(pro.taskana.exceptions.TaskanaRuntimeException) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) TaskanaRuntimeException(pro.taskana.exceptions.TaskanaRuntimeException)

Example 2 with PersistenceException

use of org.apache.ibatis.exceptions.PersistenceException in project taskana by Taskana.

the class TaskQueryImpl method list.

@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();
        checkOpenPermissionForSpecifiedWorkbaskets();
        RowBounds rowBounds = new RowBounds(offset, limit);
        List<TaskSummaryImpl> tasks = taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, 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;
    } catch (NotAuthorizedException e) {
        throw new NotAuthorizedToQueryWorkbasketException(e.getMessage());
    } finally {
        taskanaEngine.returnConnection();
        if (LOGGER.isDebugEnabled()) {
            int numberOfResultObjects = result == null ? 0 : result.size();
            LOGGER.debug("exit from list(offset,limit). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
        }
    }
}
Also used : TaskSummary(pro.taskana.TaskSummary) ArrayList(java.util.ArrayList) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) RowBounds(org.apache.ibatis.session.RowBounds) NotAuthorizedToQueryWorkbasketException(pro.taskana.exceptions.NotAuthorizedToQueryWorkbasketException) TaskanaRuntimeException(pro.taskana.exceptions.TaskanaRuntimeException) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException)

Example 3 with PersistenceException

use of org.apache.ibatis.exceptions.PersistenceException in project taskana by Taskana.

the class TaskServiceImpl method handleAttachmentsOnTaskUpdate.

private PrioDurationHolder handleAttachmentsOnTaskUpdate(TaskImpl oldTaskImpl, TaskImpl newTaskImpl) throws AttachmentPersistenceException {
    Duration minDuration = MAX_DURATION;
    int maxPrio = Integer.MIN_VALUE;
    // Iterator for removing invalid current values directly. OldAttachments can be ignored.
    Iterator<Attachment> i = newTaskImpl.getAttachments().iterator();
    while (i.hasNext()) {
        Attachment attachment = i.next();
        if (attachment != null) {
            boolean wasAlreadyPresent = false;
            if (attachment.getId() != null) {
                for (Attachment oldAttachment : oldTaskImpl.getAttachments()) {
                    if (oldAttachment != null && attachment.getId().equals(oldAttachment.getId())) {
                        wasAlreadyPresent = true;
                        if (!attachment.equals(oldAttachment)) {
                            AttachmentImpl temp = (AttachmentImpl) attachment;
                            ClassificationSummary classification = attachment.getClassificationSummary();
                            if (classification != null) {
                                PrioDurationHolder newPrioDuration = getNewPrioDuration(maxPrio, minDuration, classification.getPriority(), classification.getServiceLevel());
                                maxPrio = newPrioDuration.getPrio();
                                minDuration = newPrioDuration.getDuration();
                            }
                            temp.setModified(Instant.now());
                            attachmentMapper.update(temp);
                            LOGGER.debug("TaskService.updateTask() for TaskId={} UPDATED an Attachment={}.", newTaskImpl.getId(), attachment);
                            break;
                        }
                    }
                }
            }
            // ADD, when ID not set or not found in elements
            if (!wasAlreadyPresent) {
                AttachmentImpl attachmentImpl = (AttachmentImpl) attachment;
                initAttachment(attachmentImpl, newTaskImpl);
                ClassificationSummary classification = attachment.getClassificationSummary();
                if (classification != null) {
                    PrioDurationHolder newPrioDuration = getNewPrioDuration(maxPrio, minDuration, classification.getPriority(), classification.getServiceLevel());
                    maxPrio = newPrioDuration.getPrio();
                    minDuration = newPrioDuration.getDuration();
                }
                try {
                    attachmentMapper.insert(attachmentImpl);
                    LOGGER.debug("TaskService.updateTask() for TaskId={} INSERTED an Attachment={}.", newTaskImpl.getId(), attachmentImpl);
                } catch (PersistenceException e) {
                    LOGGER.error("TaskService.updateTask() for TaskId={} can NOT INSERT the current Attachment, because it was added fored multiple times and wasn´t persisted before. ID={}", newTaskImpl.getId(), attachmentImpl.getId());
                    throw new AttachmentPersistenceException(attachmentImpl.getId());
                }
            }
        } else {
            i.remove();
        }
    }
    // DELETE, when an Attachment was only represented before
    for (Attachment oldAttachment : oldTaskImpl.getAttachments()) {
        if (oldAttachment != null) {
            boolean isRepresented = false;
            for (Attachment newAttachment : newTaskImpl.getAttachments()) {
                if (newAttachment != null && oldAttachment.getId().equals(newAttachment.getId())) {
                    isRepresented = true;
                    break;
                }
            }
            if (!isRepresented) {
                attachmentMapper.deleteAttachment(oldAttachment.getId());
                LOGGER.debug("TaskService.updateTask() for TaskId={} DELETED an Attachment={}.", newTaskImpl.getId(), oldAttachment);
            }
        }
    }
    if (minDuration != null && MAX_DURATION.equals(minDuration)) {
        minDuration = null;
    }
    return new PrioDurationHolder(minDuration, maxPrio);
}
Also used : ClassificationSummary(pro.taskana.ClassificationSummary) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) AttachmentPersistenceException(pro.taskana.exceptions.AttachmentPersistenceException) Duration(java.time.Duration) Attachment(pro.taskana.Attachment) AttachmentPersistenceException(pro.taskana.exceptions.AttachmentPersistenceException)

Example 4 with PersistenceException

use of org.apache.ibatis.exceptions.PersistenceException in project mybatis-3 by mybatis.

the class ForEachTest method shouldAllowNullWhenAttributeIsOmitAndConfigurationIsDefault.

@Test
void shouldAllowNullWhenAttributeIsOmitAndConfigurationIsDefault() throws IOException, SQLException {
    SqlSessionFactory sqlSessionFactory;
    try (Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/foreach/mybatis-config.xml")) {
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    }
    BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), "org/apache/ibatis/submitted/foreach/CreateDB.sql");
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        Mapper mapper = sqlSession.getMapper(Mapper.class);
        User user = new User();
        user.setFriendList(null);
        mapper.countUserWithNullableIsOmit(user);
        Assertions.fail();
    } catch (PersistenceException e) {
        Assertions.assertEquals("The expression 'friendList' evaluated to a null value.", e.getCause().getMessage());
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.jupiter.api.Test)

Example 5 with PersistenceException

use of org.apache.ibatis.exceptions.PersistenceException in project mybatis-3 by mybatis.

the class NestedResultHandlerGh1551Test method useColumnLabelIsFalse.

@Test
void useColumnLabelIsFalse() {
    sqlSessionFactory.getConfiguration().setUseColumnLabel(false);
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        ProductMapper mapper = sqlSession.getMapper(ProductMapper.class);
        PersistenceException exception = Assertions.assertThrows(PersistenceException.class, () -> mapper.selectAllInfo("P001"));
        Assertions.assertTrue(exception.getMessage().contains("Error attempting to get column 'ID' from result set.  Cause: java.sql.SQLSyntaxErrorException: incompatible data type in conversion: from SQL type VARCHAR to java.lang.Integer, value: 10000000000000000000000000000001"));
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) Test(org.junit.jupiter.api.Test) BaseDataTest(org.apache.ibatis.BaseDataTest)

Aggregations

PersistenceException (org.apache.ibatis.exceptions.PersistenceException)17 BaseDataTest (org.apache.ibatis.BaseDataTest)6 Test (org.junit.jupiter.api.Test)6 Properties (java.util.Properties)5 RowBounds (org.apache.ibatis.session.RowBounds)5 SqlSession (org.apache.ibatis.session.SqlSession)5 Test (org.junit.Test)5 PropertyDefinitions (org.sonar.api.config.PropertyDefinitions)5 CorePropertyDefinitions (org.sonar.core.config.CorePropertyDefinitions)5 TaskanaRuntimeException (pro.taskana.exceptions.TaskanaRuntimeException)5 Reader (java.io.Reader)2 ArrayList (java.util.ArrayList)2 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)2 ClassificationSummary (pro.taskana.ClassificationSummary)2 Duration (java.time.Duration)1 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)1 Attachment (pro.taskana.Attachment)1 TaskSummary (pro.taskana.TaskSummary)1 WorkbasketAccessItem (pro.taskana.WorkbasketAccessItem)1 WorkbasketSummary (pro.taskana.WorkbasketSummary)1