+ added exception translation

+ fixed config
+ added docs on TM management and exception translation
This commit is contained in:
costin
2010-07-02 16:17:28 +03:00
parent 2ab5d270c1
commit 0934d7f4a5
3 changed files with 54 additions and 13 deletions

View File

@@ -29,8 +29,11 @@ import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.Resource;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.support.PersistenceExceptionTranslator;
import org.springframework.util.StringUtils;
import com.gemstone.gemfire.GemFireException;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheClosedException;
import com.gemstone.gemfire.cache.CacheFactory;
@@ -40,11 +43,18 @@ import com.gemstone.gemfire.distributed.DistributedSystem;
/**
* Factory used for configuring a Gemfire Cache manager. Allows either retrieval of an existing, opened cache
* or the creation of a new one.
* <p>This class implements the {@link org.springframework.dao.support.PersistenceExceptionTranslator}
* interface, as autodetected by Spring's
* {@link org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor},
* for AOP-based translation of native exceptions to Spring DataAccessExceptions.
* Hence, the presence of this class automatically enables
* a PersistenceExceptionTranslationPostProcessor to translate GemFire exceptions.
*
* @author Costin Leau
*/
public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanClassLoaderAware, DisposableBean,
InitializingBean, FactoryBean<Cache> {
InitializingBean, FactoryBean<Cache>, PersistenceExceptionTranslator {
private static final Log log = LogFactory.getLog(CacheFactoryBean.class);
@@ -126,6 +136,14 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
factoryLocator.destroy();
}
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
if (ex instanceof GemFireException) {
return GemfireCacheUtils.convertGemfireAccessException((GemFireException) ex);
}
return null;
}
public Cache getObject() throws Exception {
return cache;
}

View File

@@ -2,10 +2,7 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
default-lazy-init="true"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" default-lazy-init="true">
<!-- all beans are lazy to allow the same config to be used between multiple tests -->
<!-- as there can be only one cache per VM -->
@@ -21,7 +18,6 @@
<bean id="named-cache" class="org.springframework.data.gemfire.CacheFactoryBean" p:name="named-cache">
<property name="properties">
<util:properties location="classpath:/deployment/env.properties"></util:properties>
<props>
<prop key="name">cache-with-props</prop>
</props>