Skip to content

Commit 5f6ed28

Browse files
committed
add DomainPersistEvent
1 parent 7d84917 commit 5f6ed28

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.codingapi.springboot.framework.domain;
2+
3+
import com.codingapi.springboot.framework.domain.event.DomainPersistEvent;
4+
import com.codingapi.springboot.framework.event.EventPusher;
5+
6+
/**
7+
* 领域对象事件
8+
*/
9+
public interface IDomain {
10+
11+
/**
12+
* 持久化事件
13+
*/
14+
default void persist(){
15+
EventPusher.push(new DomainPersistEvent(this));
16+
}
17+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.codingapi.springboot.framework.domain.event;
2+
3+
import com.codingapi.springboot.framework.event.IEvent;
4+
import lombok.Getter;
5+
import lombok.ToString;
6+
7+
@Getter
8+
@ToString
9+
public class DomainPersistEvent implements IEvent {
10+
11+
private final Object entity;
12+
private final String simpleName;
13+
private final long timestamp;
14+
15+
public DomainPersistEvent(Object entity) {
16+
this.entity = entity;
17+
this.simpleName = entity.getClass().getSimpleName();
18+
this.timestamp = System.currentTimeMillis();
19+
}
20+
}

springboot-starter/src/test/java/com/codingapi/springboot/framework/domain/Demo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import com.codingapi.springboot.framework.serializable.MapSerializable;
77
import lombok.Getter;
88

9-
public class Demo implements JsonSerializable, MapSerializable {
9+
public class Demo implements JsonSerializable, MapSerializable, IDomain {
1010

1111
@Getter
1212
private final long id;

springboot-starter/src/test/java/com/codingapi/springboot/framework/domain/DomainProxyFactoryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ void createEntity() {
1313
demo.changeAnimalName("123");
1414
demo.changeName("test");
1515
demo.changeName("test123");
16-
System.out.println(demo);
16+
demo.persist();
1717
}
1818
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.codingapi.springboot.framework.handler;
2+
3+
import com.codingapi.springboot.framework.domain.event.DomainPersistEvent;
4+
import lombok.extern.slf4j.Slf4j;
5+
6+
@Slf4j
7+
@Handler
8+
public class DomainPersistEventHandler implements IHandler<DomainPersistEvent>{
9+
10+
@Override
11+
public void handler(DomainPersistEvent event) {
12+
log.info("DomainPersistEvent handler {}",event);
13+
}
14+
}

0 commit comments

Comments
 (0)