Skip to content

Commit

Permalink
Added RegionFactory to the default Ehcache hibernate integration. Plu…
Browse files Browse the repository at this point in the history
…s tests. Upgraded Ehcache to 2.4.1
  • Loading branch information
alexsnaps committed Apr 5, 2011
1 parent 57b60e3 commit 9fe7913
Show file tree
Hide file tree
Showing 9 changed files with 441 additions and 238 deletions.
4 changes: 2 additions & 2 deletions hibernate-ehcache/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>1.5.0</version>
<artifactId>ehcache-core</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.hibernate.cache;

import org.hibernate.cache.access.AccessType;
import org.hibernate.cfg.Settings;

import java.util.Properties;

/**
* @author Alex Snaps
*/
public class DelegatingRegionFactory implements RegionFactory {

private final RegionFactory regionFactory;

DelegatingRegionFactory(final RegionFactory regionFactory) {
this.regionFactory = regionFactory;
}

public final void start(final Settings settings, final Properties properties) throws CacheException {
regionFactory.start(settings, properties);
}

public final void stop() {
regionFactory.stop();
}

public final boolean isMinimalPutsEnabledByDefault() {
return regionFactory.isMinimalPutsEnabledByDefault();
}

public final AccessType getDefaultAccessType() {
return regionFactory.getDefaultAccessType();
}

public final long nextTimestamp() {
return regionFactory.nextTimestamp();
}

public final EntityRegion buildEntityRegion(final String regionName, final Properties properties,
final CacheDataDescription metadata) throws CacheException {
return regionFactory.buildEntityRegion(regionName, properties, metadata);
}

public final CollectionRegion buildCollectionRegion(final String regionName, final Properties properties,
final CacheDataDescription metadata) throws CacheException {
return regionFactory.buildCollectionRegion(regionName, properties, metadata);
}

public final QueryResultsRegion buildQueryResultsRegion(final String regionName, final Properties properties) throws CacheException {
return regionFactory.buildQueryResultsRegion(regionName, properties);
}

public final TimestampsRegion buildTimestampsRegion(final String regionName, final Properties properties) throws CacheException {
return regionFactory.buildTimestampsRegion(regionName, properties);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.hibernate.cache;

import java.util.Properties;

/**
* @author Alex Snaps
*/
public class EhCacheRegionFactory extends DelegatingRegionFactory {

public EhCacheRegionFactory(final Properties properties) {
super(new net.sf.ehcache.hibernate.EhCacheRegionFactory(properties));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.hibernate.cache;

import java.util.Properties;

/**
* @author Alex Snaps
*/
public class SingletonEhCacheRegionFactory extends DelegatingRegionFactory {
public SingletonEhCacheRegionFactory(Properties properties) {
super(new net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory(properties));
}
}
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
/*
* 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 junit.framework.Test;

import org.hibernate.cfg.Environment;
import org.hibernate.testing.junit.functional.FunctionalTestClassTestSuite;
import org.hibernate.testing.cache.BaseCacheProviderTestCase;

/**
* @author Emmanuel Bernard
*/
public class EhCacheTest extends BaseCacheProviderTestCase {
public EhCacheTest(String x) {
super( x );
}

public static Test suite() {
return new FunctionalTestClassTestSuite( EhCacheTest.class );
}

public String getCacheConcurrencyStrategy() {
return "read-write";
}

protected Class getCacheProvider() {
return EhCacheProvider.class;
}

protected String getConfigResourceKey() {
return Environment.CACHE_PROVIDER_CONFIG;
}

protected String getConfigResourceLocation() {
return "ehcache.xml";
}

protected boolean useTransactionManager() {
return false;
}

}
/*
* 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 junit.framework.Test;

import org.hibernate.cfg.Environment;
import org.hibernate.testing.junit.functional.FunctionalTestClassTestSuite;
import org.hibernate.testing.cache.BaseCacheProviderTestCase;

/**
* @author Emmanuel Bernard
*/
public class EhCacheProviderTest extends BaseCacheProviderTestCase {
public EhCacheProviderTest(String x) {
super(x);
}

public static Test suite() {
return new FunctionalTestClassTestSuite(EhCacheProviderTest.class);
}

public String getCacheConcurrencyStrategy() {
return "read-write";
}

protected Class getCacheProvider() {
return EhCacheProvider.class;
}

protected String getConfigResourceKey() {
return Environment.CACHE_PROVIDER_CONFIG;
}

protected String getConfigResourceLocation() {
return "ehcache.xml";
}

protected boolean useTransactionManager() {
return false;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.hibernate.cache;

import org.hibernate.cfg.Environment;
import org.hibernate.testing.junit.functional.FunctionalTestClassTestSuite;
import org.hibernate.testing.cache.BaseCacheRegionFactoryTestCase;

import junit.framework.Test;

/**
* @author Alex Snaps
*/
public class EhCacheRegionFactoryTest extends BaseCacheRegionFactoryTestCase {

public EhCacheRegionFactoryTest(String x) {
super(x);
}

protected Class getCacheRegionFactory() {
return EhCacheRegionFactory.class;
}

public static Test suite() {
return new FunctionalTestClassTestSuite(EhCacheRegionFactoryTest.class);
}

public String getCacheConcurrencyStrategy() {
return "read-write";
}

protected String getConfigResourceKey() {
return Environment.CACHE_PROVIDER_CONFIG;
}

protected String getConfigResourceLocation() {
return "ehcache.xml";
}

protected boolean useTransactionManager() {
return false;
}
}
Loading

0 comments on commit 9fe7913

Please sign in to comment.