Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add jOOQ record auto reflection registration #77

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-narayana-jta-deployment</artifactId>
</dependency>

<dependency>
<groupId>io.quarkiverse.jooq</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.List;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.function.BooleanSupplier;
import java.util.regex.Pattern;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Default;
Expand Down Expand Up @@ -31,8 +33,10 @@
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.pkg.steps.NativeBuild;
import io.quarkus.deployment.recording.RecorderContext;
import io.quarkus.gizmo.*;
import io.quarkus.runtime.util.HashUtil;
Expand All @@ -59,6 +63,18 @@ FeatureBuildItem featureBuildItem() {
return new FeatureBuildItem(FEATURE);
}

@BuildStep(onlyIf = { NativeBuild.class, RegisterClassesForReflectionEnabled.class })
public void registerReflections(CombinedIndexBuildItem indexBuildItem,
BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
JooqConfig jooqConfig) {
Pattern jooqDBReflectClasses = Pattern.compile(jooqConfig.generatedClassesRegex);
indexBuildItem.getIndex()
.getKnownClasses()
.stream()
.filter(o -> jooqDBReflectClasses.matcher(o.name().toString()).matches())
.forEach(clazz -> reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, clazz.name().toString())));
}

@SuppressWarnings("unchecked")
@Record(ExecutionTime.STATIC_INIT)
@BuildStep
Expand Down Expand Up @@ -276,4 +292,12 @@ protected void createDslContextProducerBean(BuildProducer<GeneratedBeanBuildItem
protected boolean isPresentDialect(JooqItemConfig itemConfig) {
return itemConfig.dialect != null && !itemConfig.dialect.isEmpty();
}

static class RegisterClassesForReflectionEnabled implements BooleanSupplier {
JooqConfig jooqConfig;

public boolean getAsBoolean() {
return jooqConfig.registerClassesForReflection;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ public class JooqConfig {
@ConfigItem(name = ConfigItem.PARENT)
public JooqItemConfig defaultConfig;

/**
* Whether to automatically register jOOQ records/POJOs
* for reflection.
*/
@ConfigItem(defaultValue = "true")
public Boolean registerClassesForReflection;

/**
* Regex used to determine classes to be registered for
* reflection.
*/
@ConfigItem(defaultValue = ".+\\.tables\\.(pojos|records)\\..+")
public String generatedClassesRegex;

/**
* Additional configs.
*/
Expand Down