Skip to content

Commit

Permalink
refactor: Use @ConfigMapping approach.
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Roberto Cortez <radcortez@yahoo.com>
  • Loading branch information
michael-simons and radcortez authored Aug 26, 2024
1 parent f195b74 commit fe86876
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ EntitiesBuildItem findAnnotatedClasses(CombinedIndexBuildItem indexBuildItem,
var classes = new TreeSet<Class<?>>(Comparator.comparing(Class::getName));
var ccl = Thread.currentThread().getContextClassLoader();

Predicate<DotName> packageFilter = buildTimeProperties.basePackages
Predicate<DotName> packageFilter = buildTimeProperties.basePackages()
.map(packages -> (Predicate<DotName>) (DotName n) -> packages.contains(n.packagePrefix()))
.orElseGet(() -> (DotName n) -> true);

Expand Down Expand Up @@ -170,8 +170,8 @@ Neo4jOgmSessionFactoryBuildItem createSessionFactory(Neo4jOgmRecorder recorder,
var allPackages = allClasses.getValue().stream().map(Class::getPackageName)
.distinct().toArray(String[]::new);

if (allPackages.length == 0 && buildTimeProperties.basePackages.isPresent()) {
allPackages = buildTimeProperties.basePackages.get().toArray(new String[0]);
if (allPackages.length == 0 && buildTimeProperties.basePackages().isPresent()) {
allPackages = buildTimeProperties.basePackages().get().toArray(new String[0]);
}

var sessionFactoryRuntimeValue = recorder
Expand Down
18 changes: 0 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,24 +161,6 @@
<arg>-parameters</arg>
</compilerArgs>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<forceLegacyJavacApi>true</forceLegacyJavacApi>
<compilerArgs>
<arg>-Xlint:all,-options,-path,-processing,-classfile</arg>
<arg>-parameters</arg>
<!--
Add as a 2nd execution, as the option below always issues a warning, which cannot be suppressed by -processing.
Migration to @ConfigMapping does not work with properties that have a non `quarkus` prefix, see
https://github.com/orgs/quarkiverse/discussions/228#discussioncomment-10452027
-->
<arg>-AlegacyConfigRoot=true</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
package org.neo4j.ogm.quarkus.runtime;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;

import java.util.List;
import java.util.Optional;
Expand All @@ -27,14 +27,15 @@
*
* @author Michael J. Simons
*/
@ConfigRoot(prefix = "org.neo4j", name = "ogm", phase = ConfigPhase.BUILD_TIME)
public class Neo4jOgmBuiltTimeProperties {
@ConfigMapping(prefix = "org.neo4j.ogm")
@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
public interface Neo4jOgmBuiltTimeProperties {

/**
* An optional list of packages to scan. If empty, all classes annotated with
* {@link org.neo4j.ogm.annotation.NodeEntity @NodeEntity}
* or {@link org.neo4j.ogm.annotation.RelationshipEntity @RelationshipEntity} will be added to the index.
* @return the list of packages to scan
*/
@ConfigItem
public Optional<List<String>> basePackages;
Optional<List<String>> basePackages();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2022-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.neo4j.ogm.quarkus.runtime;

import io.smallrye.config.SmallRyeConfigBuilder;
import io.smallrye.config.SmallRyeConfigBuilderCustomizer;

/**
* Config customizer to ignore validation of unmapped properties between build-time and runtime.
*
* @author Michael J. Simons
* @author Roberto Cortez
* @see Neo4jOgmBuiltTimeProperties
* @see Neo4jOgmProperties
*/
public final class Neo4jOgmConfigCustomizer implements SmallRyeConfigBuilderCustomizer {

@Override
public void configBuilder(final SmallRyeConfigBuilder builder) {
builder.withMappingIgnore("org.neo4j.ogm.**");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
*/
package org.neo4j.ogm.quarkus.runtime;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;

import java.util.Optional;

Expand All @@ -26,24 +27,24 @@
*
* @author Michael J. Simons
*/
@ConfigRoot(prefix = "org.neo4j", name = "ogm", phase = ConfigPhase.RUN_TIME)
public class Neo4jOgmProperties {
@ConfigMapping(prefix = "org.neo4j.ogm")
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
public interface Neo4jOgmProperties {

/**
* Should Neo4j native types be used for dates, times and similar?
* {@return whether Neo4j should use native types be used for dates, times and similar}
*/
@ConfigItem(defaultValue = "false")
public boolean useNativeTypes;
@WithDefault("false")
boolean useNativeTypes();

/**
* This flag instructs OGM to use all static labels when querying domain objects.
* {@return a flag that instructs OGM to use all static labels when querying domain objects}
*/
@ConfigItem(defaultValue = "false")
public boolean useStrictQuerying;
@WithDefault("false")
boolean useStrictQuerying();

/**
* The database that should be used (Neo4j EE 4.0+ only). Leave empty for using the default database.
* {@return the database that should be used (Neo4j EE 4.0+ only), Leave empty for using the default database}
*/
@ConfigItem
public Optional<String> database;
Optional<String> database();
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ public RuntimeValue<SessionFactory> initializeSessionFactory(
// Actually not needed for the driver to work, but required for the config not to stumble upon null
.uri(neo4jConfiguration.uri);

ogmProperties.database.ifPresent(builder::database);
if (ogmProperties.useNativeTypes) {
ogmProperties.database().ifPresent(builder::database);
if (ogmProperties.useNativeTypes()) {
builder.useNativeTypes();
}
if (ogmProperties.useStrictQuerying) {
if (ogmProperties.useStrictQuerying()) {
builder.strictQuerying();
}
builder.withBasePackages(allPackages);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.neo4j.ogm.quarkus.runtime.Neo4jOgmConfigCustomizer

0 comments on commit fe86876

Please sign in to comment.