HHH-12390 - Add hibernate-jipijapa for integrating with WildFly
- functional changes - building, all tests passing - formatting changes coming in next commit to isolate them - removed Infinispan dependencies (not compile/test failures in any subproject as a result)
This commit is contained in:
parent
9c97b987e1
commit
6f48fa1a49
|
@ -12,7 +12,6 @@ ext {
|
|||
junitVersion = '4.12'
|
||||
h2Version = '1.4.196'
|
||||
bytemanVersion = '4.0.1' //Compatible with JDK10
|
||||
infinispanVersion = '9.2.0.Final'
|
||||
jnpVersion = '5.0.6.CR1'
|
||||
|
||||
hibernateValidatorVersion = '6.0.7.Final'
|
||||
|
@ -116,15 +115,6 @@ ext {
|
|||
// EL required by Hibernate Validator at test runtime
|
||||
expression_language: "org.glassfish:javax.el:${elVersion}",
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~ infinsipan
|
||||
infinispan: "org.infinispan:infinispan-core:${infinispanVersion}",
|
||||
infinispan_hibernate_cache_commons: "org.infinispan:infinispan-hibernate-cache-commons:${infinispanVersion}",
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~ infinispan test
|
||||
infinispan_test: "org.infinispan:infinispan-core:${infinispanVersion}:tests@jar",
|
||||
jboss_common_core: "org.jboss:jboss-common-core:2.2.16.GA@jar",
|
||||
jnp_client: "org.jboss.naming:jnp-client:${jnpVersion}",
|
||||
jnp_server: "org.jboss.naming:jnpserver:${jnpVersion}",
|
||||
|
||||
c3p0: "com.mchange:c3p0:0.9.5.2",
|
||||
ehcache: "net.sf.ehcache:ehcache:2.10.3",
|
||||
ehcache3: "org.ehcache:ehcache:3.0.0",
|
||||
|
|
|
@ -13,9 +13,10 @@ dependencies {
|
|||
compile project( ':hibernate-core' )
|
||||
compile( libraries.jipijapa_spi )
|
||||
compile( libraries.jboss_vfs )
|
||||
compile( libraries.infinispan_hibernate_cache_commons )
|
||||
|
||||
// compile( libraries.infinispan_hibernate_cache_commons )
|
||||
|
||||
testCompile project( ':hibernate-testing' )
|
||||
testCompile( libraries.shrinkwrap )
|
||||
}
|
||||
|
||||
test {
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.util.ArrayList;
|
|||
|
||||
import javax.enterprise.inject.spi.BeanManager;
|
||||
|
||||
import org.hibernate.jpa.event.spi.jpa.ExtendedBeanManager;
|
||||
import org.hibernate.resource.beans.container.spi.ExtendedBeanManager;
|
||||
|
||||
/**
|
||||
* HibernateExtendedBeanManager helps defer the registering of entity listeners, with the CDI BeanManager until
|
||||
|
@ -49,7 +49,7 @@ public class HibernateExtendedBeanManager implements ExtendedBeanManager {
|
|||
|
||||
public void beanManagerIsAvailableForUse() {
|
||||
for (LifecycleListener hibernateCallback : lifecycleListeners) {
|
||||
hibernateCallback.beanManagerInitialized(beanManager);
|
||||
hibernateCallback.beanManagerInitialized( beanManager );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,17 +7,16 @@
|
|||
|
||||
package org.jboss.as.jpa.hibernate5;
|
||||
|
||||
import static org.jboss.as.jpa.hibernate5.JpaLogger.JPA_LOGGER;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.enterprise.inject.spi.BeanManager;
|
||||
import javax.persistence.SharedCacheMode;
|
||||
import javax.persistence.spi.PersistenceUnitInfo;
|
||||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
||||
import org.jboss.as.jpa.hibernate5.management.HibernateManagementAdaptor;
|
||||
|
||||
import org.jipijapa.cache.spi.Classification;
|
||||
import org.jipijapa.event.impl.internal.Notification;
|
||||
import org.jipijapa.plugin.spi.EntityManagerFactoryBuilder;
|
||||
|
@ -28,6 +27,8 @@ import org.jipijapa.plugin.spi.PersistenceUnitMetadata;
|
|||
import org.jipijapa.plugin.spi.Platform;
|
||||
import org.jipijapa.plugin.spi.TwoPhaseBootstrapCapable;
|
||||
|
||||
import static org.jboss.as.jpa.hibernate5.JpaLogger.JPA_LOGGER;
|
||||
|
||||
/**
|
||||
* Implements the PersistenceProviderAdaptor for Hibernate
|
||||
*
|
||||
|
@ -36,11 +37,10 @@ import org.jipijapa.plugin.spi.TwoPhaseBootstrapCapable;
|
|||
public class HibernatePersistenceProviderAdaptor implements PersistenceProviderAdaptor, TwoPhaseBootstrapCapable {
|
||||
|
||||
public static final String NAMING_STRATEGY_JPA_COMPLIANT_IMPL = "org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl";
|
||||
private static final String HIBERNATE_EXTENDED_BEANMANAGER = "org.hibernate.resource.beans.container.spi.ExtendedBeanManager";
|
||||
private volatile JtaManager jtaManager;
|
||||
private volatile Platform platform;
|
||||
private static final String SHARED_CACHE_MODE = "javax.persistence.sharedCache.mode";
|
||||
private static final String NONE = SharedCacheMode.NONE.name();
|
||||
private static final String HIBERNATE_EXTENDED_BEANMANAGER = "org.hibernate.jpa.event.spi.jpa.ExtendedBeanManager";
|
||||
|
||||
@Override
|
||||
public void injectJtaManager(JtaManager jtaManager) {
|
||||
|
@ -85,7 +85,7 @@ public class HibernatePersistenceProviderAdaptor implements PersistenceProviderA
|
|||
@Override
|
||||
public void addProviderDependencies(PersistenceUnitMetadata pu) {
|
||||
final Properties properties = pu.getProperties();
|
||||
final String sharedCacheMode = properties.getProperty(SHARED_CACHE_MODE);
|
||||
final String sharedCacheMode = properties.getProperty( AvailableSettings.JPA_SHARED_CACHE_MODE );
|
||||
|
||||
if ( Classification.NONE.equals(platform.defaultCacheClassification())) {
|
||||
if (!SharedCacheMode.NONE.equals(pu.getSharedCacheMode())) {
|
||||
|
@ -103,12 +103,12 @@ public class HibernatePersistenceProviderAdaptor implements PersistenceProviderA
|
|||
||
|
||||
(sharedCacheMode != null && (!NONE.equals(sharedCacheMode)))
|
||||
|| (!SharedCacheMode.NONE.equals(pu.getSharedCacheMode()) && (!SharedCacheMode.UNSPECIFIED.equals(pu.getSharedCacheMode())))) {
|
||||
HibernateSecondLevelCache.addSecondLevelCacheDependencies(pu.getProperties(), pu.getScopedPersistenceUnitName());
|
||||
// HibernateSecondLevelCache.addSecondLevelCacheDependencies(pu.getProperties(), pu.getScopedPersistenceUnitName());
|
||||
JPA_LOGGER.tracef("second level cache enabled for %s", pu.getScopedPersistenceUnitName());
|
||||
} else {
|
||||
JPA_LOGGER.tracef("second level cache disabled for %s, pu %s property = %s, pu.getSharedCacheMode = %s",
|
||||
pu.getScopedPersistenceUnitName(),
|
||||
SHARED_CACHE_MODE,
|
||||
AvailableSettings.JPA_SHARED_CACHE_MODE,
|
||||
sharedCacheMode,
|
||||
pu.getSharedCacheMode().toString());
|
||||
}
|
||||
|
|
|
@ -1,106 +0,0 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import static org.infinispan.hibernate.cache.commons.InfinispanRegionFactory.COLLECTION_CACHE_RESOURCE_PROP;
|
||||
import static org.infinispan.hibernate.cache.commons.InfinispanRegionFactory.DEF_ENTITY_RESOURCE;
|
||||
import static org.infinispan.hibernate.cache.commons.InfinispanRegionFactory.DEF_QUERY_RESOURCE;
|
||||
import static org.infinispan.hibernate.cache.commons.InfinispanRegionFactory.ENTITY_CACHE_RESOURCE_PROP;
|
||||
import static org.infinispan.hibernate.cache.commons.InfinispanRegionFactory.IMMUTABLE_ENTITY_CACHE_RESOURCE_PROP;
|
||||
import static org.infinispan.hibernate.cache.commons.InfinispanRegionFactory.INFINISPAN_CONFIG_RESOURCE_PROP;
|
||||
import static org.infinispan.hibernate.cache.commons.InfinispanRegionFactory.NATURAL_ID_CACHE_RESOURCE_PROP;
|
||||
import static org.infinispan.hibernate.cache.commons.InfinispanRegionFactory.PENDING_PUTS_CACHE_RESOURCE_PROP;
|
||||
import static org.infinispan.hibernate.cache.commons.InfinispanRegionFactory.QUERY_CACHE_RESOURCE_PROP;
|
||||
import static org.infinispan.hibernate.cache.commons.InfinispanRegionFactory.TIMESTAMPS_CACHE_RESOURCE_PROP;
|
||||
import static org.jboss.as.jpa.hibernate5.infinispan.InfinispanRegionFactory.CACHE_CONTAINER;
|
||||
import static org.jboss.as.jpa.hibernate5.infinispan.InfinispanRegionFactory.DEFAULT_CACHE_CONTAINER;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.jboss.as.jpa.hibernate5.infinispan.SharedInfinispanRegionFactory;
|
||||
import org.jipijapa.cache.spi.Classification;
|
||||
import org.jipijapa.event.impl.internal.Notification;
|
||||
|
||||
/**
|
||||
* Second level cache setup.
|
||||
*
|
||||
* @author Scott Marlow
|
||||
*/
|
||||
public class HibernateSecondLevelCache {
|
||||
|
||||
private static final String DEFAULT_REGION_FACTORY = SharedInfinispanRegionFactory.class.getName();
|
||||
|
||||
public static final String CACHE_TYPE = "cachetype"; // shared (jpa) or private (for native applications)
|
||||
public static final String CONTAINER = "container";
|
||||
public static final String NAME = "name";
|
||||
public static final String CACHES = "caches";
|
||||
|
||||
public static void addSecondLevelCacheDependencies(Properties mutableProperties, String scopedPersistenceUnitName) {
|
||||
|
||||
if (mutableProperties.getProperty(AvailableSettings.CACHE_REGION_PREFIX) == null) {
|
||||
// cache entries for this PU will be identified by scoped pu name + Entity class name
|
||||
|
||||
if (scopedPersistenceUnitName != null) {
|
||||
mutableProperties.setProperty(AvailableSettings.CACHE_REGION_PREFIX, scopedPersistenceUnitName);
|
||||
}
|
||||
}
|
||||
String regionFactory = mutableProperties.getProperty(AvailableSettings.CACHE_REGION_FACTORY);
|
||||
if (regionFactory == null) {
|
||||
regionFactory = DEFAULT_REGION_FACTORY;
|
||||
mutableProperties.setProperty(AvailableSettings.CACHE_REGION_FACTORY, regionFactory);
|
||||
}
|
||||
if (regionFactory.equals(DEFAULT_REGION_FACTORY)) {
|
||||
// Set infinispan defaults
|
||||
String container = mutableProperties.getProperty(CACHE_CONTAINER);
|
||||
if (container == null) {
|
||||
container = DEFAULT_CACHE_CONTAINER;
|
||||
mutableProperties.setProperty(CACHE_CONTAINER, container);
|
||||
}
|
||||
|
||||
/**
|
||||
* AS will need the ServiceBuilder<?> builder that used to be passed to PersistenceProviderAdaptor.addProviderDependencies
|
||||
*/
|
||||
Properties cacheSettings = new Properties();
|
||||
cacheSettings.setProperty(CONTAINER, container);
|
||||
cacheSettings.setProperty(CACHES, String.join(" ", findCaches(mutableProperties)));
|
||||
|
||||
Notification.addCacheDependencies(Classification.INFINISPAN, cacheSettings);
|
||||
}
|
||||
}
|
||||
|
||||
public static Set<String> findCaches(Properties properties) {
|
||||
Set<String> caches = new HashSet<>();
|
||||
|
||||
caches.add(properties.getProperty(ENTITY_CACHE_RESOURCE_PROP, DEF_ENTITY_RESOURCE));
|
||||
caches.add(properties.getProperty(IMMUTABLE_ENTITY_CACHE_RESOURCE_PROP, DEF_ENTITY_RESOURCE));
|
||||
caches.add(properties.getProperty(COLLECTION_CACHE_RESOURCE_PROP, DEF_ENTITY_RESOURCE));
|
||||
caches.add(properties.getProperty(NATURAL_ID_CACHE_RESOURCE_PROP, DEF_ENTITY_RESOURCE));
|
||||
if (properties.containsKey(PENDING_PUTS_CACHE_RESOURCE_PROP)) {
|
||||
caches.add(properties.getProperty(PENDING_PUTS_CACHE_RESOURCE_PROP));
|
||||
}
|
||||
if (Boolean.parseBoolean(properties.getProperty(AvailableSettings.USE_QUERY_CACHE))) {
|
||||
caches.add(properties.getProperty(QUERY_CACHE_RESOURCE_PROP, DEF_QUERY_RESOURCE));
|
||||
caches.add(properties.getProperty(TIMESTAMPS_CACHE_RESOURCE_PROP, DEF_QUERY_RESOURCE));
|
||||
}
|
||||
|
||||
int length = INFINISPAN_CONFIG_RESOURCE_PROP.length();
|
||||
String customRegionPrefix = INFINISPAN_CONFIG_RESOURCE_PROP.substring(0, length - 3) + properties.getProperty(AvailableSettings.CACHE_REGION_PREFIX, "");
|
||||
String customRegionSuffix = INFINISPAN_CONFIG_RESOURCE_PROP.substring(length - 4, length);
|
||||
|
||||
for (String propertyName : properties.stringPropertyNames()) {
|
||||
if (propertyName.startsWith(customRegionPrefix) && propertyName.endsWith(customRegionSuffix)) {
|
||||
caches.add(properties.getProperty(propertyName));
|
||||
}
|
||||
}
|
||||
|
||||
return caches;
|
||||
}
|
||||
}
|
|
@ -9,11 +9,10 @@ package org.jboss.as.jpa.hibernate5;
|
|||
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
|
||||
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformProvider;
|
||||
|
||||
|
||||
/**
|
||||
* @author Scott Marlow
|
||||
*/
|
||||
public class DefaultJtaPlatform implements JtaPlatformProvider {
|
||||
public class JtaPlatformProviderImpl implements JtaPlatformProvider {
|
||||
|
||||
private static volatile JBossAppServerJtaPlatform delegate;
|
||||
|
||||
|
@ -22,7 +21,7 @@ public class DefaultJtaPlatform implements JtaPlatformProvider {
|
|||
}
|
||||
|
||||
public static void setDelegate(JBossAppServerJtaPlatform delegate) {
|
||||
DefaultJtaPlatform.delegate = delegate;
|
||||
JtaPlatformProviderImpl.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
|
@ -1,79 +0,0 @@
|
|||
/*
|
||||
* 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.infinispan;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.cache.CacheException;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.infinispan.AdvancedCache;
|
||||
import org.infinispan.manager.EmbeddedCacheManager;
|
||||
import org.jboss.as.jpa.hibernate5.HibernateSecondLevelCache;
|
||||
import org.jipijapa.cache.spi.Classification;
|
||||
import org.jipijapa.cache.spi.Wrapper;
|
||||
import org.jipijapa.event.impl.internal.Notification;
|
||||
|
||||
/**
|
||||
* Infinispan-backed region factory for use with standalone (i.e. non-JPA) Hibernate applications.
|
||||
* @author Paul Ferraro
|
||||
* @author Scott Marlow
|
||||
*/
|
||||
public class InfinispanRegionFactory extends org.infinispan.hibernate.cache.commons.InfinispanRegionFactory {
|
||||
private static final long serialVersionUID = 6526170943015350422L;
|
||||
|
||||
public static final String CACHE_CONTAINER = "hibernate.cache.infinispan.container";
|
||||
public static final String DEFAULT_CACHE_CONTAINER = "hibernate";
|
||||
public static final String CACHE_PRIVATE = "private";
|
||||
|
||||
private volatile Wrapper wrapper;
|
||||
|
||||
public InfinispanRegionFactory() {
|
||||
super();
|
||||
}
|
||||
|
||||
public InfinispanRegionFactory(Properties props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EmbeddedCacheManager createCacheManager(Properties properties, final ServiceRegistry serviceRegistry) throws CacheException {
|
||||
// Find a suitable service name to represent this session factory instance
|
||||
String name = properties.getProperty(AvailableSettings.SESSION_FACTORY_NAME);
|
||||
String container = properties.getProperty(CACHE_CONTAINER, DEFAULT_CACHE_CONTAINER);
|
||||
HibernateSecondLevelCache.addSecondLevelCacheDependencies(properties, null);
|
||||
|
||||
Properties cacheSettings = new Properties();
|
||||
cacheSettings.setProperty(HibernateSecondLevelCache.CACHE_TYPE, CACHE_PRIVATE);
|
||||
cacheSettings.setProperty(HibernateSecondLevelCache.CONTAINER, container);
|
||||
if (name != null) {
|
||||
cacheSettings.setProperty(HibernateSecondLevelCache.NAME, name);
|
||||
}
|
||||
cacheSettings.setProperty(HibernateSecondLevelCache.CACHES, String.join(" ", HibernateSecondLevelCache.findCaches(properties)));
|
||||
|
||||
try {
|
||||
// start a private cache for non-JPA use and return the started cache.
|
||||
wrapper = Notification.startCache(Classification.INFINISPAN, cacheSettings);
|
||||
return (EmbeddedCacheManager)wrapper.getValue();
|
||||
} catch (Exception e) {
|
||||
throw new CacheException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void stopCacheManager() {
|
||||
// stop the private cache
|
||||
Notification.stopCache(Classification.INFINISPAN, wrapper);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
protected AdvancedCache createCacheWrapper(AdvancedCache cache) {
|
||||
return cache;
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
* 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.infinispan;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.cache.CacheException;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.infinispan.AdvancedCache;
|
||||
import org.infinispan.manager.EmbeddedCacheManager;
|
||||
import org.jboss.as.jpa.hibernate5.HibernateSecondLevelCache;
|
||||
import org.jipijapa.cache.spi.Classification;
|
||||
import org.jipijapa.cache.spi.Wrapper;
|
||||
import org.jipijapa.event.impl.internal.Notification;
|
||||
|
||||
/**
|
||||
* Infinispan-backed region factory that retrieves its cache manager from the Infinispan subsystem.
|
||||
* This is used for (JPA) container managed persistence contexts.
|
||||
* Each deployment application will use a unique Hibernate cache region name in the shared cache.
|
||||
*
|
||||
* @author Paul Ferraro
|
||||
* @author Scott Marlow
|
||||
*/
|
||||
public class SharedInfinispanRegionFactory extends InfinispanRegionFactory {
|
||||
private static final long serialVersionUID = -3277051412715973863L;
|
||||
private volatile Wrapper wrapper;
|
||||
public SharedInfinispanRegionFactory() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SharedInfinispanRegionFactory(Properties props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EmbeddedCacheManager createCacheManager(Properties properties, final ServiceRegistry serviceRegistry) {
|
||||
String container = properties.getProperty(CACHE_CONTAINER, DEFAULT_CACHE_CONTAINER);
|
||||
Properties cacheSettings = new Properties();
|
||||
cacheSettings.put(HibernateSecondLevelCache.CONTAINER, container);
|
||||
try {
|
||||
// Get the (shared) cache manager for JPA application use
|
||||
wrapper = Notification.startCache(Classification.INFINISPAN, cacheSettings);
|
||||
return (EmbeddedCacheManager)wrapper.getValue();
|
||||
} catch (Exception e) {
|
||||
throw new CacheException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not attempt to stop our cache manager because it wasn't created by this region factory.
|
||||
* Base class stop() will call the base stopCacheRegions()
|
||||
*/
|
||||
@Override
|
||||
protected void stopCacheManager() {
|
||||
// notify that the cache is not used but skip the stop since its shared for all jpa applications.
|
||||
Notification.stopCache(Classification.INFINISPAN, wrapper);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
protected AdvancedCache createCacheWrapper(AdvancedCache cache) {
|
||||
cache.start();
|
||||
return cache;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue