Skip to content

Commit 4950c72

Browse files
committed
actframework#543 MasterEntityMetaInfoRepo - support MappedSuperClass annotation registratio
1 parent 3fe93a4 commit 4950c72

3 files changed

Lines changed: 40 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# ActFramework Change Log
22

33
**1.7.4**
4+
* `MasterEntityMetaInfoRepo` - support `MappedSuperClass` annotation registration #543
45
* Add `NamedProvider` for `CacheService` #542
56
* `ProjectLayout` - provide layout for gradle_groovy combination #541
67
* Cannot run a groovy program even in PROD mode #540

src/main/java/act/db/meta/EntityInfoByteCodeScanner.java

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import act.app.AppByteCodeScannerBase;
2424
import act.asm.AnnotationVisitor;
25+
import act.asm.ClassVisitor;
2526
import act.asm.FieldVisitor;
2627
import act.asm.Type;
2728
import act.db.CreatedAt;
@@ -73,12 +74,20 @@ private class _ByteCodeVisitor extends ByteCodeVisitor {
7374

7475
boolean isMappedSuperClass;
7576
boolean isEntity;
77+
boolean isEntityListener;
7678
String className;
7779
boolean foundCreatedAt;
7880
boolean foundLastModifiedAt;
7981
boolean foundId;
8082
MasterEntityMetaInfoRepo metaInfoRepo;
8183

84+
public _ByteCodeVisitor(ClassVisitor cv) {
85+
super(cv);
86+
}
87+
88+
public _ByteCodeVisitor() {
89+
}
90+
8291
@Override
8392
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
8493
super.visit(version, access, name, signature, superName, interfaces);
@@ -89,22 +98,28 @@ public void visit(int version, int access, String name, String signature, String
8998
@Override
9099
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
91100
AnnotationVisitor av = super.visitAnnotation(desc, visible);
92-
isEntity = metaInfoRepo.isEntity(desc);
93-
if (isEntity || isMappedSuperClass) {
94-
repo.registerEntityOrMappedSuperClass(className);
95-
if (isEntity) {
96-
return new AnnotationVisitor(ASM5, av) {
97-
@Override
98-
public void visit(String name, Object value) {
99-
if ("name".equals(name) || "value".equals(name)) {
100-
repo.registerEntityName(className, (String) value);
101+
if (!isEntity && !isMappedSuperClass) {
102+
isEntity = metaInfoRepo.isEntity(desc);
103+
isMappedSuperClass = metaInfoRepo.isMappedSuperClass(desc);
104+
if (isEntity || isMappedSuperClass) {
105+
repo.registerEntityOrMappedSuperClass(className);
106+
if (isEntity) {
107+
return new AnnotationVisitor(ASM5, av) {
108+
@Override
109+
public void visit(String name, Object value) {
110+
if ("name".equals(name) || "value".equals(name)) {
111+
repo.registerEntityName(className, (String) value);
112+
}
113+
super.visit(name, value);
101114
}
102-
super.visit(name, value);
103-
}
104-
};
115+
};
116+
}
117+
}
118+
} else if (!isEntityListener) {
119+
isEntityListener = metaInfoRepo.isEntityListener(desc);
120+
if (isEntityListener) {
121+
repo.markEntityListenersFound(className);
105122
}
106-
} else if (metaInfoRepo.isEntityListener(desc)) {
107-
repo.markEntityListenersFound(className);
108123
}
109124
return av;
110125
}

src/main/java/act/db/meta/MasterEntityMetaInfoRepo.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ public class MasterEntityMetaInfoRepo extends EntityMetaInfoRepo {
4242
private Map<String, EntityMetaInfoRepo> regions = new HashMap<>();
4343

4444
private Set<String> entityAnnotations = new HashSet<>();
45-
45+
private Set<String> mappedSuperClassAnnotations = new HashSet<>();
4646
private Set<String> entityListenerAnnotations = new HashSet<>();
4747

4848
@Inject
4949
public MasterEntityMetaInfoRepo(final App app) {
5050
super(app);
5151
registerEntityAnnotation(Entity.class);
52-
registerEntityAnnotation(MappedSuperclass.class);
52+
registerMappedSuperClassAnnotation(MappedSuperclass.class);
5353
registerEntityListenerAnnotation(EntityListeners.class);
5454
final MasterEntityMetaInfoRepo me = this;
5555
JobManager jobManager = app.jobManager();
@@ -85,6 +85,10 @@ public void registerEntityAnnotation(Class<? extends Annotation> annoType) {
8585
entityAnnotations.add(Type.getType(annoType).getDescriptor());
8686
}
8787

88+
public void registerMappedSuperClassAnnotation(Class<? extends Annotation> annoType) {
89+
mappedSuperClassAnnotations.add(Type.getType(annoType).getDescriptor());
90+
}
91+
8892
public void registerEntityListenerAnnotation(Class<? extends Annotation> annoType) {
8993
entityListenerAnnotations.add(Type.getType(annoType).getDescriptor());
9094
}
@@ -93,6 +97,10 @@ public boolean isEntity(String descriptor) {
9397
return entityAnnotations.contains(descriptor);
9498
}
9599

100+
public boolean isMappedSuperClass(String descriptor) {
101+
return mappedSuperClassAnnotations.contains(descriptor);
102+
}
103+
96104
public boolean isEntityListener(String descriptor) {
97105
return entityListenerAnnotations.contains(descriptor);
98106
}

0 commit comments

Comments
 (0)