Create new Ehcache CacheRegionFactory implementation. This delegates to underlying classes in Ehcache.

This commit is contained in:
Greg Luck 2010-12-21 15:24:50 +10:00
parent bf6bd51c7e
commit 1dc7317694
7 changed files with 206 additions and 13 deletions

View File

@ -2,6 +2,6 @@ apply plugin: 'java'
dependencies {
compile( project( ':hibernate-core' ) )
compile( [group: 'net.sf.ehcache', name: 'ehcache', version: '1.5.0'] )
compile( [group: 'net.sf.ehcache', name: 'ehcache-core', version: '2.3.1'] )
testCompile( project(':hibernate-core').sourceSets.test.classes )
}
}

View File

@ -0,0 +1,111 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. ÊAll third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.cache;
import org.hibernate.cache.access.AccessType;
import org.hibernate.cfg.Settings;
import java.util.Properties;
/**
* Abstract class that will delegate all calls to org.hibernate.cache.RegionFactory to the instance it wraps.
* This abstracts the Singleton CacheManager construct of Ehcache
*
* @author Alex Snaps
*/
class AbstractEhCacheRegionFactory implements RegionFactory {
private final RegionFactory underlyingRegionFactory;
/**
* {@inheritDoc}
*/
protected AbstractEhCacheRegionFactory(RegionFactory regionFactory) {
underlyingRegionFactory = regionFactory;
}
/**
* {@inheritDoc}
*/
public final void start(final Settings settings, final Properties properties) throws CacheException {
underlyingRegionFactory.start(settings, properties);
}
/**
* {@inheritDoc}
*/
public final void stop() {
underlyingRegionFactory.stop();
}
/**
* {@inheritDoc}
*/
public final boolean isMinimalPutsEnabledByDefault() {
return underlyingRegionFactory.isMinimalPutsEnabledByDefault();
}
/**
* {@inheritDoc}
*/
public final AccessType getDefaultAccessType() {
return underlyingRegionFactory.getDefaultAccessType();
}
/**
* {@inheritDoc}
*/
public final long nextTimestamp() {
return underlyingRegionFactory.nextTimestamp();
}
/**
* {@inheritDoc}
*/
public final EntityRegion buildEntityRegion(final String regionName, final Properties properties, final CacheDataDescription metadata) throws CacheException {
return underlyingRegionFactory.buildEntityRegion(regionName, properties, metadata);
}
/**
* {@inheritDoc}
*/
public final CollectionRegion buildCollectionRegion(final String regionName, final Properties properties, final CacheDataDescription metadata) throws CacheException {
return underlyingRegionFactory.buildCollectionRegion(regionName, properties, metadata);
}
/**
* {@inheritDoc}
*/
public final QueryResultsRegion buildQueryResultsRegion(final String regionName, final Properties properties) throws CacheException {
return underlyingRegionFactory.buildQueryResultsRegion(regionName, properties);
}
/**
* {@inheritDoc}
*/
public final TimestampsRegion buildTimestampsRegion(final String regionName, final Properties properties) throws CacheException {
return underlyingRegionFactory.buildTimestampsRegion(regionName, properties);
}
}

View File

@ -23,15 +23,15 @@
*/
package org.hibernate.cache;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* EHCache plugin for Hibernate
* <p/>

View File

@ -23,15 +23,15 @@
*/
package org.hibernate.cache;
import java.util.Properties;
import java.net.URL;
import net.sf.ehcache.CacheManager;
import org.hibernate.cfg.Environment;
import org.hibernate.util.ConfigHelper;
import org.hibernate.util.StringHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.hibernate.cfg.Environment;
import org.hibernate.util.StringHelper;
import org.hibernate.util.ConfigHelper;
import java.net.URL;
import java.util.Properties;
/**
* Cache Provider plugin for Hibernate

View File

@ -0,0 +1,41 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. ÊAll third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.cache;
import java.util.Properties;
/**
* Thin wrapper class around the within Ehcache-core packaged EhCacheRegionFactory.
* It directly delegates to the wrapped instance, enabling users to upgrade Ehcache-core versions
* by simply dropping in the new jar.
*
* @author Alex Snaps
*/
public final class EhCacheRegionFactory extends AbstractEhCacheRegionFactory {
public EhCacheRegionFactory(Properties properties) {
super(new net.sf.ehcache.hibernate.EhCacheRegionFactory(properties));
}
}

View File

@ -29,8 +29,8 @@ import net.sf.ehcache.util.ClassLoaderUtil;
import java.net.URL;
import java.util.Properties;
import java.util.logging.Logger;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Singleton cache Provider plugin for Hibernate 3.2 and ehcache-1.2. New in this provider is support for

View File

@ -0,0 +1,41 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. ÊAll third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.cache;
import java.util.Properties;
/**
* Thin wrapper class around the within Ehcache-core packaged SingletonEhCacheRegionFactory.
* It directly delegates to the wrapped instance, enabling user to upgrade the Ehcache-core version
* by simply dropping in a new jar.
*
* @author Alex Snaps
*/
public final class SingletonEhCacheRegionFactory extends AbstractEhCacheRegionFactory {
public SingletonEhCacheRegionFactory(Properties properties) {
super(new net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory(properties));
}
}