}
}
+ /**
+ * Return a single result or null. If the request returns multiple rows, then
+ * the first row is returned.
+ */
+ public ResourceDto getResource(ResourceQuery query) {
+ List<ResourceDto> resources = getResources(query);
+ if (!resources.isEmpty()) {
+ return resources.get(0);
+ }
+ return null;
+ }
+
public List<Long> getResourceIds(ResourceQuery query) {
SqlSession session = mybatis.openSession();
try {
ResourceMapper mapper = session.getMapper(ResourceMapper.class);
try {
for (ResourceDto resource : resources) {
- if (resource.getId()==null) {
+ if (resource.getId() == null) {
mapper.insert(resource);
} else {
mapper.update(resource);
}
@Test
- public void getResource() {
+ public void get_resource_by_id() {
setupData("fixture");
ResourceDto resource = dao.getResource(1L);
public void getResources_filter_by_key() {
setupData("fixture");
- List<ResourceDto> resources = dao.getResources(ResourceQuery.create().setKey("org.struts:struts-core"));
+ ResourceQuery query = ResourceQuery.create().setKey("org.struts:struts-core");
+ List<ResourceDto> resources = dao.getResources(query);
assertThat(resources).hasSize(1);
assertThat(resources.get(0).getKey()).isEqualTo("org.struts:struts-core");
+
+ assertThat(dao.getResource(query).getKey()).isEqualTo("org.struts:struts-core");
}
@Test