Skip to content

Commit 02d111e

Browse files
committed
1 parent ec0ea34 commit 02d111e

File tree

16 files changed

+37
-169
lines changed

16 files changed

+37
-169
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111
<groupId>com.codingapi.springboot</groupId>
1212
<artifactId>springboot-framework-parent</artifactId>
13-
<version>1.0.3</version>
13+
<version>1.0.4</version>
1414

1515
<url>https://github.com/codingapi/springboot-framewrok</url>
1616
<name>springboot-framework-parent</name>

springboot-data-permission/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-framework-parent</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>1.0.3</version>
8+
<version>1.0.4</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

@@ -32,7 +32,7 @@
3232
<dependency>
3333
<groupId>com.codingapi.springboot</groupId>
3434
<artifactId>springboot-framework</artifactId>
35-
<version>1.0.3</version>
35+
<version>1.0.4</version>
3636
</dependency>
3737

3838
<dependency>

springboot-example/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
<parent>
55
<groupId>com.codingapi.springboot</groupId>
66
<artifactId>springboot-framework-parent</artifactId>
7-
<version>1.0.3</version>
7+
<version>1.0.4</version>
88
</parent>
99
<artifactId>springboot-example</artifactId>
10-
<version>1.0.3</version>
10+
<version>1.0.4</version>
1111

1212
<name>springboot-example</name>
1313
<description>springboot-example project for Spring Boot</description>
@@ -29,7 +29,7 @@
2929
<dependency>
3030
<groupId>com.codingapi.springboot</groupId>
3131
<artifactId>springboot-framework</artifactId>
32-
<version>1.0.3</version>
32+
<version>1.0.4</version>
3333
</dependency>
3434

3535
<dependency>

springboot-example/src/main/java/com/codingapi/springboot/example/domain/Demo.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.codingapi.springboot.example.domain.event.DemoNameChangeEvent;
44
import com.codingapi.springboot.framework.event.EventPusher;
5-
import com.codingapi.springboot.framework.persistence.IPersistence;
65
import lombok.Getter;
76
import lombok.NoArgsConstructor;
87
import lombok.Setter;
@@ -22,7 +21,7 @@
2221
@NoArgsConstructor
2322
@Entity
2423
@ToString
25-
public class Demo implements IPersistence {
24+
public class Demo {
2625

2726
@Id
2827
@GeneratedValue(strategy = GenerationType.IDENTITY)
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
package com.codingapi.springboot.example.domain.service;
22

33
import com.codingapi.springboot.example.domain.Demo;
4+
import com.codingapi.springboot.example.repository.DemoRepository;
5+
import lombok.AllArgsConstructor;
46
import org.springframework.stereotype.Service;
7+
import org.springframework.transaction.annotation.Transactional;
58

69
@Service
7-
public class DemoSwapService {
10+
@AllArgsConstructor
11+
@Transactional
12+
public class DemoService {
13+
14+
private final DemoRepository demoRepository;
815

916
public void swap(Demo demo1,Demo demo2){
1017
String demo1Name = demo1.getName();
@@ -14,4 +21,9 @@ public void swap(Demo demo1,Demo demo2){
1421
demo2.changeName(demo1Name);
1522
}
1623

24+
25+
public void save(Demo demo){
26+
demoRepository.save(demo);
27+
}
28+
1729
}
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
package com.codingapi.springboot.example.repository;
22

33
import com.codingapi.springboot.example.domain.Demo;
4-
import com.codingapi.springboot.framework.persistence.IPersistenceRepository;
54
import org.springframework.data.jpa.repository.JpaRepository;
65

76
/**
87
* @author lorne
98
* @since 1.0.0
109
*/
11-
public interface DemoRepository extends JpaRepository<Demo,Integer>, IPersistenceRepository<Demo> {
10+
public interface DemoRepository extends JpaRepository<Demo,Integer> {
11+
1212

13-
@Override
14-
default void persistenceHandler(Demo demo) {
15-
save(demo);
16-
}
1713
}

springboot-example/src/test/java/com/codingapi/springboot/example/ExampleApplicationTests.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
package com.codingapi.springboot.example;
22

33
import com.codingapi.springboot.example.domain.Demo;
4-
import com.codingapi.springboot.example.domain.service.DemoSwapService;
4+
import com.codingapi.springboot.example.domain.service.DemoService;
55
import lombok.extern.slf4j.Slf4j;
66
import org.junit.jupiter.api.Test;
77
import org.springframework.beans.factory.annotation.Autowired;
88
import org.springframework.boot.test.context.SpringBootTest;
9+
import org.springframework.test.annotation.Rollback;
10+
import org.springframework.transaction.annotation.Transactional;
911
import org.springframework.util.Assert;
1012

11-
import javax.transaction.Transactional;
12-
1313
@SpringBootTest
1414
@Slf4j
15+
@Rollback(value = false)
1516
class ExampleApplicationTests {
1617

1718
@Autowired
18-
private DemoSwapService demoSwapService;
19+
private DemoService demoService;
1920

2021
@Test
2122
@Transactional
2223
void save() {
2324
Demo demo = new Demo("xiaoming");
24-
demo.persistence();
25+
demoService.save(demo);
2526
Assert.isTrue(demo.getId()>0,"demoRepository save error.");
2627
}
2728

2829
@Test
2930
void swap(){
3031
Demo demo1 = new Demo("demo1");
3132
Demo demo2 = new Demo("demo2");
32-
demoSwapService.swap(demo1,demo2);
33+
demoService.swap(demo1,demo2);
3334
Assert.isTrue(demo1.getName().equals("demo2"),"swap service error.");
3435
Assert.isTrue(demo2.getName().equals("demo1"),"swap service error.");
3536
}

springboot-framework/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
<parent>
55
<groupId>com.codingapi.springboot</groupId>
66
<artifactId>springboot-framework-parent</artifactId>
7-
<version>1.0.3</version>
7+
<version>1.0.4</version>
88
</parent>
99
<artifactId>springboot-framework</artifactId>
10-
<version>1.0.3</version>
10+
<version>1.0.4</version>
1111

1212
<name>springboot-framework</name>
1313
<description>springboot-framework project for Spring Boot</description>

springboot-framework/src/main/java/com/codingapi/springboot/framework/event/IEvent.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
/**
55
*
66
* 默认同步事件
7+
*
8+
* 关于事件与事务之间的关系说明:
9+
* 事件本身不应该同步主业务的事务,即事件对于主业务来说,可成功可失败,成功与失败都不应该强关联主体业务。
10+
* 若需要让主体业务与分支做事务同步的时候,那不应该采用事件机制,而应该直接采用调用的方式实现业务绑定。
11+
*
712
*/
813
public interface IEvent {
914

10-
1115

1216
}

springboot-framework/src/main/java/com/codingapi/springboot/framework/persistence/IPersistence.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)