-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10078 from gytis/enchance-entity-id-access
Abstract REST Data resource and entity info
- Loading branch information
Showing
48 changed files
with
572 additions
and
430 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 0 additions & 67 deletions
67
.../quarkus/hibernate/orm/rest/data/panache/deployment/HibernateOrmRestDataResourceInfo.java
This file was deleted.
Oops, something went wrong.
58 changes: 58 additions & 0 deletions
58
...ava/io/quarkus/hibernate/orm/rest/data/panache/deployment/RestDataEntityInfoProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package io.quarkus.hibernate.orm.rest.data.panache.deployment; | ||
|
||
import javax.persistence.Id; | ||
|
||
import org.jboss.jandex.ClassInfo; | ||
import org.jboss.jandex.DotName; | ||
import org.jboss.jandex.FieldInfo; | ||
import org.jboss.jandex.IndexView; | ||
import org.jboss.jandex.MethodInfo; | ||
|
||
import io.quarkus.deployment.bean.JavaBeanUtil; | ||
import io.quarkus.gizmo.MethodDescriptor; | ||
import io.quarkus.rest.data.panache.deployment.RestDataEntityInfo; | ||
|
||
final class RestDataEntityInfoProvider { | ||
|
||
private final IndexView index; | ||
|
||
RestDataEntityInfoProvider(IndexView index) { | ||
this.index = index; | ||
} | ||
|
||
RestDataEntityInfo get(String entityType, String idType) { | ||
ClassInfo classInfo = index.getClassByName(DotName.createSimple(entityType)); | ||
FieldInfo idField = getIdField(classInfo); | ||
return new RestDataEntityInfo(classInfo.toString(), idType, idField, getSetter(classInfo, idField)); | ||
} | ||
|
||
private FieldInfo getIdField(ClassInfo classInfo) { | ||
ClassInfo tmpClassInfo = classInfo; | ||
while (tmpClassInfo != null) { | ||
for (FieldInfo field : tmpClassInfo.fields()) { | ||
if (field.hasAnnotation(DotName.createSimple(Id.class.getName()))) { | ||
return field; | ||
} | ||
} | ||
if (classInfo.superName() != null) { | ||
tmpClassInfo = index.getClassByName(classInfo.superName()); | ||
} else { | ||
tmpClassInfo = null; | ||
} | ||
} | ||
throw new IllegalArgumentException("Couldn't find id field of " + classInfo); | ||
} | ||
|
||
private MethodDescriptor getSetter(ClassInfo entityClass, FieldInfo field) { | ||
if (entityClass == null) { | ||
return null; | ||
} | ||
MethodInfo methodInfo = entityClass.method(JavaBeanUtil.getSetterName(field.name()), field.type()); | ||
if (methodInfo != null) { | ||
return MethodDescriptor.of(methodInfo); | ||
} else if (entityClass.superName() != null) { | ||
return getSetter(index.getClassByName(entityClass.superName()), field); | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.