From 78820a2a70e9068ba0cb4fc0e976605af6b9c61d Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Mon, 7 May 2012 13:10:45 +0200 Subject: [PATCH] SGF-92 - Improved error message in case no region can be found. If the region referenced by an entity managed by a repository cannot be found in the application context we now throw an exception with an error message indicating the missing configuration. --- .../repository/support/GemfireRepositoryFactory.java | 7 ++++++- .../GemfireRepositoryFactoryIntegrationTests.java | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactory.java b/src/main/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactory.java index 40f4d93b..7c09dc8c 100644 --- a/src/main/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactory.java +++ b/src/main/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactory.java @@ -93,9 +93,14 @@ public class GemfireRepositoryFactory extends RepositoryFactorySupport { private GemfireTemplate getTemplate(RepositoryMetadata metadata) { Class domainClass = metadata.getDomainType(); + GemfirePersistentEntity entity = context.getPersistentEntity(domainClass); + Region region = regions.getRegion(domainClass); - GemfirePersistentEntity entity = context.getPersistentEntity(domainClass); + if (region == null) { + throw new IllegalStateException(String.format("No region '%s' found for domain class %s! Make sure you have " + + "configured a Gemfire region of that name in your application context!", entity.getRegionName(), domainClass)); + } Class regionKeyType = region.getAttributes().getKeyConstraint(); Class entityIdType = metadata.getIdType(); diff --git a/src/test/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactoryIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactoryIntegrationTests.java index bd31ad4a..11ef0405 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactoryIntegrationTests.java +++ b/src/test/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactoryIntegrationTests.java @@ -15,10 +15,13 @@ */ package org.springframework.data.gemfire.repository.support; +import org.junit.Test; import org.springframework.data.gemfire.mapping.Regions; import org.springframework.data.gemfire.repository.sample.PersonRepository; import org.springframework.test.context.ContextConfiguration; +import com.gemstone.bp.edu.emory.mathcs.backport.java.util.Collections; + /** * Integration test for {@link GemfireRepositoryFactory}. * @@ -33,4 +36,12 @@ public class GemfireRepositoryFactoryIntegrationTests extends AbstractGemfireRep GemfireRepositoryFactory factory = new GemfireRepositoryFactory(regions, null); return factory.getRepository(PersonRepository.class); } + + @Test(expected = IllegalStateException.class) + @SuppressWarnings("unchecked") + public void throwsExceptionIfReferencedRegionIsNotConfigured() { + + GemfireRepositoryFactory factory = new GemfireRepositoryFactory(Collections.emptySet(), null); + factory.getRepository(PersonRepository.class); + } }