Skip to content

Commit

Permalink
Move config to @ConfigMapping
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez committed Aug 26, 2024
1 parent 6d4265f commit 6b6b8dd
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 20 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.
*
* @see Neo4jOgmBuiltTimeProperties
* @see Neo4jOgmProperties
*/
public class Neo4jConfigBuilderCustomizer implements SmallRyeConfigBuilderCustomizer {
@Override
public void configBuilder(SmallRyeConfigBuilder builder) {
builder.withMappingIgnore("org.neo4j.ogm.**");
}
}
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,14 @@
*
* @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.
*/
@ConfigItem
public Optional<List<String>> basePackages;
Optional<List<String>> basePackages();
}
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?
*/
@ConfigItem(defaultValue = "false")
public boolean useNativeTypes;
@WithDefault("false")
boolean useNativeTypes();

/**
* This flag 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.
*/
@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.Neo4jConfigBuilderCustomizer

0 comments on commit 6b6b8dd

Please sign in to comment.