Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port 2nd level cache integration to use infinispan-hibernate-cache-sp…
…i module. Move deprecated RegionFactory implementations to a separate legacy module.
- Loading branch information
Showing
15 changed files
with
275 additions
and
167 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
~ JBoss, Home of Professional Open Source | ||
~ Copyright 2018, Red Hat Middleware LLC, and individual contributors | ||
~ by the @authors tag. See the copyright.txt in the distribution for a | ||
~ full listing of individual contributors. | ||
~ | ||
~ 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 | ||
~ http://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. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.wildfly</groupId> | ||
<artifactId>wildfly-jpa-parent</artifactId> | ||
<!-- | ||
Maintain separation between the artifact id and the version to help prevent | ||
merge conflicts between commits changing the GA and those changing the V. | ||
--> | ||
<version>13.0.0.Alpha1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>jipijapa-hibernate5-legacy</artifactId> | ||
|
||
<name>jipijapa Hibernate 5.x (JPA 2.1) legacy integration</name> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.hibernate</groupId> | ||
<artifactId>hibernate-core</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.infinispan</groupId> | ||
<artifactId>infinispan-hibernate-cache-v51</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
</project> |
40 changes: 40 additions & 0 deletions
40
...-legacy/src/main/java/org/jboss/as/jpa/hibernate5/infinispan/InfinispanRegionFactory.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 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2013, Red Hat Middleware LLC, and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* 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 | ||
* http://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.jboss.as.jpa.hibernate5.infinispan; | ||
|
||
import java.util.Properties; | ||
|
||
import org.hibernate.boot.spi.SessionFactoryOptions; | ||
import org.hibernate.cache.CacheException; | ||
|
||
/** | ||
* Infinispan-backed region factory for use with standalone (i.e. non-JPA) Hibernate applications. | ||
* @author Paul Ferraro | ||
* @author Scott Marlow | ||
* @deprecated Use {@link org.infinispan.hibernate.cache.v51.InfinispanRegionFactory} instead in conjunction with "hibernate.cache.infinispan.shared" set to false. | ||
*/ | ||
@Deprecated | ||
public class InfinispanRegionFactory extends org.infinispan.hibernate.cache.v51.InfinispanRegionFactory { | ||
private static final long serialVersionUID = 6526170943015350422L; | ||
|
||
@Override | ||
public void start(SessionFactoryOptions settings, Properties properties) throws CacheException { | ||
properties.setProperty("hibernate.cache.infinispan.shared", "false"); | ||
super.start(settings, properties); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...y/src/main/java/org/jboss/as/jpa/hibernate5/infinispan/SharedInfinispanRegionFactory.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,43 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2013, Red Hat Middleware LLC, and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* 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 | ||
* http://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.jboss.as.jpa.hibernate5.infinispan; | ||
|
||
import java.util.Properties; | ||
|
||
import org.hibernate.boot.spi.SessionFactoryOptions; | ||
import org.hibernate.cache.CacheException; | ||
|
||
/** | ||
* 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 | ||
* @deprecated Use {@link org.infinispan.hibernate.cache.v51.InfinispanRegionFactory} instead. | ||
*/ | ||
@Deprecated | ||
public class SharedInfinispanRegionFactory extends org.infinispan.hibernate.cache.v51.InfinispanRegionFactory { | ||
private static final long serialVersionUID = -3277051412715973863L; | ||
|
||
@Override | ||
public void start(SessionFactoryOptions settings, Properties properties) throws CacheException { | ||
properties.setProperty("hibernate.cache.infinispan.shared", "true"); | ||
super.start(settings, properties); | ||
} | ||
} |
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
96 changes: 96 additions & 0 deletions
96
...rnate5/src/main/java/org/jboss/as/jpa/hibernate5/ManagedEmbeddedCacheManagerProvider.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,96 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2018, Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
|
||
package org.jboss.as.jpa.hibernate5; | ||
|
||
import java.util.Properties; | ||
|
||
import org.hibernate.cache.CacheException; | ||
import org.hibernate.cfg.AvailableSettings; | ||
import org.infinispan.hibernate.cache.spi.EmbeddedCacheManagerProvider; | ||
import org.infinispan.manager.EmbeddedCacheManager; | ||
import org.infinispan.manager.impl.AbstractDelegatingEmbeddedCacheManager; | ||
import org.jipijapa.cache.spi.Classification; | ||
import org.jipijapa.cache.spi.Wrapper; | ||
import org.jipijapa.event.impl.internal.Notification; | ||
import org.kohsuke.MetaInfServices; | ||
|
||
/** | ||
* Provides a managed {@link EmbeddedCacheManager} instance to Infinispan's region factory implementation. | ||
* @author Paul Ferraro | ||
*/ | ||
@MetaInfServices(EmbeddedCacheManagerProvider.class) | ||
public class ManagedEmbeddedCacheManagerProvider implements EmbeddedCacheManagerProvider { | ||
public static final String CACHE_CONTAINER = "hibernate.cache.infinispan.container"; | ||
public static final String DEFAULT_CACHE_CONTAINER = "hibernate"; | ||
public static final String SHARED = "hibernate.cache.infinispan.shared"; | ||
public static final String DEFAULT_SHARED = "true"; | ||
|
||
@Override | ||
public EmbeddedCacheManager getEmbeddedCacheManager(Properties properties) { | ||
|
||
Properties settings = new Properties(); | ||
String container = properties.getProperty(CACHE_CONTAINER, DEFAULT_CACHE_CONTAINER); | ||
settings.setProperty(HibernateSecondLevelCache.CONTAINER, container); | ||
|
||
if (!Boolean.parseBoolean(properties.getProperty(SHARED, DEFAULT_SHARED))) { | ||
HibernateSecondLevelCache.addSecondLevelCacheDependencies(properties, null); | ||
|
||
settings.setProperty(HibernateSecondLevelCache.CACHE_TYPE, HibernateSecondLevelCache.CACHE_PRIVATE); | ||
|
||
// Find a suitable service name to represent this session factory instance | ||
String name = properties.getProperty(AvailableSettings.SESSION_FACTORY_NAME); | ||
if (name != null) { | ||
settings.setProperty(HibernateSecondLevelCache.NAME, name); | ||
} | ||
|
||
settings.setProperty(HibernateSecondLevelCache.CACHES, String.join(" ", HibernateSecondLevelCache.findCaches(properties))); | ||
} | ||
|
||
try { | ||
return new JipiJapaCacheManager(Notification.startCache(Classification.INFINISPAN, settings)); | ||
} catch (CacheException e) { | ||
throw e; | ||
} catch (Exception e) { | ||
throw new CacheException(e); | ||
} | ||
} | ||
|
||
private static class JipiJapaCacheManager extends AbstractDelegatingEmbeddedCacheManager { | ||
private final Wrapper wrapper; | ||
|
||
JipiJapaCacheManager(Wrapper wrapper) { | ||
super((EmbeddedCacheManager) wrapper.getValue()); | ||
this.wrapper = wrapper; | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
Notification.stopCache(Classification.INFINISPAN, this.wrapper); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
this.stop(); | ||
} | ||
} | ||
} |
Oops, something went wrong.