Skip to content

Commit

Permalink
Merge pull request #21810 from geoand/#21796
Browse files Browse the repository at this point in the history
Add @CheckReturnValue to Hibernate Reactive Panache methods
  • Loading branch information
geoand authored Nov 30, 2021
2 parents f4dfa05 + fdcfc23 commit d8bae08
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.MethodInfo;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Type;

import io.quarkus.arc.deployment.UnremovableBeanBuildItem;
import io.quarkus.arc.deployment.ValidationPhaseBuildItem;
Expand All @@ -35,6 +38,8 @@
import io.quarkus.panache.common.deployment.PanacheJpaEntityOperationsEnhancer;
import io.quarkus.panache.common.deployment.PanacheMethodCustomizer;
import io.quarkus.panache.common.deployment.PanacheMethodCustomizerBuildItem;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;

public final class PanacheHibernateResourceProcessor {

Expand All @@ -49,6 +54,8 @@ public final class PanacheHibernateResourceProcessor {
protected static final String META_INF_PANACHE_ARCHIVE_MARKER = "META-INF/panache-archive.marker";

private static final DotName DOTNAME_TRANSIENT = DotName.createSimple(Transient.class.getName());
private static final DotName DOTNAME_UNI = DotName.createSimple(Uni.class.getName());
private static final DotName DOTNAME_MULTI = DotName.createSimple(Multi.class.getName());

@BuildStep
FeatureBuildItem featureBuildItem() {
Expand Down Expand Up @@ -137,4 +144,20 @@ ValidationPhaseBuildItem.ValidationErrorBuildItem validate(ValidationPhaseBuildI
}
return null;
}

private static final String CHECK_RETURN_VALUE_BINARY_NAME = "io/smallrye/common/annotation/CheckReturnValue";
private static final String CHECK_RETURN_VALUE_SIGNATURE = "L" + CHECK_RETURN_VALUE_BINARY_NAME + ";";

@BuildStep
PanacheMethodCustomizerBuildItem mutinyReturnTypes() {
return new PanacheMethodCustomizerBuildItem(new PanacheMethodCustomizer() {
@Override
public void customize(Type entityClassSignature, MethodInfo method, MethodVisitor mv) {
DotName returnType = method.returnType().name();
if (returnType.equals(DOTNAME_UNI) || returnType.equals(DOTNAME_MULTI)) {
mv.visitAnnotation(CHECK_RETURN_VALUE_SIGNATURE, true);
}
}
});
}
}
4 changes: 4 additions & 0 deletions extensions/panache/hibernate-reactive-panache/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye.common</groupId>
<artifactId>smallrye-common-annotation</artifactId>
</dependency>
<dependency>
<groupId>jakarta.json.bind</groupId>
<artifactId>jakarta.json.bind-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.quarkus.panache.common.Parameters;
import io.quarkus.panache.common.Sort;
import io.quarkus.panache.common.impl.GenerateBridge;
import io.smallrye.common.annotation.CheckReturnValue;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;

Expand Down Expand Up @@ -52,6 +53,7 @@ public static Uni<Mutiny.Session> getSession() {
* @see #persist(Stream)
* @see #persist(Object, Object...)
*/
@CheckReturnValue
public <T extends PanacheEntityBase> Uni<T> persist() {
return INSTANCE.persist(this).map(v -> (T) this);
}
Expand All @@ -67,6 +69,7 @@ public <T extends PanacheEntityBase> Uni<T> persist() {
* @see #persist(Stream)
* @see #persist(Object, Object...)
*/
@CheckReturnValue
public <T extends PanacheEntityBase> Uni<T> persistAndFlush() {
return INSTANCE.persist(this)
.flatMap(v -> INSTANCE.flush())
Expand All @@ -84,6 +87,7 @@ public <T extends PanacheEntityBase> Uni<T> persistAndFlush() {
* @see #delete(String, Parameters)
* @see #deleteAll()
*/
@CheckReturnValue
public Uni<Void> delete() {
return INSTANCE.delete(this);
}
Expand All @@ -107,6 +111,7 @@ public boolean isPersistent() {
*
* @return
*/
@CheckReturnValue
public Uni<Void> flush() {
return INSTANCE.flush();
}
Expand All @@ -131,6 +136,7 @@ public static <T extends PanacheEntityBase> Uni<T> findById(Object id) {
* @param lockModeType the locking strategy to be used when retrieving the entity.
* @return the entity found, or <code>null</code> if not found.
*/
@CheckReturnValue
@GenerateBridge
public static <T extends PanacheEntityBase> Uni<T> findById(Object id, LockModeType lockModeType) {
throw INSTANCE.implementationInjectionMissing();
Expand Down Expand Up @@ -281,6 +287,7 @@ public static <T extends PanacheEntityBase> PanacheQuery<T> findAll(Sort sort) {
* @see #find(String, Object...)
* @see #stream(String, Object...)
*/
@CheckReturnValue
@GenerateBridge
public static <T extends PanacheEntityBase> Uni<List<T>> list(String query, Object... params) {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -300,6 +307,7 @@ public static <T extends PanacheEntityBase> Uni<List<T>> list(String query, Obje
* @see #find(String, Sort, Object...)
* @see #stream(String, Sort, Object...)
*/
@CheckReturnValue
@GenerateBridge
public static <T extends PanacheEntityBase> Uni<List<T>> list(String query, Sort sort, Object... params) {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -318,6 +326,7 @@ public static <T extends PanacheEntityBase> Uni<List<T>> list(String query, Sort
* @see #find(String, Map)
* @see #stream(String, Map)
*/
@CheckReturnValue
@GenerateBridge
public static <T extends PanacheEntityBase> Uni<List<T>> list(String query, Map<String, Object> params) {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -337,6 +346,7 @@ public static <T extends PanacheEntityBase> Uni<List<T>> list(String query, Map<
* @see #find(String, Sort, Map)
* @see #stream(String, Sort, Map)
*/
@CheckReturnValue
@GenerateBridge
public static <T extends PanacheEntityBase> Uni<List<T>> list(String query, Sort sort, Map<String, Object> params) {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -355,6 +365,7 @@ public static <T extends PanacheEntityBase> Uni<List<T>> list(String query, Sort
* @see #find(String, Parameters)
* @see #stream(String, Parameters)
*/
@CheckReturnValue
@GenerateBridge
public static <T extends PanacheEntityBase> Uni<List<T>> list(String query, Parameters params) {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -374,6 +385,7 @@ public static <T extends PanacheEntityBase> Uni<List<T>> list(String query, Para
* @see #find(String, Sort, Parameters)
* @see #stream(String, Sort, Parameters)
*/
@CheckReturnValue
@GenerateBridge
public static <T extends PanacheEntityBase> Uni<List<T>> list(String query, Sort sort, Parameters params) {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -388,6 +400,7 @@ public static <T extends PanacheEntityBase> Uni<List<T>> list(String query, Sort
* @see #findAll()
* @see #streamAll()
*/
@CheckReturnValue
@GenerateBridge
public static <T extends PanacheEntityBase> Uni<List<T>> listAll() {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -403,6 +416,7 @@ public static <T extends PanacheEntityBase> Uni<List<T>> listAll() {
* @see #findAll(Sort)
* @see #streamAll(Sort)
*/
@CheckReturnValue
@GenerateBridge
public static <T extends PanacheEntityBase> Uni<List<T>> listAll(Sort sort) {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -423,6 +437,7 @@ public static <T extends PanacheEntityBase> Uni<List<T>> listAll(Sort sort) {
* @see #find(String, Object...)
* @see #list(String, Object...)
*/
@CheckReturnValue
@GenerateBridge
public static <T extends PanacheEntityBase> Multi<T> stream(String query, Object... params) {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -444,6 +459,7 @@ public static <T extends PanacheEntityBase> Multi<T> stream(String query, Object
* @see #find(String, Sort, Object...)
* @see #list(String, Sort, Object...)
*/
@CheckReturnValue
@GenerateBridge
public static <T extends PanacheEntityBase> Multi<T> stream(String query, Sort sort, Object... params) {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -464,6 +480,7 @@ public static <T extends PanacheEntityBase> Multi<T> stream(String query, Sort s
* @see #find(String, Map)
* @see #list(String, Map)
*/
@CheckReturnValue
@GenerateBridge
public static <T extends PanacheEntityBase> Multi<T> stream(String query, Map<String, Object> params) {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -485,6 +502,7 @@ public static <T extends PanacheEntityBase> Multi<T> stream(String query, Map<St
* @see #find(String, Sort, Map)
* @see #list(String, Sort, Map)
*/
@CheckReturnValue
@GenerateBridge
public static <T extends PanacheEntityBase> Multi<T> stream(String query, Sort sort, Map<String, Object> params) {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -505,6 +523,7 @@ public static <T extends PanacheEntityBase> Multi<T> stream(String query, Sort s
* @see #find(String, Parameters)
* @see #list(String, Parameters)
*/
@CheckReturnValue
@GenerateBridge
public static <T extends PanacheEntityBase> Multi<T> stream(String query, Parameters params) {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -526,6 +545,7 @@ public static <T extends PanacheEntityBase> Multi<T> stream(String query, Parame
* @see #find(String, Sort, Parameters)
* @see #list(String, Sort, Parameters)
*/
@CheckReturnValue
@GenerateBridge
public static <T extends PanacheEntityBase> Multi<T> stream(String query, Sort sort, Parameters params) {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -542,6 +562,7 @@ public static <T extends PanacheEntityBase> Multi<T> stream(String query, Sort s
* @see #findAll()
* @see #listAll()
*/
@CheckReturnValue
@GenerateBridge
public static <T extends PanacheEntityBase> Multi<T> streamAll() {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -559,6 +580,7 @@ public static <T extends PanacheEntityBase> Multi<T> streamAll() {
* @see #findAll(Sort)
* @see #listAll(Sort)
*/
@CheckReturnValue
@GenerateBridge
public static <T extends PanacheEntityBase> Multi<T> streamAll(Sort sort) {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -572,6 +594,7 @@ public static <T extends PanacheEntityBase> Multi<T> streamAll(Sort sort) {
* @see #count(String, Map)
* @see #count(String, Parameters)
*/
@CheckReturnValue
@GenerateBridge
public static Uni<Long> count() {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -587,6 +610,7 @@ public static Uni<Long> count() {
* @see #count(String, Map)
* @see #count(String, Parameters)
*/
@CheckReturnValue
@GenerateBridge
public static Uni<Long> count(String query, Object... params) {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -602,6 +626,7 @@ public static Uni<Long> count(String query, Object... params) {
* @see #count(String, Object...)
* @see #count(String, Parameters)
*/
@CheckReturnValue
@GenerateBridge
public static Uni<Long> count(String query, Map<String, Object> params) {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -617,6 +642,7 @@ public static Uni<Long> count(String query, Map<String, Object> params) {
* @see #count(String, Object...)
* @see #count(String, Map)
*/
@CheckReturnValue
@GenerateBridge
public static Uni<Long> count(String query, Parameters params) {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -633,6 +659,7 @@ public static Uni<Long> count(String query, Parameters params) {
* @see #delete(String, Map)
* @see #delete(String, Parameters)
*/
@CheckReturnValue
@GenerateBridge
public static Uni<Long> deleteAll() {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -644,6 +671,7 @@ public static Uni<Long> deleteAll() {
* @param id the ID of the entity to delete.
* @return false if the entity was not deleted (not found).
*/
@CheckReturnValue
@GenerateBridge
public static Uni<Boolean> deleteById(Object id) {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -662,6 +690,7 @@ public static Uni<Boolean> deleteById(Object id) {
* @see #delete(String, Map)
* @see #delete(String, Parameters)
*/
@CheckReturnValue
@GenerateBridge
public static Uni<Long> delete(String query, Object... params) {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -680,6 +709,7 @@ public static Uni<Long> delete(String query, Object... params) {
* @see #delete(String, Object...)
* @see #delete(String, Parameters)
*/
@CheckReturnValue
@GenerateBridge
public static Uni<Long> delete(String query, Map<String, Object> params) {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -698,6 +728,7 @@ public static Uni<Long> delete(String query, Map<String, Object> params) {
* @see #delete(String, Object...)
* @see #delete(String, Map)
*/
@CheckReturnValue
@GenerateBridge
public static Uni<Long> delete(String query, Parameters params) {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -712,6 +743,7 @@ public static Uni<Long> delete(String query, Parameters params) {
* @see #persist(Stream)
* @see #persist(Object,Object...)
*/
@CheckReturnValue
@GenerateBridge(callSuperMethod = true)
public static Uni<Void> persist(Iterable<?> entities) {
return INSTANCE.persist(entities);
Expand All @@ -726,6 +758,7 @@ public static Uni<Void> persist(Iterable<?> entities) {
* @see #persist(Iterable)
* @see #persist(Object,Object...)
*/
@CheckReturnValue
@GenerateBridge(callSuperMethod = true)
public static Uni<Void> persist(Stream<?> entities) {
return INSTANCE.persist(entities);
Expand All @@ -740,6 +773,7 @@ public static Uni<Void> persist(Stream<?> entities) {
* @see #persist(Stream)
* @see #persist(Iterable)
*/
@CheckReturnValue
@GenerateBridge(callSuperMethod = true)
public static Uni<Void> persist(Object firstEntity, Object... entities) {
return INSTANCE.persist(firstEntity, entities);
Expand All @@ -754,6 +788,7 @@ public static Uni<Void> persist(Object firstEntity, Object... entities) {
* @see #update(String, Map)
* @see #update(String, Parameters)
*/
@CheckReturnValue
@GenerateBridge
public static Uni<Integer> update(String query, Object... params) {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -769,6 +804,7 @@ public static Uni<Integer> update(String query, Object... params) {
* @see #update(String, Parameters)
*
*/
@CheckReturnValue
@GenerateBridge
public static Uni<Integer> update(String query, Map<String, Object> params) {
throw INSTANCE.implementationInjectionMissing();
Expand All @@ -783,6 +819,7 @@ public static Uni<Integer> update(String query, Map<String, Object> params) {
* @see #update(String, Object...)
* @see #update(String, Map)
*/
@CheckReturnValue
@GenerateBridge
public static Uni<Integer> update(String query, Parameters params) {
throw INSTANCE.implementationInjectionMissing();
Expand Down
Loading

0 comments on commit d8bae08

Please sign in to comment.