Add Transactional support

pull/235/head
johnniang 2019-07-02 16:20:19 +08:00
parent d42e4c2599
commit 74349a11e2
4 changed files with 58 additions and 24 deletions

View File

@ -18,6 +18,7 @@ import java.util.List;
* @author ryanwang * @author ryanwang
* @date : 2019-03-14 * @date : 2019-03-14
*/ */
@Transactional(readOnly = true)
public interface CategoryService extends CrudService<Category, Integer> { public interface CategoryService extends CrudService<Category, Integer> {
/** /**

View File

@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.lang.NonNull; import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import run.halo.app.exception.AlreadyExistsException; import run.halo.app.exception.AlreadyExistsException;
@ -46,6 +47,7 @@ public class CategoryServiceImpl extends AbstractCrudService<Category, Integer>
} }
@Override @Override
@Transactional
public Category create(Category category) { public Category create(Category category) {
Assert.notNull(category, "Category to create must not be null"); Assert.notNull(category, "Category to create must not be null");
@ -161,6 +163,7 @@ public class CategoryServiceImpl extends AbstractCrudService<Category, Integer>
} }
@Override @Override
@Transactional
public void removeCategoryAndPostCategoryBy(Integer categoryId) { public void removeCategoryAndPostCategoryBy(Integer categoryId) {
// Remove category // Remove category
removeById(categoryId); removeById(categoryId);

View File

@ -2,6 +2,7 @@ package run.halo.app.service.impl;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import run.halo.app.exception.AlreadyExistsException; import run.halo.app.exception.AlreadyExistsException;
@ -35,6 +36,7 @@ public class TagServiceImpl extends AbstractCrudService<Tag, Integer> implements
} }
@Override @Override
@Transactional
public Tag create(Tag tag) { public Tag create(Tag tag) {
// Check if the tag is exist // Check if the tag is exist
long count = tagRepository.countByNameOrSlugName(tag.getName(), tag.getSlugName()); long count = tagRepository.countByNameOrSlugName(tag.getName(), tag.getSlugName());

View File

@ -1,24 +1,52 @@
//package run.halo.app.service.impl; package run.halo.app.service.impl;
//
//import org.junit.Assert; import org.junit.Ignore;
//import org.junit.Test; import org.junit.Test;
//import org.junit.runner.RunWith; import org.junit.runner.RunWith;
//import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ActiveProfiles;
//import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
//
//@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
//@SpringBootTest @SpringBootTest
//@ActiveProfiles("dev") @ActiveProfiles("dev")
//public class PostServiceImplTest { public class PostServiceImplTest {
//
// @Autowired String standardMdContent = "---\n" +
// private PostServiceImpl postService; "title: springfox-swagger2配置成功但无法访问/swagger-ui.html\n" +
// "tags:\n" +
// @Test " - spring boot\n" +
// public void getContent(){ " - swagger\n" +
// String exportMarkdown = postService.exportMarkdown(18); " - solution\n" +
// System.out.println(exportMarkdown); "date: 2018-11-23 16:11:28\n" +
// } "---\n" +
//} "\n" +
"# Pre\n" +
"\n" +
"在前后端分离项目中,通常需要用到 API 文档springfox 开发的 **[SpringFox](https://github.com/springfox/springfox)** 可以实现自动化 json API 文档。";
String nonStandardMdContent = "---\n" +
"title: Basic concepts of JPA\n" +
"date: 2018-08-03 11:57:00\n" +
"tags: ['spring', 'jpa', 'database', 'concept']\n" +
"---\n" +
"\n" +
"以下将讲解关系型数据的关系描述。仅仅是作为总结。";
@Autowired
private PostServiceImpl postService;
@Test
@Ignore
public void getContent() {
String exportMarkdown = postService.exportMarkdown(18);
System.out.println(exportMarkdown);
}
@Test
public void markdownImportTest() {
postService.importMarkdown(standardMdContent, "standard");
postService.importMarkdown(nonStandardMdContent, "nonStandard");
}
}