-
Notifications
You must be signed in to change notification settings - Fork 276
Expand file tree
/
Copy pathKeyRelation.java
More file actions
98 lines (84 loc) · 2.18 KB
/
KeyRelation.java
File metadata and controls
98 lines (84 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Copyright DDDplus Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.github.dddplus.dsl;
import java.lang.annotation.*;
/**
* 业务对象间关系.
*
* <p>JDK8+才支持在一处多次标注</p>
* <p>Example:</p>
* <pre>
* {@code
*
* ℗KeyRelation(whom = ShipmentOrderItem.class, type = KeyRelation.Type.HasMany)
* ℗KeyRelation(whom = Pack.class, type = KeyRelation.Type.HasMany, remark = "一个订单可能多个包裹")
* class ShipmentOrder {}
* class ShipmentOrderItem {}
* class Pack {}
* }
* </pre>
*/
@Target({ElementType.TYPE, ElementType.FIELD})
@Retention(RetentionPolicy.SOURCE)
@Repeatable(KeyRelations.class)
public @interface KeyRelation {
/**
* 跟哪个领域对象发生关系.
*/
Class whom();
/**
* 发生什么关系.
*/
Type type();
/**
* 这种关系是否某些特定场景才发生.
*/
boolean contextual() default false;
String remark() default "";
/**
* 业务对象间关系的分类.
*/
enum Type {
/**
* 非此即彼.
*/
Union,
HasOne,
HasMany,
BelongTo,
Associate,
/**
* 面向对象构想的信息结构是树形,而关系模型是集合,它们有一个天然的鸿沟.
*
* <p>模型之间本质上没有多对多关系,如果有,说明存在一个隐含的成员关系,这个关系没有被充分的分析出来.</p>
* @deprecated
*/
@Deprecated
Many2Many,
/**
* 特定场景对象.
*
* @see io.github.dddplus.model.BoundedDomainModel
*/
Contextual,
/**
* 当前对象来自于{@link #whom()}.
*/
From,
Extends,
Implements;
public static boolean match(String typeStr) {
boolean matched = false;
for (Type type : values()) {
if (type.toString().equals(typeStr)) {
matched = true;
break;
}
}
return matched;
}
}
}