Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@

import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.toList;
import static org.hibernate.processor.annotation.AnnotationMetaEntity.usingReactiveSession;
import static org.hibernate.processor.annotation.AnnotationMetaEntity.usingReactiveSessionAccess;
import static org.hibernate.processor.annotation.AnnotationMetaEntity.usingStatelessSession;
import static org.hibernate.processor.util.Constants.ENTITY_MANAGER;
import static org.hibernate.processor.util.Constants.OBJECTS;
import static org.hibernate.processor.util.TypeUtils.hasAnnotation;
Expand Down Expand Up @@ -50,15 +47,15 @@ boolean isUsingEntityManager() {
}

boolean isUsingStatelessSession() {
return usingStatelessSession(sessionType);
return annotationMetaEntity.isStatelessSession();
}

boolean isReactive() {
return usingReactiveSession(sessionType);
return annotationMetaEntity.isReactive();
}

boolean isReactiveSessionAccess() {
return usingReactiveSessionAccess(sessionType);
return annotationMetaEntity.isReactiveSessionAccess();
}

String localSessionName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import javax.lang.model.element.ExecutableElement;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.toList;
import static org.hibernate.processor.util.Constants.BOXED_VOID;
import static org.hibernate.processor.util.Constants.COLLECTORS;
import static org.hibernate.processor.util.Constants.HIB_KEYED_PAGE;
import static org.hibernate.processor.util.Constants.HIB_KEYED_RESULT_LIST;
import static org.hibernate.processor.util.Constants.HIB_ORDER;
Expand All @@ -28,6 +28,7 @@
import static org.hibernate.processor.util.Constants.JD_PAGE_REQUEST;
import static org.hibernate.processor.util.Constants.JD_SORT;
import static org.hibernate.processor.util.Constants.LIST;
import static org.hibernate.processor.util.Constants.NONNULL;
import static org.hibernate.processor.util.Constants.OPTIONAL;
import static org.hibernate.processor.util.Constants.QUERY;
import static org.hibernate.processor.util.Constants.SESSION_TYPES;
Expand Down Expand Up @@ -177,7 +178,7 @@ void notNull(StringBuilder declaration) {
if ( addNonnullAnnotation ) {
declaration
.append('@')
.append(annotationMetaEntity.importType("jakarta.annotation.Nonnull"))
.append(annotationMetaEntity.importType(NONNULL))
.append(' ');
}
}
Expand Down Expand Up @@ -363,7 +364,7 @@ void makeKeyedPage(StringBuilder declaration, List<String> paramTypes) {
annotationMetaEntity.staticImport(HIB_ORDER, "by");
annotationMetaEntity.staticImport(HIB_PAGE, "page");
annotationMetaEntity.staticImport("org.hibernate.query.KeyedPage.KeyInterpretation", "*");
annotationMetaEntity.staticImport(Collectors.class.getName(), "toList");
annotationMetaEntity.staticImport(COLLECTORS, "toList");
if ( returnTypeName == null ) {
throw new AssertionFailure("entity class cannot be null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import javax.lang.model.element.Element;

import static org.hibernate.processor.util.Constants.STRING;
import static org.hibernate.processor.util.StringUtil.getUpperUnderscoreCaseFromLowerCamelCase;
import static org.hibernate.processor.util.TypeUtils.propertyName;

Expand Down Expand Up @@ -70,7 +71,7 @@ public String getAttributeNameDeclarationString(){
.append(getPropertyName())
.append( "\n **/\n" )
.append("public static final ")
.append(parent.importType(String.class.getName()))
.append(parent.importType(STRING))
.append(' ')
.append(getUpperUnderscoreCaseFromLowerCamelCase(getPropertyName()))
.append(" = ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @author Emmanuel Bernard
*/
public class AnnotationMetaCollection extends AnnotationMetaAttribute implements MetaCollection {
private String collectionType;
private final String collectionType;

public AnnotationMetaCollection(AnnotationMetaEntity parent, Element element, String collectionType, String elementType) {
super( parent, element, elementType );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -172,7 +173,7 @@ public AnnotationMetaEntity(
this.element = element;
this.context = context;
this.managed = managed;
this.members = new HashMap<>();
this.members = new LinkedHashMap<>();
this.quarkusInjection = context.isQuarkusInjection();
this.importContext = parent != null ? parent : new ImportContextImpl( getPackageName( context, element ) );
jakartaDataStaticModel = jakartaDataStaticMetamodel;
Expand Down Expand Up @@ -517,7 +518,7 @@ else if ( declaredType == parameterType
}

private void validateStatelessSessionType() {
if ( !usingStatelessSession(sessionType) ) {
if ( !isStatelessSession() ) {
message( element,
"repository must be backed by a 'StatelessSession'",
Diagnostic.Kind.ERROR );
Expand Down Expand Up @@ -645,7 +646,7 @@ else if ( element.getKind() == ElementKind.INTERFACE

private boolean needsEventBus() {
return jakartaDataRepository
&& !usingReactiveSession( sessionType ) // non-reactive
&& !isReactive() // non-reactive
&& context.isDataEventPackageAvailable() // events
&& context.addInjectAnnotation() // @nject
&& context.addDependentAnnotation(); // CDI
Expand Down Expand Up @@ -700,11 +701,18 @@ boolean needsDefaultConstructor() {
return null;
}

@Override
public boolean isStatelessSession() {
return usingStatelessSession(sessionType);
}

public boolean isReactive() {
return usingReactiveSession(sessionType);
}

public boolean isReactiveSessionAccess() {
return usingReactiveSessionAccess(sessionType);
}

private boolean isPanacheType(TypeElement type) {
return context.usesQuarkusOrm() && isOrmPanacheType( type )
|| context.usesQuarkusReactive() && isReactivePanacheType( type );
Expand Down Expand Up @@ -1195,7 +1203,7 @@ else if ( kind == TypeKind.DECLARED ) {
private TypeMirror unUniIfPossible(ExecutableElement method, TypeMirror returnType) {
final TypeMirror result = ununi( returnType );
if ( repository ) {
if ( usingReactiveSession( sessionType ) ) {
if ( isReactive() ) {
if ( result == returnType ) {
message( method, "backed by a reactive session, must return 'Uni'", Diagnostic.Kind.ERROR );
}
Expand Down Expand Up @@ -1464,7 +1472,7 @@ private static boolean isVoid(TypeMirror returnType) {
case DECLARED:
final DeclaredType declaredType = (DeclaredType) returnType;
final TypeElement typeElement = (TypeElement) declaredType.asElement();
return typeElement.getQualifiedName().contentEquals(Void.class.getName());
return typeElement.getQualifiedName().contentEquals(VOID);
default:
return false;
}
Expand Down Expand Up @@ -2016,7 +2024,7 @@ private void createSingleParameterFinder(
}
}

private FieldType pickStrategy(FieldType fieldType, String sessionType, List<String> profiles) {
private static FieldType pickStrategy(FieldType fieldType, String sessionType, List<String> profiles) {
if ( ( usingStatelessSession(sessionType) || usingReactiveSession(sessionType) )
&& !profiles.isEmpty() ) {
// no support for passing fetch profiles i.e. IdentifierLoadAccess
Expand Down Expand Up @@ -2063,7 +2071,7 @@ enum FieldType {
}
else if ( containsAnnotation( param, PATTERN ) ) {
final AnnotationMirror mirror = getAnnotationMirror(param, PATTERN);
if ( mirror!=null && !typeNameEquals(param.asType(), String.class.getName()) ) {
if ( mirror!=null && !typeNameEquals(param.asType(), STRING) ) {
message( param, mirror,
"parameter annotated '@Pattern' is not of type 'String'",
Diagnostic.Kind.ERROR );
Expand Down Expand Up @@ -2537,7 +2545,7 @@ private void validateUpdateHql(
@Nullable TypeMirror returnType,
AnnotationMirror mirror,
AnnotationValue value) {
boolean reactive = usingReactiveSession( sessionType );
final boolean reactive = isReactive();
if ( !isValidUpdateReturnType( returnType, method, reactive ) ) {
message( method, mirror, value,
"return type of mutation query method must be "
Expand Down Expand Up @@ -3095,20 +3103,20 @@ private static boolean hasParameter(String hql, int i, String param) {
.matcher(hql).matches();
}

static boolean usingReactiveSession(String sessionType) {
private static boolean usingReactiveSession(String sessionType) {
return MUTINY_SESSION.equals(sessionType)
|| MUTINY_STATELESS_SESSION.equals(sessionType)
|| UNI_MUTINY_SESSION.equals(sessionType)
|| UNI_MUTINY_STATELESS_SESSION.equals(sessionType);
}

static boolean usingStatelessSession(String sessionType) {
private static boolean usingStatelessSession(String sessionType) {
return HIB_STATELESS_SESSION.equals(sessionType)
|| MUTINY_STATELESS_SESSION.equals(sessionType)
|| UNI_MUTINY_STATELESS_SESSION.equals(sessionType);
}

static boolean usingReactiveSessionAccess(String sessionType) {
private static boolean usingReactiveSessionAccess(String sessionType) {
return UNI_MUTINY_SESSION.equals(sessionType)
|| UNI_MUTINY_STATELESS_SESSION.equals(sessionType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.hibernate.processor.model.MetaAttribute;
import org.hibernate.processor.model.Metamodel;
import org.hibernate.processor.util.Constants;
import org.hibernate.metamodel.model.domain.ManagedDomainType;

import static org.hibernate.processor.util.TypeUtils.hasAnnotation;

Expand Down Expand Up @@ -53,7 +52,7 @@ public String getAttributeNameDeclarationString() {

@Override
public String getMetaType() {
return ManagedDomainType.class.getName();
return "org.hibernate.metamodel.model.domain.ManagedDomainType";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import javax.lang.model.element.Element;

import static org.hibernate.processor.util.Constants.STRING;
import static org.hibernate.processor.util.StringUtil.getUpperUnderscoreCaseFromLowerCamelCase;
import static org.hibernate.processor.util.TypeUtils.propertyName;

Expand Down Expand Up @@ -44,7 +45,7 @@ public boolean hasStringAttribute() {
}

private boolean isTextual() {
return String.class.getName().equals(type);
return STRING.equals(type);
}

@Override
Expand Down Expand Up @@ -81,7 +82,7 @@ public String getAttributeNameDeclarationString(){
.append("#")
.append( getPropertyName().replace('.','_') )
.append( "\n **/\n" )
.append(parent.importType(String.class.getName()))
.append(parent.importType(STRING))
.append(" ")
.append(fieldName())
.append(" = ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@
import org.hibernate.processor.model.Metamodel;
import org.hibernate.processor.util.Constants;

import static org.hibernate.processor.annotation.AnnotationMetaEntity.usingReactiveSession;
import static org.hibernate.processor.util.Constants.ENTITY_MANAGER_FACTORY;
import static org.hibernate.processor.util.Constants.HIB_SESSION_FACTORY;
import static org.hibernate.processor.util.Constants.INJECT;
import static org.hibernate.processor.util.Constants.MUTINY_SESSION;
import static org.hibernate.processor.util.Constants.MUTINY_SESSION_FACTORY;
import static org.hibernate.processor.util.Constants.MUTINY_STATELESS_SESSION;
import static org.hibernate.processor.util.Constants.PERSISTENCE_UNIT;
import static org.hibernate.processor.util.Constants.POST_CONSTRUCT;
import static org.hibernate.processor.util.Constants.PRE_DESTROY;

/**
* Used by the container to instantiate a Jakarta Data repository.
*
* @author Gavin King
*/
public class DefaultConstructor implements MetaAttribute {
private final Metamodel annotationMetaEntity;
private final AnnotationMetaEntity annotationMetaEntity;
private final String constructorName;
private final String methodName;
private final String sessionTypeName;
Expand All @@ -31,7 +34,7 @@ public class DefaultConstructor implements MetaAttribute {
private final boolean addInjectAnnotation;

public DefaultConstructor(
Metamodel annotationMetaEntity,
AnnotationMetaEntity annotationMetaEntity,
String constructorName,
String methodName,
String sessionTypeName,
Expand All @@ -48,7 +51,7 @@ public DefaultConstructor(
}

private boolean isReactive() {
return usingReactiveSession(sessionTypeName);
return annotationMetaEntity.isReactive();
}

@Override
Expand All @@ -69,7 +72,7 @@ public String getAttributeDeclarationString() {
if ( annotationMetaEntity.getSuperTypeElement() == null ) {
declaration
.append("@")
.append(annotationMetaEntity.importType("jakarta.persistence.PersistenceUnit"));
.append(annotationMetaEntity.importType(PERSISTENCE_UNIT));
if ( dataStore != null ) {
declaration
.append("(unitName=\"")
Expand All @@ -82,15 +85,16 @@ public String getAttributeDeclarationString() {
.append(" ")
.append(sessionVariableName)
.append("Factory;\n\n");
final String sessionFactoryType = isReactive() ? MUTINY_SESSION_FACTORY : HIB_SESSION_FACTORY;
declaration.append('@')
.append(annotationMetaEntity.importType("jakarta.annotation.PostConstruct"))
.append(annotationMetaEntity.importType(POST_CONSTRUCT))
.append("\nprivate void openSession() {")
.append("\n\t")
.append(sessionVariableName)
.append(" = ")
.append(sessionVariableName)
.append("Factory.unwrap(")
.append(annotationMetaEntity.importType(isReactive() ? MUTINY_SESSION_FACTORY : HIB_SESSION_FACTORY))
.append(annotationMetaEntity.importType( sessionFactoryType ))
.append(".class).openStatelessSession()");
if ( MUTINY_SESSION.equals(sessionTypeName)
|| MUTINY_STATELESS_SESSION.equals(sessionTypeName) ) {
Expand All @@ -103,7 +107,7 @@ public String getAttributeDeclarationString() {
// TODO: is it a problem that we never close the session?
if ( !isReactive() ) {
declaration.append('@')
.append(annotationMetaEntity.importType("jakarta.annotation.PreDestroy"))
.append(annotationMetaEntity.importType(PRE_DESTROY))
.append("\nprivate void closeSession() {")
.append("\n\t")
.append(sessionVariableName)
Expand All @@ -124,7 +128,7 @@ private void inject(StringBuilder declaration) {
if ( addInjectAnnotation ) {
declaration
.append('@')
.append(annotationMetaEntity.importType("jakarta.inject.Inject"))
.append(annotationMetaEntity.importType(INJECT))
.append('\n');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
import org.hibernate.processor.model.Metamodel;
import org.hibernate.processor.util.Constants;

import static org.hibernate.processor.util.Constants.INJECT;
import static org.hibernate.processor.util.Constants.JD_LIFECYCLE_EVENT;


/**
* Used by the container to instantiate a Jakarta Data repository.
* Holds a reference to the CDI {@code Event} object.
*
* @author Gavin King
*/
Expand All @@ -34,8 +37,8 @@ public boolean hasStringAttribute() {

@Override
public String getAttributeDeclarationString() {
annotationMetaEntity.importType("jakarta.inject.Inject");
annotationMetaEntity.importType("jakarta.data.event.LifecycleEvent");
annotationMetaEntity.importType(INJECT);
annotationMetaEntity.importType(JD_LIFECYCLE_EVENT);
return "\n@Inject\nprivate Event<? super LifecycleEvent<?>> event;";
}

Expand Down
Loading
Loading