From 801354574d3cb0e51bcb1c5b55615fd9ad54d04b Mon Sep 17 00:00:00 2001 From: Justin Lee Date: Thu, 14 May 2020 12:18:42 -0400 Subject: [PATCH] update documentation/kdoc add autoboxing code for non-nullable ID types --- .../KotlinPanacheRepositoryClassVisitor.java | 84 +++- .../KotlinPanacheResourceProcessor.java | 40 ++ .../runtime/pom.xml | 40 +- .../panache/kotlin/runtime/JpaOperations.java | 290 ++++++------- .../kotlin/runtime/PanacheQueryImpl.java | 37 +- .../orm/panache/kotlin/PanacheCompanion.kt | 357 +++++++--------- .../orm/panache/kotlin/PanacheEntity.kt | 25 +- .../orm/panache/kotlin/PanacheEntityBase.kt | 53 ++- .../orm/panache/kotlin/PanacheQuery.kt | 84 ++-- .../orm/panache/kotlin/PanacheRepository.kt | 6 +- .../panache/kotlin/PanacheRepositoryBase.kt | 391 ++++++++---------- .../quarkus/it/panache/kotlin/TestEndpoint.kt | 20 +- 12 files changed, 717 insertions(+), 710 deletions(-) diff --git a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/main/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/KotlinPanacheRepositoryClassVisitor.java b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/main/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/KotlinPanacheRepositoryClassVisitor.java index 6e186d8651e54..b33606d74e29f 100644 --- a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/main/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/KotlinPanacheRepositoryClassVisitor.java +++ b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/main/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/KotlinPanacheRepositoryClassVisitor.java @@ -1,19 +1,21 @@ package io.quarkus.hibernate.orm.panache.kotlin.deployment; import static io.quarkus.gizmo.Gizmo.ASM_API_VERSION; -import static io.quarkus.hibernate.orm.panache.kotlin.deployment.KotlinPanacheResourceProcessor.CLASS_SIGNATURE; -import static io.quarkus.hibernate.orm.panache.kotlin.deployment.KotlinPanacheResourceProcessor.ID_TYPE_SIGNATURE; import static io.quarkus.hibernate.orm.panache.kotlin.deployment.KotlinPanacheResourceProcessor.JPA_OPERATIONS; -import static io.quarkus.hibernate.orm.panache.kotlin.deployment.KotlinPanacheResourceProcessor.OBJECT_SIGNATURE; -import static io.quarkus.hibernate.orm.panache.kotlin.deployment.KotlinPanacheResourceProcessor.PANACHE_ENTITY_SIGNATURE; import static io.quarkus.hibernate.orm.panache.kotlin.deployment.KotlinPanacheResourceProcessor.PANACHE_REPOSITORY_BASE_DOTNAME; -import static io.quarkus.hibernate.orm.panache.kotlin.deployment.KotlinPanacheResourceProcessor.PANACHE_REPOSITORY_BASE_SIGNATURE; -import static io.quarkus.hibernate.orm.panache.kotlin.deployment.KotlinPanacheResourceProcessor.PANACHE_REPOSITORY_SIGNATURE; +import static io.quarkus.hibernate.orm.panache.kotlin.deployment.KotlinPanacheResourceProcessor.autobox; +import static io.quarkus.hibernate.orm.panache.kotlin.deployment.KotlinPanacheResourceProcessor.sanitize; +import static io.quarkus.panache.common.deployment.JandexUtil.getDescriptor; import static io.quarkus.panache.common.deployment.PanacheRepositoryEnhancer.PanacheRepositoryClassVisitor.findEntityTypeArgumentsForPanacheRepository; import static org.jboss.jandex.DotName.createSimple; import static org.objectweb.asm.Opcodes.ALOAD; import static org.objectweb.asm.Opcodes.INVOKESTATIC; +import static org.objectweb.asm.Opcodes.LLOAD; +import static org.objectweb.asm.Type.getArgumentTypes; +import static org.objectweb.asm.Type.getMethodDescriptor; +import static org.objectweb.asm.Type.getReturnType; +import java.util.HashMap; import java.util.Map; import java.util.TreeMap; import java.util.regex.Pattern; @@ -39,17 +41,13 @@ class KotlinPanacheRepositoryClassVisitor extends ClassVisitor { private final IndexView indexView; private org.objectweb.asm.Type entityType; private String entitySignature; + protected Map typeArguments = new HashMap<>(); + private String idBinaryType; + private String idSignature; public KotlinPanacheRepositoryClassVisitor(String className, ClassVisitor outputClassVisitor, IndexView indexView) { super(Gizmo.ASM_API_VERSION, outputClassVisitor); this.indexView = indexView; - indexView.getClassByName(createSimple(className)) - .methods() - .forEach(method -> { - if (method.hasAnnotation(JandexUtil.DOTNAME_GENERATE_BRIDGE)) { - bridgeMethods.put(method.name() + JandexUtil.getDescriptor(method, m -> null), method); - } - }); } @Override @@ -64,38 +62,80 @@ public void visit(int version, int access, String name, String signature, String String entityBinaryType = foundTypeArguments[0]; entitySignature = "L" + entityBinaryType + ";"; entityType = Type.getType(entitySignature); + idBinaryType = foundTypeArguments[1]; + idSignature = "L" + idBinaryType + ";"; + + typeArguments.put("Entity", entitySignature); + typeArguments.put("Id", idSignature); + indexView.getClassByName(createSimple(repositoryClassName)) + .methods() + .forEach(method -> { + if (method.hasAnnotation(JandexUtil.DOTNAME_GENERATE_BRIDGE)) { + bridgeMethods.put(method.name() + getDescriptor(method, m -> typeArguments.get(m)), method); + } + }); } @Override public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) { MethodVisitor mv = super.visitMethod(access, name, descriptor, signature, exceptions); if (bridgeMethods.get(name + descriptor) != null) { + final Type[] argumentTypes = getArgumentTypes(descriptor); + int primitive = -1; + + for (int i = 0; i < argumentTypes.length; i++) { + if (argumentTypes[i].getInternalName().length() == 1) { + primitive = i; + } + } + + int finalPrimitive = primitive; mv = new MethodVisitor(ASM_API_VERSION, mv) { + /** + * This method tracks the location of any primitive value (ID types) passed in. The javac-generated + * bytecode is expecting an Object but with non-nullable "primitive" types in kotlin, those are + * expressed as primitives and not the wrapper types (e.g., Long). This method will catch the cases + * where the ID values passed in are loaded on to the stack prior to invoking the call to JpaOperations. + * It will then inject an autoboxing-like call to ensure that any long values because Long values. + */ @Override public void visitVarInsn(int opcode, int var) { if (opcode == ALOAD && var == 0) { visitLdcInsn(entityType); } else { super.visitVarInsn(opcode, var); + if (opcode == LLOAD && var == (finalPrimitive + 1)) { + Type wrapper = autobox(argumentTypes[finalPrimitive]); + super.visitMethodInsn(INVOKESTATIC, wrapper.getInternalName(), "valueOf", + getMethodDescriptor(wrapper, argumentTypes[finalPrimitive]), false); + + } } } + /** + * This method redirects the kotlinc generated call to $DefaultImpls to JpaOperations. In case of IDs, + * e.g., these parameters are represented using primitives by kotlinc since they can never be null. + * JpaOperation expects an object reference so we need to update the descriptor for the method + * invocation to reflect that rather than the primitive type. + */ @Override - public void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) { + public void visitMethodInsn(int opcode, String owner, String name, String descriptor, + boolean isInterface) { if (opcode == INVOKESTATIC && DEFAULT_IMPLS.matcher(owner).matches()) { - String replace = descriptor - .replace(PANACHE_REPOSITORY_BASE_SIGNATURE, CLASS_SIGNATURE) - .replace(PANACHE_REPOSITORY_SIGNATURE, CLASS_SIGNATURE) - .replace(PANACHE_ENTITY_SIGNATURE, OBJECT_SIGNATURE) - .replace(ID_TYPE_SIGNATURE, OBJECT_SIGNATURE); - super.visitMethodInsn(opcode, JPA_OPERATIONS, name, replace, isInterface); - } else { - super.visitMethodInsn(opcode, owner, name, descriptor, isInterface); + + owner = JPA_OPERATIONS; + Type[] arguments = getArgumentTypes(descriptor); + sanitize(arguments); + descriptor = getMethodDescriptor(getReturnType(descriptor), arguments); } + + super.visitMethodInsn(opcode, owner, name, descriptor, isInterface); } }; } return mv; } + } diff --git a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/main/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/KotlinPanacheResourceProcessor.java b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/main/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/KotlinPanacheResourceProcessor.java index 42a4a8813c81b..f31be7514f6c8 100644 --- a/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/main/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/KotlinPanacheResourceProcessor.java +++ b/extensions/panache/hibernate-orm-panache-kotlin/deployment/src/main/java/io/quarkus/hibernate/orm/panache/kotlin/deployment/KotlinPanacheResourceProcessor.java @@ -1,5 +1,6 @@ package io.quarkus.hibernate.orm.panache.kotlin.deployment; +import static java.util.Arrays.asList; import static org.jboss.jandex.DotName.createSimple; import java.util.Collections; @@ -63,6 +64,45 @@ public final class KotlinPanacheResourceProcessor { static final String OBJECT_SIGNATURE = toBinarySignature(Object.class); static final String CLASS_SIGNATURE = toBinarySignature(Class.class); + static final org.objectweb.asm.Type CLASS_TYPE = org.objectweb.asm.Type.getType(Class.class); + static final org.objectweb.asm.Type OBJECT_TYPE = org.objectweb.asm.Type.getType(Object.class); + static final List REPOSITORY_TYPES = asList( + org.objectweb.asm.Type.getType(PanacheRepositoryBase.class), + org.objectweb.asm.Type.getType(PanacheRepository.class)); + static final List ENTITY_TYPES = asList( + org.objectweb.asm.Type.getType(PanacheEntityBase.class), + org.objectweb.asm.Type.getType(PanacheEntity.class), + org.objectweb.asm.Type.getType(PanacheCompanion.class)); + public static final List PRIMITIVE_TYPES = asList( + org.objectweb.asm.Type.getType(Void.class), + org.objectweb.asm.Type.getType(Boolean.class), + org.objectweb.asm.Type.getType(Character.class), + org.objectweb.asm.Type.getType(Byte.class), + org.objectweb.asm.Type.getType(Short.class), + org.objectweb.asm.Type.getType(Integer.class), + org.objectweb.asm.Type.getType(Float.class), + org.objectweb.asm.Type.getType(Long.class)); + + static org.objectweb.asm.Type sanitize(org.objectweb.asm.Type[] argumentTypes) { + org.objectweb.asm.Type primitiveReplaced = null; + + for (int i = 0; i < argumentTypes.length; i++) { + if (REPOSITORY_TYPES.contains(argumentTypes[i])) { + argumentTypes[i] = CLASS_TYPE; + } else if (ENTITY_TYPES.contains(argumentTypes[i])) { + argumentTypes[i] = OBJECT_TYPE; + } else if (argumentTypes[i].getInternalName().length() == 1) { + primitiveReplaced = argumentTypes[i]; + argumentTypes[i] = OBJECT_TYPE; + } + } + return primitiveReplaced; + } + + static org.objectweb.asm.Type autobox(org.objectweb.asm.Type primitive) { + return PRIMITIVE_TYPES.get(primitive.getSort()); + } + @NotNull static String toBinarySignature(Class type) { return org.objectweb.asm.Type.getType(type).getDescriptor(); diff --git a/extensions/panache/hibernate-orm-panache-kotlin/runtime/pom.xml b/extensions/panache/hibernate-orm-panache-kotlin/runtime/pom.xml index 601f38cbe1580..7b468b79fa036 100644 --- a/extensions/panache/hibernate-orm-panache-kotlin/runtime/pom.xml +++ b/extensions/panache/hibernate-orm-panache-kotlin/runtime/pom.xml @@ -71,6 +71,14 @@ + + + jcenter + JCenter + https://jcenter.bintray.com/ + + + @@ -137,7 +145,9 @@ java-compile compile - compile + + compile + java-test-compile @@ -146,6 +156,34 @@ + + org.jetbrains.dokka + dokka-maven-plugin + 0.10.1 + + + javadoc + pre-site + + dokka + + + + + 8 + html + + src/main/kotlin + + + + + https://docs.oracle.com/javase/8/docs/api/ + https://docs.oracle.com/javase/8/docs/api/package-list + + + + diff --git a/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/java/io/quarkus/hibernate/orm/panache/kotlin/runtime/JpaOperations.java b/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/java/io/quarkus/hibernate/orm/panache/kotlin/runtime/JpaOperations.java index 36f6fd793c4e4..c4128d3f1a5f6 100644 --- a/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/java/io/quarkus/hibernate/orm/panache/kotlin/runtime/JpaOperations.java +++ b/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/java/io/quarkus/hibernate/orm/panache/kotlin/runtime/JpaOperations.java @@ -17,136 +17,96 @@ public class JpaOperations { - private static class KotlinJpaOperations extends AbstractJpaOperations> { - - @Override - protected PanacheQueryImpl createPanacheQuery(EntityManager em, String query, String orderBy, - Object paramsArrayOrMap) { - return new PanacheQueryImpl<>(em, query, orderBy, paramsArrayOrMap); - } - - @Override - protected List list(PanacheQueryImpl query) { - return query.list(); - } - - @Override - protected Stream stream(PanacheQueryImpl query) { - return query.stream(); - } + private static final KotlinJpaOperations delegate = new KotlinJpaOperations(); + public static Query bindParameters(Query query, Object[] params) { + return AbstractJpaOperations.bindParameters(query, params); } - private static final KotlinJpaOperations delegate = new KotlinJpaOperations(); - // // Instance methods - public static void persist(Object entity) { - delegate.persist(entity); + public static Query bindParameters(Query query, Map params) { + return AbstractJpaOperations.bindParameters(query, params); } - public static void persist(EntityManager em, Object entity) { - delegate.persist(em, entity); + public static long count(Class entityClass) { + return delegate.count(entityClass); } - public static void persist(Iterable entities) { - delegate.persist(entities); + public static long count(Class entityClass, String query, Object... params) { + return delegate.count(entityClass, query, params); } - public static void persist(Object firstEntity, Object... entities) { - delegate.persist(firstEntity, entities); + public static long count(Class entityClass, String query, Map params) { + return delegate.count(entityClass, query, params); } - public static void persist(Stream entities) { - delegate.persist(entities); + public static long count(Class entityClass, String query, Parameters params) { + return delegate.count(entityClass, query, params); } - public static void delete(Object entity) { - delegate.delete(entity); + static String createFindQuery(Class entityClass, String query, int paramCount) { + return delegate.createFindQuery(entityClass, query, paramCount); } - public static boolean isPersistent(Object entity) { - return delegate.isPersistent(entity); + public static void delete(Object entity) { + delegate.delete(entity); } - public static void flush() { - delegate.flush(); + public static long delete(Class entityClass, String query, Object... params) { + return delegate.delete(entityClass, query, params); } // // Private stuff - public static EntityManager getEntityManager() { - return delegate.getEntityManager(); + public static long delete(Class entityClass, String query, Map params) { + return delegate.delete(entityClass, query, params); } - public static TransactionManager getTransactionManager() { - return delegate.getTransactionManager(); + public static long delete(Class entityClass, String query, Parameters params) { + return delegate.delete(entityClass, query, params); } - public static Query bindParameters(Query query, Object[] params) { - return AbstractJpaOperations.bindParameters(query, params); + public static long deleteAll(Class entityClass) { + return delegate.deleteAll(entityClass); } - public static Query bindParameters(Query query, Map params) { - return AbstractJpaOperations.bindParameters(query, params); + public static boolean deleteById(Class entityClass, Object id) { + return delegate.deleteById(entityClass, id); } - static int paramCount(Object[] params) { - return delegate.paramCount(params); + public static int executeUpdate(String query, Object... params) { + return delegate.executeUpdate(query, params); } - static int paramCount(Map params) { - return delegate.paramCount(params); + public static int executeUpdate(String query, Map params) { + return delegate.executeUpdate(query, params); } - // - // private static String getEntityName(Class entityClass) { - // return delegate.getEntityName(entityClass); - // } - // - static String createFindQuery(Class entityClass, String query, int paramCount) { - return delegate.createFindQuery(entityClass, query, paramCount); + public static int executeUpdate(Class entityClass, String query, Object... params) { + return delegate.executeUpdate(entityClass, query, params); } - // - // static boolean isNamedQuery(String query) { - // return delegate.isNamedQuery(query); - // } - // - // private static String createCountQuery(Class entityClass, String query, int paramCount) { - // return delegate.createCountQuery(entityClass, query, paramCount); - // } - // - // private static String createUpdateQuery(Class entityClass, String query, int paramCount) { - // return delegate.createUpdateQuery(entityClass, query, paramCount); - // } - // - // private static String createDeleteQuery(Class entityClass, String query, int paramCount) { - // return delegate.createDeleteQuery(entityClass, query, paramCount); - // } - public static String toOrderBy(Sort sort) { - return delegate.toOrderBy(sort); + public static int executeUpdate(Class entityClass, String query, Map params) { + return delegate.executeUpdate(entityClass, query, params); } - // - // Queries - - public static Object findById(Class entityClass, Object id) { - return delegate.findById(entityClass, id); + public static boolean exists(Class entityClass) { + return delegate.exists(entityClass); } - public static Object findById(Class entityClass, Object id, LockModeType lockModeType) { - return delegate.findById(entityClass, id, lockModeType); + public static boolean exists(Class entityClass, String query, Object... params) { + return delegate.exists(entityClass, query, params); } - public static Optional findByIdOptional(Class entityClass, Object id) { - return delegate.findByIdOptional(entityClass, id); + public static boolean exists(Class entityClass, String query, Map params) { + return delegate.exists(entityClass, query, params); } - public static Optional findByIdOptional(Class entityClass, Object id, LockModeType lockModeType) { - return delegate.findByIdOptional(entityClass, id, lockModeType); + public static boolean exists(Class entityClass, String query, Parameters params) { + return delegate.exists(entityClass, query, params); } public static PanacheQuery find(Class entityClass, String query, Object... params) { @@ -173,148 +133,148 @@ public static PanacheQuery find(Class entityClass, String query, Sort sort return delegate.find(entityClass, query, sort, params); } - public static List list(Class entityClass, String query, Object... params) { - return delegate.list(entityClass, query, params); + public static PanacheQuery findAll(Class entityClass) { + return delegate.findAll(entityClass); } - public static List list(Class entityClass, String query, Sort sort, Object... params) { - return delegate.list(entityClass, query, sort, params); + public static PanacheQuery findAll(Class entityClass, Sort sort) { + return delegate.findAll(entityClass, sort); } - public static List list(Class entityClass, String query, Map params) { - return delegate.list(entityClass, query, params); + public static Object findById(Class entityClass, Object id) { + return delegate.findById(entityClass, id); } - public static List list(Class entityClass, String query, Sort sort, Map params) { - return delegate.list(entityClass, query, sort, params); + public static Object findById(Class entityClass, Object id, LockModeType lockModeType) { + return delegate.findById(entityClass, id, lockModeType); } - public static List list(Class entityClass, String query, Parameters params) { - return delegate.list(entityClass, query, params); + public static Optional findByIdOptional(Class entityClass, Object id) { + return delegate.findByIdOptional(entityClass, id); } - public static List list(Class entityClass, String query, Sort sort, Parameters params) { - return delegate.list(entityClass, query, sort, params); + public static Optional findByIdOptional(Class entityClass, Object id, LockModeType lockModeType) { + return delegate.findByIdOptional(entityClass, id, lockModeType); } - public static Stream stream(Class entityClass, String query, Object... params) { - return delegate.stream(entityClass, query, params); + public static void flush() { + delegate.flush(); } - public static Stream stream(Class entityClass, String query, Sort sort, Object... params) { - return delegate.stream(entityClass, query, sort, params); + public static EntityManager getEntityManager() { + return delegate.getEntityManager(); } - public static Stream stream(Class entityClass, String query, Map params) { - return delegate.stream(entityClass, query, params); + public static TransactionManager getTransactionManager() { + return delegate.getTransactionManager(); } - public static Stream stream(Class entityClass, String query, Sort sort, Map params) { - return delegate.stream(entityClass, query, sort, params); + public static IllegalStateException implementationInjectionMissing() { + return delegate.implementationInjectionMissing(); } - public static Stream stream(Class entityClass, String query, Parameters params) { - return delegate.stream(entityClass, query, params); + public static boolean isPersistent(Object entity) { + return delegate.isPersistent(entity); } - public static Stream stream(Class entityClass, String query, Sort sort, Parameters params) { - return delegate.stream(entityClass, query, sort, params); + public static List list(Class entityClass, String query, Object... params) { + return delegate.list(entityClass, query, params); } - public static PanacheQuery findAll(Class entityClass) { - return delegate.findAll(entityClass); + public static List list(Class entityClass, String query, Sort sort, Object... params) { + return delegate.list(entityClass, query, sort, params); } - public static PanacheQuery findAll(Class entityClass, Sort sort) { - return delegate.findAll(entityClass, sort); + public static List list(Class entityClass, String query, Map params) { + return delegate.list(entityClass, query, params); } - public static List listAll(Class entityClass) { - return delegate.listAll(entityClass); + public static List list(Class entityClass, String query, Sort sort, Map params) { + return delegate.list(entityClass, query, sort, params); } - public static List listAll(Class entityClass, Sort sort) { - return delegate.listAll(entityClass, sort); + public static List list(Class entityClass, String query, Parameters params) { + return delegate.list(entityClass, query, params); } - public static Stream streamAll(Class entityClass) { - return delegate.streamAll(entityClass); + public static List list(Class entityClass, String query, Sort sort, Parameters params) { + return delegate.list(entityClass, query, sort, params); } - public static Stream streamAll(Class entityClass, Sort sort) { - return delegate.streamAll(entityClass, sort); + public static List listAll(Class entityClass) { + return delegate.listAll(entityClass); } - public static long count(Class entityClass) { - return delegate.count(entityClass); + public static List listAll(Class entityClass, Sort sort) { + return delegate.listAll(entityClass, sort); } - public static long count(Class entityClass, String query, Object... params) { - return delegate.count(entityClass, query, params); + static int paramCount(Object[] params) { + return delegate.paramCount(params); } - public static long count(Class entityClass, String query, Map params) { - return delegate.count(entityClass, query, params); + static int paramCount(Map params) { + return delegate.paramCount(params); } - public static long count(Class entityClass, String query, Parameters params) { - return delegate.count(entityClass, query, params); + public static void persist(Object entity) { + delegate.persist(entity); } - public static boolean exists(Class entityClass) { - return delegate.exists(entityClass); + public static void persist(EntityManager em, Object entity) { + delegate.persist(em, entity); } - public static boolean exists(Class entityClass, String query, Object... params) { - return delegate.exists(entityClass, query, params); + public static void persist(Iterable entities) { + delegate.persist(entities); } - public static boolean exists(Class entityClass, String query, Map params) { - return delegate.exists(entityClass, query, params); + public static void persist(Object firstEntity, Object... entities) { + delegate.persist(firstEntity, entities); } - public static boolean exists(Class entityClass, String query, Parameters params) { - return delegate.exists(entityClass, query, params); + public static void persist(Stream entities) { + delegate.persist(entities); } - public static long deleteAll(Class entityClass) { - return delegate.deleteAll(entityClass); + public static void setRollbackOnly() { + delegate.setRollbackOnly(); } - public static boolean deleteById(Class entityClass, Object id) { - return delegate.deleteById(entityClass, id); + public static Stream stream(Class entityClass, String query, Object... params) { + return delegate.stream(entityClass, query, params); } - public static long delete(Class entityClass, String query, Object... params) { - return delegate.delete(entityClass, query, params); + public static Stream stream(Class entityClass, String query, Sort sort, Object... params) { + return delegate.stream(entityClass, query, sort, params); } - public static long delete(Class entityClass, String query, Map params) { - return delegate.delete(entityClass, query, params); + public static Stream stream(Class entityClass, String query, Map params) { + return delegate.stream(entityClass, query, params); } - public static long delete(Class entityClass, String query, Parameters params) { - return delegate.delete(entityClass, query, params); + public static Stream stream(Class entityClass, String query, Sort sort, Map params) { + return delegate.stream(entityClass, query, sort, params); } - public static IllegalStateException implementationInjectionMissing() { - return delegate.implementationInjectionMissing(); + public static Stream stream(Class entityClass, String query, Parameters params) { + return delegate.stream(entityClass, query, params); } - public static int executeUpdate(String query, Object... params) { - return delegate.executeUpdate(query, params); + public static Stream stream(Class entityClass, String query, Sort sort, Parameters params) { + return delegate.stream(entityClass, query, sort, params); } - public static int executeUpdate(String query, Map params) { - return delegate.executeUpdate(query, params); + public static Stream streamAll(Class entityClass) { + return delegate.streamAll(entityClass); } - public static int executeUpdate(Class entityClass, String query, Object... params) { - return delegate.executeUpdate(entityClass, query, params); + public static Stream streamAll(Class entityClass, Sort sort) { + return delegate.streamAll(entityClass, sort); } - public static int executeUpdate(Class entityClass, String query, Map params) { - return delegate.executeUpdate(entityClass, query, params); + public static String toOrderBy(Sort sort) { + return delegate.toOrderBy(sort); } public static int update(Class entityClass, String query, Map params) { @@ -329,8 +289,24 @@ public static int update(Class entityClass, String query, Object... params) { return delegate.update(entityClass, query, params); } - public static void setRollbackOnly() { - delegate.setRollbackOnly(); + private static class KotlinJpaOperations extends AbstractJpaOperations> { + + @Override + protected PanacheQueryImpl createPanacheQuery(EntityManager em, String query, String orderBy, + Object paramsArrayOrMap) { + return new PanacheQueryImpl<>(em, query, orderBy, paramsArrayOrMap); + } + + @Override + protected List list(PanacheQueryImpl query) { + return query.list(); + } + + @Override + protected Stream stream(PanacheQueryImpl query) { + return query.stream(); + } + } } diff --git a/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/java/io/quarkus/hibernate/orm/panache/kotlin/runtime/PanacheQueryImpl.java b/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/java/io/quarkus/hibernate/orm/panache/kotlin/runtime/PanacheQueryImpl.java index 6069b665f297c..e9866f8399c1a 100644 --- a/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/java/io/quarkus/hibernate/orm/panache/kotlin/runtime/PanacheQueryImpl.java +++ b/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/java/io/quarkus/hibernate/orm/panache/kotlin/runtime/PanacheQueryImpl.java @@ -3,7 +3,6 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.stream.Stream; import javax.persistence.EntityManager; @@ -40,42 +39,42 @@ public PanacheQuery project(Class type) { @Override public PanacheQuery page(@NotNull Page page) { delegate.page(page); - return (PanacheQuery) this; + return this; } @NotNull @Override public PanacheQuery page(int pageIndex, int pageSize) { delegate.page(pageIndex, pageSize); - return (PanacheQuery) this; + return this; } @NotNull @Override public PanacheQuery nextPage() { delegate.nextPage(); - return (PanacheQuery) this; + return this; } @NotNull @Override public PanacheQuery previousPage() { delegate.previousPage(); - return (PanacheQuery) this; + return this; } @NotNull @Override public PanacheQuery firstPage() { delegate.firstPage(); - return (PanacheQuery) this; + return this; } @NotNull @Override public PanacheQuery lastPage() { delegate.lastPage(); - return (PanacheQuery) this; + return this; } @Override @@ -103,28 +102,28 @@ public Page page() { @Override public PanacheQuery range(int startIndex, int lastIndex) { delegate.range(startIndex, lastIndex); - return (PanacheQuery) this; + return this; } @NotNull @Override public PanacheQuery withLock(@NotNull LockModeType lockModeType) { delegate.withLock(lockModeType); - return (PanacheQuery) this; + return this; } @NotNull @Override public PanacheQuery withHint(@NotNull String hintName, @NotNull Object value) { delegate.withHint(hintName, value); - return (PanacheQuery) this; + return this; } @NotNull @Override public PanacheQuery filter(@NotNull String filterName, @NotNull Parameters parameters) { delegate.filter(filterName, parameters.map()); - return (PanacheQuery) this; + return this; } @SuppressWarnings({ "rawtypes", "unchecked" }) @@ -132,14 +131,14 @@ public PanacheQuery filter(@NotNull String filterName, @NotNull Paramete @Override public PanacheQuery filter(@NotNull String filterName, @NotNull Map parameters) { delegate.filter(filterName, (Map) parameters); - return (PanacheQuery) this; + return this; } @NotNull @Override public PanacheQuery filter(@NotNull String filterName) { delegate.filter(filterName, Collections.emptyMap()); - return (PanacheQuery) this; + return this; } // Results @@ -166,21 +165,9 @@ public Entity firstResult() { return delegate.firstResult(); } - @NotNull - @Override - public Optional firstResultOptional() { - return delegate.firstResultOptional(); - } - @NotNull @Override public Entity singleResult() { return delegate.singleResult(); } - - @NotNull - @Override - public Optional singleResultOptional() { - return delegate.singleResultOptional(); - } } diff --git a/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/kotlin/io/quarkus/hibernate/orm/panache/kotlin/PanacheCompanion.kt b/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/kotlin/io/quarkus/hibernate/orm/panache/kotlin/PanacheCompanion.kt index ebc741a028220..707f32647e9e7 100644 --- a/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/kotlin/io/quarkus/hibernate/orm/panache/kotlin/PanacheCompanion.kt +++ b/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/kotlin/io/quarkus/hibernate/orm/panache/kotlin/PanacheCompanion.kt @@ -7,6 +7,12 @@ import io.quarkus.panache.common.impl.GenerateBridge import java.util.stream.Stream import javax.persistence.LockModeType +/** + * Defines methods to be used via the companion objects of entities. + * + * @param Entity the entity type + * @param Id the ID type + */ interface PanacheCompanion { /** @@ -16,7 +22,7 @@ interface PanacheCompanion { * @return the entity found, or `null` if not found. */ @GenerateBridge(targetReturnTypeErased = true) - fun findById(id: Id): Entity = injectionMissing() + fun findById(id: Id): Entity? = injectionMissing() /** * Find an entity of this type by ID and lock it. @@ -26,19 +32,17 @@ interface PanacheCompanion { * @return the entity found, or `null` if not found. */ @GenerateBridge(targetReturnTypeErased = true) - fun findById(id: Id, lockModeType: LockModeType): Entity = injectionMissing() + fun findById(id: Id, lockModeType: LockModeType): Entity? = injectionMissing() /** * Find entities using a query, with optional indexed parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param params optional sequence of indexed parameters * @return a new [PanacheQuery] instance for the given query - * @see .find - * @see .find - * @see .find - * @see .list - * @see .stream + * @see [PanacheCompanion.find] + * @see [PanacheCompanion.list] + * @see [PanacheCompanion.stream] */ @GenerateBridge fun find(query: String, vararg params: Any): PanacheQuery = injectionMissing() @@ -46,15 +50,13 @@ interface PanacheCompanion { /** * Find entities using a query and the given sort options, with optional indexed parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param sort the sort strategy to use * @param params optional sequence of indexed parameters * @return a new [PanacheQuery] instance for the given query - * @see .find - * @see .find - * @see .find - * @see .list - * @see .stream + * @see [PanacheCompanion.find] + * @see [PanacheCompanion.list] + * @see [PanacheCompanion.stream] */ @GenerateBridge fun find(query: String, sort: Sort, vararg params: Any): PanacheQuery = injectionMissing() @@ -62,14 +64,12 @@ interface PanacheCompanion { /** * Find entities using a query, with named parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param params [Map] of named parameters * @return a new [PanacheQuery] instance for the given query - * @see .find - * @see .find - * @see .find - * @see .list - * @see .stream + * @see [PanacheCompanion.find] + * @see [PanacheCompanion.list] + * @see [PanacheCompanion.stream] */ @GenerateBridge fun find(query: String, params: Map): PanacheQuery = injectionMissing() @@ -77,15 +77,13 @@ interface PanacheCompanion { /** * Find entities using a query and the given sort options, with named parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param sort the sort strategy to use * @param params [Map] of indexed parameters * @return a new [PanacheQuery] instance for the given query - * @see .find - * @see .find - * @see .find - * @see .list - * @see .stream + * @see [PanacheCompanion.find] + * @see [PanacheCompanion.list] + * @see [PanacheCompanion.stream] */ @GenerateBridge fun find(query: String, sort: Sort, params: Map): PanacheQuery = injectionMissing() @@ -93,14 +91,12 @@ interface PanacheCompanion { /** * Find entities using a query, with named parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] - * @param params [Parameters] of named parameters + * @param query a query string + * @param params Parameters of named parameters * @return a new [PanacheQuery] instance for the given query - * @see .find - * @see .find - * @see .find - * @see .list - * @see .stream + * @see [PanacheCompanion.find] + * @see [PanacheCompanion.list] + * @see [PanacheCompanion.stream] */ @GenerateBridge fun find(query: String, params: Parameters): PanacheQuery = injectionMissing() @@ -108,15 +104,13 @@ interface PanacheCompanion { /** * Find entities using a query and the given sort options, with named parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param sort the sort strategy to use - * @param params [Parameters] of indexed parameters + * @param params Parameters of indexed parameters * @return a new [PanacheQuery] instance for the given query - * @see .find - * @see .find - * @see .find - * @see .list - * @see .stream + * @see [PanacheCompanion.find] + * @see [PanacheCompanion.list] + * @see [PanacheCompanion.stream] */ @GenerateBridge fun find(query: String, sort: Sort, params: Parameters): PanacheQuery = injectionMissing() @@ -125,9 +119,9 @@ interface PanacheCompanion { * Find all entities of this type. * * @return a new [PanacheQuery] instance to find all entities of this type. - * @see .findAll - * @see .listAll - * @see .streamAll + * @see [PanacheCompanion.findAll] + * @see [PanacheCompanion.listAll] + * @see [PanacheCompanion.streamAll] */ @GenerateBridge fun findAll(): PanacheQuery = injectionMissing() @@ -137,9 +131,9 @@ interface PanacheCompanion { * * @param sort the sort order to use * @return a new [PanacheQuery] instance to find all entities of this type. - * @see .findAll - * @see .listAll - * @see .streamAll + * @see [PanacheCompanion.findAll] + * @see [PanacheCompanion.listAll] + * @see [PanacheCompanion.streamAll] */ @GenerateBridge fun findAll(sort: Sort): PanacheQuery = injectionMissing() @@ -148,14 +142,12 @@ interface PanacheCompanion { * Find entities matching a query, with optional indexed parameters. * This method is a shortcut for `find(query, params).list()`. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param params optional sequence of indexed parameters * @return a [List] containing all results, without paging - * @see .list - * @see .list - * @see .list - * @see .find - * @see .stream + * @see [PanacheCompanion.list] + * @see [PanacheCompanion.find] + * @see [PanacheCompanion.stream] */ @GenerateBridge fun list(query: String, vararg params: Any): List = injectionMissing() @@ -164,15 +156,13 @@ interface PanacheCompanion { * Find entities matching a query and the given sort options, with optional indexed parameters. * This method is a shortcut for `find(query, sort, params).list()`. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param sort the sort strategy to use * @param params optional sequence of indexed parameters * @return a [List] containing all results, without paging - * @see .list - * @see .list - * @see .list - * @see .find - * @see .stream + * @see [PanacheCompanion.list] + * @see [PanacheCompanion.find] + * @see [PanacheCompanion.stream] */ @GenerateBridge fun list(query: String, sort: Sort, vararg params: Any): List = injectionMissing() @@ -181,14 +171,12 @@ interface PanacheCompanion { * Find entities matching a query, with named parameters. * This method is a shortcut for `find(query, params).list()`. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param params [Map] of named parameters * @return a [List] containing all results, without paging - * @see .list - * @see .list - * @see .list - * @see .find - * @see .stream + * @see [PanacheCompanion.list] + * @see [PanacheCompanion.find] + * @see [PanacheCompanion.stream] */ @GenerateBridge fun list(query: String, params: Map): List = injectionMissing() @@ -197,15 +185,13 @@ interface PanacheCompanion { * Find entities matching a query and the given sort options, with named parameters. * This method is a shortcut for `find(query, sort, params).list()`. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param sort the sort strategy to use * @param params [Map] of indexed parameters * @return a [List] containing all results, without paging - * @see .list - * @see .list - * @see .list - * @see .find - * @see .stream + * @see [PanacheCompanion.list] + * @see [PanacheCompanion.find] + * @see [PanacheCompanion.stream] */ @GenerateBridge fun list(query: String, sort: Sort, params: Map): List = injectionMissing() @@ -214,14 +200,12 @@ interface PanacheCompanion { * Find entities matching a query, with named parameters. * This method is a shortcut for `find(query, params).list()`. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] - * @param params [Parameters] of named parameters + * @param query a query string + * @param params Parameters of named parameters * @return a [List] containing all results, without paging - * @see .list - * @see .list - * @see .list - * @see .find - * @see .stream + * @see [PanacheCompanion.list] + * @see [PanacheCompanion.find] + * @see [PanacheCompanion.stream] */ @GenerateBridge fun list(query: String, params: Parameters): List = injectionMissing() @@ -230,15 +214,13 @@ interface PanacheCompanion { * Find entities matching a query and the given sort options, with named parameters. * This method is a shortcut for `find(query, sort, params).list()`. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param sort the sort strategy to use - * @param params [Parameters] of indexed parameters + * @param params Parameters of indexed parameters * @return a [List] containing all results, without paging - * @see .list - * @see .list - * @see .list - * @see .find - * @see .stream + * @see [PanacheCompanion.list] + * @see [PanacheCompanion.find] + * @see [PanacheCompanion.stream] */ @GenerateBridge fun list(query: String, sort: Sort, params: Parameters): List = injectionMissing() @@ -248,9 +230,9 @@ interface PanacheCompanion { * This method is a shortcut for `findAll().list()`. * * @return a [List] containing all results, without paging - * @see .listAll - * @see .findAll - * @see .streamAll + * @see [PanacheCompanion.listAll] + * @see [PanacheCompanion.findAll] + * @see [PanacheCompanion.streamAll] */ @GenerateBridge fun listAll(): List = injectionMissing() @@ -261,9 +243,9 @@ interface PanacheCompanion { * * @param sort the sort order to use * @return a [List] containing all results, without paging - * @see .listAll - * @see .findAll - * @see .streamAll + * @see [PanacheCompanion.listAll] + * @see [PanacheCompanion.findAll] + * @see [PanacheCompanion.streamAll] */ @GenerateBridge fun listAll(sort: Sort): List = injectionMissing() @@ -274,14 +256,12 @@ interface PanacheCompanion { * It requires a transaction to work. * Without a transaction, the underlying cursor can be closed before the end of the stream. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param params optional sequence of indexed parameters - * @return a [Stream] containing all results, without paging - * @see .stream - * @see .stream - * @see .stream - * @see .find - * @see .list + * @return a Stream containing all results, without paging + * @see [PanacheCompanion.stream] + * @see [PanacheCompanion.find] + * @see [PanacheCompanion.list] */ @GenerateBridge fun stream(query: String, vararg params: Any): Stream = injectionMissing() @@ -292,15 +272,13 @@ interface PanacheCompanion { * It requires a transaction to work. * Without a transaction, the underlying cursor can be closed before the end of the stream. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param sort the sort strategy to use * @param params optional sequence of indexed parameters - * @return a [Stream] containing all results, without paging - * @see .stream - * @see .stream - * @see .stream - * @see .find - * @see .list + * @return a Stream containing all results, without paging + * @see [PanacheCompanion.stream] + * @see [PanacheCompanion.find] + * @see [PanacheCompanion.list] */ @GenerateBridge fun stream(query: String, sort: Sort, vararg params: Any): Stream = injectionMissing() @@ -311,14 +289,12 @@ interface PanacheCompanion { * It requires a transaction to work. * Without a transaction, the underlying cursor can be closed before the end of the stream. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param params [Map] of named parameters - * @return a [Stream] containing all results, without paging - * @see .stream - * @see .stream - * @see .stream - * @see .find - * @see .list + * @return a Stream containing all results, without paging + * @see [PanacheCompanion.stream] + * @see [PanacheCompanion.find] + * @see [PanacheCompanion.list] */ @GenerateBridge fun stream(query: String, params: Map): Stream = injectionMissing() @@ -329,15 +305,13 @@ interface PanacheCompanion { * It requires a transaction to work. * Without a transaction, the underlying cursor can be closed before the end of the stream. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param sort the sort strategy to use * @param params [Map] of indexed parameters - * @return a [Stream] containing all results, without paging - * @see .stream - * @see .stream - * @see .stream - * @see .find - * @see .list + * @return a Stream containing all results, without paging + * @see [PanacheCompanion.stream] + * @see [PanacheCompanion.find] + * @see [PanacheCompanion.list] */ @GenerateBridge fun stream(query: String, sort: Sort, params: Map): Stream = injectionMissing() @@ -348,14 +322,12 @@ interface PanacheCompanion { * It requires a transaction to work. * Without a transaction, the underlying cursor can be closed before the end of the stream. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] - * @param params [Parameters] of named parameters - * @return a [Stream] containing all results, without paging - * @see .stream - * @see .stream - * @see .stream - * @see .find - * @see .list + * @param query a query string + * @param params Parameters of named parameters + * @return a Stream containing all results, without paging + * @see [PanacheCompanion.stream] + * @see [PanacheCompanion.find] + * @see [PanacheCompanion.list] */ @GenerateBridge fun stream(query: String, params: Parameters): Stream = injectionMissing() @@ -366,15 +338,13 @@ interface PanacheCompanion { * It requires a transaction to work. * Without a transaction, the underlying cursor can be closed before the end of the stream. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param sort the sort strategy to use - * @param params [Parameters] of indexed parameters - * @return a [Stream] containing all results, without paging - * @see .stream - * @see .stream - * @see .stream - * @see .find - * @see .list + * @param params Parameters of indexed parameters + * @return a Stream containing all results, without paging + * @see [PanacheCompanion.stream] + * @see [PanacheCompanion.find] + * @see [PanacheCompanion.list] */ @GenerateBridge fun stream(query: String, sort: Sort, params: Parameters): Stream = injectionMissing() @@ -385,10 +355,10 @@ interface PanacheCompanion { * It requires a transaction to work. * Without a transaction, the underlying cursor can be closed before the end of the stream. * - * @return a [Stream] containing all results, without paging - * @see .streamAll - * @see .findAll - * @see .listAll + * @return a Stream containing all results, without paging + * @see [PanacheCompanion.streamAll] + * @see [PanacheCompanion.findAll] + * @see [PanacheCompanion.listAll] */ @GenerateBridge fun streamAll(): Stream = injectionMissing() @@ -400,10 +370,10 @@ interface PanacheCompanion { * Without a transaction, the underlying cursor can be closed before the end of the stream. * * @param sort the sort order to use - * @return a [Stream] containing all results, without paging - * @see .streamAll - * @see .findAll - * @see .listAll + * @return a Stream containing all results, without paging + * @see [PanacheCompanion.streamAll] + * @see [PanacheCompanion.findAll] + * @see [PanacheCompanion.listAll] */ @GenerateBridge fun streamAll(sort: Sort): Stream = injectionMissing() @@ -412,9 +382,7 @@ interface PanacheCompanion { * Counts the number of this type of entity in the database. * * @return the number of this type of entity in the database. - * @see .count - * @see .count - * @see .count + * @see [PanacheCompanion.count] */ @GenerateBridge fun count(): Long = injectionMissing() @@ -422,12 +390,10 @@ interface PanacheCompanion { /** * Counts the number of this type of entity matching the given query, with optional indexed parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param params optional sequence of indexed parameters * @return the number of entities counted. - * @see .count - * @see .count - * @see .count + * @see [PanacheCompanion.count] */ @GenerateBridge fun count(query: String, vararg params: Any): Long = injectionMissing() @@ -435,12 +401,10 @@ interface PanacheCompanion { /** * Counts the number of this type of entity matching the given query, with named parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param params [Map] of named parameters * @return the number of entities counted. - * @see .count - * @see .count - * @see .count + * @see [PanacheCompanion.count] */ @GenerateBridge fun count(query: String, params: Map): Long = injectionMissing() @@ -448,12 +412,10 @@ interface PanacheCompanion { /** * Counts the number of this type of entity matching the given query, with named parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] - * @param params [Parameters] of named parameters + * @param query a query string + * @param params Parameters of named parameters * @return the number of entities counted. - * @see .count - * @see .count - * @see .count + * @see [PanacheCompanion.count] */ @GenerateBridge fun count(query: String, params: Parameters): Long = injectionMissing() @@ -462,9 +424,7 @@ interface PanacheCompanion { * Delete all entities of this type from the database. * * @return the number of entities deleted. - * @see .delete - * @see .delete - * @see .delete + * @see [PanacheCompanion.delete] */ @GenerateBridge fun deleteAll(): Long = injectionMissing() @@ -472,34 +432,23 @@ interface PanacheCompanion { /** * Delete all entities of this type matching the given query, with optional indexed parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param params optional sequence of indexed parameters * @return the number of entities deleted. - * @see .deleteAll - * @see .delete - * @see .delete + * @see [PanacheCompanion.deleteAll] + * @see [PanacheCompanion.delete] */ @GenerateBridge fun delete(query: String, vararg params: Any): Long = injectionMissing() - /** - * Delete an entity of this type by ID. - * - * @param id the ID of the entity to delete. - * @return false if the entity was not deleted (not found). - */ - @GenerateBridge - fun deleteById(id: Id): Boolean = throw JpaOperations.implementationInjectionMissing() - /** * Delete all entities of this type matching the given query, with named parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param params [Map] of named parameters * @return the number of entities deleted. - * @see .deleteAll - * @see .delete - * @see .delete + * @see [PanacheCompanion.deleteAll] + * @see [PanacheCompanion.delete] */ @GenerateBridge fun delete(query: String, params: Map): Long = injectionMissing() @@ -507,23 +456,29 @@ interface PanacheCompanion { /** * Delete all entities of this type matching the given query, with named parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] - * @param params [Parameters] of named parameters + * @param query a query string + * @param params Parameters of named parameters * @return the number of entities deleted. - * @see .deleteAll - * @see .delete - * @see .delete + * @see [PanacheCompanion.deleteAll] + * @see [PanacheCompanion.delete] */ @GenerateBridge fun delete(query: String, params: Parameters): Long = injectionMissing() + /** + * Delete an entity of this type by ID. + * + * @param id the ID of the entity to delete. + * @return false if the entity was not deleted (not found). + */ + @GenerateBridge + fun deleteById(id: Id): Boolean = throw JpaOperations.implementationInjectionMissing() + /** * Persist all given entities. * * @param entities the entities to persist - * @see .persist - * @see .persist - * @see .persist + * @see [PanacheCompanion.persist] */ fun persist(entities: Iterable) { JpaOperations.persist(entities) @@ -533,9 +488,7 @@ interface PanacheCompanion { * Persist all given entities. * * @param entities the entities to persist - * @see .persist - * @see .persist - * @see .persist + * @see [PanacheCompanion.persist] */ fun persist(entities: Stream) { JpaOperations.persist(entities) @@ -545,22 +498,19 @@ interface PanacheCompanion { * Persist all given entities. * * @param entities the entities to persist - * @see .persist - * @see .persist - * @see .persist + * @see [PanacheCompanion.persist] */ - fun persist(firstEntity: Any, vararg entities: Any) { + fun persist(firstEntity: Entity, vararg entities: Entity) { JpaOperations.persist(firstEntity, *entities) } /** - * Update all entities of this type matching the given query, with mandatory indexed parameters. + * Update all entities of this type matching the given query, with optional indexed parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param params optional sequence of indexed parameters * @return the number of entities updated. - * @see .update - * @see .update + * @see [PanacheCompanion.update] */ @GenerateBridge fun update(query: String, vararg params: Any): Int = injectionMissing() @@ -568,11 +518,10 @@ interface PanacheCompanion { /** * Update all entities of this type matching the given query, with named parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param params [Map] of named parameters * @return the number of entities updated. - * @see .update - * @see .update + * @see [PanacheCompanion.update] */ @GenerateBridge fun update(query: String, params: Map): Int = injectionMissing() @@ -580,13 +529,11 @@ interface PanacheCompanion { /** * Update all entities of this type matching the given query, with named parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] - * @param params [Parameters] of named parameters + * @param query a query string + * @param params Parameters of named parameters * @return the number of entities updated. - * @see .update - * @see .update + * @see [PanacheCompanion.update] */ @GenerateBridge fun update(query: String, params: Parameters): Int = injectionMissing() } - diff --git a/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/kotlin/io/quarkus/hibernate/orm/panache/kotlin/PanacheEntity.kt b/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/kotlin/io/quarkus/hibernate/orm/panache/kotlin/PanacheEntity.kt index 0118318f72c98..5e0c97e7c7840 100644 --- a/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/kotlin/io/quarkus/hibernate/orm/panache/kotlin/PanacheEntity.kt +++ b/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/kotlin/io/quarkus/hibernate/orm/panache/kotlin/PanacheEntity.kt @@ -5,12 +5,35 @@ import javax.persistence.GeneratedValue import javax.persistence.Id import javax.persistence.MappedSuperclass +/** + * Represents an entity with a generated ID field [id] of type [Long]. If your + * Hibernate entities extend this class they gain the ID field and auto-generated accessors + * to all their public fields (unless annotated with [Transient]), as well as all + * the useful methods from [PanacheEntityBase]. + *

+ * If you want a custom ID type or strategy, you can directly extend [PanacheEntityBase] + * instead, and write your own ID field. You will still get auto-generated accessors and + * all the useful methods. + * + * @see PanacheEntityBase + */ @MappedSuperclass open class PanacheEntity: PanacheEntityBase { + /** + * The auto-generated ID field. This field is set by Hibernate ORM when this entity + * is persisted. + * + * @see [PanacheEntity.persist] + */ @Id @GeneratedValue @JvmField var id: Long? = null - override fun toString() = this.javaClass.simpleName + "<" + id + ">" + /** + * Default toString() implementation + * + * @return the class type and ID type + */ + override fun toString() = "${javaClass.simpleName}<$id>" } diff --git a/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/kotlin/io/quarkus/hibernate/orm/panache/kotlin/PanacheEntityBase.kt b/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/kotlin/io/quarkus/hibernate/orm/panache/kotlin/PanacheEntityBase.kt index a7683296d3d62..5bb19bc9567b5 100644 --- a/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/kotlin/io/quarkus/hibernate/orm/panache/kotlin/PanacheEntityBase.kt +++ b/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/kotlin/io/quarkus/hibernate/orm/panache/kotlin/PanacheEntityBase.kt @@ -4,19 +4,64 @@ import com.fasterxml.jackson.annotation.JsonIgnore import io.quarkus.hibernate.orm.panache.kotlin.runtime.JpaOperations import javax.json.bind.annotation.JsonbTransient +/** + * Represents an entity. If your Hibernate entities extend this class they gain auto-generated accessors + * to all their public fields (unless annotated with [Transient]), as well as a lot of useful + * methods. Unless you have a custom ID strategy, you should not extend this class directly but extend + * [PanacheEntity] instead. + * + * @see PanacheEntity + */ interface PanacheEntityBase { + /** + * Returns true if this entity is persistent in the database. If yes, all modifications to + * its persistent fields will be automatically committed to the database at transaction + * commit time. + * + * @return true if this entity is persistent in the database. + */ @JsonbTransient @JsonIgnore - fun isPersistent() = JpaOperations.isPersistent(this) + fun isPersistent(): Boolean = JpaOperations.isPersistent(this) - fun persist() = JpaOperations.persist(this) + /** + * Persist this entity in the database, if not already persisted. This will set your ID field if it is not already set. + * + * @see PanacheEntityBase.isPersistent + * @see PanacheEntityBase.flush + * @see PanacheEntityBase.persistAndFlush + */ + fun persist() { + JpaOperations.persist(this) + } + /** + * Persist this entity in the database, if not already persisted. This will set your ID field if it is not already set. + * Then flushes all pending changes to the database. + * + * @see [PanacheEntityBase.isPersistent] + * @see [PanacheEntityBase.flush] + * @see [PanacheEntityBase.persist] + */ fun persistAndFlush() { JpaOperations.persist(this) JpaOperations.flush() } - fun delete() = JpaOperations.delete(this) + /** + * Delete this entity from the database, if it is already persisted. + * + * @see [PanacheEntityBase.isPersistent] + * @see [PanacheCompanion.deleteAll] + */ + fun delete() { + JpaOperations.delete(this) + } - fun flush() = JpaOperations.flush() + /** + * Flushes all pending changes to the database. + */ + fun flush() { + JpaOperations.flush() + } } diff --git a/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/kotlin/io/quarkus/hibernate/orm/panache/kotlin/PanacheQuery.kt b/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/kotlin/io/quarkus/hibernate/orm/panache/kotlin/PanacheQuery.kt index fc51c79c58e04..e2995b7c8c2e6 100644 --- a/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/kotlin/io/quarkus/hibernate/orm/panache/kotlin/PanacheQuery.kt +++ b/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/kotlin/io/quarkus/hibernate/orm/panache/kotlin/PanacheQuery.kt @@ -2,22 +2,21 @@ package io.quarkus.hibernate.orm.panache.kotlin import io.quarkus.panache.common.Page import io.quarkus.panache.common.Parameters -import java.util.Optional -import java.util.stream.Stream -import javax.persistence.LockModeType -import javax.persistence.NonUniqueResultException import org.hibernate.Session import org.hibernate.annotations.Filter import org.hibernate.annotations.FilterDef +import java.util.stream.Stream +import javax.persistence.LockModeType +import javax.persistence.NonUniqueResultException /** * Interface representing an entity query, which abstracts the use of paging, getting the number of results, and - * operating on [List] or [Stream]. + * operating on [List] or java.util.Stream. * * Instances of this interface cannot mutate the query itself or its parameters: only paging information can be * modified, and instances of this interface can be reused to obtain multiple pages of results. * - * @param The entity type being queried + * @param Entity The entity type being queried */ interface PanacheQuery { /** @@ -26,15 +25,14 @@ interface PanacheQuery { * * @return a new query with the same state as the previous one (params, page, range, lockMode, hints, ...). */ - fun project(type: Class?): PanacheQuery + fun project(type: Class): PanacheQuery /** * Sets the current page. * * @param page the new page * @return this query, modified - * @see .page - * @see .page + * @see [PanacheQuery.page] */ fun page(page: Page): PanacheQuery @@ -44,8 +42,7 @@ interface PanacheQuery { * @param pageIndex the page index * @param pageSize the page size * @return this query, modified - * @see .page - * @see .page + * @see [PanacheQuery.page] */ fun page(pageIndex: Int, pageSize: Int): PanacheQuery @@ -54,7 +51,7 @@ interface PanacheQuery { * * @return this query, modified * @throws UnsupportedOperationException if a page hasn't been set or if a range is already set - * @see .previousPage + * @see [PanacheQuery.previousPage] */ fun nextPage(): PanacheQuery @@ -63,7 +60,7 @@ interface PanacheQuery { * * @return this query, modified * @throws UnsupportedOperationException if a page hasn't been set or if a range is already set - * @see .nextPage + * @see [PanacheQuery.nextPage] */ fun previousPage(): PanacheQuery @@ -72,7 +69,7 @@ interface PanacheQuery { * * @return this query, modified * @throws UnsupportedOperationException if a page hasn't been set or if a range is already set - * @see .lastPage + * @see [PanacheQuery.lastPage] */ fun firstPage(): PanacheQuery @@ -81,8 +78,8 @@ interface PanacheQuery { * * @return this query, modified * @throws UnsupportedOperationException if a page hasn't been set or if a range is already set - * @see .firstPage - * @see .count + * @see [PanacheQuery.firstPage] + * @see [PanacheQuery.count] */ fun lastPage(): PanacheQuery @@ -92,8 +89,8 @@ interface PanacheQuery { * * @return true if there is another page to read * @throws UnsupportedOperationException if a page hasn't been set or if a range is already set - * @see .hasPreviousPage - * @see .count + * @see [PanacheQuery.hasPreviousPage] + * @see [PanacheQuery.count] */ fun hasNextPage(): Boolean @@ -102,7 +99,7 @@ interface PanacheQuery { * * @return true if there is a previous page to read * @throws UnsupportedOperationException if a page hasn't been set or if a range is already set - * @see .hasNextPage + * @see [PanacheQuery.hasNextPage] */ fun hasPreviousPage(): Boolean @@ -120,8 +117,7 @@ interface PanacheQuery { * * @return the current page * @throws UnsupportedOperationException if a page hasn't been set or if a range is already set - * @see .page - * @see .page + * @see [PanacheQuery.page] */ fun page(): Page @@ -161,7 +157,7 @@ interface PanacheQuery { * will modify the session's filters for the duration of obtaining the results (not while building * the query). Enabled filters will be removed from the session afterwards, but no effort is made to * preserve filters enabled on the session outside of this API. - * + * * @param filterName The name of the filter to enable * @param parameters The set of parameters for the filter, if the filter requires parameters * @return this query, modified @@ -177,7 +173,7 @@ interface PanacheQuery { * will modify the session's filters for the duration of obtaining the results (not while building * the query). Enabled filters will be removed from the session afterwards, but no effort is made to * preserve filters enabled on the session outside of this API. - * + * * @param filterName The name of the filter to enable * @param parameters The set of parameters for the filter, if the filter requires parameters * @return this query, modified @@ -193,7 +189,7 @@ interface PanacheQuery { * will modify the session's filters for the duration of obtaining the results (not while building * the query). Enabled filters will be removed from the session afterwards, but no effort is made to * preserve filters enabled on the session outside of this API. - * + * * @param filterName The name of the filter to enable * @return this query, modified */ @@ -201,7 +197,7 @@ interface PanacheQuery { /** * Reads and caches the total number of entities this query operates on. This causes a database - * query with `SELECT COUNT(*)` and a query equivalent to the current query, minus + * query with SELECT COUNT(*) and a query equivalent to the current query, minus * ordering. * * @return the total number of entities this query operates on, cached. @@ -212,19 +208,17 @@ interface PanacheQuery { * Returns the current page of results as a [List]. * * @return the current page of results as a [List]. - * @see .stream - * @see .page - * @see .page + * @see [PanacheQuery.stream] + * @see [PanacheQuery.page] */ fun list(): List /** - * Returns the current page of results as a [Stream]. + * Returns the current page of results as a Stream. * - * @return the current page of results as a [Stream]. - * @see .list - * @see .page - * @see .page + * @return the current page of results as a Stream. + * @see [PanacheQuery.list] + * @see [PanacheQuery.page] */ fun stream(): Stream @@ -233,35 +227,17 @@ interface PanacheQuery { * a single result. * * @return the first result of the current page index, or null if there are no results. - * @see .singleResult + * @see [PanacheQuery.singleResult] */ fun firstResult(): Entity? - /** - * Returns the first result of the current page index. This ignores the current page size to fetch - * a single result. - * - * @return if found, an optional containing the entity, else `Optional.empty()`. - * @see .singleResultOptional - */ - fun firstResultOptional(): Optional - /** * Executes this query for the current page and return a single result. * * @return the single result (throws if there is not exactly one) * @throws NoResultException if there is no result * @throws NonUniqueResultException if there are more than one result - * @see .firstResult - */ - fun singleResult(): Entity - - /** - * Executes this query for the current page and return a single result. - * - * @return if found, an optional containing the entity, else `Optional.empty()`. - * @throws NonUniqueResultException if there are more than one result - * @see .firstResultOptional + * @see [PanacheQuery.firstResult] */ - fun singleResultOptional(): Optional + fun singleResult(): Entity? } \ No newline at end of file diff --git a/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/kotlin/io/quarkus/hibernate/orm/panache/kotlin/PanacheRepository.kt b/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/kotlin/io/quarkus/hibernate/orm/panache/kotlin/PanacheRepository.kt index a116b34c0373b..63387c66abddc 100644 --- a/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/kotlin/io/quarkus/hibernate/orm/panache/kotlin/PanacheRepository.kt +++ b/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/kotlin/io/quarkus/hibernate/orm/panache/kotlin/PanacheRepository.kt @@ -2,9 +2,9 @@ package io.quarkus.hibernate.orm.panache.kotlin /** * Represents a Repository for a specific type of entity `Entity`, with an ID type of `Long`. Implementing this - * repository will gain you the exact same useful methods that are on [PanacheEntityBase]. If you have a custom ID - * strategy, you should implement [PanacheRepositoryBase] instead. + * interface will gain you the exact same useful methods that are on [PanacheEntity] and [PanacheCompanion]. If you + * have a custom ID strategy, you should implement [PanacheRepositoryBase] instead. * - * @param The type of entity to operate on + * @param Entity The type of entity to operate on */ interface PanacheRepository: PanacheRepositoryBase \ No newline at end of file diff --git a/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/kotlin/io/quarkus/hibernate/orm/panache/kotlin/PanacheRepositoryBase.kt b/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/kotlin/io/quarkus/hibernate/orm/panache/kotlin/PanacheRepositoryBase.kt index ee24a6124ed8c..a482eca820ea6 100644 --- a/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/kotlin/io/quarkus/hibernate/orm/panache/kotlin/PanacheRepositoryBase.kt +++ b/extensions/panache/hibernate-orm-panache-kotlin/runtime/src/main/kotlin/io/quarkus/hibernate/orm/panache/kotlin/PanacheRepositoryBase.kt @@ -8,34 +8,31 @@ import java.util.stream.Stream import javax.persistence.LockModeType /** - * Represents a Repository for a specific type of entity `Entity`, with an ID type - * of `Long`. Implementing this repository will gain you the exact same useful methods - * that are on [PanacheEntityBase]. If you have a custom ID strategy, you should - * implement [PanacheRepositoryBase] instead. + * Represents a Repository for a specific type of entity `Entity`, with an ID type of `Id`. Implementing this interface + * will gain you the exact same useful methods that are on [PanacheEntity] and [PanacheCompanion]. * - * @param The type of entity to operate on + * @param Entity The type of entity to operate on + * @param Id The ID type of the entity */ interface PanacheRepositoryBase { /** * Persist the given entity in the database, if not already persisted. * * @param entity the entity to persist. - * @see .isPersistent - * @see .persist - * @see .persist - * @see .persist + * @see [PanacheRepositoryBase.isPersistent] + * @see [PanacheRepositoryBase.persist] */ - fun persist(entity: Entity) = JpaOperations.persist(entity) + fun persist(entity: Entity) { + JpaOperations.persist(entity) + } /** * Persist the given entity in the database, if not already persisted. * Then flushes all pending changes to the database. * * @param entity the entity to persist. - * @see .isPersistent - * @see .persist - * @see .persist - * @see .persist + * @see [PanacheRepositoryBase.isPersistent] + * @see [PanacheRepositoryBase.persist] */ fun persistAndFlush(entity: Entity) { JpaOperations.persist(entity) @@ -46,13 +43,13 @@ interface PanacheRepositoryBase { * Delete the given entity from the database, if it is already persisted. * * @param entity the entity to delete. - * @see .isPersistent - * @see .delete - * @see .delete - * @see .delete - * @see .deleteAll + * @see [PanacheRepositoryBase.isPersistent] + * @see [PanacheRepositoryBase.delete] + * @see [PanacheRepositoryBase.deleteAll] */ - fun delete(entity: Entity) = JpaOperations.delete(entity) + fun delete(entity: Entity) { + JpaOperations.delete(entity) + } /** * Returns true if the given entity is persistent in the database. If yes, all modifications to @@ -67,7 +64,9 @@ interface PanacheRepositoryBase { /** * Flushes all pending changes to the database. */ - fun flush() = JpaOperations.flush() + fun flush() { + JpaOperations.flush() + } /** * Find an entity of this type by ID. @@ -76,7 +75,7 @@ interface PanacheRepositoryBase { * @return the entity found, or `null` if not found. */ @GenerateBridge(targetReturnTypeErased = true) - fun findById(id: Id?): Entity? = injectionMissing() + fun findById(id: Id): Entity? = injectionMissing() /** * Find an entity of this type by ID and lock it. @@ -86,19 +85,17 @@ interface PanacheRepositoryBase { * @return the entity found, or `null` if not found. */ @GenerateBridge(targetReturnTypeErased = true) - fun findById(id: Id?, lockModeType: LockModeType): Entity? = injectionMissing() + fun findById(id: Id, lockModeType: LockModeType): Entity? = injectionMissing() /** * Find entities using a query, with optional indexed parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param params optional sequence of indexed parameters * @return a new [PanacheQuery] instance for the given query - * @see .find - * @see .find - * @see .find - * @see .list - * @see .stream + * @see [PanacheRepositoryBase.find] + * @see [PanacheRepositoryBase.list] + * @see [PanacheRepositoryBase.stream] */ @GenerateBridge fun find(query: String, vararg params: Any): PanacheQuery = injectionMissing() @@ -106,15 +103,13 @@ interface PanacheRepositoryBase { /** * Find entities using a query and the given sort options, with optional indexed parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param sort the sort strategy to use * @param params optional sequence of indexed parameters * @return a new [PanacheQuery] instance for the given query - * @see .find - * @see .find - * @see .find - * @see .list - * @see .stream + * @see [PanacheRepositoryBase.find] + * @see [PanacheRepositoryBase.list] + * @see [PanacheRepositoryBase.stream] */ @GenerateBridge fun find(query: String, sort: Sort, vararg params: Any): PanacheQuery = injectionMissing() @@ -122,14 +117,12 @@ interface PanacheRepositoryBase { /** * Find entities using a query, with named parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param params [Map] of named parameters * @return a new [PanacheQuery] instance for the given query - * @see .find - * @see .find - * @see .find - * @see .list - * @see .stream + * @see [PanacheRepositoryBase.find] + * @see [PanacheRepositoryBase.list] + * @see [PanacheRepositoryBase.stream] */ @GenerateBridge fun find(query: String, params: Map): PanacheQuery = injectionMissing() @@ -137,15 +130,13 @@ interface PanacheRepositoryBase { /** * Find entities using a query and the given sort options, with named parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param sort the sort strategy to use * @param params [Map] of indexed parameters * @return a new [PanacheQuery] instance for the given query - * @see .find - * @see .find - * @see .find - * @see .list - * @see .stream + * @see [PanacheRepositoryBase.find] + * @see [PanacheRepositoryBase.list] + * @see [PanacheRepositoryBase.stream] */ @GenerateBridge fun find(query: String, sort: Sort, params: Map): PanacheQuery = injectionMissing() @@ -153,14 +144,12 @@ interface PanacheRepositoryBase { /** * Find entities using a query, with named parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] - * @param params [Parameters] of named parameters + * @param query a query string + * @param params Parameters of named parameters * @return a new [PanacheQuery] instance for the given query - * @see .find - * @see .find - * @see .find - * @see .list - * @see .stream + * @see [PanacheRepositoryBase.find] + * @see [PanacheRepositoryBase.list] + * @see [PanacheRepositoryBase.stream] */ @GenerateBridge fun find(query: String, params: Parameters): PanacheQuery = injectionMissing() @@ -168,15 +157,13 @@ interface PanacheRepositoryBase { /** * Find entities using a query and the given sort options, with named parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param sort the sort strategy to use - * @param params [Parameters] of indexed parameters + * @param params Parameters of indexed parameters * @return a new [PanacheQuery] instance for the given query - * @see .find - * @see .find - * @see .find - * @see .list - * @see .stream + * @see [PanacheRepositoryBase.find] + * @see [PanacheRepositoryBase.list] + * @see [PanacheRepositoryBase.stream] */ @GenerateBridge fun find(query: String, sort: Sort, params: Parameters): PanacheQuery = injectionMissing() @@ -185,9 +172,9 @@ interface PanacheRepositoryBase { * Find all entities of this type. * * @return a new [PanacheQuery] instance to find all entities of this type. - * @see .findAll - * @see .listAll - * @see .streamAll + * @see [PanacheRepositoryBase.findAll] + * @see [PanacheRepositoryBase.listAll] + * @see [PanacheRepositoryBase.streamAll] */ @GenerateBridge fun findAll(): PanacheQuery = injectionMissing() @@ -197,9 +184,9 @@ interface PanacheRepositoryBase { * * @param sort the sort order to use * @return a new [PanacheQuery] instance to find all entities of this type. - * @see .findAll - * @see .listAll - * @see .streamAll + * @see [PanacheRepositoryBase.findAll] + * @see [PanacheRepositoryBase.listAll] + * @see [PanacheRepositoryBase.streamAll] */ @GenerateBridge fun findAll(sort: Sort): PanacheQuery = injectionMissing() @@ -208,14 +195,12 @@ interface PanacheRepositoryBase { * Find entities matching a query, with optional indexed parameters. * This method is a shortcut for `find(query, params).list()`. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param params optional sequence of indexed parameters * @return a [List] containing all results, without paging - * @see .list - * @see .list - * @see .list - * @see .find - * @see .stream + * @see [PanacheRepositoryBase.list] + * @see [PanacheRepositoryBase.find] + * @see [PanacheRepositoryBase.stream] */ @GenerateBridge fun list(query: String, vararg params: Any): List = injectionMissing() @@ -224,15 +209,13 @@ interface PanacheRepositoryBase { * Find entities matching a query and the given sort options, with optional indexed parameters. * This method is a shortcut for `find(query, sort, params).list()`. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param sort the sort strategy to use * @param params optional sequence of indexed parameters * @return a [List] containing all results, without paging - * @see .list - * @see .list - * @see .list - * @see .find - * @see .stream + * @see [PanacheRepositoryBase.list] + * @see [PanacheRepositoryBase.find] + * @see [PanacheRepositoryBase.stream] */ @GenerateBridge fun list(query: String, sort: Sort, vararg params: Any): List = injectionMissing() @@ -241,14 +224,12 @@ interface PanacheRepositoryBase { * Find entities matching a query, with named parameters. * This method is a shortcut for `find(query, params).list()`. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param params [Map] of named parameters * @return a [List] containing all results, without paging - * @see .list - * @see .list - * @see .list - * @see .find - * @see .stream + * @see [PanacheRepositoryBase.list] + * @see [PanacheRepositoryBase.find] + * @see [PanacheRepositoryBase.stream] */ @GenerateBridge fun list(query: String, params: Map): List = injectionMissing() @@ -257,15 +238,13 @@ interface PanacheRepositoryBase { * Find entities matching a query and the given sort options, with named parameters. * This method is a shortcut for `find(query, sort, params).list()`. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param sort the sort strategy to use * @param params [Map] of indexed parameters * @return a [List] containing all results, without paging - * @see .list - * @see .list - * @see .list - * @see .find - * @see .stream + * @see [PanacheRepositoryBase.list] + * @see [PanacheRepositoryBase.find] + * @see [PanacheRepositoryBase.stream] */ @GenerateBridge fun list(query: String, sort: Sort, params: Map): List = injectionMissing() @@ -274,14 +253,12 @@ interface PanacheRepositoryBase { * Find entities matching a query, with named parameters. * This method is a shortcut for `find(query, params).list()`. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] - * @param params [Parameters] of named parameters + * @param query a query string + * @param params Parameters of named parameters * @return a [List] containing all results, without paging - * @see .list - * @see .list - * @see .list - * @see .find - * @see .stream + * @see [PanacheRepositoryBase.list] + * @see [PanacheRepositoryBase.find] + * @see [PanacheRepositoryBase.stream] */ @GenerateBridge fun list(query: String, params: Parameters): List = injectionMissing() @@ -290,15 +267,13 @@ interface PanacheRepositoryBase { * Find entities matching a query and the given sort options, with named parameters. * This method is a shortcut for `find(query, sort, params).list()`. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param sort the sort strategy to use - * @param params [Parameters] of indexed parameters + * @param params Parameters of indexed parameters * @return a [List] containing all results, without paging - * @see .list - * @see .list - * @see .list - * @see .find - * @see .stream + * @see [PanacheRepositoryBase.list] + * @see [PanacheRepositoryBase.find] + * @see [PanacheRepositoryBase.stream] */ @GenerateBridge fun list(query: String, sort: Sort, params: Parameters): List = injectionMissing() @@ -308,9 +283,9 @@ interface PanacheRepositoryBase { * This method is a shortcut for `findAll().list()`. * * @return a [List] containing all results, without paging - * @see .listAll - * @see .findAll - * @see .streamAll + * @see [PanacheRepositoryBase.listAll] + * @see [PanacheRepositoryBase.findAll] + * @see [PanacheRepositoryBase.streamAll] */ @GenerateBridge fun listAll(): List = injectionMissing() @@ -321,9 +296,9 @@ interface PanacheRepositoryBase { * * @param sort the sort order to use * @return a [List] containing all results, without paging - * @see .listAll - * @see .findAll - * @see .streamAll + * @see [PanacheRepositoryBase.listAll] + * @see [PanacheRepositoryBase.findAll] + * @see [PanacheRepositoryBase.streamAll] */ @GenerateBridge fun listAll(sort: Sort): List = injectionMissing() @@ -334,34 +309,29 @@ interface PanacheRepositoryBase { * It requires a transaction to work. * Without a transaction, the underlying cursor can be closed before the end of the stream. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param params optional sequence of indexed parameters - * @return a [Stream] containing all results, without paging - * @see .stream - * @see .stream - * @see .stream - * @see .find - * @see .list + * @return a Stream containing all results, without paging + * @see [PanacheRepositoryBase.stream] + * @see [PanacheRepositoryBase.find] + * @see [PanacheRepositoryBase.list] */ @GenerateBridge fun stream(query: String, vararg params: Any): Stream = injectionMissing() - /** * Find entities matching a query and the given sort options, with optional indexed parameters. * This method is a shortcut for `find(query, sort, params).stream()`. * It requires a transaction to work. * Without a transaction, the underlying cursor can be closed before the end of the stream. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param sort the sort strategy to use * @param params optional sequence of indexed parameters - * @return a [Stream] containing all results, without paging - * @see .stream - * @see .stream - * @see .stream - * @see .find - * @see .list + * @return a Stream containing all results, without paging + * @see [PanacheRepositoryBase.stream] + * @see [PanacheRepositoryBase.find] + * @see [PanacheRepositoryBase.list] */ @GenerateBridge fun stream(query: String, sort: Sort, vararg params: Any): Stream = injectionMissing() @@ -372,14 +342,12 @@ interface PanacheRepositoryBase { * It requires a transaction to work. * Without a transaction, the underlying cursor can be closed before the end of the stream. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param params [Map] of named parameters - * @return a [Stream] containing all results, without paging - * @see .stream - * @see .stream - * @see .stream - * @see .find - * @see .list + * @return a Stream containing all results, without paging + * @see [PanacheRepositoryBase.stream] + * @see [PanacheRepositoryBase.find] + * @see [PanacheRepositoryBase.list] */ @GenerateBridge fun stream(query: String, params: Map): Stream = injectionMissing() @@ -390,15 +358,13 @@ interface PanacheRepositoryBase { * It requires a transaction to work. * Without a transaction, the underlying cursor can be closed before the end of the stream. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param sort the sort strategy to use * @param params [Map] of indexed parameters - * @return a [Stream] containing all results, without paging - * @see .stream - * @see .stream - * @see .stream - * @see .find - * @see .list + * @return a Stream containing all results, without paging + * @see [PanacheRepositoryBase.stream] + * @see [PanacheRepositoryBase.find] + * @see [PanacheRepositoryBase.list] */ @GenerateBridge fun stream(query: String, sort: Sort, params: Map): Stream = injectionMissing() @@ -409,14 +375,12 @@ interface PanacheRepositoryBase { * It requires a transaction to work. * Without a transaction, the underlying cursor can be closed before the end of the stream. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] - * @param params [Parameters] of named parameters - * @return a [Stream] containing all results, without paging - * @see .stream - * @see .stream - * @see .stream - * @see .find - * @see .list + * @param query a query string + * @param params Parameters of named parameters + * @return a Stream containing all results, without paging + * @see [PanacheRepositoryBase.stream] + * @see [PanacheRepositoryBase.find] + * @see [PanacheRepositoryBase.list] */ @GenerateBridge fun stream(query: String, params: Parameters): Stream = injectionMissing() @@ -427,15 +391,13 @@ interface PanacheRepositoryBase { * It requires a transaction to work. * Without a transaction, the underlying cursor can be closed before the end of the stream. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param sort the sort strategy to use - * @param params [Parameters] of indexed parameters - * @return a [Stream] containing all results, without paging - * @see .stream - * @see .stream - * @see .stream - * @see .find - * @see .list + * @param params Parameters of indexed parameters + * @return a Stream containing all results, without paging + * @see [PanacheRepositoryBase.stream] + * @see [PanacheRepositoryBase.find] + * @see [PanacheRepositoryBase.list] */ @GenerateBridge fun stream(query: String, sort: Sort, params: Parameters): Stream = injectionMissing() @@ -446,35 +408,34 @@ interface PanacheRepositoryBase { * It requires a transaction to work. * Without a transaction, the underlying cursor can be closed before the end of the stream. * - * @return a [Stream] containing all results, without paging - * @see .streamAll - * @see .findAll - * @see .listAll + * @return a Stream containing all results, without paging + * @see [PanacheRepositoryBase.streamAll] + * @see [PanacheRepositoryBase.findAll] + * @see [PanacheRepositoryBase.listAll] */ @GenerateBridge - fun streamAll(sort: Sort): Stream = injectionMissing() + fun streamAll(): Stream = injectionMissing() /** * Find all entities of this type, in the given order. - * This method is a shortcut for `findAll().stream()`. + * This method is a shortcut for `findAll(sort).stream()`. * It requires a transaction to work. * Without a transaction, the underlying cursor can be closed before the end of the stream. * - * @return a [Stream] containing all results, without paging - * @see .streamAll - * @see .findAll - * @see .listAll + * @param sort the sort order to use + * @return a Stream containing all results, without paging + * @see [PanacheRepositoryBase.streamAll] + * @see [PanacheRepositoryBase.findAll] + * @see [PanacheRepositoryBase.listAll] */ @GenerateBridge - fun streamAll(): Stream = injectionMissing() + fun streamAll(sort: Sort): Stream = injectionMissing() /** * Counts the number of this type of entity in the database. * * @return the number of this type of entity in the database. - * @see .count - * @see .count - * @see .count + * @see [PanacheRepositoryBase.count] */ @GenerateBridge fun count(): Long = injectionMissing() @@ -482,12 +443,10 @@ interface PanacheRepositoryBase { /** * Counts the number of this type of entity matching the given query, with optional indexed parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param params optional sequence of indexed parameters * @return the number of entities counted. - * @see .count - * @see .count - * @see .count + * @see [PanacheRepositoryBase.count] */ @GenerateBridge fun count(query: String, vararg params: Any): Long = injectionMissing() @@ -495,12 +454,10 @@ interface PanacheRepositoryBase { /** * Counts the number of this type of entity matching the given query, with named parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param params [Map] of named parameters * @return the number of entities counted. - * @see .count - * @see .count - * @see .count + * @see [PanacheRepositoryBase.count] */ @GenerateBridge fun count(query: String, params: Map): Long = injectionMissing() @@ -508,12 +465,10 @@ interface PanacheRepositoryBase { /** * Counts the number of this type of entity matching the given query, with named parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] - * @param params [Parameters] of named parameters + * @param query a query string + * @param params Parameters of named parameters * @return the number of entities counted. - * @see .count - * @see .count - * @see .count + * @see [PanacheRepositoryBase.count] */ @GenerateBridge fun count(query: String, params: Parameters): Long = injectionMissing() @@ -522,9 +477,7 @@ interface PanacheRepositoryBase { * Delete all entities of this type from the database. * * @return the number of entities deleted. - * @see .delete - * @see .delete - * @see .delete + * @see [PanacheRepositoryBase.delete] */ @GenerateBridge fun deleteAll(): Long = injectionMissing() @@ -532,12 +485,11 @@ interface PanacheRepositoryBase { /** * Delete all entities of this type matching the given query, with optional indexed parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param params optional sequence of indexed parameters * @return the number of entities deleted. - * @see .deleteAll - * @see .delete - * @see .delete + * @see [PanacheRepositoryBase.deleteAll] + * @see [PanacheRepositoryBase.delete] */ @GenerateBridge fun delete(query: String, vararg params: Any): Long = injectionMissing() @@ -545,12 +497,11 @@ interface PanacheRepositoryBase { /** * Delete all entities of this type matching the given query, with named parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param params [Map] of named parameters * @return the number of entities deleted. - * @see .deleteAll - * @see .delete - * @see .delete + * @see [PanacheRepositoryBase.deleteAll] + * @see [PanacheRepositoryBase.delete] */ @GenerateBridge fun delete(query: String, params: Map): Long = injectionMissing() @@ -558,12 +509,11 @@ interface PanacheRepositoryBase { /** * Delete all entities of this type matching the given query, with named parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] - * @param params [Parameters] of named parameters + * @param query a query string + * @param params Parameters of named parameters * @return the number of entities deleted. - * @see .deleteAll - * @see .delete - * @see .delete + * @see [PanacheRepositoryBase.deleteAll] + * @see [PanacheRepositoryBase.delete] */ @GenerateBridge fun delete(query: String, params: Parameters): Long = injectionMissing() @@ -581,40 +531,39 @@ interface PanacheRepositoryBase { * Persist all given entities. * * @param entities the entities to persist - * @see .persist - * @see .persist - * @see .persist + * @see [PanacheRepositoryBase.persist] */ - fun persist(entities: Iterable) = JpaOperations.persist(entities) + fun persist(entities: Iterable) { + JpaOperations.persist(entities) + } /** * Persist all given entities. * * @param entities the entities to persist - * @see .persist - * @see .persist - * @see .persist + * @see [PanacheRepositoryBase.persist] */ - fun persist(entities: Stream) = JpaOperations.persist(entities) + fun persist(entities: Stream) { + JpaOperations.persist(entities) + } /** * Persist all given entities. * * @param entities the entities to persist - * @see .persist - * @see .persist - * @see .persist + * @see [PanacheRepositoryBase.persist] */ - fun persist(firstEntity: Entity, vararg entities: Entity) = JpaOperations.persist(firstEntity, *entities) + fun persist(firstEntity: Entity, vararg entities: Entity) { + JpaOperations.persist(firstEntity, *entities) + } /** * Update all entities of this type matching the given query, with optional indexed parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param params optional sequence of indexed parameters * @return the number of entities updated. - * @see .update - * @see .update + * @see [PanacheRepositoryBase.update] */ @GenerateBridge fun update(query: String, vararg params: Any): Int = injectionMissing() @@ -622,11 +571,10 @@ interface PanacheRepositoryBase { /** * Update all entities of this type matching the given query, with named parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] + * @param query a query string * @param params [Map] of named parameters * @return the number of entities updated. - * @see .update - * @see .update + * @see [PanacheRepositoryBase.update] */ @GenerateBridge fun update(query: String, params: Map): Int = injectionMissing() @@ -634,12 +582,11 @@ interface PanacheRepositoryBase { /** * Update all entities of this type matching the given query, with named parameters. * - * @param query a [query string][io.quarkus.hibernate.orm.panache] - * @param params [Parameters] of named parameters + * @param query a query string + * @param params Parameters of named parameters * @return the number of entities updated. - * @see .update - * @see .update + * @see [PanacheRepositoryBase.update] */ @GenerateBridge fun update(query: String, params: Parameters): Int = injectionMissing() -} \ No newline at end of file +} diff --git a/integration-tests/hibernate-orm-panache-kotlin/src/main/kotlin/io/quarkus/it/panache/kotlin/TestEndpoint.kt b/integration-tests/hibernate-orm-panache-kotlin/src/main/kotlin/io/quarkus/it/panache/kotlin/TestEndpoint.kt index e0a83fb199970..0f742dead73b4 100644 --- a/integration-tests/hibernate-orm-panache-kotlin/src/main/kotlin/io/quarkus/it/panache/kotlin/TestEndpoint.kt +++ b/integration-tests/hibernate-orm-panache-kotlin/src/main/kotlin/io/quarkus/it/panache/kotlin/TestEndpoint.kt @@ -137,7 +137,7 @@ class TestEndpoint { Assertions.assertEquals(person, Person.find("name", "stef").firstResult()) Assertions.assertEquals(person, Person.find("name", "stef").singleResult()) - var byId: Person = Person.findById(person.id!!) + var byId: Person? = person.id?.let { Person.findById(it) } Assertions.assertEquals(person, byId) Assertions.assertEquals("Person<" + person.id + ">", byId.toString()) @@ -145,7 +145,7 @@ class TestEndpoint { // Assertions.assertEquals(person, byId) // Assertions.assertEquals("Person<" + person.id + ">", byId.toString()) - byId = Person.findById(person.id!!, LockModeType.PESSIMISTIC_READ) + byId = person.id?.let { Person.findById(it, LockModeType.PESSIMISTIC_READ) } Assertions.assertEquals(person, byId) Assertions.assertEquals("Person<" + person.id + ">", byId.toString()) @@ -481,12 +481,8 @@ class TestEndpoint { } catch (x: NoResultException) { } - Assertions.assertFalse(personRepository.findAll().singleResultOptional().isPresent()) - Assertions.assertNull(personRepository.findAll().firstResult()) - Assertions.assertFalse(personRepository.findAll().firstResultOptional().isPresent()) - var person: Person = makeSavedPersonDao() Assertions.assertNotNull(person.id) @@ -515,7 +511,6 @@ class TestEndpoint { Assertions.assertEquals(person, personRepository.findAll().firstResult()) Assertions.assertEquals(person, personRepository.findAll().singleResult()) -// Assertions.assertEquals(person, personDao.findAll().singleResultOptional().get()) persons = personRepository.find("name = ?1", "stef").list() Assertions.assertEquals(1, persons.size) @@ -566,20 +561,13 @@ class TestEndpoint { Assertions.assertEquals(person, personRepository.find("name", "stef").firstResult()) Assertions.assertEquals(person, personRepository.find("name", "stef").singleResult()) -// Assertions.assertEquals(person, personDao.find("name", "stef").singleResultOptional().get()) - var byId = personRepository.findById(person.id) + var byId = person.id?.let { personRepository.findById(it) } Assertions.assertEquals(person, byId) -// byId = personDao.findByIdOptional(person.id).get() -// Assertions.assertEquals(person, byId) - - byId = personRepository.findById(person.id, LockModeType.PESSIMISTIC_READ) + byId = person.id?.let { personRepository.findById(it, LockModeType.PESSIMISTIC_READ) } Assertions.assertEquals(person, byId) -// byId = personDao.findByIdOptional(person.id, LockModeType.PESSIMISTIC_READ).get() -// Assertions.assertEquals(person, byId) - personRepository.delete(person) Assertions.assertEquals(0, personRepository.count())