HHH-12544 - Add jipijapa hook to plug in specialized caching and transaction services

This commit is contained in:
Steve Ebersole 2018-05-04 11:22:21 -05:00
parent 14a9c0a56d
commit 350d330159
7 changed files with 107 additions and 2 deletions

View File

@ -102,6 +102,11 @@ public class RegionFactoryInitiator implements StandardServiceInitiator<RegionFa
}
final RegionFactory fallback = getFallback( configurationValues, registry );
if ( fallback != null ) {
return fallback;
}
if ( implementors.size() == 1 ) {
final RegionFactory registeredFactory = selector.resolveStrategy( RegionFactory.class, implementors.iterator().next() );
configurationValues.put( AvailableSettings.CACHE_REGION_FACTORY, registeredFactory );
@ -118,4 +123,9 @@ public class RegionFactoryInitiator implements StandardServiceInitiator<RegionFa
return NoCachingRegionFactory.INSTANCE;
}
@SuppressWarnings({"WeakerAccess", "unused"})
protected RegionFactory getFallback(Map configurationValues, ServiceRegistryImplementor registry) {
return null;
}
}

View File

@ -37,11 +37,23 @@ public class JtaPlatformInitiator implements StandardServiceInitiator<JtaPlatfor
@SuppressWarnings( {"unchecked"})
public JtaPlatform initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
final Object setting = configurationValues.get( AvailableSettings.JTA_PLATFORM );
final JtaPlatform platform = registry.getService( StrategySelector.class ).resolveStrategy( JtaPlatform.class, setting );
JtaPlatform platform = registry.getService( StrategySelector.class ).resolveStrategy( JtaPlatform.class, setting );
if ( platform == null ) {
LOG.debugf( "No JtaPlatform was specified, checking resolver" );
return registry.getService( JtaPlatformResolver.class ).resolveJtaPlatform( configurationValues, registry );
platform = registry.getService( JtaPlatformResolver.class ).resolveJtaPlatform( configurationValues, registry );
}
if ( platform == null ) {
LOG.debugf( "No JtaPlatform was specified, checking resolver" );
platform = getFallbackProvider( configurationValues, registry );
}
return platform;
}
@SuppressWarnings({"WeakerAccess", "unused"})
protected JtaPlatform getFallbackProvider(Map configurationValues, ServiceRegistryImplementor registry) {
return null;
}
}

View File

@ -11,6 +11,9 @@ import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
/**
* Contract for contributing services.
*
* @implSpec Implementations can be auto-discovered via Java's {@link java.util.ServiceLoader}
* mechanism.
*
* @author Steve Ebersole
*/
public interface ServiceContributor {

View File

@ -0,0 +1,26 @@
/*
* 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.jboss.as.jpa.hibernate5.service;
import java.util.Map;
import org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
import org.hibernate.service.spi.ServiceRegistryImplementor;
/**
* Custom JtaPlatform initiator for use inside WildFly picking an appropriate
* fallback JtaPlatform.
*
* @author Steve Ebersole
*/
public class CustomJtaPlatformInitiator extends JtaPlatformInitiator {
@Override
protected JtaPlatform getFallbackProvider(Map configurationValues, ServiceRegistryImplementor registry) {
return new org.hibernate.engine.transaction.jta.platform.internal.JBossAppServerJtaPlatform();
}
}

View File

@ -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.jboss.as.jpa.hibernate5.service;
import java.util.Map;
import org.hibernate.cache.internal.NoCachingRegionFactory;
import org.hibernate.cache.internal.RegionFactoryInitiator;
import org.hibernate.cache.spi.RegionFactory;
import org.hibernate.service.spi.ServiceRegistryImplementor;
/**
* @author Steve Ebersole
*/
public class CustomRegionFactoryInitiator extends RegionFactoryInitiator {
@Override
protected RegionFactory getFallback(Map configurationValues, ServiceRegistryImplementor registry) {
return NoCachingRegionFactory.INSTANCE;
}
}

View File

@ -0,0 +1,23 @@
/*
* 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.jboss.as.jpa.hibernate5.service;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.service.spi.ServiceContributor;
/**
* Contribute specialized Hibernate Service impls
*
* @author Steve Ebersole
*/
public class ServiceContributorImpl implements ServiceContributor {
@Override
public void contribute(StandardServiceRegistryBuilder serviceRegistryBuilder) {
serviceRegistryBuilder.addInitiator( new CustomJtaPlatformInitiator() );
serviceRegistryBuilder.addInitiator( new CustomRegionFactoryInitiator() );
}
}

View File

@ -0,0 +1,7 @@
#
# 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
org.jboss.as.jpa.hibernate5.service.ServiceContributorImpl