TSK-1355: Adjust all single() methods to use mybatis selectOne
This commit is contained in:
parent
cc2c5eb58c
commit
2a6d97132b
|
@ -493,14 +493,10 @@ public class ClassificationHistoryQueryImpl implements ClassificationHistoryQuer
|
|||
LOGGER.debug("entry to single(), this = {}", this);
|
||||
ClassificationHistoryEvent result = null;
|
||||
try {
|
||||
|
||||
taskanaHistoryEngine.openConnection();
|
||||
List<ClassificationHistoryEvent> results =
|
||||
taskanaHistoryEngine.getSqlSession().selectList(LINK_TO_MAPPER, this);
|
||||
if (results.isEmpty()) {
|
||||
return result;
|
||||
} else {
|
||||
result = results.get(0);
|
||||
}
|
||||
result = taskanaHistoryEngine.getSqlSession().selectOne(LINK_TO_MAPPER, this);
|
||||
|
||||
return result;
|
||||
} catch (SQLException e) {
|
||||
LOGGER.error(SQL_EXCEPTION_MESSAGE, e.getCause());
|
||||
|
|
|
@ -702,14 +702,10 @@ public class TaskHistoryQueryImpl implements TaskHistoryQuery {
|
|||
TaskHistoryEvent result = null;
|
||||
try {
|
||||
taskanaHistoryEngine.openConnection();
|
||||
List<TaskHistoryEvent> results =
|
||||
taskanaHistoryEngine.getSqlSession().selectList(LINK_TO_MAPPER, this);
|
||||
if (results.isEmpty()) {
|
||||
return result;
|
||||
} else {
|
||||
result = results.get(0);
|
||||
}
|
||||
result = taskanaHistoryEngine.getSqlSession().selectOne(LINK_TO_MAPPER, this);
|
||||
|
||||
return result;
|
||||
|
||||
} catch (SQLException e) {
|
||||
LOGGER.error(SQL_EXCEPTION_MESSAGE, e.getCause());
|
||||
return result;
|
||||
|
|
|
@ -546,13 +546,8 @@ public class WorkbasketHistoryQueryImpl implements WorkbasketHistoryQuery {
|
|||
WorkbasketHistoryEvent result = null;
|
||||
try {
|
||||
taskanaHistoryEngine.openConnection();
|
||||
List<WorkbasketHistoryEvent> results =
|
||||
taskanaHistoryEngine.getSqlSession().selectList(LINK_TO_MAPPER, this);
|
||||
if (results.isEmpty()) {
|
||||
return result;
|
||||
} else {
|
||||
result = results.get(0);
|
||||
}
|
||||
result = taskanaHistoryEngine.getSqlSession().selectOne(LINK_TO_MAPPER, this);
|
||||
|
||||
return result;
|
||||
} catch (SQLException e) {
|
||||
LOGGER.error(SQL_EXCEPTION_MESSAGE, e.getCause());
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package acceptance.query;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
import acceptance.AbstractAccTest;
|
||||
import java.time.Instant;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.exceptions.TooManyResultsException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import pro.taskana.classification.api.ClassificationCustomField;
|
||||
|
@ -96,17 +98,31 @@ class QueryClassificationHistoryAccTest extends AbstractAccTest {
|
|||
@Test
|
||||
void should_ReturnSingleHistoryEvent_When_UsingSingleMethod() {
|
||||
ClassificationHistoryEvent single =
|
||||
historyService.createClassificationHistoryQuery().userIdIn("peter").single();
|
||||
historyService
|
||||
.createClassificationHistoryQuery()
|
||||
.userIdIn("peter")
|
||||
.classificationIdIn("CLI:000000000000000000000000000000000001")
|
||||
.single();
|
||||
assertThat(single.getEventType()).isEqualTo(ClassificationHistoryEventType.CREATED.getName());
|
||||
|
||||
single =
|
||||
historyService
|
||||
.createClassificationHistoryQuery()
|
||||
.eventTypeIn(ClassificationHistoryEventType.CREATED.getName(), "xy")
|
||||
.classificationIdIn("CLI:000000000000000000000000000000000001")
|
||||
.single();
|
||||
assertThat(single.getUserId()).isEqualTo("peter");
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_ThrowException_When_SingleMethodRetrievesMoreThanOneEventFromDatabase() {
|
||||
|
||||
ClassificationHistoryQuery query =
|
||||
getHistoryService().createClassificationHistoryQuery().userIdIn("peter");
|
||||
|
||||
assertThatThrownBy(() -> query.single()).isInstanceOf(TooManyResultsException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_ReturnCountOfEvents_When_UsingCountMethod() {
|
||||
long count = historyService.createClassificationHistoryQuery().userIdIn("peter").count();
|
||||
|
|
|
@ -2,11 +2,13 @@ package acceptance.query;
|
|||
|
||||
import static java.lang.String.CASE_INSENSITIVE_ORDER;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
import acceptance.AbstractAccTest;
|
||||
import java.time.Instant;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.exceptions.TooManyResultsException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import pro.taskana.common.api.BaseQuery.SortDirection;
|
||||
|
@ -86,17 +88,31 @@ class QueryTaskHistoryAccTest extends AbstractAccTest {
|
|||
@Test
|
||||
void should_ReturnSingleHistoryEvent_When_UsingSingleMethod() {
|
||||
TaskHistoryEvent single =
|
||||
getHistoryService().createTaskHistoryQuery().userIdIn("peter").single();
|
||||
getHistoryService()
|
||||
.createTaskHistoryQuery()
|
||||
.userIdIn("peter")
|
||||
.taskIdIn("TKI:000000000000000000000000000000000036")
|
||||
.single();
|
||||
|
||||
assertThat(single.getEventType()).isEqualTo(TaskHistoryEventType.CREATED.getName());
|
||||
|
||||
single =
|
||||
getHistoryService()
|
||||
.createTaskHistoryQuery()
|
||||
.eventTypeIn(TaskHistoryEventType.CREATED.getName(), "xy")
|
||||
.idIn("THI:000000000000000000000000000000000003")
|
||||
.single();
|
||||
assertThat(single.getUserId()).isEqualTo("peter");
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_ThrowException_When_SingleMethodRetrievesMoreThanOneEventFromDatabase() {
|
||||
|
||||
TaskHistoryQuery query = getHistoryService().createTaskHistoryQuery().userIdIn("peter");
|
||||
|
||||
assertThatThrownBy(() -> query.single()).isInstanceOf(TooManyResultsException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_ReturnCountOfEvents_When_UsingCountMethod() {
|
||||
long count = getHistoryService().createTaskHistoryQuery().userIdIn("peter").count();
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package acceptance.query;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
import acceptance.AbstractAccTest;
|
||||
import java.time.Instant;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.exceptions.TooManyResultsException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import pro.taskana.common.api.BaseQuery.SortDirection;
|
||||
|
@ -96,17 +98,31 @@ class QueryWorkbasketHistoryAccTest extends AbstractAccTest {
|
|||
@Test
|
||||
void should_ReturnSingleHistoryEvent_When_UsingSingleMethod() {
|
||||
WorkbasketHistoryEvent single =
|
||||
historyService.createWorkbasketHistoryQuery().userIdIn("peter").single();
|
||||
historyService
|
||||
.createWorkbasketHistoryQuery()
|
||||
.userIdIn("peter")
|
||||
.idIn("WHI:000000000000000000000000000000000000")
|
||||
.single();
|
||||
assertThat(single.getEventType()).isEqualTo(WorkbasketHistoryEventType.CREATED.getName());
|
||||
|
||||
single =
|
||||
historyService
|
||||
.createWorkbasketHistoryQuery()
|
||||
.eventTypeIn(WorkbasketHistoryEventType.CREATED.getName(), "xy")
|
||||
.idIn("WHI:000000000000000000000000000000000000")
|
||||
.single();
|
||||
assertThat(single.getUserId()).isEqualTo("peter");
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_ThrowException_When_SingleMethodRetrievesMoreThanOneEventFromDatabase() {
|
||||
|
||||
WorkbasketHistoryQuery query =
|
||||
getHistoryService().createWorkbasketHistoryQuery().userIdIn("peter");
|
||||
|
||||
assertThatThrownBy(() -> query.single()).isInstanceOf(TooManyResultsException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_ReturnCountOfEvents_When_UsingCountMethod() {
|
||||
long count = historyService.createWorkbasketHistoryQuery().userIdIn("peter").count();
|
||||
|
|
Loading…
Reference in New Issue