Support sessions of type Uni<Mutiny.Session>
This commit is contained in:
parent
3ca494be79
commit
36c9ce9d20
|
@ -183,7 +183,29 @@ public abstract class AbstractQueryMethod implements MetaAttribute {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isReactive() {
|
boolean isReactive() {
|
||||||
return MUTINY_SESSION.equals(sessionType);
|
return MUTINY_SESSION.equals(sessionType)
|
||||||
|
|| UNI_MUTINY_SESSION.equals(sessionType);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isReactiveSession() {
|
||||||
|
return UNI_MUTINY_SESSION.equals(sessionType);
|
||||||
|
}
|
||||||
|
|
||||||
|
String localSessionName() {
|
||||||
|
return isReactiveSession() ? "resolvedSession" : sessionName;
|
||||||
|
}
|
||||||
|
|
||||||
|
void chainSession(StringBuilder declaration) {
|
||||||
|
// Reactive calls always have a return type
|
||||||
|
if ( isReactiveSession() ) {
|
||||||
|
declaration.append("\treturn ").append(sessionName).append(".chain(").append(localSessionName()).append(" -> {\n\t");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void chainSessionEnd(boolean isUpdate, StringBuilder declaration) {
|
||||||
|
if ( isReactiveSession() ) {
|
||||||
|
declaration.append("\n\t});");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPage(StringBuilder declaration, String paramName, String paramType) {
|
void setPage(StringBuilder declaration, String paramName, String paramType) {
|
||||||
|
|
|
@ -459,7 +459,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
if ( method.getParameters().isEmpty() ) {
|
if ( method.getParameters().isEmpty() ) {
|
||||||
final TypeMirror type = method.getReturnType();
|
final TypeMirror type = method.getReturnType();
|
||||||
if ( type.getKind() == TypeKind.DECLARED ) {
|
if ( type.getKind() == TypeKind.DECLARED ) {
|
||||||
final DeclaredType declaredType = (DeclaredType) type;
|
final DeclaredType declaredType = ununi( (DeclaredType) type );
|
||||||
final Element element = declaredType.asElement();
|
final Element element = declaredType.asElement();
|
||||||
if ( element.getKind() == ElementKind.INTERFACE ) {
|
if ( element.getKind() == ElementKind.INTERFACE ) {
|
||||||
final Name name = ((TypeElement) element).getQualifiedName();
|
final Name name = ((TypeElement) element).getQualifiedName();
|
||||||
|
|
|
@ -59,12 +59,14 @@ public class CriteriaFinderMethod extends AbstractFinderMethod {
|
||||||
comment( declaration );
|
comment( declaration );
|
||||||
modifiers( declaration );
|
modifiers( declaration );
|
||||||
preamble( declaration, returnType(), paramTypes );
|
preamble( declaration, returnType(), paramTypes );
|
||||||
|
chainSession( declaration );
|
||||||
nullChecks( paramTypes, declaration );
|
nullChecks( paramTypes, declaration );
|
||||||
createCriteriaQuery( declaration );
|
createCriteriaQuery( declaration );
|
||||||
where( declaration, paramTypes );
|
where( declaration, paramTypes );
|
||||||
// orderBy( paramTypes, declaration );
|
// orderBy( paramTypes, declaration );
|
||||||
executeQuery( declaration, paramTypes );
|
executeQuery( declaration, paramTypes );
|
||||||
convertExceptions( declaration );
|
convertExceptions( declaration );
|
||||||
|
chainSessionEnd( false, declaration );
|
||||||
closingBrace( declaration );
|
closingBrace( declaration );
|
||||||
return declaration.toString();
|
return declaration.toString();
|
||||||
}
|
}
|
||||||
|
@ -102,7 +104,7 @@ public class CriteriaFinderMethod extends AbstractFinderMethod {
|
||||||
@Override
|
@Override
|
||||||
void createQuery(StringBuilder declaration) {
|
void createQuery(StringBuilder declaration) {
|
||||||
declaration
|
declaration
|
||||||
.append(sessionName)
|
.append(localSessionName())
|
||||||
.append(".createQuery(_query)\n");
|
.append(".createQuery(_query)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +121,7 @@ public class CriteriaFinderMethod extends AbstractFinderMethod {
|
||||||
private void createCriteriaQuery(StringBuilder declaration) {
|
private void createCriteriaQuery(StringBuilder declaration) {
|
||||||
declaration
|
declaration
|
||||||
.append("\tvar _builder = ")
|
.append("\tvar _builder = ")
|
||||||
.append(sessionName)
|
.append(localSessionName())
|
||||||
.append(isUsingEntityManager()
|
.append(isUsingEntityManager()
|
||||||
? ".getEntityManagerFactory()"
|
? ".getEntityManagerFactory()"
|
||||||
: ".getFactory()")
|
: ".getFactory()")
|
||||||
|
|
|
@ -85,6 +85,7 @@ public class QueryMethod extends AbstractQueryMethod {
|
||||||
modifiers( paramTypes, declaration );
|
modifiers( paramTypes, declaration );
|
||||||
preamble( declaration, returnType, paramTypes );
|
preamble( declaration, returnType, paramTypes );
|
||||||
collectOrdering( declaration, paramTypes );
|
collectOrdering( declaration, paramTypes );
|
||||||
|
chainSession( declaration );
|
||||||
tryReturn( declaration, paramTypes, containerType );
|
tryReturn( declaration, paramTypes, containerType );
|
||||||
castResult( declaration, returnType );
|
castResult( declaration, returnType );
|
||||||
createQuery( declaration );
|
createQuery( declaration );
|
||||||
|
@ -94,6 +95,7 @@ public class QueryMethod extends AbstractQueryMethod {
|
||||||
unwrapped = applyOrder( declaration, paramTypes, containerType, unwrapped );
|
unwrapped = applyOrder( declaration, paramTypes, containerType, unwrapped );
|
||||||
execute( declaration, unwrapped );
|
execute( declaration, unwrapped );
|
||||||
convertExceptions( declaration );
|
convertExceptions( declaration );
|
||||||
|
chainSessionEnd( isUpdate, declaration );
|
||||||
closingBrace( declaration );
|
closingBrace( declaration );
|
||||||
return declaration.toString();
|
return declaration.toString();
|
||||||
}
|
}
|
||||||
|
@ -107,7 +109,7 @@ public class QueryMethod extends AbstractQueryMethod {
|
||||||
@Override
|
@Override
|
||||||
void createQuery(StringBuilder declaration) {
|
void createQuery(StringBuilder declaration) {
|
||||||
declaration
|
declaration
|
||||||
.append(sessionName)
|
.append(localSessionName())
|
||||||
.append(isNative ? ".createNativeQuery" : ".createQuery")
|
.append(isNative ? ".createNativeQuery" : ".createQuery")
|
||||||
.append("(")
|
.append("(")
|
||||||
.append(getConstantName());
|
.append(getConstantName());
|
||||||
|
|
|
@ -98,6 +98,7 @@ public final class Constants {
|
||||||
public static final String TUPLE = "jakarta.persistence.Tuple";
|
public static final String TUPLE = "jakarta.persistence.Tuple";
|
||||||
|
|
||||||
public static final String UNI = "io.smallrye.mutiny.Uni";
|
public static final String UNI = "io.smallrye.mutiny.Uni";
|
||||||
|
public static final String UNI_MUTINY_SESSION = UNI+"<org.hibernate.reactive.mutiny.Mutiny.Session>";
|
||||||
|
|
||||||
public static final String SINGULAR_ATTRIBUTE = "jakarta.persistence.metamodel.SingularAttribute";
|
public static final String SINGULAR_ATTRIBUTE = "jakarta.persistence.metamodel.SingularAttribute";
|
||||||
public static final String COLLECTION_ATTRIBUTE = "jakarta.persistence.metamodel.CollectionAttribute";
|
public static final String COLLECTION_ATTRIBUTE = "jakarta.persistence.metamodel.CollectionAttribute";
|
||||||
|
@ -129,7 +130,8 @@ public final class Constants {
|
||||||
Constants.ENTITY_MANAGER,
|
Constants.ENTITY_MANAGER,
|
||||||
Constants.HIB_SESSION,
|
Constants.HIB_SESSION,
|
||||||
Constants.HIB_STATELESS_SESSION,
|
Constants.HIB_STATELESS_SESSION,
|
||||||
Constants.MUTINY_SESSION
|
Constants.MUTINY_SESSION,
|
||||||
|
Constants.UNI_MUTINY_SESSION
|
||||||
);
|
);
|
||||||
|
|
||||||
//TODO: this is not even an exhaustive list of built-in basic types
|
//TODO: this is not even an exhaustive list of built-in basic types
|
||||||
|
|
Loading…
Reference in New Issue