Remove reading mapping annotations from "Getters" with associated refactoring for performance (#1971)

* #1970 - Change test code only moving mapping annotations to fields

First step in remove support for mapping annotations on "Getters" (so field only target for mapping annotations)

* #1970 - Remove reading mapping annotations from "Getters"

* #1970 - Refactor to use simple annotation lookup where possible

* #1970 - Remove GenerationType.TABLE and SequenceGenerator from type/class

* #1970 - Refactor meta annotation reading

* #1970 - Read @Aggregation as a meta annotation
This commit is contained in:
Rob Bygrave
2020-03-09 16:09:41 +13:00
committed by GitHub
parent 7692d9782a
commit a861e8bdcc
33 changed files with 590 additions and 680 deletions
@@ -31,8 +31,7 @@ import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import static io.ebean.util.AnnotationUtil.findAnnotationRecursive;
import static io.ebean.util.AnnotationUtil.findAnnotationsRecursive;
import static io.ebean.util.AnnotationUtil.typeGet;
/**
* Read the class level deployment annotations.
@@ -62,9 +61,8 @@ public class AnnotationClass extends AnnotationParser {
* Parse any AttributeOverride set on the class.
*/
void parseAttributeOverride() {
Class<?> cls = descriptor.getBeanType();
AttributeOverride override = findAnnotationRecursive(cls, AttributeOverride.class);
AttributeOverride override = typeGet(cls, AttributeOverride.class);
if (override != null) {
String propertyName = override.name();
Column column = override.column();
@@ -104,16 +102,15 @@ public class AnnotationClass extends AnnotationParser {
}
private void read(Class<?> cls) {
// maybe doc store only so check for this before @Entity
DocStore docStore = findAnnotationRecursive(cls, DocStore.class);
DocStore docStore = typeGet(cls, DocStore.class);
if (docStore != null) {
descriptor.readDocStore(docStore);
descriptor.setEntityType(EntityType.DOC);
descriptor.setName(cls.getSimpleName());
}
Entity entity = findAnnotationRecursive(cls, Entity.class);
Entity entity = typeGet(cls, Entity.class);
if (entity != null) {
descriptor.setEntityType(EntityType.ORM);
if (entity.name().isEmpty()) {
@@ -123,37 +120,37 @@ public class AnnotationClass extends AnnotationParser {
}
}
Identity identity = findAnnotationRecursive(cls, Identity.class);
Identity identity = typeGet(cls, Identity.class);
if (identity != null) {
descriptor.setIdentityMode(identity);
}
IdClass idClass = findAnnotationRecursive(cls, IdClass.class);
IdClass idClass = typeGet(cls, IdClass.class);
if (idClass != null) {
descriptor.setIdClass(idClass.value());
}
Embeddable embeddable = findAnnotationRecursive(cls, Embeddable.class);
Embeddable embeddable = typeGet(cls, Embeddable.class);
if (embeddable != null) {
descriptor.setEntityType(EntityType.EMBEDDED);
descriptor.setName("Embeddable:" + cls.getSimpleName());
}
for (Index index : findAnnotationsRecursive(cls, Index.class)) {
for (Index index : annotationClassIndexes(cls)) {
descriptor.addIndex(new IndexDefinition(convertColumnNames(index.columnNames()), index.name(),
index.unique(), index.platforms(), index.concurrent(), index.definition()));
}
UniqueConstraint uc = findAnnotationRecursive(cls, UniqueConstraint.class);
UniqueConstraint uc = typeGet(cls, UniqueConstraint.class);
if (uc != null) {
descriptor.addIndex(new IndexDefinition(convertColumnNames(uc.columnNames())));
}
View view = findAnnotationRecursive(cls, View.class);
View view = typeGet(cls, View.class);
if (view != null) {
descriptor.setView(view.name(), view.dependentTables());
}
Table table = findAnnotationRecursive(cls, Table.class);
Table table = typeGet(cls, Table.class);
if (table != null) {
UniqueConstraint[] uniqueConstraints = table.uniqueConstraints();
for (UniqueConstraint c : uniqueConstraints) {
@@ -161,54 +158,54 @@ public class AnnotationClass extends AnnotationParser {
}
}
StorageEngine storage = findAnnotationRecursive(cls, StorageEngine.class);
StorageEngine storage = typeGet(cls, StorageEngine.class);
if (storage != null) {
descriptor.setStorageEngine(storage.value());
}
DbPartition partition = findAnnotationRecursive(cls, DbPartition.class);
DbPartition partition = typeGet(cls, DbPartition.class);
if (partition != null) {
descriptor.setPartitionMeta(new PartitionMeta(partition.mode(), partition.property()));
}
Draftable draftable = findAnnotationRecursive(cls, Draftable.class);
Draftable draftable = typeGet(cls, Draftable.class);
if (draftable != null) {
descriptor.setDraftable();
}
DraftableElement draftableElement = findAnnotationRecursive(cls, DraftableElement.class);
DraftableElement draftableElement = typeGet(cls, DraftableElement.class);
if (draftableElement != null) {
descriptor.setDraftableElement();
}
ReadAudit readAudit = findAnnotationRecursive(cls, ReadAudit.class);
ReadAudit readAudit = typeGet(cls, ReadAudit.class);
if (readAudit != null) {
descriptor.setReadAuditing();
}
History history = findAnnotationRecursive(cls, History.class);
History history = typeGet(cls, History.class);
if (history != null) {
descriptor.setHistorySupport();
}
DbComment comment = findAnnotationRecursive(cls, DbComment.class);
DbComment comment = typeGet(cls, DbComment.class);
if (comment != null) {
descriptor.setDbComment(comment.value());
}
if (!disableL2Cache) {
Cache cache = findAnnotationRecursive(cls, Cache.class);
Cache cache = typeGet(cls, Cache.class);
if (cache != null) {
descriptor.setCache(cache);
} else {
InvalidateQueryCache invalidateQueryCache = findAnnotationRecursive(cls, InvalidateQueryCache.class);
InvalidateQueryCache invalidateQueryCache = typeGet(cls, InvalidateQueryCache.class);
if (invalidateQueryCache != null) {
descriptor.setInvalidateQueryCache(invalidateQueryCache.region());
}
}
}
for (NamedQuery namedQuery : findAnnotationsRecursive(cls, NamedQuery.class)) {
for (NamedQuery namedQuery : annotationClassNamedQuery(cls)) {
descriptor.addNamedQuery(namedQuery.name(), namedQuery.query());
}
}