org.springframework.data.relational.core.query.ValueFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-data-relational Show documentation
Show all versions of spring-data-relational Show documentation
Spring Data Relational support
/*
* Copyright 2020-2022 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.springframework.data.relational.core.query;
import java.util.function.Function;
import java.util.function.Supplier;
import org.springframework.data.relational.core.dialect.Escaper;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
* Represents a value function to return arbitrary values that can be escaped before returning the actual value. Can be
* used with the criteria API for deferred value retrieval.
*
* @author Mark Paluch
* @since 2.0
* @see Escaper
* @see Supplier
*/
@FunctionalInterface
public interface ValueFunction extends Function {
/**
* Produces a value by considering the given {@link Escaper}.
*
* @param escaper the escaper to use.
* @return the return value, may be {@literal null}.
*/
@Nullable
@Override
T apply(Escaper escaper);
/**
* Adapts this value factory into a {@link Supplier} by using the given {@link Escaper}.
*
* @param escaper the escaper to use.
* @return the value factory
*/
default Supplier toSupplier(Escaper escaper) {
Assert.notNull(escaper, "Escaper must not be null");
return () -> apply(escaper);
}
}