mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-27 14:30:16 +00:00
HHH-17772 interpret @Repository(dataSource) as a CDI @Named qualifier
This is sort of the simplest possible thing to do.
This commit is contained in:
parent
484fcb2984
commit
1e32439b3c
@ -336,6 +336,17 @@ else if ( containsAnnotation( method, JD_INSERT, JD_UPDATE, JD_DELETE ) ) {
|
|||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private @Nullable String dataStore() {
|
||||||
|
final AnnotationMirror repo = getAnnotationMirror( element, JD_REPOSITORY );
|
||||||
|
if ( repo != null ) {
|
||||||
|
final String dataStore = (String) getAnnotationValue( repo, "dataStore" );
|
||||||
|
if ( dataStore != null && !dataStore.isEmpty() ) {
|
||||||
|
return dataStore;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private void findSessionGetter(TypeElement type) {
|
private void findSessionGetter(TypeElement type) {
|
||||||
if ( !hasAnnotation( type, Constants.ENTITY )
|
if ( !hasAnnotation( type, Constants.ENTITY )
|
||||||
&& !hasAnnotation( type, Constants.MAPPED_SUPERCLASS )
|
&& !hasAnnotation( type, Constants.MAPPED_SUPERCLASS )
|
||||||
@ -379,6 +390,7 @@ private String addDaoConstructor(@Nullable ExecutableElement method) {
|
|||||||
name,
|
name,
|
||||||
sessionType,
|
sessionType,
|
||||||
sessionVariableName,
|
sessionVariableName,
|
||||||
|
dataStore(),
|
||||||
context.addInjectAnnotation(),
|
context.addInjectAnnotation(),
|
||||||
context.addNonnullAnnotation(),
|
context.addNonnullAnnotation(),
|
||||||
method != null
|
method != null
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.hibernate.jpamodelgen.annotation;
|
package org.hibernate.jpamodelgen.annotation;
|
||||||
|
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.hibernate.jpamodelgen.model.MetaAttribute;
|
import org.hibernate.jpamodelgen.model.MetaAttribute;
|
||||||
import org.hibernate.jpamodelgen.model.Metamodel;
|
import org.hibernate.jpamodelgen.model.Metamodel;
|
||||||
import org.hibernate.jpamodelgen.util.Constants;
|
import org.hibernate.jpamodelgen.util.Constants;
|
||||||
@ -19,6 +20,7 @@ public class DaoConstructor implements MetaAttribute {
|
|||||||
private final String methodName;
|
private final String methodName;
|
||||||
private final String sessionTypeName;
|
private final String sessionTypeName;
|
||||||
private final String sessionVariableName;
|
private final String sessionVariableName;
|
||||||
|
private final @Nullable String dataStore;
|
||||||
private final boolean addInjectAnnotation;
|
private final boolean addInjectAnnotation;
|
||||||
private final boolean addNonnullAnnotation;
|
private final boolean addNonnullAnnotation;
|
||||||
private final boolean addOverrideAnnotation;
|
private final boolean addOverrideAnnotation;
|
||||||
@ -29,6 +31,7 @@ public DaoConstructor(
|
|||||||
String methodName,
|
String methodName,
|
||||||
String sessionTypeName,
|
String sessionTypeName,
|
||||||
String sessionVariableName,
|
String sessionVariableName,
|
||||||
|
@Nullable String dataStore,
|
||||||
boolean addInjectAnnotation,
|
boolean addInjectAnnotation,
|
||||||
boolean addNonnullAnnotation,
|
boolean addNonnullAnnotation,
|
||||||
boolean addOverrideAnnotation) {
|
boolean addOverrideAnnotation) {
|
||||||
@ -37,6 +40,7 @@ public DaoConstructor(
|
|||||||
this.methodName = methodName;
|
this.methodName = methodName;
|
||||||
this.sessionTypeName = sessionTypeName;
|
this.sessionTypeName = sessionTypeName;
|
||||||
this.sessionVariableName = sessionVariableName;
|
this.sessionVariableName = sessionVariableName;
|
||||||
|
this.dataStore = dataStore;
|
||||||
this.addInjectAnnotation = addInjectAnnotation;
|
this.addInjectAnnotation = addInjectAnnotation;
|
||||||
this.addNonnullAnnotation = addNonnullAnnotation;
|
this.addNonnullAnnotation = addNonnullAnnotation;
|
||||||
this.addOverrideAnnotation = addOverrideAnnotation;
|
this.addOverrideAnnotation = addOverrideAnnotation;
|
||||||
@ -70,6 +74,7 @@ public String getAttributeDeclarationString() {
|
|||||||
.append(constructorName)
|
.append(constructorName)
|
||||||
.append("(");
|
.append("(");
|
||||||
notNull( declaration );
|
notNull( declaration );
|
||||||
|
named( declaration );
|
||||||
declaration
|
declaration
|
||||||
.append(annotationMetaEntity.importType(sessionTypeName))
|
.append(annotationMetaEntity.importType(sessionTypeName))
|
||||||
.append(" ")
|
.append(" ")
|
||||||
@ -100,6 +105,17 @@ public String getAttributeDeclarationString() {
|
|||||||
return declaration.toString();
|
return declaration.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void named(StringBuilder declaration) {
|
||||||
|
if ( addInjectAnnotation && dataStore != null ) {
|
||||||
|
declaration
|
||||||
|
.append("@")
|
||||||
|
.append(annotationMetaEntity.importType("jakarta.inject.Named"))
|
||||||
|
.append("(\"")
|
||||||
|
.append(dataStore)
|
||||||
|
.append("\") ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void inject(StringBuilder declaration) {
|
private void inject(StringBuilder declaration) {
|
||||||
if ( addInjectAnnotation ) {
|
if ( addInjectAnnotation ) {
|
||||||
declaration
|
declaration
|
||||||
|
Loading…
x
Reference in New Issue
Block a user