quarkiverse / quarkus-jnosql

The Quarkus JNoSql Extension adds support for JNoSQL, an implementation of Jakarta NoSQL.
http://www.jnosql.org/
Apache License 2.0
13 stars 4 forks source link

Integrate Eclipse JNoSQL Lite as an Alternative Metadata Generator in Quarkus #95

Closed otaviojava closed 5 months ago

otaviojava commented 5 months ago

Description

Objective:
This issue aims to explore the integration of Eclipse JNoSQL Lite into Quarkus as a replacement for the current reflection-based metadata generator. Eclipse JNoSQL Lite leverages an annotation processor for metadata generation, which is anticipated to enhance performance by eliminating the need for reflection.

Background:
Currently, Quarkus uses a reflection-based approach to manage JNoSQL metadata. While effective, this method can be optimized by adopting Eclipse JNoSQL Lite, which uses compile-time annotation processing. This change is expected to yield performance improvements and better align with Quarkus's philosophy of reducing runtime overhead.

Proposed Changes:

  1. Exclusion of Reflection-Based Metadata:
    Modify the Quarkus JNoSQL configuration to exclude the traditional reflection-based metadata generator. It can be achieved by updating the project dependencies to exclude the jnosql-mapping-reflection module.

    <dependency>
       <groupId>org.eclipse.jnosql.databases</groupId>
       <artifactId>chosen-database-artifact-id</artifactId>
       <version>chosen-database-version</version>
       <exclusions>
           <exclusion>
               <groupId>org.eclipse.jnosql.mapping</groupId>
               <artifactId>jnosql-mapping-reflection</artifactId>
           </exclusion>
       </exclusions>
    </dependency>
  2. Inclusion of Eclipse JNoSQL Lite:

    Introduce the Eclipse JNoSQL Lite annotation processor to the build process as a provided dependency. It ensures the metadata is generated at compile time without adding additional runtime dependencies.

    <dependency>
       <groupId>org.eclipse.jnosql.lite</groupId>
       <artifactId>mapping-lite-processor</artifactId>
       <version>1.1.0</version>
       <scope>provided</scope>
    </dependency>

Expected Benefits:

otaviojava commented 5 months ago

@amoscatelli @dearrudam, do you know how to enable the dependency only during build time?

amoscatelli commented 5 months ago

@otaviojava I am not sure I get this right.

First things first, I can't find jnosql-mapping-reflection among the dependency of, for example, jnosql-mongodb : https://mvnrepository.com/artifact/org.eclipse.jnosql.databases/jnosql-mongodb/1.1.0

Then why should I exclude it ?

amoscatelli commented 5 months ago

Oh I see, here it is : https://mvnrepository.com/artifact/org.eclipse.jnosql.mapping/jnosql-mapping-core/1.1.0

Ok then next question is : What do you mean by only "during build time" ? Isn't this what the "provided" dependencies are for ? Also Quarkus drops, by treeshake, everything you don't actively use ...

amoscatelli commented 5 months ago

Anyway I excluded the reflection and included the annotation processon but I am getting this exception :

Caused by: org.eclipse.jnosql.mapping.metadata.MetadataException: No implementation of ClassConverter found via ServiceLoader
    at org.eclipse.jnosql.mapping.metadata.ClassConverter.lambda$load$0(ClassConverter.java:48)
    at java.base/java.util.Optional.orElseThrow(Optional.java:403)
    at org.eclipse.jnosql.mapping.metadata.ClassConverter.load(ClassConverter.java:47)
    at org.eclipse.jnosql.mapping.core.spi.EntityMetadataExtension.<init>(EntityMetadataExtension.java:48)
    at io.quarkiverse.jnosql.core.runtime.QuarkusEntityMetadataExtension.<init>(QuarkusEntityMetadataExtension.java:10)
    at io.quarkiverse.jnosql.core.runtime.QuarkusEntityMetadataExtension_Bean.doCreate(Unknown Source)
    at io.quarkiverse.jnosql.core.runtime.QuarkusEntityMetadataExtension_Bean.create(Unknown Source)
    at io.quarkiverse.jnosql.core.runtime.QuarkusEntityMetadataExtension_Bean.create(Unknown Source)
    at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:113)
    at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:37)
    at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:34)
    at io.quarkus.arc.impl.LazyValue.get(LazyValue.java:32)
    at io.quarkus.arc.impl.ComputingCache.computeIfAbsent(ComputingCache.java:69)
    at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:34)
    at io.quarkiverse.jnosql.core.runtime.QuarkusEntityMetadataExtension_Observer_onStart_a4bf6a2f117149897853c96ef7c42e7f5a772f37.notify(Unknown Source)
    at io.quarkus.arc.impl.EventImpl$Notifier.notifyObservers(EventImpl.java:346)
    at io.quarkus.arc.impl.EventImpl$Notifier.notify(EventImpl.java:328)
    at io.quarkus.arc.impl.EventImpl.fire(EventImpl.java:82)
    at io.quarkus.arc.runtime.ArcRecorder.fireLifecycleEvent(ArcRecorder.java:155)
    at io.quarkus.arc.runtime.ArcRecorder.handleLifecycleEvents(ArcRecorder.java:106)
    at io.quarkus.deployment.steps.LifecycleEventsBuildStep$startupEvent1144526294.deploy_0(Unknown Source)
    at io.quarkus.deployment.steps.LifecycleEventsBuildStep$startupEvent1144526294.deploy(Unknown Source)
    ... 11 more

Anyway I can't see any generated class under 'target/generated-sources/annotations' ... that's strange. I get the feeling the annotation processor isn't triggered.

@otaviojava I can't remember what I have to do to make an Annotation Processor start in Quarkus, I need some more time

otaviojava commented 5 months ago

Oh I see, here it is : https://mvnrepository.com/artifact/org.eclipse.jnosql.mapping/jnosql-mapping-core/1.1.0

Ok then next question is : What do you mean by only "during build time" ? Isn't this what the "provided" dependencies are for ? Also Quarkus drops, by treeshake, everything you don't actively use ...

The goal is instead of using reflection use Java annotation processor.

otaviojava commented 5 months ago

Anyway I excluded the reflection and included the annotation processon but I am getting this exception :

Caused by: org.eclipse.jnosql.mapping.metadata.MetadataException: No implementation of ClassConverter found via ServiceLoader
  at org.eclipse.jnosql.mapping.metadata.ClassConverter.lambda$load$0(ClassConverter.java:48)
  at java.base/java.util.Optional.orElseThrow(Optional.java:403)
  at org.eclipse.jnosql.mapping.metadata.ClassConverter.load(ClassConverter.java:47)
  at org.eclipse.jnosql.mapping.core.spi.EntityMetadataExtension.<init>(EntityMetadataExtension.java:48)
  at io.quarkiverse.jnosql.core.runtime.QuarkusEntityMetadataExtension.<init>(QuarkusEntityMetadataExtension.java:10)
  at io.quarkiverse.jnosql.core.runtime.QuarkusEntityMetadataExtension_Bean.doCreate(Unknown Source)
  at io.quarkiverse.jnosql.core.runtime.QuarkusEntityMetadataExtension_Bean.create(Unknown Source)
  at io.quarkiverse.jnosql.core.runtime.QuarkusEntityMetadataExtension_Bean.create(Unknown Source)
  at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:113)
  at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:37)
  at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:34)
  at io.quarkus.arc.impl.LazyValue.get(LazyValue.java:32)
  at io.quarkus.arc.impl.ComputingCache.computeIfAbsent(ComputingCache.java:69)
  at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:34)
  at io.quarkiverse.jnosql.core.runtime.QuarkusEntityMetadataExtension_Observer_onStart_a4bf6a2f117149897853c96ef7c42e7f5a772f37.notify(Unknown Source)
  at io.quarkus.arc.impl.EventImpl$Notifier.notifyObservers(EventImpl.java:346)
  at io.quarkus.arc.impl.EventImpl$Notifier.notify(EventImpl.java:328)
  at io.quarkus.arc.impl.EventImpl.fire(EventImpl.java:82)
  at io.quarkus.arc.runtime.ArcRecorder.fireLifecycleEvent(ArcRecorder.java:155)
  at io.quarkus.arc.runtime.ArcRecorder.handleLifecycleEvents(ArcRecorder.java:106)
  at io.quarkus.deployment.steps.LifecycleEventsBuildStep$startupEvent1144526294.deploy_0(Unknown Source)
  at io.quarkus.deployment.steps.LifecycleEventsBuildStep$startupEvent1144526294.deploy(Unknown Source)
  ... 11 more

Anyway I can't see any generated class under 'target/generated-sources/annotations' ... that's strange. I get the feeling the annotation processor isn't triggered.

@otaviojava I can't remember what I have to do to make an Annotation Processor start in Quarkus, I need some more time

Did you created a branch with this test? If yes, can you share?

Maybe is because the Java Annotation Processor is not available for the application.

amoscatelli commented 5 months ago

@otaviojava https://github.com/quarkiverse/quarkus-jnosql/pull/96

This is going to fail :D

otaviojava commented 5 months ago

Nice, @amoscatelli how can we generate a new version?

amoscatelli commented 5 months ago

I believe we can close this.

https://github.com/quarkiverse/quarkus-jnosql/releases/tag/3.3.0

otaviojava commented 5 months ago

Yes, thanks @amoscatelli