HHH-14745 Add FunctionContributor contract
This commit is contained in:
parent
76df5a5f4b
commit
21dd7a35f1
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* 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.boot.model;
|
||||
|
||||
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
|
||||
|
||||
/**
|
||||
* Defines the target for contributing functions via {@link FunctionContributor}
|
||||
*
|
||||
* @author Karel Maesen
|
||||
*/
|
||||
public interface FunctionContributions {
|
||||
/**
|
||||
* Add the function under the specified name
|
||||
* @param registrationKey the name under which to register the function
|
||||
* @param function the function description
|
||||
*/
|
||||
void contributeFunction(String registrationKey, SqmFunctionDescriptor function);
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* 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.boot.model;
|
||||
|
||||
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
/**
|
||||
* Contract for contributing functions
|
||||
*
|
||||
* @author Karel Maesen
|
||||
*/
|
||||
public interface FunctionContributor {
|
||||
|
||||
/**
|
||||
* Contribute functions
|
||||
*
|
||||
* @param functionContributions The callback for contributing functions
|
||||
* @param serviceRegistry The service registry
|
||||
*/
|
||||
void contributeTypes(FunctionContributions functionContributions, ServiceRegistry serviceRegistry);
|
||||
}
|
|
@ -7,6 +7,9 @@
|
|||
package org.hibernate.query.spi;
|
||||
|
||||
import org.hibernate.Incubating;
|
||||
import org.hibernate.boot.model.FunctionContributions;
|
||||
import org.hibernate.boot.model.FunctionContributor;
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.boot.spi.BootstrapContext;
|
||||
import org.hibernate.boot.spi.MetadataImplementor;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
@ -25,6 +28,7 @@ import org.hibernate.query.internal.QueryInterpretationCacheDisabledImpl;
|
|||
import org.hibernate.query.internal.QueryInterpretationCacheStandardImpl;
|
||||
import org.hibernate.query.named.NamedObjectRepository;
|
||||
import org.hibernate.query.sqm.NodeBuilder;
|
||||
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
|
||||
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
|
||||
import org.hibernate.query.sqm.internal.SqmCreationOptionsStandard;
|
||||
import org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder;
|
||||
|
@ -127,6 +131,11 @@ public class QueryEngine {
|
|||
userDefinedRegistry.overlay( sqmFunctionRegistry );
|
||||
}
|
||||
|
||||
for ( FunctionContributor contributor : serviceRegistry.getService( ClassLoaderService.class )
|
||||
.loadJavaServices( FunctionContributor.class ) ) {
|
||||
contributor.contributeTypes( sqmFunctionRegistry::register, serviceRegistry );
|
||||
}
|
||||
|
||||
final boolean showSQLFunctions = ConfigurationHelper.getBoolean(
|
||||
AvailableSettings.SHOW_HQL_FUNCTIONS,
|
||||
serviceRegistry.getService( ConfigurationService.class ).getSettings(),
|
||||
|
@ -281,7 +290,9 @@ public class QueryEngine {
|
|||
return new StandardSqmTranslatorFactory();
|
||||
}
|
||||
|
||||
private static QueryInterpretationCache buildInterpretationCache(Supplier<StatisticsImplementor> statisticsSupplier, Map properties) {
|
||||
private static QueryInterpretationCache buildInterpretationCache(
|
||||
Supplier<StatisticsImplementor> statisticsSupplier,
|
||||
Map properties) {
|
||||
final boolean explicitUseCache = ConfigurationHelper.getBoolean(
|
||||
AvailableSettings.QUERY_PLAN_CACHE_ENABLED,
|
||||
properties,
|
||||
|
|
Loading…
Reference in New Issue