HHH-12416 : Drop `hibernate-ehcache`
This commit is contained in:
parent
af3031a3d5
commit
703a121c00
|
@ -1,17 +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>.
|
||||
*/
|
||||
|
||||
description = "Integration for using Ehcache 2.x as a Hibernate second-level-cache provider"
|
||||
|
||||
apply from: rootProject.file( 'gradle/published-java-module.gradle' )
|
||||
|
||||
dependencies {
|
||||
compile project( ':hibernate-core' )
|
||||
compile( libraries.ehcache )
|
||||
|
||||
testCompile project( ':hibernate-testing' )
|
||||
}
|
|
@ -1,40 +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.hibernate.cache.ehcache;
|
||||
|
||||
import net.sf.ehcache.CacheManager;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface ConfigSettings {
|
||||
String PROP_PREFIX = "hibernate.cache.ehcache.";
|
||||
|
||||
/**
|
||||
* Allows providing `hibernate-ehcache` with a custom Ehcache {@link CacheManager}.
|
||||
*/
|
||||
String CACHE_MANAGER = PROP_PREFIX + "cache_manager";
|
||||
|
||||
/**
|
||||
* Define the behavior of the region factory when a cache is missing,
|
||||
* i.e. when the cache was not created by the cache manager as it started.
|
||||
*
|
||||
* See {@link MissingCacheStrategy} for the various possible values.
|
||||
*
|
||||
* Default value is {@link MissingCacheStrategy#FAIL}.
|
||||
*/
|
||||
String MISSING_CACHE_STRATEGY = PROP_PREFIX + "missing_cache_strategy";
|
||||
|
||||
/**
|
||||
* This is the legacy property name. No need to change it to fit under {@link #PROP_PREFIX}
|
||||
*/
|
||||
String EHCACHE_CONFIGURATION_RESOURCE_NAME = "net.sf.ehcache.configurationResourceName";
|
||||
|
||||
String EHCACHE_CONFIGURATION_CACHE_MANAGER_NAME = "net.sf.ehcache.cacheManagerName";
|
||||
|
||||
String EHCACHE_CONFIGURATION_CACHE_LOCK_TIMEOUT = "net.sf.ehcache.hibernate.cache_lock_timeout";
|
||||
}
|
|
@ -1,64 +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.hibernate.cache.ehcache;
|
||||
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
|
||||
public enum MissingCacheStrategy {
|
||||
|
||||
/**
|
||||
* Fail with an exception on missing caches.
|
||||
*/
|
||||
FAIL("fail"),
|
||||
|
||||
/**
|
||||
* Create a new cache when a cache is not found (see {@link #CREATE})
|
||||
* and also log a warning about the missing cache.
|
||||
*/
|
||||
CREATE_WARN("create-warn"),
|
||||
|
||||
/**
|
||||
* Create a new cache when a cache is not found,
|
||||
* without logging any warning about the missing cache.
|
||||
*
|
||||
* Note that caches created this way may be very badly configured (large size in particular)
|
||||
* unless an appropriate `<defaultCache>` entry is added to the Ehcache configuration.
|
||||
*/
|
||||
CREATE("create");
|
||||
|
||||
private final String externalRepresentation;
|
||||
|
||||
MissingCacheStrategy(String externalRepresentation) {
|
||||
this.externalRepresentation = externalRepresentation;
|
||||
}
|
||||
|
||||
public String getExternalRepresentation() {
|
||||
return externalRepresentation;
|
||||
}
|
||||
|
||||
public static MissingCacheStrategy interpretSetting(Object value) {
|
||||
if ( value instanceof MissingCacheStrategy ) {
|
||||
return (MissingCacheStrategy) value;
|
||||
}
|
||||
|
||||
final String externalRepresentation = value == null ? null : value.toString().trim();
|
||||
|
||||
if ( StringHelper.isEmpty( externalRepresentation ) ) {
|
||||
// Use the default
|
||||
// Default is CREATE_WARN for backward compatibility reasons; we should switch to FAIL at some point.
|
||||
return MissingCacheStrategy.CREATE_WARN;
|
||||
}
|
||||
|
||||
for ( MissingCacheStrategy strategy : values() ) {
|
||||
if ( strategy.externalRepresentation.equals( externalRepresentation ) ) {
|
||||
return strategy;
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException( "Unrecognized missing cache strategy value : `" + value + '`');
|
||||
}
|
||||
}
|
|
@ -1,44 +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.hibernate.cache.ehcache.internal;
|
||||
|
||||
import org.jboss.logging.BasicLogger;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.jboss.logging.annotations.LogMessage;
|
||||
import org.jboss.logging.annotations.Message;
|
||||
import org.jboss.logging.annotations.MessageLogger;
|
||||
import org.jboss.logging.annotations.ValidIdRange;
|
||||
|
||||
import static org.hibernate.internal.log.DeprecationLogger.CATEGORY;
|
||||
import static org.jboss.logging.Logger.Level.WARN;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@MessageLogger(projectCode = "HHH")
|
||||
@ValidIdRange( min = 20100, max = 20100)
|
||||
public interface DeprecationLogger extends BasicLogger {
|
||||
/**
|
||||
* Singleton access
|
||||
*/
|
||||
DeprecationLogger INSTANCE = Logger.getMessageLogger(
|
||||
DeprecationLogger.class,
|
||||
CATEGORY
|
||||
);
|
||||
|
||||
/**
|
||||
* Log a message (WARN) about this provider being deprecated
|
||||
*/
|
||||
@LogMessage(level = WARN)
|
||||
@Message(
|
||||
value = "The Ehcache second-level cache provider for Hibernate is deprecated. " +
|
||||
"See https://hibernate.atlassian.net/browse/HHH-12441 for details.",
|
||||
id = 20100
|
||||
)
|
||||
void logDeprecation();
|
||||
|
||||
}
|
|
@ -1,116 +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.hibernate.cache.ehcache.internal;
|
||||
|
||||
|
||||
import org.hibernate.cache.ehcache.ConfigSettings;
|
||||
import org.hibernate.cache.ehcache.MissingCacheStrategy;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
import org.jboss.logging.annotations.LogMessage;
|
||||
import org.jboss.logging.annotations.Message;
|
||||
import org.jboss.logging.annotations.MessageLogger;
|
||||
import org.jboss.logging.annotations.ValidIdRange;
|
||||
|
||||
import static org.jboss.logging.Logger.Level.WARN;
|
||||
|
||||
/**
|
||||
* The jboss-logging {@link MessageLogger} for the hibernate-ehcache module. It reserves message ids ranging from
|
||||
* 20001 to 20099 (allow 20100 for our DeprecationLogger) inclusively.
|
||||
* <p/>
|
||||
* New messages must be added after the last message defined to ensure message codes are unique.
|
||||
*/
|
||||
@MessageLogger(projectCode = "HHH")
|
||||
@ValidIdRange(min = 20001, max = 20099)
|
||||
public interface EhCacheMessageLogger extends CoreMessageLogger {
|
||||
EhCacheMessageLogger INSTANCE = Logger.getMessageLogger(
|
||||
EhCacheMessageLogger.class,
|
||||
"org.hibernate.orm.cache.ehcache"
|
||||
);
|
||||
|
||||
/**
|
||||
* Log a message (WARN) about inability to find configuration file
|
||||
*
|
||||
* @param name The name of the configuration file
|
||||
*/
|
||||
@LogMessage(level = WARN)
|
||||
@Message(value = "Could not find configuration [%s]; using defaults.", id = 20002)
|
||||
void unableToFindConfiguration(String name);
|
||||
|
||||
/**
|
||||
* Log a message (WARN) about inability to find named cache configuration
|
||||
*
|
||||
* @param name The name of the cache configuration
|
||||
*/
|
||||
@LogMessage(level = WARN)
|
||||
@Message(value = "Could not find a specific ehcache configuration for cache named [%s]; using defaults.", id = 20003)
|
||||
void unableToFindEhCacheConfiguration(String name);
|
||||
|
||||
/**
|
||||
* Logs a message about not being able to resolve the configuration by resource name.
|
||||
*
|
||||
* @param configurationResourceName The resource name we attempted to resolve
|
||||
*/
|
||||
@LogMessage(level = WARN)
|
||||
@Message(
|
||||
value = "A configurationResourceName was set to %s but the resource could not be loaded from the classpath. " +
|
||||
"Ehcache will configure itself using defaults.",
|
||||
id = 20004
|
||||
)
|
||||
void unableToLoadConfiguration(String configurationResourceName);
|
||||
|
||||
/**
|
||||
* Logs a message (WARN) about attempt to use an incompatible
|
||||
* {@link net.sf.ehcache.config.TerracottaConfiguration.ValueMode}.
|
||||
*/
|
||||
@LogMessage(level = WARN)
|
||||
@Message(
|
||||
value = "The default cache value mode for this Ehcache configuration is \"identity\". " +
|
||||
"This is incompatible with clustered Hibernate caching - the value mode has therefore been " +
|
||||
"switched to \"serialization\"",
|
||||
id = 20005
|
||||
)
|
||||
void incompatibleCacheValueMode();
|
||||
|
||||
/**
|
||||
* Logs a message (WARN) about attempt to use an incompatible
|
||||
* {@link net.sf.ehcache.config.TerracottaConfiguration.ValueMode}.
|
||||
*
|
||||
* @param cacheName The name of the cache whose config attempted to specify value mode.
|
||||
*/
|
||||
@LogMessage(level = WARN)
|
||||
@Message(value = "The value mode for the cache[%s] is \"identity\". This is incompatible with clustered Hibernate caching - "
|
||||
+ "the value mode has therefore been switched to \"serialization\"", id = 20006)
|
||||
void incompatibleCacheValueModePerCache(String cacheName);
|
||||
|
||||
/**
|
||||
* Log a message (WARN) about an attempt to specify read-only caching for a mutable entity
|
||||
*
|
||||
* @param entityName The name of the entity
|
||||
*/
|
||||
@LogMessage(level = WARN)
|
||||
@Message(value = "read-only cache configured for mutable entity [%s]", id = 20007)
|
||||
void readOnlyCacheConfiguredForMutableEntity(String entityName);
|
||||
|
||||
/**
|
||||
* Log a message (WARN) about expiry of soft-locked region.
|
||||
*
|
||||
* @param regionName The region name
|
||||
* @param key The cache key
|
||||
* @param lock The lock
|
||||
*/
|
||||
@LogMessage(level = WARN)
|
||||
@Message(
|
||||
value = "Cache[%s] Key[%s] Lockable[%s]\n" +
|
||||
"A soft-locked cache entry was expired by the underlying Ehcache. If this happens regularly you " +
|
||||
"should consider increasing the cache timeouts and/or capacity limits",
|
||||
id = 20008
|
||||
)
|
||||
void softLockedCacheExpired(String regionName, Object key, String lock);
|
||||
|
||||
}
|
|
@ -1,356 +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.hibernate.cache.ehcache.internal;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sf.ehcache.CacheManager;
|
||||
import net.sf.ehcache.Ehcache;
|
||||
import net.sf.ehcache.config.Configuration;
|
||||
import net.sf.ehcache.config.ConfigurationFactory;
|
||||
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.boot.spi.SessionFactoryOptions;
|
||||
import org.hibernate.cache.CacheException;
|
||||
import org.hibernate.cache.cfg.spi.DomainDataRegionBuildingContext;
|
||||
import org.hibernate.cache.cfg.spi.DomainDataRegionConfig;
|
||||
import org.hibernate.cache.ehcache.ConfigSettings;
|
||||
import org.hibernate.cache.ehcache.MissingCacheStrategy;
|
||||
import org.hibernate.cache.internal.DefaultCacheKeysFactory;
|
||||
import org.hibernate.cache.spi.CacheKeysFactory;
|
||||
import org.hibernate.cache.spi.DomainDataRegion;
|
||||
import org.hibernate.cache.spi.SecondLevelCacheLogger;
|
||||
import org.hibernate.cache.spi.support.DomainDataRegionImpl;
|
||||
import org.hibernate.cache.spi.support.DomainDataStorageAccess;
|
||||
import org.hibernate.cache.spi.support.RegionFactoryTemplate;
|
||||
import org.hibernate.cache.spi.support.RegionNameQualifier;
|
||||
import org.hibernate.cache.spi.support.SimpleTimestamper;
|
||||
import org.hibernate.cache.spi.support.StorageAccess;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
|
||||
import static org.hibernate.cache.ehcache.ConfigSettings.EHCACHE_CONFIGURATION_RESOURCE_NAME;
|
||||
import static org.hibernate.cache.ehcache.internal.HibernateEhcacheUtils.setCacheManagerNameIfNeeded;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
* @author Alex Snaps
|
||||
*/
|
||||
public class EhcacheRegionFactory extends RegionFactoryTemplate {
|
||||
private static final EhCacheMessageLogger LOG = EhCacheMessageLogger.INSTANCE;
|
||||
|
||||
private final CacheKeysFactory cacheKeysFactory;
|
||||
|
||||
private volatile CacheManager cacheManager;
|
||||
private volatile MissingCacheStrategy missingCacheStrategy;
|
||||
private volatile long cacheLockTimeout;
|
||||
|
||||
public EhcacheRegionFactory() {
|
||||
this( DefaultCacheKeysFactory.INSTANCE );
|
||||
}
|
||||
|
||||
public EhcacheRegionFactory(CacheKeysFactory cacheKeysFactory) {
|
||||
this.cacheKeysFactory = cacheKeysFactory;
|
||||
DeprecationLogger.INSTANCE.logDeprecation();
|
||||
}
|
||||
|
||||
public CacheManager getCacheManager() {
|
||||
return cacheManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CacheKeysFactory getImplicitCacheKeysFactory() {
|
||||
return cacheKeysFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DomainDataRegion buildDomainDataRegion(
|
||||
DomainDataRegionConfig regionConfig, DomainDataRegionBuildingContext buildingContext) {
|
||||
return new DomainDataRegionImpl(
|
||||
regionConfig,
|
||||
this,
|
||||
createDomainDataStorageAccess( regionConfig, buildingContext ),
|
||||
cacheKeysFactory,
|
||||
buildingContext
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DomainDataStorageAccess createDomainDataStorageAccess(
|
||||
DomainDataRegionConfig regionConfig,
|
||||
DomainDataRegionBuildingContext buildingContext) {
|
||||
return new StorageAccessImpl(
|
||||
getOrCreateCache( regionConfig.getRegionName(), buildingContext.getSessionFactory() )
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StorageAccess createQueryResultsRegionStorageAccess(
|
||||
String regionName,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
String defaultedRegionName = defaultRegionName(
|
||||
regionName,
|
||||
sessionFactory,
|
||||
DEFAULT_QUERY_RESULTS_REGION_UNQUALIFIED_NAME,
|
||||
LEGACY_QUERY_RESULTS_REGION_UNQUALIFIED_NAMES
|
||||
);
|
||||
return new StorageAccessImpl( getOrCreateCache( defaultedRegionName, sessionFactory ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StorageAccess createTimestampsRegionStorageAccess(
|
||||
String regionName,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
String defaultedRegionName = defaultRegionName(
|
||||
regionName,
|
||||
sessionFactory,
|
||||
DEFAULT_UPDATE_TIMESTAMPS_REGION_UNQUALIFIED_NAME,
|
||||
LEGACY_UPDATE_TIMESTAMPS_REGION_UNQUALIFIED_NAMES
|
||||
);
|
||||
return new StorageAccessImpl( getOrCreateCache( defaultedRegionName, sessionFactory ) );
|
||||
}
|
||||
|
||||
protected final String defaultRegionName(String regionName, SessionFactoryImplementor sessionFactory,
|
||||
String defaultRegionName, List<String> legacyDefaultRegionNames) {
|
||||
if ( defaultRegionName.equals( regionName )
|
||||
&& !cacheExists( regionName, sessionFactory ) ) {
|
||||
// Maybe the user configured caches explicitly with legacy names; try them and use the first that exists
|
||||
|
||||
for ( String legacyDefaultRegionName : legacyDefaultRegionNames ) {
|
||||
if ( cacheExists( legacyDefaultRegionName, sessionFactory ) ) {
|
||||
SecondLevelCacheLogger.INSTANCE.usingLegacyCacheName( defaultRegionName, legacyDefaultRegionName );
|
||||
return legacyDefaultRegionName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return regionName;
|
||||
}
|
||||
|
||||
protected Ehcache getOrCreateCache(String unqualifiedRegionName, SessionFactoryImplementor sessionFactory) {
|
||||
verifyStarted();
|
||||
assert !RegionNameQualifier.INSTANCE.isQualified( unqualifiedRegionName, sessionFactory.getSessionFactoryOptions() );
|
||||
|
||||
final String qualifiedRegionName = RegionNameQualifier.INSTANCE.qualify(
|
||||
unqualifiedRegionName,
|
||||
sessionFactory.getSessionFactoryOptions()
|
||||
);
|
||||
|
||||
final Ehcache cache = cacheManager.getEhcache( qualifiedRegionName );
|
||||
if ( cache == null ) {
|
||||
return createCache( qualifiedRegionName );
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
|
||||
protected Ehcache createCache(String regionName) {
|
||||
switch ( missingCacheStrategy ) {
|
||||
case CREATE_WARN:
|
||||
SecondLevelCacheLogger.INSTANCE.missingCacheCreated(
|
||||
regionName,
|
||||
ConfigSettings.MISSING_CACHE_STRATEGY, MissingCacheStrategy.CREATE.getExternalRepresentation()
|
||||
);
|
||||
cacheManager.addCache( regionName );
|
||||
return cacheManager.getEhcache( regionName );
|
||||
case CREATE:
|
||||
cacheManager.addCache( regionName );
|
||||
return cacheManager.getEhcache( regionName );
|
||||
case FAIL:
|
||||
throw new CacheException( "On-the-fly creation of Ehcache Cache objects is not supported [" + regionName + "]" );
|
||||
default:
|
||||
throw new IllegalStateException( "Unsupported missing cache strategy: " + missingCacheStrategy );
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean cacheExists(String unqualifiedRegionName, SessionFactoryImplementor sessionFactory) {
|
||||
final String qualifiedRegionName = RegionNameQualifier.INSTANCE.qualify(
|
||||
unqualifiedRegionName,
|
||||
sessionFactory.getSessionFactoryOptions()
|
||||
);
|
||||
return cacheManager.getEhcache( qualifiedRegionName ) != null;
|
||||
}
|
||||
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Lifecycle
|
||||
|
||||
@Override
|
||||
protected boolean isStarted() {
|
||||
return super.isStarted() && cacheManager != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareForUse(SessionFactoryOptions settings, Map configValues) {
|
||||
synchronized ( this ) {
|
||||
this.cacheManager = resolveCacheManager( settings, configValues );
|
||||
if ( this.cacheManager == null ) {
|
||||
throw new CacheException( "Could not start Ehcache CacheManager" );
|
||||
}
|
||||
this.missingCacheStrategy = MissingCacheStrategy.interpretSetting(
|
||||
configValues.get( ConfigSettings.MISSING_CACHE_STRATEGY )
|
||||
);
|
||||
|
||||
Object cacheLockTimeoutConfigValue = configValues.get(
|
||||
ConfigSettings.EHCACHE_CONFIGURATION_CACHE_LOCK_TIMEOUT
|
||||
);
|
||||
if ( cacheLockTimeoutConfigValue != null ) {
|
||||
Integer lockTimeoutInMillis = null;
|
||||
if ( cacheLockTimeoutConfigValue instanceof String ) {
|
||||
lockTimeoutInMillis = Integer.decode( (String) cacheLockTimeoutConfigValue );
|
||||
}
|
||||
else if ( cacheLockTimeoutConfigValue instanceof Number ) {
|
||||
lockTimeoutInMillis = ( (Number) cacheLockTimeoutConfigValue ).intValue();
|
||||
}
|
||||
if ( lockTimeoutInMillis != null ) {
|
||||
this.cacheLockTimeout = SimpleTimestamper.ONE_MS * lockTimeoutInMillis;
|
||||
}
|
||||
else {
|
||||
this.cacheLockTimeout = super.getTimeout();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected CacheManager resolveCacheManager(SessionFactoryOptions settings, Map properties) {
|
||||
final Object explicitCacheManager = properties.get( ConfigSettings.CACHE_MANAGER );
|
||||
if ( explicitCacheManager != null ) {
|
||||
return useExplicitCacheManager( settings, explicitCacheManager );
|
||||
}
|
||||
|
||||
return useNormalCacheManager( settings, properties );
|
||||
}
|
||||
|
||||
/**
|
||||
* Locate the CacheManager during start-up. protected to allow for subclassing
|
||||
* such as SingletonEhcacheRegionFactory
|
||||
*/
|
||||
protected static CacheManager useNormalCacheManager(SessionFactoryOptions settings, Map properties) {
|
||||
try {
|
||||
String configurationResourceName = null;
|
||||
if ( properties != null ) {
|
||||
configurationResourceName = (String) properties.get( EHCACHE_CONFIGURATION_RESOURCE_NAME );
|
||||
}
|
||||
if ( configurationResourceName == null || configurationResourceName.length() == 0 ) {
|
||||
final Configuration configuration = ConfigurationFactory.parseConfiguration();
|
||||
setCacheManagerNameIfNeeded( settings, configuration, properties );
|
||||
return new CacheManager( configuration );
|
||||
}
|
||||
else {
|
||||
final URL url = loadResource( configurationResourceName, settings );
|
||||
final Configuration configuration = HibernateEhcacheUtils.loadAndCorrectConfiguration( url );
|
||||
setCacheManagerNameIfNeeded( settings, configuration, properties );
|
||||
return new CacheManager( configuration );
|
||||
}
|
||||
}
|
||||
catch (net.sf.ehcache.CacheException e) {
|
||||
if ( e.getMessage().startsWith(
|
||||
"Cannot parseConfiguration CacheManager. Attempt to create a new instance of " +
|
||||
"CacheManager using the diskStorePath"
|
||||
) ) {
|
||||
throw new CacheException(
|
||||
"Attempt to restart an already started EhCacheRegionFactory. " +
|
||||
"Use sessionFactory.close() between repeated calls to buildSessionFactory. " +
|
||||
"Consider using SingletonEhCacheRegionFactory. Error from ehcache was: " + e.getMessage()
|
||||
);
|
||||
}
|
||||
else {
|
||||
throw new CacheException( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static URL loadResource(String configurationResourceName, SessionFactoryOptions settings) {
|
||||
URL url = settings.getServiceRegistry()
|
||||
.getService( ClassLoaderService.class )
|
||||
.locateResource( configurationResourceName );
|
||||
|
||||
if ( url == null ) {
|
||||
final ClassLoader standardClassloader = Thread.currentThread().getContextClassLoader();
|
||||
if ( standardClassloader != null ) {
|
||||
url = standardClassloader.getResource( configurationResourceName );
|
||||
}
|
||||
if ( url == null ) {
|
||||
url = EhcacheRegionFactory.class.getResource( configurationResourceName );
|
||||
}
|
||||
if ( url == null ) {
|
||||
try {
|
||||
url = new URL( configurationResourceName );
|
||||
}
|
||||
catch ( MalformedURLException e ) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( LOG.isDebugEnabled() ) {
|
||||
LOG.debugf(
|
||||
"Creating EhCacheRegionFactory from a specified resource: %s. Resolved to URL: %s",
|
||||
configurationResourceName,
|
||||
url
|
||||
);
|
||||
}
|
||||
if ( url == null ) {
|
||||
EhCacheMessageLogger.INSTANCE.unableToLoadConfiguration( configurationResourceName );
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a resource from the classpath.
|
||||
*/
|
||||
protected URL loadResource(String configurationResourceName) {
|
||||
// we use this method to create the cache manager so we can't check it is non null
|
||||
// calling the super method then
|
||||
if ( ! super.isStarted() ) {
|
||||
throw new IllegalStateException( "Cannot load resource through a non-started EhcacheRegionFactory" );
|
||||
}
|
||||
|
||||
return loadResource( configurationResourceName, getOptions() );
|
||||
}
|
||||
|
||||
private CacheManager useExplicitCacheManager(SessionFactoryOptions settings, Object setting) {
|
||||
if ( setting instanceof CacheManager ) {
|
||||
return (CacheManager) setting;
|
||||
}
|
||||
|
||||
final Class<? extends CacheManager> cacheManagerClass;
|
||||
if ( setting instanceof Class ) {
|
||||
cacheManagerClass = (Class<? extends CacheManager>) setting;
|
||||
}
|
||||
else {
|
||||
cacheManagerClass = settings.getServiceRegistry().getService( ClassLoaderService.class )
|
||||
.classForName( setting.toString() );
|
||||
}
|
||||
|
||||
try {
|
||||
return cacheManagerClass.newInstance();
|
||||
}
|
||||
catch (InstantiationException | IllegalAccessException e) {
|
||||
throw new CacheException( "Could not use explicit CacheManager : " + setting );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void releaseFromUse() {
|
||||
try {
|
||||
// todo (5.3) : if this is a manager instance that was provided to us we should probably not close it...
|
||||
// - when the explicit `setting` passed to `#useExplicitCacheManager` is
|
||||
// a CacheManager instance
|
||||
cacheManager.shutdown();
|
||||
}
|
||||
finally {
|
||||
cacheManager = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTimeout() {
|
||||
return cacheLockTimeout;
|
||||
}
|
||||
}
|
|
@ -1,96 +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.hibernate.cache.ehcache.internal;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sf.ehcache.config.CacheConfiguration;
|
||||
import net.sf.ehcache.config.Configuration;
|
||||
import net.sf.ehcache.config.ConfigurationFactory;
|
||||
import net.sf.ehcache.config.NonstopConfiguration;
|
||||
import net.sf.ehcache.config.TimeoutBehaviorConfiguration.TimeoutBehaviorType;
|
||||
|
||||
import org.hibernate.boot.spi.SessionFactoryOptions;
|
||||
|
||||
import static org.hibernate.cache.ehcache.ConfigSettings.EHCACHE_CONFIGURATION_CACHE_MANAGER_NAME;
|
||||
|
||||
|
||||
/**
|
||||
* Copy of Ehcache utils into Hibernate code base
|
||||
*
|
||||
* @author Chris Dennis
|
||||
* @author Abhishek Sanoujam
|
||||
* @author Alex Snaps
|
||||
*/
|
||||
public final class HibernateEhcacheUtils {
|
||||
|
||||
private HibernateEhcacheUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a cache manager configuration from the supplied url, correcting it for Hibernate compatibility.
|
||||
* <p/>
|
||||
* Currently "correcting" for Hibernate compatibility means simply switching any identity based value modes
|
||||
* to serialization.
|
||||
*
|
||||
* @param url The url to load the config from
|
||||
*
|
||||
* @return The Ehcache Configuration object
|
||||
*/
|
||||
public static Configuration loadAndCorrectConfiguration(URL url) {
|
||||
final Configuration config = ConfigurationFactory.parseConfiguration( url );
|
||||
|
||||
// EHC-875 / HHH-6576
|
||||
if ( config == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( config.getDefaultCacheConfiguration() != null
|
||||
&& config.getDefaultCacheConfiguration().isTerracottaClustered() ) {
|
||||
setupHibernateTimeoutBehavior(
|
||||
config.getDefaultCacheConfiguration()
|
||||
.getTerracottaConfiguration()
|
||||
.getNonstopConfiguration()
|
||||
);
|
||||
}
|
||||
|
||||
for ( CacheConfiguration cacheConfig : config.getCacheConfigurations().values() ) {
|
||||
if ( cacheConfig.isTerracottaClustered() ) {
|
||||
setupHibernateTimeoutBehavior( cacheConfig.getTerracottaConfiguration().getNonstopConfiguration() );
|
||||
}
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
static void setCacheManagerNameIfNeeded(SessionFactoryOptions settings, Configuration configuration, Map properties) {
|
||||
overwriteCacheManagerIfConfigured( configuration, properties );
|
||||
if (configuration.getName() == null) {
|
||||
String sessionFactoryName = settings.getSessionFactoryName();
|
||||
if (sessionFactoryName != null) {
|
||||
configuration.setName( sessionFactoryName );
|
||||
}
|
||||
else {
|
||||
configuration.setName( "Hibernate " + settings.getUuid() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Configuration overwriteCacheManagerIfConfigured(final Configuration configuration, final Map properties) {
|
||||
if (properties != null) {
|
||||
final String cacheManagerName = (String) properties.get( EHCACHE_CONFIGURATION_CACHE_MANAGER_NAME );
|
||||
if (cacheManagerName != null) {
|
||||
configuration.setName( cacheManagerName );
|
||||
}
|
||||
}
|
||||
return configuration;
|
||||
}
|
||||
|
||||
private static void setupHibernateTimeoutBehavior(NonstopConfiguration nonstopConfig) {
|
||||
nonstopConfig.getTimeoutBehavior().setType( TimeoutBehaviorType.EXCEPTION.getTypeName() );
|
||||
}
|
||||
}
|
|
@ -1,90 +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.hibernate.cache.ehcache.internal;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import net.sf.ehcache.CacheManager;
|
||||
|
||||
import net.sf.ehcache.config.Configuration;
|
||||
import org.hibernate.boot.spi.SessionFactoryOptions;
|
||||
import org.hibernate.cache.CacheException;
|
||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import static org.hibernate.cache.ehcache.ConfigSettings.EHCACHE_CONFIGURATION_RESOURCE_NAME;
|
||||
import static org.hibernate.cache.ehcache.internal.HibernateEhcacheUtils.overwriteCacheManagerIfConfigured;
|
||||
import static org.hibernate.cache.ehcache.internal.HibernateEhcacheUtils.setCacheManagerNameIfNeeded;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SingletonEhcacheRegionFactory extends EhcacheRegionFactory {
|
||||
private static final Logger LOG = Logger.getLogger( SingletonEhcacheRegionFactory.class );
|
||||
|
||||
private static final AtomicInteger REFERENCE_COUNT = new AtomicInteger();
|
||||
|
||||
@Override
|
||||
protected CacheManager resolveCacheManager(SessionFactoryOptions settings, Map properties) {
|
||||
try {
|
||||
String configurationResourceName = getOptions().getServiceRegistry()
|
||||
.getService( ConfigurationService.class )
|
||||
.getSetting( EHCACHE_CONFIGURATION_RESOURCE_NAME, value -> value == null ? null : value.toString() );
|
||||
|
||||
if ( configurationResourceName == null || configurationResourceName.length() == 0 ) {
|
||||
try {
|
||||
REFERENCE_COUNT.incrementAndGet();
|
||||
return CacheManager.create();
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
REFERENCE_COUNT.decrementAndGet();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
URL url;
|
||||
try {
|
||||
url = new URL( configurationResourceName );
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
if ( !configurationResourceName.startsWith( "/" ) ) {
|
||||
configurationResourceName = "/" + configurationResourceName;
|
||||
LOG.debugf(
|
||||
"prepending / to %s. It should be placed in the root of the classpath rather than in a package.",
|
||||
configurationResourceName
|
||||
);
|
||||
}
|
||||
url = loadResource( configurationResourceName );
|
||||
}
|
||||
|
||||
try {
|
||||
REFERENCE_COUNT.incrementAndGet();
|
||||
Configuration config = HibernateEhcacheUtils.loadAndCorrectConfiguration( url );
|
||||
setCacheManagerNameIfNeeded( settings, config, properties );
|
||||
return CacheManager.create( config );
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
REFERENCE_COUNT.decrementAndGet();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
catch (net.sf.ehcache.CacheException e) {
|
||||
throw new CacheException( e );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void releaseFromUse() {
|
||||
if ( REFERENCE_COUNT.decrementAndGet() == 0 ) {
|
||||
super.releaseFromUse();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,145 +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.hibernate.cache.ehcache.internal;
|
||||
|
||||
import net.sf.ehcache.Ehcache;
|
||||
import net.sf.ehcache.Element;
|
||||
import net.sf.ehcache.constructs.nonstop.NonStopCacheException;
|
||||
import net.sf.ehcache.hibernate.nonstop.HibernateNonstopCacheExceptionHandler;
|
||||
|
||||
import org.hibernate.cache.CacheException;
|
||||
import org.hibernate.cache.spi.support.DomainDataStorageAccess;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* Implementation of StorageAccess for "talking to" Ehcache
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class StorageAccessImpl implements DomainDataStorageAccess {
|
||||
private static final Logger LOG = Logger.getLogger( StorageAccessImpl.class );
|
||||
|
||||
private final Ehcache cache;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public StorageAccessImpl(Ehcache cache) {
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
public Ehcache getCache() {
|
||||
return cache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object key) {
|
||||
return getCache().isKeyInCache( key );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getFromCache(Object key, SharedSessionContractImplementor session) {
|
||||
try {
|
||||
final Element element = getCache().get( key );
|
||||
if ( element == null ) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return element.getObjectValue();
|
||||
}
|
||||
}
|
||||
catch (net.sf.ehcache.CacheException e) {
|
||||
if ( e instanceof NonStopCacheException ) {
|
||||
HibernateNonstopCacheExceptionHandler.getInstance()
|
||||
.handleNonstopCacheException( (NonStopCacheException) e );
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw new CacheException( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putIntoCache(Object key, Object value, SharedSessionContractImplementor session) {
|
||||
try {
|
||||
final Element element = new Element( key, value );
|
||||
getCache().put( element );
|
||||
}
|
||||
catch (IllegalArgumentException | IllegalStateException e) {
|
||||
throw new CacheException( e );
|
||||
}
|
||||
catch (net.sf.ehcache.CacheException e) {
|
||||
if ( e instanceof NonStopCacheException ) {
|
||||
HibernateNonstopCacheExceptionHandler.getInstance()
|
||||
.handleNonstopCacheException( (NonStopCacheException) e );
|
||||
}
|
||||
else {
|
||||
throw new CacheException( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evictData(Object key) {
|
||||
try {
|
||||
getCache().remove( key );
|
||||
}
|
||||
catch (ClassCastException | IllegalStateException e) {
|
||||
throw new CacheException( e );
|
||||
}
|
||||
catch (net.sf.ehcache.CacheException e) {
|
||||
if ( e instanceof NonStopCacheException ) {
|
||||
HibernateNonstopCacheExceptionHandler.getInstance()
|
||||
.handleNonstopCacheException( (NonStopCacheException) e );
|
||||
}
|
||||
else {
|
||||
throw new CacheException( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evictData() {
|
||||
try {
|
||||
getCache().removeAll();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
throw new CacheException( e );
|
||||
}
|
||||
catch (net.sf.ehcache.CacheException e) {
|
||||
if ( e instanceof NonStopCacheException ) {
|
||||
HibernateNonstopCacheExceptionHandler.getInstance()
|
||||
.handleNonstopCacheException( (NonStopCacheException) e );
|
||||
}
|
||||
else {
|
||||
throw new CacheException( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release() {
|
||||
try {
|
||||
getCache().getCacheManager().removeCache( getCache().getName() );
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
//When Spring and Hibernate are both involved this will happen in normal shutdown operation.
|
||||
//Do not throw an exception, simply log this one.
|
||||
LOG.debug( "This can happen if multiple frameworks both try to shutdown ehcache", e );
|
||||
}
|
||||
catch (net.sf.ehcache.CacheException e) {
|
||||
if ( e instanceof NonStopCacheException ) {
|
||||
HibernateNonstopCacheExceptionHandler.getInstance()
|
||||
.handleNonstopCacheException( (NonStopCacheException) e );
|
||||
}
|
||||
else {
|
||||
throw new CacheException( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,58 +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.hibernate.cache.ehcache.internal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.boot.registry.selector.SimpleStrategyRegistrationImpl;
|
||||
import org.hibernate.boot.registry.selector.StrategyRegistration;
|
||||
import org.hibernate.boot.registry.selector.StrategyRegistrationProvider;
|
||||
import org.hibernate.cache.spi.RegionFactory;
|
||||
|
||||
/**
|
||||
* Makes the 2 contained region factory implementations available to the Hibernate
|
||||
* {@link org.hibernate.boot.registry.selector.spi.StrategySelector} service.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public final class StrategyRegistrationProviderImpl implements StrategyRegistrationProvider {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Iterable<StrategyRegistration> getStrategyRegistrations() {
|
||||
final List<StrategyRegistration> strategyRegistrations = new ArrayList<StrategyRegistration>( 2 );
|
||||
|
||||
strategyRegistrations.add(
|
||||
new SimpleStrategyRegistrationImpl(
|
||||
RegionFactory.class,
|
||||
EhcacheRegionFactory.class,
|
||||
"ehcache",
|
||||
EhcacheRegionFactory.class.getName(),
|
||||
EhcacheRegionFactory.class.getSimpleName(),
|
||||
// legacy impl class name
|
||||
"org.hibernate.cache.EhCacheRegionFactory",
|
||||
"org.hibernate.cache.ehcache.EhCacheRegionFactory"
|
||||
)
|
||||
);
|
||||
|
||||
strategyRegistrations.add(
|
||||
new SimpleStrategyRegistrationImpl(
|
||||
RegionFactory.class,
|
||||
SingletonEhcacheRegionFactory.class,
|
||||
"ehcache-singleton",
|
||||
SingletonEhcacheRegionFactory.class.getName(),
|
||||
SingletonEhcacheRegionFactory.class.getSimpleName(),
|
||||
// legacy impl class name
|
||||
"org.hibernate.cache.SingletonEhCacheRegionFactory",
|
||||
"org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory"
|
||||
)
|
||||
);
|
||||
|
||||
return strategyRegistrations;
|
||||
}
|
||||
}
|
|
@ -1,13 +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
|
||||
#
|
||||
#
|
||||
# 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.hibernate.cache.ehcache.internal.StrategyRegistrationProviderImpl
|
|
@ -1,37 +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.hibernate.cache.ehcache.test;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.hibernate.annotations.Cache;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
import org.hibernate.cache.ehcache.ConfigSettings;
|
||||
import org.hibernate.cache.ehcache.internal.EhcacheRegionFactory;
|
||||
import org.hibernate.cache.spi.CacheImplementor;
|
||||
import org.hibernate.cache.spi.support.SimpleTimestamper;
|
||||
import org.hibernate.cfg.Environment;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class EhcacheLockTimeoutIntegerConfigurationTest
|
||||
extends EhcacheLockTimeoutStringConfigurationTest {
|
||||
|
||||
@Override
|
||||
protected void addSettings(Map settings) {
|
||||
super.addSettings( settings );
|
||||
settings.put( ConfigSettings.EHCACHE_CONFIGURATION_CACHE_LOCK_TIMEOUT, 1000 );
|
||||
}
|
||||
|
||||
}
|
|
@ -1,59 +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.hibernate.cache.ehcache.test;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.hibernate.annotations.Cache;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
import org.hibernate.cache.ehcache.ConfigSettings;
|
||||
import org.hibernate.cache.ehcache.internal.EhcacheRegionFactory;
|
||||
import org.hibernate.cache.spi.CacheImplementor;
|
||||
import org.hibernate.cache.spi.support.SimpleTimestamper;
|
||||
import org.hibernate.cfg.Environment;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class EhcacheLockTimeoutStringConfigurationTest
|
||||
extends BaseNonConfigCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected void addSettings(Map settings) {
|
||||
settings.put( Environment.CACHE_REGION_FACTORY, "ehcache" );
|
||||
settings.put( ConfigSettings.EHCACHE_CONFIGURATION_CACHE_LOCK_TIMEOUT, "1000" );
|
||||
}
|
||||
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
Event.class
|
||||
};
|
||||
}
|
||||
|
||||
@Entity(name = "Event")
|
||||
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
|
||||
public static class Event {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
CacheImplementor cacheImplementor = sessionFactory().getCache();
|
||||
EhcacheRegionFactory regionFactory = (EhcacheRegionFactory) cacheImplementor.getRegion( Event.class.getName() ).getRegionFactory();
|
||||
assertEquals( TimeUnit.SECONDS.toMillis( 1 ) * SimpleTimestamper.ONE_MS, regionFactory.getTimeout() );
|
||||
}
|
||||
|
||||
}
|
|
@ -1,162 +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.hibernate.cache.ehcache.test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
|
||||
import org.hibernate.annotations.Cache;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
import org.hibernate.boot.SessionFactoryBuilder;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
|
||||
import org.hibernate.testing.jdbc.SQLStatementInterceptor;
|
||||
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class EhcacheTransactionalCacheConcurrencyStrategyTest
|
||||
extends BaseNonConfigCoreFunctionalTestCase {
|
||||
|
||||
private SQLStatementInterceptor sqlStatementInterceptor;
|
||||
|
||||
@Override
|
||||
protected void configureSessionFactoryBuilder(SessionFactoryBuilder sfb) {
|
||||
sqlStatementInterceptor = new SQLStatementInterceptor( sfb );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addSettings(Map settings) {
|
||||
settings.put( Environment.ENABLE_LAZY_LOAD_NO_TRANS, "true" );
|
||||
|
||||
TestingJtaBootstrap.prepare( settings );
|
||||
settings.put( Environment.TRANSACTION_COORDINATOR_STRATEGY, "jta" );
|
||||
settings.put( Environment.CACHE_REGION_FACTORY, "ehcache" );
|
||||
}
|
||||
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
Parent.class,
|
||||
Child.class
|
||||
};
|
||||
}
|
||||
|
||||
@Entity(name = "Parent")
|
||||
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
|
||||
public static class Parent {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "parent")
|
||||
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
|
||||
private List<Child> children = new ArrayList<Child>();
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public List<Child> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(List<Child> children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
Child addChild() {
|
||||
final Child c = new Child();
|
||||
c.setParent( this );
|
||||
this.children.add( c );
|
||||
return c;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Entity(name = "Child")
|
||||
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
|
||||
public static class Child {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@ManyToOne(
|
||||
fetch = FetchType.LAZY
|
||||
)
|
||||
private Parent parent;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Parent getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(Parent parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTransactional() {
|
||||
Parent parent = new Parent();
|
||||
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
for ( int i = 0; i < 2; i++ ) {
|
||||
parent.addChild();
|
||||
|
||||
session.persist( parent );
|
||||
}
|
||||
} );
|
||||
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
sqlStatementInterceptor.getSqlQueries().clear();
|
||||
|
||||
Parent _parent = session.find( Parent.class, parent.getId() );
|
||||
|
||||
assertEquals( 0, sqlStatementInterceptor.getSqlQueries().size() );
|
||||
|
||||
assertEquals( 2, _parent.getChildren().size() );
|
||||
} );
|
||||
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
sqlStatementInterceptor.getSqlQueries().clear();
|
||||
|
||||
Parent _parent = session.find( Parent.class, parent.getId() );
|
||||
|
||||
assertEquals( 2, _parent.getChildren().size() );
|
||||
|
||||
assertEquals( 0, sqlStatementInterceptor.getSqlQueries().size() );
|
||||
} );
|
||||
}
|
||||
|
||||
}
|
|
@ -1,229 +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.hibernate.cache.ehcache.test;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
import org.hibernate.FlushMode;
|
||||
import org.hibernate.annotations.Cache;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
import org.hibernate.cache.ehcache.internal.SingletonEhcacheRegionFactory;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
|
||||
/**
|
||||
* @author Chris Cranford
|
||||
*/
|
||||
public class IdentityIdentifierDelayedInsertTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||
@Override
|
||||
protected void addSettings(Map settings) {
|
||||
super.addSettings( settings );
|
||||
|
||||
settings.put( AvailableSettings.FLUSH_MODE, FlushMode.COMMIT );
|
||||
settings.put( AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "false" );
|
||||
settings.put( AvailableSettings.USE_SECOND_LEVEL_CACHE, "true" );
|
||||
settings.put( AvailableSettings.USE_QUERY_CACHE, "false" );
|
||||
settings.put( AvailableSettings.AUTO_EVICT_COLLECTION_CACHE, "true" );
|
||||
settings.put( AvailableSettings.CACHE_REGION_FACTORY, SingletonEhcacheRegionFactory.class.getName() );
|
||||
settings.put( AvailableSettings.GENERATE_STATISTICS, "false" );
|
||||
}
|
||||
|
||||
@Entity(name = "NonCachedEntity")
|
||||
public static class NonCachedEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
private String data;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if ( this == o ) {
|
||||
return true;
|
||||
}
|
||||
if ( o == null || getClass() != o.getClass() ) {
|
||||
return false;
|
||||
}
|
||||
NonCachedEntity that = (NonCachedEntity) o;
|
||||
return Objects.equals( id, that.id ) &&
|
||||
Objects.equals( data, that.data );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash( id, data );
|
||||
}
|
||||
}
|
||||
|
||||
@Entity(name = "CachedEntity")
|
||||
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
|
||||
public static class CachedEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
private String name;
|
||||
@ManyToOne
|
||||
@JoinColumn(nullable = false)
|
||||
private NonCachedEntity nonCachedEntity;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public NonCachedEntity getNonCachedEntity() {
|
||||
return nonCachedEntity;
|
||||
}
|
||||
|
||||
public void setNonCachedEntity(NonCachedEntity nonCachedEntity) {
|
||||
this.nonCachedEntity = nonCachedEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if ( this == o ) {
|
||||
return true;
|
||||
}
|
||||
if ( o == null || getClass() != o.getClass() ) {
|
||||
return false;
|
||||
}
|
||||
CachedEntity that = (CachedEntity) o;
|
||||
return Objects.equals( id, that.id ) &&
|
||||
Objects.equals( name, that.name ) &&
|
||||
Objects.equals( nonCachedEntity, that.nonCachedEntity );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash( id, name, nonCachedEntity );
|
||||
}
|
||||
}
|
||||
|
||||
@Entity(name = "SomeEntity")
|
||||
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
|
||||
public static class SomeEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
private String name;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
SomeEntity asset = (SomeEntity) o;
|
||||
if (asset.id == null || id == null) {
|
||||
return false;
|
||||
}
|
||||
return Objects.equals(id, asset.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
return Objects.hashCode(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SomeEntity{" + "id=" + id + ", name='" + name + '\'' + '}';
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class<?>[] { SomeEntity.class, NonCachedEntity.class, CachedEntity.class };
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-13147")
|
||||
public void testPersistingCachedEntityWithIdentityBasedIdentifier() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
SomeEntity entity = new SomeEntity();
|
||||
session.persist( entity );
|
||||
|
||||
entity.setName( "foo" );
|
||||
session.persist( entity );
|
||||
|
||||
session.flush();
|
||||
session.clear();
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-13164")
|
||||
public void testPersistingCachedEntityWithIdentityBasedIdentifierReferencingNonCachedEntity() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
final NonCachedEntity nonCachedEntity = new NonCachedEntity();
|
||||
nonCachedEntity.setData( "NonCachedEntity" );
|
||||
session.persist( nonCachedEntity );
|
||||
|
||||
final CachedEntity cachedEntity = new CachedEntity();
|
||||
cachedEntity.setName( "CachedEntity" );
|
||||
cachedEntity.setNonCachedEntity( nonCachedEntity );
|
||||
session.persist( cachedEntity );
|
||||
} );
|
||||
}
|
||||
}
|
|
@ -1,210 +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.hibernate.cache.ehcache.test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cache.CacheException;
|
||||
import org.hibernate.cache.ehcache.ConfigSettings;
|
||||
import org.hibernate.cache.spi.SecondLevelCacheLogger;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.service.spi.ServiceException;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.hibernate.testing.logger.LoggerInspectionRule;
|
||||
import org.hibernate.testing.logger.Triggerable;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class MissingCacheStrategyTest extends BaseUnitTestCase {
|
||||
|
||||
@Rule
|
||||
public LoggerInspectionRule logInspection = new LoggerInspectionRule( SecondLevelCacheLogger.INSTANCE );
|
||||
|
||||
@Test
|
||||
public void testMissingCacheStrategyDefault() {
|
||||
doTestMissingCacheStrategyCreateWarn(
|
||||
ignored -> { } // default settings
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingCacheStrategyFail() {
|
||||
/*
|
||||
* The cache manager is created per session factory, and we don't use any specific ehcache configuration,
|
||||
* so we know the caches don't exist before we start the session factory.
|
||||
*/
|
||||
|
||||
// let's try to build the standard testing SessionFactory, without pre-defining caches
|
||||
try ( SessionFactoryImplementor ignored = TestHelper.buildStandardSessionFactory(
|
||||
builder -> builder.applySetting( ConfigSettings.MISSING_CACHE_STRATEGY, "fail" )
|
||||
) ) {
|
||||
fail();
|
||||
}
|
||||
catch (ServiceException expected) {
|
||||
assertTyping( CacheException.class, expected.getCause() );
|
||||
assertThat( expected.getMessage(), CoreMatchers.equalTo( "Unable to create requested service [" + org.hibernate.cache.spi.CacheImplementor.class.getName() + "]" ) );
|
||||
assertThat( expected.getCause().getMessage(), CoreMatchers.startsWith( "On-the-fly creation of Ehcache Cache objects is not supported" ) );
|
||||
}
|
||||
catch (CacheException expected) {
|
||||
assertThat( expected.getMessage(), CoreMatchers.equalTo( "On-the-fly creation of Ehcache Cache objects is not supported" ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingCacheStrategyFail_legacyNames() {
|
||||
/*
|
||||
* The cache manager is created per session factory, and we don't use any specific ehcache configuration,
|
||||
* so we know the caches don't exist before we start the session factory.
|
||||
*/
|
||||
|
||||
// let's try to build the standard testing SessionFactory, without pre-defining caches
|
||||
try ( SessionFactoryImplementor ignored = TestHelper.buildStandardSessionFactory(
|
||||
builder -> builder.applySetting( ConfigSettings.MISSING_CACHE_STRATEGY, "fail" )
|
||||
) ) {
|
||||
fail();
|
||||
}
|
||||
catch (ServiceException expected) {
|
||||
assertTyping( CacheException.class, expected.getCause() );
|
||||
assertThat( expected.getMessage(), CoreMatchers.equalTo( "Unable to create requested service [" + org.hibernate.cache.spi.CacheImplementor.class.getName() + "]" ) );
|
||||
assertThat( expected.getCause().getMessage(), CoreMatchers.startsWith( "On-the-fly creation of Ehcache Cache objects is not supported" ) );
|
||||
}
|
||||
catch (CacheException expected) {
|
||||
assertThat( expected.getMessage(), CoreMatchers.equalTo( "On-the-fly creation of Ehcache Cache objects is not supported" ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingCacheStrategyCreate() {
|
||||
/*
|
||||
* The cache manager is created per session factory, and we don't use any specific ehcache configuration,
|
||||
* so we know the caches don't exist before we start the session factory.
|
||||
*/
|
||||
|
||||
// and now let's try to build the standard testing SessionFactory, without pre-defining caches
|
||||
try ( SessionFactoryImplementor sessionFactory = TestHelper.buildStandardSessionFactory(
|
||||
builder -> builder.applySetting( ConfigSettings.MISSING_CACHE_STRATEGY, "create" )
|
||||
) ) {
|
||||
// The caches should have been created automatically
|
||||
for ( String regionName : TestHelper.allDomainRegionNames ) {
|
||||
assertThat( "Cache '" + regionName + "' should have been created",
|
||||
TestHelper.getCache( sessionFactory, regionName ), notNullValue() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingCacheStrategyCreateWarn() {
|
||||
doTestMissingCacheStrategyCreateWarn(
|
||||
builder -> builder.applySetting( ConfigSettings.MISSING_CACHE_STRATEGY, "create-warn" )
|
||||
);
|
||||
}
|
||||
|
||||
private void doTestMissingCacheStrategyCreateWarn(Consumer<StandardServiceRegistryBuilder> additionalSettings) {
|
||||
/*
|
||||
* The cache manager is created per session factory, and we don't use any specific ehcache configuration,
|
||||
* so we know the caches don't exist before we start the session factory.
|
||||
*/
|
||||
|
||||
Map<String, Triggerable> triggerables = new HashMap<>();
|
||||
for ( String regionName : TestHelper.allDomainRegionNames ) {
|
||||
triggerables.put(
|
||||
regionName,
|
||||
logInspection.watchForLogMessages(
|
||||
"HHH90001006: Missing cache[" + TestHelper.prefix( regionName ) + "] was created on-the-fly"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
try ( SessionFactoryImplementor sessionFactory = TestHelper.buildStandardSessionFactory( additionalSettings ) ) {
|
||||
for ( String regionName : TestHelper.allDomainRegionNames ) {
|
||||
// The caches should have been created automatically
|
||||
assertThat(
|
||||
"Cache '" + regionName + "' should have been created",
|
||||
TestHelper.getCache( sessionFactory, regionName ), notNullValue()
|
||||
);
|
||||
// Logs should have been triggered
|
||||
assertTrue(
|
||||
"Cache '" + regionName + "' should have triggered a warning",
|
||||
triggerables.get( regionName ).wasTriggered()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingCacheStrategyFailLegacyNames1() {
|
||||
doTestMissingCacheStrategyFailLegacyNames(
|
||||
"/hibernate-config/ehcache-explicitlegacy1.xml",
|
||||
TestHelper.queryRegionLegacyNames1, TestHelper.queryRegionLegacyNames2
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingCacheStrategyFailLegacyNames2() {
|
||||
doTestMissingCacheStrategyFailLegacyNames(
|
||||
"/hibernate-config/ehcache-explicitlegacy2.xml",
|
||||
TestHelper.queryRegionLegacyNames2, TestHelper.queryRegionLegacyNames1
|
||||
);
|
||||
}
|
||||
|
||||
private void doTestMissingCacheStrategyFailLegacyNames(String configurationPath,
|
||||
String[] existingLegacyCaches, String[] nonExistingLegacyCaches) {
|
||||
Map<String, Triggerable> triggerables = new HashMap<>();
|
||||
|
||||
// This is used later for log-related assertions
|
||||
for ( int i = 0; i < TestHelper.queryRegionNames.length; ++i ) {
|
||||
String currentName = TestHelper.queryRegionNames[i];
|
||||
String legacyName = existingLegacyCaches[i];
|
||||
|
||||
triggerables.put(
|
||||
legacyName,
|
||||
logInspection.watchForLogMessages(
|
||||
"HHH90001007: Using legacy cache name [" + legacyName +
|
||||
"] because configuration could not be found for cache [" + currentName + "]."
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// and now let's try to build the standard testing SessionFactory
|
||||
try ( SessionFactoryImplementor sessionFactory = TestHelper.buildStandardSessionFactory(
|
||||
builder -> builder.applySetting( ConfigSettings.MISSING_CACHE_STRATEGY, "fail" )
|
||||
.applySetting( ConfigSettings.EHCACHE_CONFIGURATION_RESOURCE_NAME, configurationPath )
|
||||
) ) {
|
||||
// The session should start successfully (if we reach this line, we're good)
|
||||
|
||||
// Logs should have been to notify that legacy cache names are being used
|
||||
for ( String regionName : existingLegacyCaches ) {
|
||||
assertTrue(
|
||||
"Use of cache '" + regionName + "' should have triggered a warning",
|
||||
triggerables.get( regionName ).wasTriggered()
|
||||
);
|
||||
}
|
||||
|
||||
// and these caches shouldn't exist
|
||||
for ( String regionName : nonExistingLegacyCaches ) {
|
||||
assertThat( TestHelper.getCache( sessionFactory, regionName ), nullValue() );
|
||||
}
|
||||
for ( String regionName : TestHelper.queryRegionNames ) {
|
||||
assertThat( TestHelper.getCache( sessionFactory, regionName ), nullValue() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,35 +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.hibernate.cache.ehcache.test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cache.ehcache.ConfigSettings;
|
||||
import org.hibernate.cache.ehcache.internal.SingletonEhcacheRegionFactory;
|
||||
import org.hibernate.cache.spi.RegionFactory;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.Test;
|
||||
|
||||
@TestForIssue(jiraKey = "HHH-12869")
|
||||
public class SingletonEhCacheRegionFactoryClasspathConfigurationFileTest {
|
||||
|
||||
@Test
|
||||
public void testCacheInitialization() {
|
||||
try ( SessionFactoryImplementor sessionFactory = TestHelper.buildStandardSessionFactory(
|
||||
builder -> builder.applySetting( AvailableSettings.CACHE_REGION_FACTORY, "ehcache-singleton" )
|
||||
.applySetting( ConfigSettings.EHCACHE_CONFIGURATION_RESOURCE_NAME,
|
||||
"/hibernate-config/ehcache-configuration.xml" ) ) ) {
|
||||
assertNotNull( sessionFactory );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,62 +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.hibernate.cache.ehcache.test;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
||||
import org.hibernate.cache.ehcache.internal.EhcacheRegionFactory;
|
||||
import org.hibernate.cache.ehcache.internal.SingletonEhcacheRegionFactory;
|
||||
import org.hibernate.cache.spi.RegionFactory;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SmokeTest {
|
||||
@Test
|
||||
public void testStrategySelectorRegistrations() {
|
||||
final BootstrapServiceRegistry registry = new BootstrapServiceRegistryBuilder().build();
|
||||
final Collection<Class<? extends RegionFactory>> implementors = registry
|
||||
.getService( StrategySelector.class )
|
||||
.getRegisteredStrategyImplementors( RegionFactory.class );
|
||||
assertTrue( implementors.contains( EhcacheRegionFactory.class ) );
|
||||
assertTrue( implementors.contains( SingletonEhcacheRegionFactory.class ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEhcacheShortName() {
|
||||
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.CACHE_REGION_FACTORY, "ehcache" )
|
||||
.build();
|
||||
assertThat(
|
||||
registry.getService( RegionFactory.class ),
|
||||
instanceOf( EhcacheRegionFactory.class )
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingletonEhcacheShortName() {
|
||||
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.CACHE_REGION_FACTORY, "ehcache-singleton" )
|
||||
.build();
|
||||
assertThat(
|
||||
registry.getService( RegionFactory.class ),
|
||||
instanceOf( SingletonEhcacheRegionFactory.class )
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,102 +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.hibernate.cache.ehcache.test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import net.sf.ehcache.Cache;
|
||||
import net.sf.ehcache.CacheManager;
|
||||
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cache.ehcache.internal.EhcacheRegionFactory;
|
||||
import org.hibernate.cache.ehcache.test.domain.Event;
|
||||
import org.hibernate.cache.ehcache.test.domain.Item;
|
||||
import org.hibernate.cache.ehcache.test.domain.VersionedItem;
|
||||
import org.hibernate.cache.spi.RegionFactory;
|
||||
import org.hibernate.cache.spi.support.RegionNameQualifier;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.tool.schema.Action;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class TestHelper {
|
||||
public static String[] entityRegionNames = new String[] {
|
||||
Item.class.getName(),
|
||||
VersionedItem.class.getName(),
|
||||
Event.class.getName()
|
||||
};
|
||||
public static String[] collectionRegionNames = new String[] {
|
||||
Event.class.getName() + ".participants"
|
||||
};
|
||||
|
||||
public static String[] allDomainRegionNames =
|
||||
Stream.concat( Arrays.stream( entityRegionNames ), Arrays.stream( collectionRegionNames ) )
|
||||
.toArray( String[]::new );
|
||||
|
||||
public static String[] queryRegionNames = new String[] {
|
||||
RegionFactory.DEFAULT_QUERY_RESULTS_REGION_UNQUALIFIED_NAME,
|
||||
RegionFactory.DEFAULT_UPDATE_TIMESTAMPS_REGION_UNQUALIFIED_NAME
|
||||
};
|
||||
public static String[] queryRegionLegacyNames1 = new String[] {
|
||||
"org.hibernate.cache.spi.QueryResultsRegion",
|
||||
"org.hibernate.cache.spi.TimestampsRegion"
|
||||
};
|
||||
public static String[] queryRegionLegacyNames2 = new String[] {
|
||||
"org.hibernate.cache.internal.StandardQueryCache",
|
||||
"org.hibernate.cache.spi.UpdateTimestampsCache"
|
||||
};
|
||||
|
||||
public static SessionFactoryImplementor buildStandardSessionFactory() {
|
||||
return buildStandardSessionFactory( ignored -> { } );
|
||||
}
|
||||
|
||||
public static SessionFactoryImplementor buildStandardSessionFactory(Consumer<StandardServiceRegistryBuilder> additionalSettings) {
|
||||
final StandardServiceRegistryBuilder ssrb = getStandardServiceRegistryBuilder();
|
||||
|
||||
additionalSettings.accept( ssrb );
|
||||
|
||||
final StandardServiceRegistry ssr = ssrb.build();
|
||||
|
||||
return (SessionFactoryImplementor) new MetadataSources( ssr ).buildMetadata().buildSessionFactory();
|
||||
}
|
||||
|
||||
public static StandardServiceRegistryBuilder getStandardServiceRegistryBuilder() {
|
||||
final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder()
|
||||
.configure( "hibernate-config/hibernate.cfg.xml" )
|
||||
.applySetting( AvailableSettings.GENERATE_STATISTICS, "true" )
|
||||
.applySetting( AvailableSettings.HBM2DDL_DATABASE_ACTION, Action.CREATE_DROP )
|
||||
.applySetting( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
|
||||
|
||||
if ( H2Dialect.class.equals( Dialect.getDialect().getClass() ) ) {
|
||||
ssrb.applySetting( AvailableSettings.URL, "jdbc:h2:mem:db-mvcc;MVCC=true" );
|
||||
}
|
||||
return ssrb;
|
||||
}
|
||||
|
||||
public static String prefix(String regionName) {
|
||||
return RegionNameQualifier.INSTANCE.qualify( "hibernate.test", regionName );
|
||||
}
|
||||
|
||||
public static Cache getCache(SessionFactoryImplementor sessionFactoryImplementor, String regionName) {
|
||||
final RegionFactory regionFactory = sessionFactoryImplementor.getCache().getRegionFactory();
|
||||
final EhcacheRegionFactory ehcacheRegionFactory = (EhcacheRegionFactory) regionFactory;
|
||||
final CacheManager cacheManager = ehcacheRegionFactory.getCacheManager();
|
||||
regionName = prefix( regionName );
|
||||
return cacheManager.getCache( regionName );
|
||||
}
|
||||
|
||||
private TestHelper() {
|
||||
}
|
||||
}
|
|
@ -1,38 +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.hibernate.cache.ehcache.test.domain;
|
||||
|
||||
public class Account {
|
||||
|
||||
private Long id;
|
||||
private Person person;
|
||||
|
||||
public Account() {
|
||||
//
|
||||
}
|
||||
|
||||
public Person getPerson() {
|
||||
return person;
|
||||
}
|
||||
|
||||
public void setPerson(Person person) {
|
||||
this.person = person;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
}
|
|
@ -1,74 +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.hibernate.cache.ehcache.test.domain;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class Event {
|
||||
private Long id;
|
||||
|
||||
private String title;
|
||||
private Date date;
|
||||
private Set participants = new HashSet();
|
||||
private Person organizer;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public void setOrganizer(Person organizer) {
|
||||
this.organizer = organizer;
|
||||
}
|
||||
|
||||
public Person getOrganizer() {
|
||||
return organizer;
|
||||
}
|
||||
|
||||
public Set getParticipants() {
|
||||
return participants;
|
||||
}
|
||||
|
||||
public void setParticipants(Set participants) {
|
||||
this.participants = participants;
|
||||
}
|
||||
|
||||
public void addParticipant(Person person) {
|
||||
participants.add(person);
|
||||
person.getEvents().add(this);
|
||||
}
|
||||
|
||||
public void removeParticipant(Person person) {
|
||||
participants.remove(person);
|
||||
person.getEvents().remove(this);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getTitle() + ": " + getDate();
|
||||
}
|
||||
}
|
|
@ -1,260 +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.hibernate.cache.ehcache.test.domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
|
||||
import org.hibernate.query.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
|
||||
public class EventManager {
|
||||
|
||||
private final SessionFactory sessionFactory;
|
||||
|
||||
public EventManager(SessionFactory sessionFactory) {
|
||||
this.sessionFactory = sessionFactory;
|
||||
}
|
||||
|
||||
public List listEmailsOfEvent(Long eventId) {
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
session.beginTransaction();
|
||||
|
||||
List emailList = new ArrayList();
|
||||
Event event = (Event)session.load(Event.class, eventId);
|
||||
for (Iterator it = event.getParticipants().iterator(); it.hasNext(); ) {
|
||||
Person person = (Person)it.next();
|
||||
emailList.addAll(person.getEmailAddresses());
|
||||
}
|
||||
|
||||
session.getTransaction().commit();
|
||||
return emailList;
|
||||
}
|
||||
|
||||
public Long createAndStoreEvent(String title, Person organizer, Date theDate) {
|
||||
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
|
||||
session.beginTransaction();
|
||||
|
||||
Event theEvent = new Event();
|
||||
theEvent.setTitle(title);
|
||||
theEvent.setDate(theDate);
|
||||
theEvent.setOrganizer(organizer);
|
||||
|
||||
Long eventId = (Long)session.save(theEvent);
|
||||
|
||||
session.getTransaction().commit();
|
||||
return eventId;
|
||||
}
|
||||
|
||||
public Long createAndStorePerson(String firstName, String lastName) {
|
||||
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
|
||||
session.beginTransaction();
|
||||
|
||||
Person person = new Person();
|
||||
person.setFirstname(firstName);
|
||||
person.setLastname(lastName);
|
||||
|
||||
Long personId = (Long)session.save(person);
|
||||
|
||||
session.getTransaction().commit();
|
||||
return personId;
|
||||
}
|
||||
|
||||
public Long createAndStorePerson(Person person) {
|
||||
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
|
||||
session.beginTransaction();
|
||||
|
||||
Long personId = (Long)session.save(person);
|
||||
|
||||
session.getTransaction().commit();
|
||||
return personId;
|
||||
}
|
||||
|
||||
public List listEvents() {
|
||||
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
|
||||
session.beginTransaction();
|
||||
|
||||
List result = session.createQuery("from Event").setCacheable(true).list();
|
||||
|
||||
session.getTransaction().commit();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call setEntity() on a cacheable query - see FORGE-265
|
||||
*/
|
||||
public List listEventsOfOrganizer(Person organizer) {
|
||||
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
|
||||
try {
|
||||
session.beginTransaction();
|
||||
Query query = session.createQuery( "from Event ev where ev.organizer = :organizer" );
|
||||
|
||||
query.setCacheable( true );
|
||||
query.setParameter( "organizer", organizer );
|
||||
List result = query.list();
|
||||
|
||||
session.getTransaction().commit();
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (Exception e) {
|
||||
if ( session.getTransaction().isActive() ) {
|
||||
session.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use a Criteria query - see FORGE-247
|
||||
*/
|
||||
public List listEventsWithCriteria() {
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
|
||||
try {
|
||||
session.beginTransaction();
|
||||
CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<Event> criteria = criteriaBuilder.createQuery( Event.class );
|
||||
criteria.from( Event.class );
|
||||
List<Event> result = session.createQuery( criteria ).setCacheable( true ).list();
|
||||
// List result = session.createCriteria(Event.class)
|
||||
// .setCacheable(true)
|
||||
// .list();
|
||||
|
||||
session.getTransaction().commit();
|
||||
return result;
|
||||
}
|
||||
catch (Exception e) {
|
||||
if ( session.getTransaction().isActive() ) {
|
||||
session.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public void addPersonToEvent(Long personId, Long eventId) {
|
||||
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
session.beginTransaction();
|
||||
|
||||
Person aPerson = (Person)session.load(Person.class, personId);
|
||||
Event anEvent = (Event)session.load(Event.class, eventId);
|
||||
|
||||
aPerson.getEvents().add(anEvent);
|
||||
|
||||
session.getTransaction().commit();
|
||||
}
|
||||
|
||||
public Long addPersonToAccount(Long personId, Account account) {
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
session.beginTransaction();
|
||||
|
||||
Person aPerson = (Person)session.load(Person.class, personId);
|
||||
account.setPerson(aPerson);
|
||||
|
||||
Long accountId = (Long)session.save(account);
|
||||
|
||||
session.getTransaction().commit();
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public Account getAccount(Long accountId) {
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
session.beginTransaction();
|
||||
|
||||
Account account = (Account)session.load(Account.class, accountId);
|
||||
|
||||
session.getTransaction().commit();
|
||||
return account;
|
||||
}
|
||||
|
||||
public void addEmailToPerson(Long personId, String emailAddress) {
|
||||
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
session.beginTransaction();
|
||||
|
||||
Person aPerson = (Person)session.load(Person.class, personId);
|
||||
|
||||
// The getEmailAddresses() might trigger a lazy load of the collection
|
||||
aPerson.getEmailAddresses().add(emailAddress);
|
||||
|
||||
session.getTransaction().commit();
|
||||
}
|
||||
|
||||
public void addPhoneNumberToPerson(Long personId, PhoneNumber pN) {
|
||||
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
session.beginTransaction();
|
||||
|
||||
Person aPerson = (Person)session.load(Person.class, personId);
|
||||
pN.setPersonId(personId.longValue());
|
||||
aPerson.getPhoneNumbers().add(pN);
|
||||
|
||||
session.getTransaction().commit();
|
||||
}
|
||||
|
||||
public void addTalismanToPerson(Long personId, String talisman) {
|
||||
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
session.beginTransaction();
|
||||
|
||||
Person aPerson = (Person)session.load(Person.class, personId);
|
||||
aPerson.addTalisman(talisman);
|
||||
|
||||
session.getTransaction().commit();
|
||||
}
|
||||
|
||||
public Long createHolidayCalendar() {
|
||||
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
session.beginTransaction();
|
||||
|
||||
// delete all existing calendars
|
||||
List calendars = session.createQuery("from HolidayCalendar").setCacheable(true).list();
|
||||
for (ListIterator li = calendars.listIterator(); li.hasNext(); ) {
|
||||
session.delete(li.next());
|
||||
}
|
||||
|
||||
HolidayCalendar calendar = new HolidayCalendar();
|
||||
calendar.init();
|
||||
|
||||
Long calendarId = (Long)session.save(calendar);
|
||||
|
||||
session.getTransaction().commit();
|
||||
return calendarId;
|
||||
}
|
||||
|
||||
public HolidayCalendar getHolidayCalendar() {
|
||||
Session session = sessionFactory.getCurrentSession();
|
||||
|
||||
session.beginTransaction();
|
||||
|
||||
List calendars = session.createQuery("from HolidayCalendar").setCacheable(true).list();
|
||||
|
||||
session.getTransaction().commit();
|
||||
|
||||
return calendars.isEmpty() ? null : (HolidayCalendar)calendars.get(0);
|
||||
}
|
||||
}
|
|
@ -1,66 +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.hibernate.cache.ehcache.test.domain;
|
||||
|
||||
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class HolidayCalendar {
|
||||
|
||||
|
||||
private Long id;
|
||||
// Date -> String
|
||||
private Map holidays = new HashMap();
|
||||
|
||||
public HolidayCalendar init() {
|
||||
DateFormat df = new SimpleDateFormat("yyyy.MM.dd");
|
||||
try {
|
||||
holidays.clear();
|
||||
holidays.put(df.parse("2009.01.01"), "New Year's Day");
|
||||
holidays.put(df.parse("2009.02.14"), "Valentine's Day");
|
||||
holidays.put(df.parse("2009.11.11"), "Armistice Day");
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Map getHolidays() {
|
||||
return holidays;
|
||||
}
|
||||
|
||||
protected void setHolidays(Map holidays) {
|
||||
this.holidays = holidays;
|
||||
}
|
||||
|
||||
public void addHoliday(Date d, String name) {
|
||||
holidays.put(d, name);
|
||||
}
|
||||
|
||||
public String getHoliday(Date d) {
|
||||
return (String)holidays.get(d);
|
||||
}
|
||||
|
||||
public boolean isHoliday(Date d) {
|
||||
return holidays.containsKey(d);
|
||||
}
|
||||
|
||||
protected Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
protected void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,37 +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.hibernate.cache.ehcache.test.domain;
|
||||
|
||||
public class Item {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String description;
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
|
@ -1,111 +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.hibernate.cache.ehcache.test.domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class Person {
|
||||
|
||||
private Long id;
|
||||
private int age;
|
||||
private String firstname;
|
||||
private String lastname;
|
||||
private List events = new ArrayList(); // list semantics, e.g., indexed
|
||||
private Set emailAddresses = new HashSet();
|
||||
private Set phoneNumbers = new HashSet();
|
||||
private List talismans = new ArrayList(); // a Bag of good-luck charms.
|
||||
|
||||
public Person() {
|
||||
//
|
||||
}
|
||||
|
||||
public List getEvents() {
|
||||
return events;
|
||||
}
|
||||
|
||||
protected void setEvents(List events) {
|
||||
this.events = events;
|
||||
}
|
||||
|
||||
public void addToEvent(Event event) {
|
||||
this.getEvents().add(event);
|
||||
event.getParticipants().add(this);
|
||||
}
|
||||
|
||||
public void removeFromEvent(Event event) {
|
||||
this.getEvents().remove(event);
|
||||
event.getParticipants().remove(this);
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
|
||||
public void setFirstname(String firstname) {
|
||||
this.firstname = firstname;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getLastname() {
|
||||
return lastname;
|
||||
}
|
||||
|
||||
public void setLastname(String lastname) {
|
||||
this.lastname = lastname;
|
||||
}
|
||||
|
||||
public Set getEmailAddresses() {
|
||||
return emailAddresses;
|
||||
}
|
||||
|
||||
public void setEmailAddresses(Set emailAddresses) {
|
||||
this.emailAddresses = emailAddresses;
|
||||
}
|
||||
|
||||
public Set getPhoneNumbers() {
|
||||
return phoneNumbers;
|
||||
}
|
||||
|
||||
public void setPhoneNumbers(Set phoneNumbers) {
|
||||
this.phoneNumbers = phoneNumbers;
|
||||
}
|
||||
|
||||
public void addTalisman(String name) {
|
||||
talismans.add(name);
|
||||
}
|
||||
|
||||
public List getTalismans() {
|
||||
return talismans;
|
||||
}
|
||||
|
||||
public void setTalismans(List talismans) {
|
||||
this.talismans = talismans;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getFirstname() + " " + getLastname();
|
||||
}
|
||||
}
|
|
@ -1,78 +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.hibernate.cache.ehcache.test.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* PhoneNumber
|
||||
*/
|
||||
public class PhoneNumber implements Serializable {
|
||||
private long personId = 0;
|
||||
private String numberType = "home";
|
||||
private long phone = 0;
|
||||
|
||||
public long getPersonId() {
|
||||
return personId;
|
||||
}
|
||||
|
||||
public void setPersonId(long personId) {
|
||||
this.personId = personId;
|
||||
}
|
||||
|
||||
public String getNumberType() {
|
||||
return numberType;
|
||||
}
|
||||
|
||||
public void setNumberType(String numberType) {
|
||||
this.numberType = numberType;
|
||||
}
|
||||
|
||||
public long getPhone() {
|
||||
return phone;
|
||||
}
|
||||
|
||||
public void setPhone(long phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result
|
||||
+ ((numberType == null) ? 0 : numberType.hashCode());
|
||||
result = prime * result + (int)(personId ^ (personId >>> 32));
|
||||
result = prime * result + (int)(phone ^ (phone >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
final PhoneNumber other = (PhoneNumber)obj;
|
||||
if (numberType == null) {
|
||||
if (other.numberType != null)
|
||||
return false;
|
||||
} else if (!numberType.equals(other.numberType))
|
||||
return false;
|
||||
if (personId != other.personId)
|
||||
return false;
|
||||
if (phone != other.phone)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return numberType + ":" + phone;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,37 +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.hibernate.cache.ehcache.test.domain;
|
||||
|
||||
public class UuidItem {
|
||||
private String id;
|
||||
private String name;
|
||||
private String description;
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
|
@ -1,19 +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.hibernate.cache.ehcache.test.domain;
|
||||
|
||||
public class VersionedItem extends Item {
|
||||
private Long version;
|
||||
|
||||
public Long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Long version) {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
<?xml version="1.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>.
|
||||
-->
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping>
|
||||
|
||||
<class name="org.hibernate.cache.ehcache.test.domain.Account" table="ACCOUNT" lazy="false">
|
||||
<id name="id" column="ACCOUNT_ID">
|
||||
<generator class="native"/>
|
||||
</id>
|
||||
|
||||
<many-to-one name="person" class="org.hibernate.cache.ehcache.test.domain.Person" cascade="save-update,lock"
|
||||
column="person_id"
|
||||
unique="true"
|
||||
not-null="true"/>
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
|
@ -1,32 +0,0 @@
|
|||
<?xml version="1.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>.
|
||||
-->
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping>
|
||||
|
||||
<class name="org.hibernate.cache.ehcache.test.domain.Event" table="EVENTS">
|
||||
<cache usage="read-write"/>
|
||||
<id name="id" column="EVENT_ID">
|
||||
<generator class="native"/>
|
||||
</id>
|
||||
<property name="date" type="timestamp" column="EVENT_DATE"/>
|
||||
<property name="title"/>
|
||||
<many-to-one name="organizer" column="EVENT_ORGANIZER" class="org.hibernate.cache.ehcache.test.domain.Person"/>
|
||||
|
||||
<set name="participants" table="PERSON_EVENT" lazy="false"
|
||||
inverse="true" cascade="lock">
|
||||
<cache usage="read-write"/>
|
||||
<key column="EVENT_ID"/>
|
||||
<many-to-many column="PERSON_ID"
|
||||
class="org.hibernate.cache.ehcache.test.domain.Person"/>
|
||||
</set>
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
|
@ -1,27 +0,0 @@
|
|||
<?xml version="1.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>.
|
||||
-->
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping>
|
||||
|
||||
<class name="org.hibernate.cache.ehcache.test.domain.HolidayCalendar" table="CALENDAR" lazy="false">
|
||||
<id name="id" column="CALENDAR_ID">
|
||||
<generator class="native"/>
|
||||
</id>
|
||||
|
||||
<map name="holidays" table="CALENDAR_HOLIDAYS" lazy="false">
|
||||
<key column="CALENDAR_ID"/>
|
||||
<map-key column="hol_date" type="date"/>
|
||||
<element column="hol_name" type="string"/>
|
||||
</map>
|
||||
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
|
@ -1,34 +0,0 @@
|
|||
<?xml version="1.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>.
|
||||
-->
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping package="org.hibernate.cache.ehcache.test.domain">
|
||||
|
||||
|
||||
<class name="Item" table="Items">
|
||||
<cache usage="read-write"/>
|
||||
<id name="id">
|
||||
<generator class="increment"/>
|
||||
</id>
|
||||
<property name="name" not-null="true"/>
|
||||
<property name="description" not-null="true"/>
|
||||
</class>
|
||||
|
||||
<class name="VersionedItem" table="VersionedItems">
|
||||
<cache usage="read-write"/>
|
||||
<id name="id">
|
||||
<generator class="increment"/>
|
||||
</id>
|
||||
<version name="version" type="long"/>
|
||||
<property name="name" not-null="true"/>
|
||||
<property name="description" not-null="true"/>
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
|
@ -1,46 +0,0 @@
|
|||
<?xml version="1.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>.
|
||||
-->
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping>
|
||||
|
||||
<class name="org.hibernate.cache.ehcache.test.domain.Person" table="PERSON" lazy="true">
|
||||
<id name="id" column="PERSON_ID">
|
||||
<generator class="native"/>
|
||||
</id>
|
||||
<property name="age"/>
|
||||
<property name="firstname"/>
|
||||
<property name="lastname"/>
|
||||
|
||||
<list name="events" table="PERSON_EVENT" lazy="true">
|
||||
<key column="PERSON_ID"/>
|
||||
<list-index column="EVENT_ORDER"/>
|
||||
<many-to-many column="EVENT_ID" class="org.hibernate.cache.ehcache.test.domain.Event"/>
|
||||
</list>
|
||||
|
||||
<bag name="talismans" table="PERSON_TALISMAN" lazy="true">
|
||||
<key column="PERSON_ID"/>
|
||||
<element type="string" column="TALISMAN_NAME"/>
|
||||
</bag>
|
||||
|
||||
<set name="emailAddresses" table="PERSON_EMAIL_ADDR" lazy="true">
|
||||
<key column="PERSON_ID"/>
|
||||
<element type="string" column="EMAIL_ADDR"/>
|
||||
</set>
|
||||
|
||||
<set name="phoneNumbers" cascade="all" lazy="true">
|
||||
<key column="PERSON_ID"/>
|
||||
<one-to-many class="org.hibernate.cache.ehcache.test.domain.PhoneNumber"/>
|
||||
</set>
|
||||
|
||||
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
|
@ -1,26 +0,0 @@
|
|||
<?xml version="1.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>.
|
||||
-->
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping>
|
||||
|
||||
<class name="org.hibernate.cache.ehcache.test.domain.PhoneNumber" table="PHONE_NUMBERS">
|
||||
<composite-id>
|
||||
<key-property column="PERSON_ID" name="personId" type="java.lang.Long"/>
|
||||
<key-property column="NUMBER_TYPE" name="numberType" type="java.lang.String"/>
|
||||
</composite-id>
|
||||
|
||||
<property name="phone" type="java.lang.Long">
|
||||
<column name="PHONE" precision="22" scale="0"/>
|
||||
</property>
|
||||
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
|
@ -1,19 +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>.
|
||||
-->
|
||||
<ehcache>
|
||||
<diskStore path="java.io.tmpdir"/>
|
||||
|
||||
<!-- Domain caches -->
|
||||
<cache name="hibernate.test.org.hibernate.cache.ehcache.test.domain.Item" maxElementsInMemory="10000" />
|
||||
<cache name="hibernate.test.org.hibernate.cache.ehcache.test.domain.VersionedItem" maxElementsInMemory="10000" />
|
||||
<cache name="hibernate.test.org.hibernate.cache.ehcache.test.domain.Event" maxElementsInMemory="10000" />
|
||||
<cache name="hibernate.test.org.hibernate.cache.ehcache.test.domain.Event.participants" maxElementsInMemory="10000" />
|
||||
|
||||
<!-- Query caches with legacy names -->
|
||||
<cache name="hibernate.test.org.hibernate.cache.spi.QueryResultsRegion" maxElementsInMemory="10000" />
|
||||
<cache name="hibernate.test.org.hibernate.cache.spi.TimestampsRegion" maxElementsInMemory="10000" />
|
||||
</ehcache>
|
|
@ -1,20 +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>.
|
||||
-->
|
||||
<ehcache>
|
||||
<diskStore path="java.io.tmpdir"/>
|
||||
|
||||
<!-- Domain caches -->
|
||||
<cache name="hibernate.test.org.hibernate.cache.ehcache.test.domain.Item" maxElementsInMemory="10000" />
|
||||
<cache name="hibernate.test.org.hibernate.cache.ehcache.test.domain.VersionedItem" maxElementsInMemory="10000" />
|
||||
<cache name="hibernate.test.org.hibernate.cache.ehcache.test.domain.Event" maxElementsInMemory="10000" />
|
||||
<cache name="hibernate.test.org.hibernate.cache.ehcache.test.domain.Event.participants" maxElementsInMemory="10000" />
|
||||
|
||||
<!-- Query caches with legacy names -->
|
||||
<cache name="hibernate.test.org.hibernate.cache.spi.QueryResultsRegion" maxElementsInMemory="10000" />
|
||||
<cache name="hibernate.test.org.hibernate.cache.spi.TimestampsRegion" maxElementsInMemory="10000" />
|
||||
|
||||
</ehcache>
|
|
@ -1,20 +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>.
|
||||
-->
|
||||
<ehcache>
|
||||
<diskStore path="java.io.tmpdir"/>
|
||||
|
||||
<!-- Domain caches -->
|
||||
<cache name="hibernate.test.org.hibernate.cache.ehcache.test.domain.Item" maxElementsInMemory="10000" />
|
||||
<cache name="hibernate.test.org.hibernate.cache.ehcache.test.domain.VersionedItem" maxElementsInMemory="10000" />
|
||||
<cache name="hibernate.test.org.hibernate.cache.ehcache.test.domain.Event" maxElementsInMemory="10000" />
|
||||
<cache name="hibernate.test.org.hibernate.cache.ehcache.test.domain.Event.participants" maxElementsInMemory="10000" />
|
||||
|
||||
<!-- Query caches with legacy names -->
|
||||
<cache name="hibernate.test.org.hibernate.cache.internal.StandardQueryCache" maxElementsInMemory="10000" />
|
||||
<cache name="hibernate.test.org.hibernate.cache.spi.TimestampsCache" maxElementsInMemory="10000" />
|
||||
|
||||
</ehcache>
|
|
@ -1,36 +0,0 @@
|
|||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<!--
|
||||
~ 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>.
|
||||
-->
|
||||
<!DOCTYPE hibernate-configuration PUBLIC
|
||||
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
||||
|
||||
<hibernate-configuration>
|
||||
|
||||
<session-factory>
|
||||
|
||||
<!-- Enable Hibernate's automatic session context management -->
|
||||
<property name="current_session_context_class">thread</property>
|
||||
|
||||
<property name="cache.use_query_cache">true</property>
|
||||
<property name="cache.use_second_level_cache">true</property>
|
||||
<property name="cache.use_structured_entries">true</property>
|
||||
<property name="cache.region.factory_class">ehcache</property>
|
||||
<!-- Echo all executed SQL to stdout -->
|
||||
<property name="show_sql">true</property>
|
||||
|
||||
<mapping resource="hibernate-config/domain/Event.hbm.xml"/>
|
||||
<mapping resource="hibernate-config/domain/Person.hbm.xml"/>
|
||||
<mapping resource="hibernate-config/domain/PhoneNumber.hbm.xml"/>
|
||||
<mapping resource="hibernate-config/domain/Account.hbm.xml"/>
|
||||
<mapping resource="hibernate-config/domain/HolidayCalendar.hbm.xml"/>
|
||||
|
||||
<mapping resource="hibernate-config/domain/Item.hbm.xml"/>
|
||||
|
||||
</session-factory>
|
||||
|
||||
</hibernate-configuration>
|
|
@ -1,17 +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>.
|
||||
#
|
||||
hibernate.dialect @db.dialect@
|
||||
hibernate.connection.driver_class @jdbc.driver@
|
||||
hibernate.connection.url @jdbc.url@
|
||||
hibernate.connection.username @jdbc.user@
|
||||
hibernate.connection.password @jdbc.pass@
|
||||
|
||||
hibernate.connection.pool_size 5
|
||||
|
||||
hibernate.cache.region_prefix hibernate.test
|
||||
|
||||
hibernate.service.allow_crawling=false
|
|
@ -1,17 +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
|
||||
#
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.Target=System.out
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
|
||||
|
||||
log4j.rootLogger=info, stdout
|
||||
|
||||
log4j.logger.org.hibernate.test=info
|
||||
|
||||
# SQL Logging - HHH-6833
|
||||
log4j.logger.org.hibernate.SQL=debug
|
|
@ -103,8 +103,6 @@ include 'hibernate-jcache'
|
|||
include 'hibernate-micrometer'
|
||||
include 'hibernate-graalvm'
|
||||
|
||||
include 'hibernate-ehcache'
|
||||
|
||||
// The plugin used to generate Java modules was compiled using JDK11.
|
||||
// This means even with toolchains, Gradle needs to be run with Java 11+ in order to run Java modules ITs.
|
||||
// We might be able to get rid of that limitation by relying on Gradle's built-in support for Java modules,
|
||||
|
|
Loading…
Reference in New Issue