OpenElements / BenchScape

Collect and analyze JMH benchmark results for continuous integration
https://app.benchscape.cloud
Apache License 2.0
3 stars 3 forks source link

Provide JPA metamodel for better queries #392

Closed Ndacyayisenga-droid closed 5 months ago

Ndacyayisenga-droid commented 5 months ago

Fixes https://github.com/OpenElements/BenchScape/issues/385

Ndacyayisenga-droid commented 5 months ago

Is the code working? All the static attributes are never assigned to a concrete field. Maybe Spring does that as magic, no idea but have you checked that everything works as exected?

@hendrikebbers yea the code worked fine but I had manually created JPA Metamodel Classes which I think its kinda wrong. I included a build script in my pom.xml and am able to generate JPA Metamodel Classes for all the entities in the /server/target/generated-sources/annotations/com/openelements/benchscape/server/store/entities not sure yet thats the directory(/target) the JPA Metamodel Classes should be created. Still have a few build failures but trying to make everything useful :)

I added something like

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
          <source>17</source>
          <target>17</target>
          <annotationProcessorPaths>
            <path>
              <groupId>org.hibernate.orm</groupId>
              <artifactId>hibernate-jpamodelgen</artifactId>
              <version>6.2.0.Final</version> 
            </path>
          </annotationProcessorPaths>
        </configuration>
</plugin>

Am able to generate something like

package com.openelements.benchscape.server.store.entities;

import jakarta.persistence.metamodel.MapAttribute;
import jakarta.persistence.metamodel.SetAttribute;
import jakarta.persistence.metamodel.SingularAttribute;
import jakarta.persistence.metamodel.StaticMetamodel;
import java.time.Duration;
import javax.annotation.processing.Generated;

@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
@StaticMetamodel(MeasurementMetadataEntity.class)
public abstract class MeasurementMetadataEntity_ extends com.openelements.server.base.tenantdata.AbstractEntityWithTenant_ {

    public static volatile SingularAttribute<MeasurementMetadataEntity, Integer> jmhThreadCount;
    public static volatile SingularAttribute<MeasurementMetadataEntity, Integer> jmhWarmupIterations;
    public static volatile SingularAttribute<MeasurementMetadataEntity, Integer> jmhWarmupBatchSize;
    public static volatile SingularAttribute<MeasurementMetadataEntity, Duration> jmhWarmupTime;
    public static volatile MapAttribute<MeasurementMetadataEntity, String, String> environmentProperties;
    public static volatile SingularAttribute<MeasurementMetadataEntity, Integer> jmhForks;
    public static volatile SingularAttribute<MeasurementMetadataEntity, String> jmhVersion;
    public static volatile SingularAttribute<MeasurementMetadataEntity, String> gitOriginUrl;
    public static volatile SingularAttribute<MeasurementMetadataEntity, Boolean> gitDirty;
    public static volatile SingularAttribute<MeasurementMetadataEntity, String> systemArch;
    public static volatile SingularAttribute<MeasurementMetadataEntity, String> osName;
    public static volatile MapAttribute<MeasurementMetadataEntity, String, String> systemProperties;
    public static volatile SingularAttribute<MeasurementMetadataEntity, Duration> jmhTimeout;
    public static volatile SetAttribute<MeasurementMetadataEntity, String> gitTags;
    public static volatile SingularAttribute<MeasurementMetadataEntity, String> osVersion;
    public static volatile SingularAttribute<MeasurementMetadataEntity, String> jvmVersion;
    public static volatile SingularAttribute<MeasurementMetadataEntity, String> jvmName;
    public static volatile SingularAttribute<MeasurementMetadataEntity, Duration> jmhMeasurementTime;
    public static volatile SingularAttribute<MeasurementMetadataEntity, Integer> jmhMeasurementBatchSize;
    public static volatile SingularAttribute<MeasurementMetadataEntity, Long> systemMemory;
    public static volatile SingularAttribute<MeasurementMetadataEntity, String> gitCommitId;
    public static volatile SingularAttribute<MeasurementMetadataEntity, String> gitBranch;
    public static volatile SingularAttribute<MeasurementMetadataEntity, Integer> jmhMeasurementIterations;
    public static volatile SingularAttribute<MeasurementMetadataEntity, Integer> systemProcessors;

    public static final String JMH_THREAD_COUNT = "jmhThreadCount";
    public static final String JMH_WARMUP_ITERATIONS = "jmhWarmupIterations";
    public static final String JMH_WARMUP_BATCH_SIZE = "jmhWarmupBatchSize";
    public static final String JMH_WARMUP_TIME = "jmhWarmupTime";
    public static final String ENVIRONMENT_PROPERTIES = "environmentProperties";
    public static final String JMH_FORKS = "jmhForks";
    public static final String JMH_VERSION = "jmhVersion";
    public static final String GIT_ORIGIN_URL = "gitOriginUrl";
    public static final String GIT_DIRTY = "gitDirty";
    public static final String SYSTEM_ARCH = "systemArch";
    public static final String OS_NAME = "osName";
    public static final String SYSTEM_PROPERTIES = "systemProperties";
    public static final String JMH_TIMEOUT = "jmhTimeout";
    public static final String GIT_TAGS = "gitTags";
    public static final String OS_VERSION = "osVersion";
    public static final String JVM_VERSION = "jvmVersion";
    public static final String JVM_NAME = "jvmName";
    public static final String JMH_MEASUREMENT_TIME = "jmhMeasurementTime";
    public static final String JMH_MEASUREMENT_BATCH_SIZE = "jmhMeasurementBatchSize";
    public static final String SYSTEM_MEMORY = "systemMemory";
    public static final String GIT_COMMIT_ID = "gitCommitId";
    public static final String GIT_BRANCH = "gitBranch";
    public static final String JMH_MEASUREMENT_ITERATIONS = "jmhMeasurementIterations";
    public static final String SYSTEM_PROCESSORS = "systemProcessors";

}
hendrikebbers commented 5 months ago

@Ndacyayisenga-droid the code that you show in your comment is exactly what I would suspect.

The addition to the pom will automatically trigger the generation of the code whenever java is compiled. Since it is no "hand-written" code it is added to the generated-sources folder in the target directory (internally the Hibernate lib uses the Java Annotation processor standard to generate the new sources <- just a technical detail). The generated sources will be part if the project when starting the server and therefore everything should work as expected.

The interesting point here is that the generated sources will not be commited by git (since the target folder is ignored). But since it happens automatically when java compilation is happened (like when calling mvn verify) everyone will have that generated sources automatically.

So what you put in your comment (the pom addition) should be what is part of the PR. I assume nothing more is needed :)