-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Preliminary support for Panache2 #10411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7205879
c3e659d
12697ff
dbcbc50
623cbf8
41f262b
1a8fbb7
aaa58e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -253,9 +253,16 @@ private boolean handleSettings(ProcessingEnvironment environment) { | |
PackageElement quarkusOrmPanachePackage = | ||
context.getProcessingEnvironment().getElementUtils() | ||
.getPackageElement( "io.quarkus.hibernate.orm.panache" ); | ||
PackageElement quarkusPanache2Package = | ||
context.getProcessingEnvironment().getElementUtils() | ||
.getPackageElement( "io.quarkus.hibernate.panache" ); | ||
PackageElement quarkusReactivePanachePackage = | ||
context.getProcessingEnvironment().getElementUtils() | ||
.getPackageElement( "io.quarkus.hibernate.reactive.panache" ); | ||
// This is imported automatically by Quarkus extensions when HR is also imported | ||
PackageElement quarkusReactivePanacheCommonPackage = | ||
context.getProcessingEnvironment().getElementUtils() | ||
.getPackageElement( "io.quarkus.hibernate.reactive.panache.common" ); | ||
|
||
if ( packagePresent(quarkusReactivePanachePackage) | ||
&& packagePresent(quarkusOrmPanachePackage) ) { | ||
|
@@ -275,6 +282,8 @@ && packagePresent(quarkusOrmPanachePackage) ) { | |
context.setQuarkusInjection( packagePresent(quarkusOrmPackage) || packagePresent(quarkusReactivePackage) ); | ||
context.setUsesQuarkusOrm( packagePresent(quarkusOrmPanachePackage) ); | ||
context.setUsesQuarkusReactive( packagePresent(quarkusReactivePanachePackage) ); | ||
context.setUsesQuarkusPanache2( packagePresent(quarkusPanache2Package) ); | ||
context.setUsesQuarkusReactiveCommon( packagePresent(quarkusReactivePanacheCommonPackage) ); | ||
|
||
final Map<String, String> options = environment.getOptions(); | ||
|
||
|
@@ -373,7 +382,7 @@ private void processClasses(RoundEnvironment roundEnvironment) { | |
try { | ||
final AnnotationMetaEntity metaEntity = | ||
AnnotationMetaEntity.create( typeElement, context, | ||
parentMetadata( typeElement, context::getMetaEntity ) ); | ||
parentMetadata( typeElement, context::getMetaEntity ), null ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about overloading There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was waiting for Java to get defaulted params. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good plan. |
||
context.addMetaAuxiliary( metaEntity.getQualifiedName(), metaEntity ); | ||
context.removeElementToRedo( elementName ); | ||
} | ||
|
@@ -389,72 +398,7 @@ private void processClasses(RoundEnvironment roundEnvironment) { | |
|
||
private void processElement(Element element, @Nullable Element parent) { | ||
try { | ||
if ( !included( element ) | ||
|| hasAnnotation( element, Constants.EXCLUDE ) | ||
|| hasPackageAnnotation( element, Constants.EXCLUDE ) | ||
|| element.getModifiers().contains( Modifier.PRIVATE ) ) { | ||
// skip it completely | ||
return; | ||
} | ||
else if ( isEntityOrEmbeddable( element ) | ||
&& !element.getModifiers().contains( Modifier.PRIVATE ) ) { | ||
context.logMessage( Diagnostic.Kind.OTHER, "Processing annotated entity class '" + element + "'" ); | ||
handleRootElementAnnotationMirrors( element, parent ); | ||
} | ||
else if ( hasAuxiliaryAnnotations( element ) ) { | ||
context.logMessage( Diagnostic.Kind.OTHER, "Processing annotated class '" + element + "'" ); | ||
handleRootElementAuxiliaryAnnotationMirrors( element ); | ||
} | ||
else if ( element instanceof TypeElement typeElement ) { | ||
final AnnotationMirror repository = getAnnotationMirror( element, JD_REPOSITORY ); | ||
if ( repository != null ) { | ||
final AnnotationValue provider = getAnnotationValue( repository, "provider" ); | ||
if ( provider == null | ||
|| provider.getValue().toString().isEmpty() | ||
|| provider.getValue().toString().equalsIgnoreCase("hibernate") ) { | ||
context.logMessage( Diagnostic.Kind.OTHER, "Processing repository class '" + element + "'" ); | ||
final AnnotationMetaEntity metaEntity = | ||
AnnotationMetaEntity.create( typeElement, context, | ||
parentMetadata( parent, context::getMetaEntity ) ); | ||
if ( metaEntity.isInitialized() ) { | ||
context.addMetaAuxiliary( metaEntity.getQualifiedName(), metaEntity ); | ||
} | ||
// otherwise discard it (assume it has query by magical method name stuff) | ||
} | ||
} | ||
else { | ||
for ( Element member : typeElement.getEnclosedElements() ) { | ||
if ( hasAnnotation( member, HQL, SQL, FIND ) ) { | ||
context.logMessage( Diagnostic.Kind.OTHER, "Processing annotated class '" + element + "'" ); | ||
final AnnotationMetaEntity metaEntity = | ||
AnnotationMetaEntity.create( typeElement, context, | ||
parentMetadata( parent, context::getMetaEntity ) ); | ||
context.addMetaAuxiliary( metaEntity.getQualifiedName(), metaEntity ); | ||
break; | ||
} | ||
} | ||
if ( enclosesEntityOrEmbeddable( element ) ) { | ||
final NonManagedMetamodel metaEntity = | ||
NonManagedMetamodel.create( typeElement, context, false, | ||
parentMetadata( parent, context::getMetamodel ) ); | ||
context.addMetaEntity( metaEntity.getQualifiedName(), metaEntity ); | ||
if ( context.generateJakartaDataStaticMetamodel() ) { | ||
final NonManagedMetamodel dataMetaEntity = | ||
NonManagedMetamodel.create( typeElement, context, true, | ||
parentMetadata( parent, context::getDataMetaEntity ) ); | ||
context.addDataMetaEntity( dataMetaEntity.getQualifiedName(), dataMetaEntity ); | ||
} | ||
|
||
} | ||
} | ||
} | ||
if ( isClassRecordOrInterfaceType( element ) ) { | ||
for ( final Element child : element.getEnclosedElements() ) { | ||
if ( isClassRecordOrInterfaceType( child ) ) { | ||
processElement( child, element ); | ||
} | ||
} | ||
} | ||
inspectRootElement(element, parent, null); | ||
} | ||
catch ( ProcessLaterException processLaterException ) { | ||
if ( element instanceof TypeElement typeElement ) { | ||
|
@@ -484,6 +428,77 @@ private boolean hasPackageAnnotation(Element element, String annotation) { | |
return pack != null && hasAnnotation( pack, annotation ); | ||
} | ||
|
||
private void inspectRootElement(Element element, @Nullable Element parent, @Nullable TypeElement primaryEntity) { | ||
if ( !included( element ) | ||
|| hasAnnotation( element, Constants.EXCLUDE ) | ||
|| hasPackageAnnotation( element, Constants.EXCLUDE ) | ||
|| element.getModifiers().contains( Modifier.PRIVATE ) ) { | ||
// skip it completely | ||
return; | ||
} | ||
else if ( isEntityOrEmbeddable( element ) | ||
&& !element.getModifiers().contains( Modifier.PRIVATE ) ) { | ||
context.logMessage( Diagnostic.Kind.OTHER, "Processing annotated entity class '" + element + "'" ); | ||
handleRootElementAnnotationMirrors( element, parent ); | ||
} | ||
else if ( hasAuxiliaryAnnotations( element ) ) { | ||
context.logMessage( Diagnostic.Kind.OTHER, "Processing annotated class '" + element + "'" ); | ||
handleRootElementAuxiliaryAnnotationMirrors( element ); | ||
} | ||
else if ( element instanceof TypeElement typeElement ) { | ||
final AnnotationMirror repository = getAnnotationMirror( element, JD_REPOSITORY ); | ||
if ( repository != null ) { | ||
final AnnotationValue provider = getAnnotationValue( repository, "provider" ); | ||
if ( provider == null | ||
|| provider.getValue().toString().isEmpty() | ||
|| provider.getValue().toString().equalsIgnoreCase("hibernate") ) { | ||
context.logMessage( Diagnostic.Kind.OTHER, "Processing repository class '" + element + "'" ); | ||
final AnnotationMetaEntity metaEntity = | ||
AnnotationMetaEntity.create( typeElement, context, | ||
parentMetadata( parent, context::getMetaEntity ), | ||
primaryEntity ); | ||
if ( metaEntity.isInitialized() ) { | ||
context.addMetaAuxiliary( metaEntity.getQualifiedName(), metaEntity ); | ||
} | ||
// otherwise discard it (assume it has query by magical method name stuff) | ||
} | ||
} | ||
else { | ||
for ( Element member : typeElement.getEnclosedElements() ) { | ||
if ( hasAnnotation( member, HQL, SQL, FIND ) ) { | ||
context.logMessage( Diagnostic.Kind.OTHER, "Processing annotated class '" + element + "'" ); | ||
final AnnotationMetaEntity metaEntity = | ||
AnnotationMetaEntity.create( typeElement, context, | ||
parentMetadata( parent, context::getMetaEntity ), | ||
primaryEntity ); | ||
context.addMetaAuxiliary( metaEntity.getQualifiedName(), metaEntity ); | ||
break; | ||
} | ||
} | ||
if ( enclosesEntityOrEmbeddable( element ) ) { | ||
final NonManagedMetamodel metaEntity = | ||
NonManagedMetamodel.create( typeElement, context, false, | ||
parentMetadata( parent, context::getMetamodel ) ); | ||
context.addMetaEntity( metaEntity.getQualifiedName(), metaEntity ); | ||
if ( context.generateJakartaDataStaticMetamodel() ) { | ||
final NonManagedMetamodel dataMetaEntity = | ||
NonManagedMetamodel.create( typeElement, context, true, | ||
parentMetadata( parent, context::getDataMetaEntity ) ); | ||
context.addDataMetaEntity( dataMetaEntity.getQualifiedName(), dataMetaEntity ); | ||
} | ||
|
||
} | ||
} | ||
} | ||
if ( isClassRecordOrInterfaceType( element ) ) { | ||
for ( final Element child : element.getEnclosedElements() ) { | ||
if ( isClassRecordOrInterfaceType( child ) ) { | ||
processElement( child, element ); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private void createMetaModelClasses() { | ||
|
||
for ( Metamodel aux : context.getMetaAuxiliaries() ) { | ||
|
@@ -635,6 +650,7 @@ private void handleRootElementAnnotationMirrors(final Element element, @Nullable | |
final TypeElement typeElement = (TypeElement) element; | ||
indexEntityName( typeElement ); | ||
indexEnumFields( typeElement ); | ||
indexQueryInterfaces( typeElement ); | ||
|
||
final String qualifiedName = typeElement.getQualifiedName().toString(); | ||
final Metamodel alreadyExistingMetaEntity = | ||
|
@@ -653,7 +669,7 @@ private void handleRootElementAnnotationMirrors(final Element element, @Nullable | |
final AnnotationMetaEntity metaEntity = | ||
AnnotationMetaEntity.create( typeElement, context, | ||
requiresLazyMemberInitialization, | ||
true, false, parentMetaEntity ); | ||
true, false, parentMetaEntity, typeElement ); | ||
if ( alreadyExistingMetaEntity != null ) { | ||
metaEntity.mergeInMembers( alreadyExistingMetaEntity ); | ||
} | ||
|
@@ -672,7 +688,7 @@ && hasAnnotation( element, ENTITY, MAPPED_SUPERCLASS ) | |
final AnnotationMetaEntity dataMetaEntity = | ||
AnnotationMetaEntity.create( typeElement, context, | ||
requiresLazyMemberInitialization, | ||
true, true, parentDataEntity ); | ||
true, true, parentDataEntity, typeElement ); | ||
// final Metamodel alreadyExistingDataMetaEntity = | ||
// tryGettingExistingDataEntityFromContext( mirror, '_' + qualifiedName ); | ||
// if ( alreadyExistingDataMetaEntity != null ) { | ||
|
@@ -691,6 +707,14 @@ private static boolean hasHandwrittenMetamodel(Element element) { | |
.contentEquals('_' + element.getSimpleName().toString())); | ||
} | ||
|
||
private void indexQueryInterfaces(TypeElement typeElement) { | ||
for ( Element element : typeElement.getEnclosedElements() ) { | ||
if( element.getKind() == ElementKind.INTERFACE ) { | ||
inspectRootElement( element, typeElement, typeElement ); | ||
} | ||
} | ||
} | ||
|
||
private void indexEntityName(TypeElement typeElement) { | ||
final AnnotationMirror mirror = getAnnotationMirror( typeElement, ENTITY ); | ||
if ( mirror != null ) { | ||
|
@@ -749,7 +773,8 @@ private void handleRootElementAuxiliaryAnnotationMirrors(final Element element) | |
if ( element instanceof TypeElement ) { | ||
final AnnotationMetaEntity metaEntity = | ||
AnnotationMetaEntity.create( (TypeElement) element, context, | ||
parentMetadata( element.getEnclosingElement(), context::getMetaEntity ) ); | ||
parentMetadata( element.getEnclosingElement(), context::getMetaEntity ), | ||
null ); | ||
context.addMetaAuxiliary( metaEntity.getQualifiedName(), metaEntity ); | ||
} | ||
else if ( element instanceof PackageElement ) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed at some point going with "Quarkus Data" instead of "Panache 2"... Are you sure you still want to go with this name and package?
io.quarkus.data.hibernate
could work too, in that case?Maybe this is a discussion we should take offline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we? Or are you just trying to trick me because you know my memory doesn't go that far? 🤔