Skip to content

Commit

Permalink
Panache ORM/Mongo: fixed bridge generation
Browse files Browse the repository at this point in the history
Now it's all automated, no more forgetting methods to bridge
  • Loading branch information
FroMage committed Apr 15, 2020
1 parent fe07f6e commit 9802fce
Show file tree
Hide file tree
Showing 7 changed files with 456 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
import org.jboss.jandex.IndexView;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

import io.quarkus.hibernate.orm.panache.PanacheRepository;
import io.quarkus.hibernate.orm.panache.PanacheRepositoryBase;
import io.quarkus.panache.common.deployment.JandexUtil;
import io.quarkus.panache.common.deployment.PanacheRepositoryEnhancer;

public class PanacheJpaRepositoryEnhancer extends PanacheRepositoryEnhancer {
Expand Down Expand Up @@ -50,58 +48,6 @@ protected String getPanacheOperationsBinaryName() {
return PanacheJpaEntityEnhancer.JPA_OPERATIONS_BINARY_NAME;
}

@Override
public void visitEnd() {
// Bridge for findById, but only if we actually know the end entity (which we don't for intermediate
// abstract repositories that haven't fixed their entity type yet
if (!"Ljava/lang/Object;".equals(entitySignature)) {
if (!JandexUtil.containsMethod(daoClassInfo, "findById",
Object.class.getName(),
Object.class.getName())) {
MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_BRIDGE,
"findById",
"(Ljava/lang/Object;)Ljava/lang/Object;",
null,
null);
mv.visitParameter("id", 0);
mv.visitCode();
mv.visitIntInsn(Opcodes.ALOAD, 0);
mv.visitIntInsn(Opcodes.ALOAD, 1);

mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
daoBinaryName,
"findById",
"(Ljava/lang/Object;)" + entitySignature, false);
mv.visitInsn(Opcodes.ARETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
if (!JandexUtil.containsMethod(daoClassInfo, "findById",
Object.class.getName(),
Object.class.getName(), "javax.persistence.LockModeType")) {
MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_BRIDGE,
"findById",
"(Ljava/lang/Object;Ljavax/persistence/LockModeType;)Ljava/lang/Object;",
null,
null);
mv.visitParameter("id", 0);
mv.visitParameter("lockModeType", 0);
mv.visitCode();
mv.visitIntInsn(Opcodes.ALOAD, 0);
mv.visitIntInsn(Opcodes.ALOAD, 1);
mv.visitIntInsn(Opcodes.ALOAD, 2);
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
daoBinaryName,
"findById",
"(Ljava/lang/Object;Ljavax/persistence/LockModeType;)" + entitySignature, false);
mv.visitInsn(Opcodes.ARETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
}
super.visitEnd();
}

@Override
protected void injectModel(MethodVisitor mv) {
// inject Class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
import org.jboss.jandex.IndexView;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

import io.quarkus.mongodb.panache.PanacheMongoRepository;
import io.quarkus.mongodb.panache.PanacheMongoRepositoryBase;
import io.quarkus.panache.common.deployment.JandexUtil;
import io.quarkus.panache.common.deployment.PanacheRepositoryEnhancer;

public class PanacheMongoRepositoryEnhancer extends PanacheRepositoryEnhancer {
Expand Down Expand Up @@ -49,36 +47,6 @@ protected String getPanacheOperationsBinaryName() {
return PanacheMongoEntityEnhancer.MONGO_OPERATIONS_BINARY_NAME;
}

@Override
public void visitEnd() {
// Bridge for findById, but only if we actually know the end entity (which we don't for intermediate
// abstract repositories that haven't fixed their entity type yet
if (!entitySignature.equals("Ljava/lang/Object;")) {
if (!JandexUtil.containsMethod(daoClassInfo, "findById",
Object.class.getName(),
Object.class.getName())) {
MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_BRIDGE,
"findById",
"(Ljava/lang/Object;)Ljava/lang/Object;",
null,
null);
mv.visitParameter("id", 0);
mv.visitCode();
mv.visitIntInsn(Opcodes.ALOAD, 0);
mv.visitIntInsn(Opcodes.ALOAD, 1);
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
daoBinaryName,
"findById",
"(Ljava/lang/Object;)" + entitySignature, false);
mv.visitInsn(Opcodes.ARETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
}

super.visitEnd();
}

@Override
protected void injectModel(MethodVisitor mv) {
// inject Class
Expand Down
Loading

0 comments on commit 9802fce

Please sign in to comment.