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));
}
}
}
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));
}
}
}
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);
}
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());
}
}
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"));
}
}
Aggregations