Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-3386 Make sure that errors occurring when querying properties…
… include some context In particular: * if an error occurs while retrieving a bean, we should display the property key and the bean reference; * if an error occurs because a mandatory property was missing, we should display the property key.
- Loading branch information
Showing
17 changed files
with
266 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...ne/src/main/java/org/hibernate/search/engine/cfg/impl/DefaultedConfigurationProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.engine.cfg.impl; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
final class DefaultedConfigurationProperty<T> extends AbstractConfigurationProperty<T> { | ||
|
||
private final Function<Object, Optional<T>> converter; | ||
private final Supplier<T> defaultValueSupplier; | ||
|
||
DefaultedConfigurationProperty(String key, Function<Object, Optional<T>> converter, Supplier<T> defaultValueSupplier) { | ||
super( key ); | ||
this.converter = converter; | ||
this.defaultValueSupplier = defaultValueSupplier; | ||
} | ||
|
||
@Override | ||
<R> R convert(Optional<?> rawValue, Function<T, R> transform) { | ||
T defaultedValue = rawValue.flatMap( converter ).orElseGet( defaultValueSupplier ); | ||
return transform.apply( defaultedValue ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...src/main/java/org/hibernate/search/engine/cfg/impl/OptionalConfigurationPropertyImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.engine.cfg.impl; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Function; | ||
|
||
import org.hibernate.search.engine.cfg.ConfigurationPropertySource; | ||
import org.hibernate.search.engine.cfg.spi.OptionalConfigurationProperty; | ||
|
||
final class OptionalConfigurationPropertyImpl<T> extends AbstractConfigurationProperty<Optional<T>> | ||
implements OptionalConfigurationProperty<T> { | ||
|
||
private final Function<Object, Optional<T>> converter; | ||
|
||
OptionalConfigurationPropertyImpl(String key, Function<Object, Optional<T>> converter) { | ||
super( key ); | ||
this.converter = converter; | ||
} | ||
|
||
@Override | ||
public <R> Optional<R> getAndMap(ConfigurationPropertySource source, Function<T, R> transform) { | ||
return getAndTransform( source, optional -> optional.map( transform ) ); | ||
} | ||
|
||
@Override | ||
public T getOrThrow(ConfigurationPropertySource source, Function<String, RuntimeException> exceptionFunction) { | ||
return get( source ).orElseThrow( () -> exceptionFunction.apply( resolveOrRaw( source ) ) ); | ||
} | ||
|
||
@Override | ||
<R> R convert(Optional<?> rawValue, Function<Optional<T>, R> transform) { | ||
return transform.apply( rawValue.flatMap( converter ) ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
engine/src/main/java/org/hibernate/search/engine/cfg/spi/OptionalConfigurationProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.engine.cfg.spi; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Function; | ||
|
||
import org.hibernate.search.engine.cfg.ConfigurationPropertySource; | ||
|
||
public interface OptionalConfigurationProperty<T> extends ConfigurationProperty<Optional<T>> { | ||
|
||
/** | ||
* Get and transform the value of this configuration property. | ||
* <p> | ||
* Similar to calling {@link #getAndTransform(ConfigurationPropertySource, Function)}, | ||
* but easier to use, since the transform function is applied to the content of the optional, | ||
* not to the optional itself. | ||
* <p> | ||
* Any exception occurring during transformation will be wrapped in another exception adding some context, | ||
* such as the {@link #resolveOrRaw(ConfigurationPropertySource) resolved key} for this property. | ||
* | ||
* @param source A configuration source. | ||
* @return The value of this property according to the given source. | ||
*/ | ||
<R> Optional<R> getAndMap(ConfigurationPropertySource source, Function<T, R> transform); | ||
|
||
/** | ||
* Get the value of this configuration property, throwing an exception if the value is not present. | ||
* | ||
* @param source A configuration source. | ||
* @param exceptionFunction A function that will be called with the property key as a parameter | ||
* to create an exception if the value is missing. | ||
* @return The value of this property according to the given source. | ||
*/ | ||
T getOrThrow(ConfigurationPropertySource source, Function<String, RuntimeException> exceptionFunction); | ||
|
||
} |
Oops, something went wrong.