From c6cb3720993172695e72829c96cf5234ad8ede24 Mon Sep 17 00:00:00 2001 From: jxblum Date: Mon, 23 Sep 2013 23:01:25 -0700 Subject: [PATCH 1/5] Fix for JIRA issues SGF-195 concerning colocated Regions. --- .../AliasReplacingBeanDefinitionParser.java | 17 +--- .../config/PartitionedRegionParser.java | 89 +++++++++++-------- 2 files changed, 57 insertions(+), 49 deletions(-) diff --git a/src/main/java/org/springframework/data/gemfire/config/AliasReplacingBeanDefinitionParser.java b/src/main/java/org/springframework/data/gemfire/config/AliasReplacingBeanDefinitionParser.java index c06b9f19..dc0a435a 100644 --- a/src/main/java/org/springframework/data/gemfire/config/AliasReplacingBeanDefinitionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/AliasReplacingBeanDefinitionParser.java @@ -16,9 +16,7 @@ package org.springframework.data.gemfire.config; -import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.data.gemfire.SubRegionFactoryBean; @@ -29,9 +27,10 @@ import org.w3c.dom.Element; * region name to be considered a bean alias. Overrides the automatic alias * detection and replaces it with its own using meta attributes (since the * parsing method is final). - * + * * @author Costin Leau * @author David Turanski + * @author John Blum */ abstract class AliasReplacingBeanDefinitionParser extends AbstractSingleBeanDefinitionParser { @@ -50,21 +49,13 @@ abstract class AliasReplacingBeanDefinitionParser extends AbstractSingleBeanDefi @Override protected final void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { - - ParsingUtils.addBeanAliasAsMetadata(element, builder); - doParseInternal(element, parserContext, builder); } - @Override - protected void registerBeanDefinition(BeanDefinitionHolder definition, BeanDefinitionRegistry registry) { - // add the aliases from the metadata - super.registerBeanDefinition(ParsingUtils.replaceBeanAliasAsMetadata(definition), registry); - } - protected boolean isSubRegion(Element element) { return element.getParentNode().getLocalName().endsWith("region"); } protected abstract void doParseInternal(Element element, ParserContext parserContext, BeanDefinitionBuilder builder); -} \ No newline at end of file + +} diff --git a/src/main/java/org/springframework/data/gemfire/config/PartitionedRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/PartitionedRegionParser.java index da6855db..c0b7a612 100644 --- a/src/main/java/org/springframework/data/gemfire/config/PartitionedRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/PartitionedRegionParser.java @@ -25,23 +25,23 @@ import org.springframework.data.gemfire.FixedPartitionAttributesFactoryBean; import org.springframework.data.gemfire.PartitionAttributesFactoryBean; import org.springframework.data.gemfire.PartitionedRegionFactoryBean; import org.springframework.data.gemfire.RegionAttributesFactoryBean; -import org.springframework.util.StringUtils; import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; -import com.gemstone.gemfire.management.internal.cli.parser.ParserUtils; - /** * Parser for <partitioned-region;gt; definitions. - * + * * To avoid eager evaluations, the region attributes are declared as a nested * definition. - * + * * @author Costin Leau * @author David Turanski + * @author John Blum */ class PartitionedRegionParser extends AbstractRegionParser { + @Override protected Class getRegionFactoryClass() { return PartitionedRegionFactoryBean.class; @@ -53,41 +53,40 @@ class PartitionedRegionParser extends AbstractRegionParser { boolean subRegion) { super.doParse(element, builder); - BeanDefinitionBuilder attrBuilder = subRegion ? builder : BeanDefinitionBuilder - .genericBeanDefinition(RegionAttributesFactoryBean.class); + BeanDefinitionBuilder regionAttributesBuilder = (subRegion ? builder + : BeanDefinitionBuilder.genericBeanDefinition(RegionAttributesFactoryBean.class)); + + super.doParseCommonRegionConfiguration(element, parserContext, builder, regionAttributesBuilder, subRegion); + + BeanDefinitionBuilder partitionAttributesBuilder = BeanDefinitionBuilder.genericBeanDefinition( + PartitionAttributesFactoryBean.class); + + parseColocatedWith(element, builder, partitionAttributesBuilder, "colocated-with"); + ParsingUtils.setPropertyValue(element, partitionAttributesBuilder, "local-max-memory"); + ParsingUtils.setPropertyValue(element, partitionAttributesBuilder, "copies","redundantCopies"); + ParsingUtils.setPropertyValue(element, partitionAttributesBuilder, "recovery-delay"); + ParsingUtils.setPropertyValue(element, partitionAttributesBuilder, "startup-recovery-delay"); + ParsingUtils.setPropertyValue(element, partitionAttributesBuilder, "total-max-memory"); + ParsingUtils.setPropertyValue(element, partitionAttributesBuilder, "total-buckets","totalNumBuckets"); - super.doParseCommonRegionConfiguration(element, parserContext, builder, attrBuilder, subRegion); - // - // partition attributes - BeanDefinitionBuilder parAttrBuilder = BeanDefinitionBuilder - .genericBeanDefinition(PartitionAttributesFactoryBean.class); - - ParsingUtils.setPropertyValue(element, parAttrBuilder, "colocated-with"); - ParsingUtils.setPropertyValue(element, parAttrBuilder, "local-max-memory"); - ParsingUtils.setPropertyValue(element, parAttrBuilder, "copies","redundantCopies"); - ParsingUtils.setPropertyValue(element, parAttrBuilder, "recovery-delay"); - ParsingUtils.setPropertyValue(element, parAttrBuilder, "startup-recovery-delay"); - ParsingUtils.setPropertyValue(element, parAttrBuilder, "total-max-memory"); - ParsingUtils.setPropertyValue(element, parAttrBuilder, "total-buckets","totalNumBuckets"); - // Element subElement = DomUtils.getChildElementByTagName(element, "partition-resolver"); // parse nested partition resolver element if (subElement != null) { - parAttrBuilder.addPropertyValue("partitionResolver", - parsePartitionResolver(parserContext, subElement, builder)); + partitionAttributesBuilder.addPropertyValue("partitionResolver", + parsePartitionResolver(parserContext, subElement, builder)); } subElement = DomUtils.getChildElementByTagName(element, "partition-listener"); - // parse nested partition resolver element + // parse nested partition listener element if (subElement != null) { - parAttrBuilder.addPropertyValue("partitionListeners", - parsePartitionListeners(parserContext, subElement, builder)); + partitionAttributesBuilder.addPropertyValue("partitionListeners", + parsePartitionListeners(parserContext, subElement, builder)); } - + List fixedPartitions = DomUtils.getChildElementsByTagName(element, "fixed-partition"); - if (! CollectionUtils.isEmpty(fixedPartitions)){ - - @SuppressWarnings("rawtypes") + + if (!CollectionUtils.isEmpty(fixedPartitions)){ + @SuppressWarnings("rawtypes") ManagedList fixedPartitionAttributes = new ManagedList(); for (Element fp: fixedPartitions) { BeanDefinitionBuilder fpaBuilder = BeanDefinitionBuilder.genericBeanDefinition(FixedPartitionAttributesFactoryBean.class); @@ -96,14 +95,31 @@ class PartitionedRegionParser extends AbstractRegionParser { ParsingUtils.setPropertyValue(fp, fpaBuilder, "primary"); fixedPartitionAttributes.add(fpaBuilder.getBeanDefinition()); } - parAttrBuilder.addPropertyValue("fixedPartitionAttributes", fixedPartitionAttributes); + partitionAttributesBuilder.addPropertyValue("fixedPartitionAttributes", fixedPartitionAttributes); } - // // add partition attributes attributes - attrBuilder.addPropertyValue("partitionAttributes", parAttrBuilder.getBeanDefinition()); - // add partition/overflow settings as attributes + // add partition attributes to region attributes + regionAttributesBuilder.addPropertyValue("partitionAttributes", partitionAttributesBuilder.getBeanDefinition()); + // add partition/overflow settings as attributes to Region (via PartitionRegionFactoryBean -> RegionFactoryBean) if (!subRegion) { - builder.addPropertyValue("attributes", attrBuilder.getBeanDefinition()); + builder.addPropertyValue("attributes", regionAttributesBuilder.getBeanDefinition()); + } + } + + private void parseColocatedWith(Element element, BeanDefinitionBuilder regionBuilder, + BeanDefinitionBuilder partitionAttributesBuilder, String attributeName) { + // NOTE rather than using a dependency (with depends-on) we could also set the colocatedWith property of the + // PartitionAttributesFactoryBean with a reference to the Region "this" Partitioned Region will be colocated + // with, where the colocated-with attribute refers to the the bean name/alias of the other, depended on Region + // providing that the Region's name is also a bean alias of the bean definition. + //ParsingUtils.setPropertyReference(element, partitionAttributesBuilder, attributeName, "colocatedWith"); + + ParsingUtils.setPropertyValue(element, partitionAttributesBuilder, attributeName); + + String colocatedWithBeanAlias = element.getAttribute(attributeName); + + if (StringUtils.hasText(colocatedWithBeanAlias)) { + regionBuilder.addDependsOn(colocatedWithBeanAlias); } } @@ -115,4 +131,5 @@ class PartitionedRegionParser extends AbstractRegionParser { BeanDefinitionBuilder builder) { return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder); } -} \ No newline at end of file + +} From 591e7c5d053bb7386bbc515fbf62d08c3dac37b9 Mon Sep 17 00:00:00 2001 From: jxblum Date: Mon, 23 Sep 2013 23:09:49 -0700 Subject: [PATCH 2/5] Adding test code for the fix of JIRA issue SGF-195, colocated Regions. --- .../ColocatedRegionIntegrationTest.java | 52 +++++++++++++++++ .../PartitionAttributesFactoryBeanTest.java | 58 +++++++++++++++++++ .../data/gemfire/colocated-region.xml | 15 +++++ 3 files changed, 125 insertions(+) create mode 100644 src/test/java/org/springframework/data/gemfire/ColocatedRegionIntegrationTest.java create mode 100644 src/test/java/org/springframework/data/gemfire/PartitionAttributesFactoryBeanTest.java create mode 100644 src/test/resources/org/springframework/data/gemfire/colocated-region.xml diff --git a/src/test/java/org/springframework/data/gemfire/ColocatedRegionIntegrationTest.java b/src/test/java/org/springframework/data/gemfire/ColocatedRegionIntegrationTest.java new file mode 100644 index 00000000..e8d11248 --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/ColocatedRegionIntegrationTest.java @@ -0,0 +1,52 @@ +package org.springframework.data.gemfire; + +import static org.junit.Assert.*; + +import javax.annotation.Resource; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.gemstone.gemfire.cache.Region; + +/** + * The ColocatedRegionIntegrationTest class is a test suite class containing test cases for JIRA issue SGF-195, + * concerning colocated Regions in GemFire. + *

+ * @author John Blum + * @link https://jira.springsource.org/browse/SGF-195 + * @see org.junit.Test + * @see org.junit.runner.RunWith + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner + * @since 1.3.2 + */ +@ContextConfiguration("/org/springframework/data/gemfire/colocated-region.xml") +@RunWith(SpringJUnit4ClassRunner.class) +@SuppressWarnings("unused") +public class ColocatedRegionIntegrationTest { + + @Resource(name = "colocatedRegion") + private Region colocatedRegion; + + @Resource(name = "sourceRegion") + private Region sourceRegion; + + protected static void assertRegionExists(final String expectedRegionName, final Region region) { + assertNotNull(region); + assertEquals(String.format("Expected Region with name %1$s; but was %2$s!", + expectedRegionName, region.getName()), expectedRegionName, region.getName()); + } + + @Test + public void testRegionsColocated() { + assertRegionExists("Source", sourceRegion); + assertRegionExists("Colocated", colocatedRegion); + assertNotNull(colocatedRegion.getAttributes()); + assertNotNull(colocatedRegion.getAttributes().getPartitionAttributes()); + assertEquals(sourceRegion.getName(), colocatedRegion.getAttributes().getPartitionAttributes().getColocatedWith()); + } + +} diff --git a/src/test/java/org/springframework/data/gemfire/PartitionAttributesFactoryBeanTest.java b/src/test/java/org/springframework/data/gemfire/PartitionAttributesFactoryBeanTest.java new file mode 100644 index 00000000..7c71005b --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/PartitionAttributesFactoryBeanTest.java @@ -0,0 +1,58 @@ +package org.springframework.data.gemfire; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +import org.junit.Test; + +import com.gemstone.gemfire.cache.PartitionAttributes; +import com.gemstone.gemfire.cache.PartitionResolver; + +/** + * The PartitionAttributesFactoryBeanTest class is test suite of test cases testing the contract and functionality of + * the PartitionAttributesFactoryBean class. + *

+ * @author John Blum + * @see org.junit.Test + * @see org.springframework.data.gemfire.PartitionAttributesFactoryBean + * @since 1.3.2 + */ +@SuppressWarnings("unused") +public class PartitionAttributesFactoryBeanTest { + + protected PartitionResolver createMockPartitionResolver(final String name) { + PartitionResolver partitionResolver = mock(PartitionResolver.class); + + when(partitionResolver.getName()).thenReturn(name); + + return partitionResolver; + } + + @Test + public void testSetBasicProperties() throws Exception { + PartitionAttributesFactoryBean partitionAttributesFactoryBean = new PartitionAttributesFactoryBean(); + + partitionAttributesFactoryBean.setColocatedWith("mockColocatedRegion"); + partitionAttributesFactoryBean.setLocalMaxMemory(1024); + partitionAttributesFactoryBean.setPartitionResolver(createMockPartitionResolver("mockPartitionResolver")); + partitionAttributesFactoryBean.setRecoveryDelay(1000l); + partitionAttributesFactoryBean.setRedundantCopies(1); + partitionAttributesFactoryBean.setStartupRecoveryDelay(60000l); + partitionAttributesFactoryBean.setTotalMaxMemory(8192l); + partitionAttributesFactoryBean.setTotalNumBuckets(42); + + PartitionAttributes partitionAttributes = partitionAttributesFactoryBean.getObject(); + + assertNotNull(partitionAttributes); + assertEquals("mockColocatedRegion", partitionAttributes.getColocatedWith()); + assertEquals(1024, partitionAttributes.getLocalMaxMemory()); + assertNotNull(partitionAttributes.getPartitionResolver()); + assertEquals("mockPartitionResolver", partitionAttributes.getPartitionResolver().getName()); + assertEquals(1000l, partitionAttributes.getRecoveryDelay()); + assertEquals(1, partitionAttributes.getRedundantCopies()); + assertEquals(60000l, partitionAttributes.getStartupRecoveryDelay()); + assertEquals(8192l, partitionAttributes.getTotalMaxMemory()); + assertEquals(42, partitionAttributes.getTotalNumBuckets()); + } + +} diff --git a/src/test/resources/org/springframework/data/gemfire/colocated-region.xml b/src/test/resources/org/springframework/data/gemfire/colocated-region.xml new file mode 100644 index 00000000..b81c1f15 --- /dev/null +++ b/src/test/resources/org/springframework/data/gemfire/colocated-region.xml @@ -0,0 +1,15 @@ + + + + + + + + + + From 93079f9de9e4f52df8a490079c3514fdc12f1c4c Mon Sep 17 00:00:00 2001 From: jxblum Date: Tue, 24 Sep 2013 12:08:44 -0700 Subject: [PATCH 3/5] Fixed the syntactically incorrect colocated-with-ref attribute on gfe:*-region elements, renaming back to colocated-with. Changed the ClientRegionNamespaceTest and associated context configuration file to allow Region names to be used as bean aliases in the Spring container using Spring GemFire configuration. --- .../config/ClientRegionNamespaceTest.java | 11 +++---- .../data/gemfire/colocated-region.xml | 2 +- .../data/gemfire/config/client-ns.xml | 30 +++++++++---------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java index 39f87ccd..e9139cc3 100644 --- a/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java @@ -32,8 +32,6 @@ import org.springframework.context.ApplicationContext; import org.springframework.data.gemfire.SimpleObjectSizer; import org.springframework.data.gemfire.TestUtils; import org.springframework.data.gemfire.client.ClientRegionFactoryBean; -import org.springframework.data.gemfire.client.Interest; -import org.springframework.data.gemfire.client.RegexInterest; import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -44,7 +42,6 @@ import com.gemstone.gemfire.cache.DataPolicy; import com.gemstone.gemfire.cache.EvictionAction; import com.gemstone.gemfire.cache.EvictionAlgorithm; import com.gemstone.gemfire.cache.EvictionAttributes; -import com.gemstone.gemfire.cache.InterestResultPolicy; import com.gemstone.gemfire.cache.Region; import com.gemstone.gemfire.cache.RegionAttributes; import com.gemstone.gemfire.cache.util.ObjectSizer; @@ -82,7 +79,11 @@ public class ClientRegionNamespaceTest { @Test public void testBeanNames() throws Exception { - assertTrue(ObjectUtils.isEmpty(context.getAliases("publisher"))); + assertTrue(context.containsBean("SimpleRegion")); + assertTrue(context.containsBean("publisher")); + assertTrue(context.containsBean("ComplexRegion")); + assertTrue(context.containsBean("PersistentRegion")); + assertTrue(context.containsBean("OverflowRegion")); } @SuppressWarnings("rawtypes") @@ -134,4 +135,4 @@ public class ClientRegionNamespaceTest { ObjectSizer sizer = evicAttr.getObjectSizer(); assertEquals(SimpleObjectSizer.class, sizer.getClass()); } -} \ No newline at end of file +} diff --git a/src/test/resources/org/springframework/data/gemfire/colocated-region.xml b/src/test/resources/org/springframework/data/gemfire/colocated-region.xml index b81c1f15..9e565672 100644 --- a/src/test/resources/org/springframework/data/gemfire/colocated-region.xml +++ b/src/test/resources/org/springframework/data/gemfire/colocated-region.xml @@ -9,7 +9,7 @@ - + diff --git a/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml index 870dc8e5..cfc70c5a 100644 --- a/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml +++ b/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml @@ -10,12 +10,12 @@ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> - - - + + + - - + + @@ -23,20 +23,20 @@ - + - + - - - - - - - + + + + + + + @@ -44,4 +44,4 @@ - \ No newline at end of file + From c3ea6d4f92fd2009a086ca79d52aebcb20f22cfb Mon Sep 17 00:00:00 2001 From: jxblum Date: Thu, 26 Sep 2013 16:50:37 -0700 Subject: [PATCH 4/5] Removed the AliasReplacingBeanDefinitionParser class from the Region/bean definition parsing hierarchy moving the remaining methods: getBeanClass, getRegionFactoryClass and isSubRegion to the AbstractRegionParser class. Modified ClientRegionParser to extends AbstractRegionParser directly and provide an supported doParseRegion method since ClientRegionParser overrides doParse directly. Modified AbstractRegionParser class to extend org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser directly changing the overridden doParseInternal method from AliasReplacingBeanDefinitionParser to the overridden to doParse method from AbstractSingleBeanDefintionParser. --- .../gemfire/config/AbstractRegionParser.java | 20 +++++- .../AliasReplacingBeanDefinitionParser.java | 61 ------------------- .../gemfire/config/ClientRegionParser.java | 16 ++++- 3 files changed, 30 insertions(+), 67 deletions(-) delete mode 100644 src/main/java/org/springframework/data/gemfire/config/AliasReplacingBeanDefinitionParser.java diff --git a/src/main/java/org/springframework/data/gemfire/config/AbstractRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/AbstractRegionParser.java index 144a06db..85de831f 100644 --- a/src/main/java/org/springframework/data/gemfire/config/AbstractRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/AbstractRegionParser.java @@ -24,7 +24,9 @@ import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.ManagedArray; +import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.data.gemfire.SubRegionFactoryBean; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; @@ -35,11 +37,23 @@ import org.w3c.dom.Element; * * @author David Turanski */ -abstract class AbstractRegionParser extends AliasReplacingBeanDefinitionParser { +abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser { + protected final Log log = LogFactory.getLog(getClass()); @Override - protected void doParseInternal(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { + protected Class getBeanClass(Element element) { + return (isSubRegion(element) ? SubRegionFactoryBean.class : getRegionFactoryClass()); + } + + protected abstract Class getRegionFactoryClass(); + + protected boolean isSubRegion(Element element) { + return element.getParentNode().getLocalName().endsWith("region"); + } + + @Override + protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { super.doParse(element, builder); boolean subRegion = isSubRegion(element); @@ -196,4 +210,4 @@ abstract class AbstractRegionParser extends AliasReplacingBeanDefinitionParser { String name = element.getAttribute(NAME_ATTRIBUTE); return StringUtils.hasText(name) ? name : element.getAttribute(ID_ATTRIBUTE); } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/gemfire/config/AliasReplacingBeanDefinitionParser.java b/src/main/java/org/springframework/data/gemfire/config/AliasReplacingBeanDefinitionParser.java deleted file mode 100644 index dc0a435a..00000000 --- a/src/main/java/org/springframework/data/gemfire/config/AliasReplacingBeanDefinitionParser.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2012 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.config; - -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.data.gemfire.SubRegionFactoryBean; -import org.w3c.dom.Element; - -/** - * Extension class dealing with the attribute clash (name) that triggers the - * region name to be considered a bean alias. Overrides the automatic alias - * detection and replaces it with its own using meta attributes (since the - * parsing method is final). - * - * @author Costin Leau - * @author David Turanski - * @author John Blum - */ -abstract class AliasReplacingBeanDefinitionParser extends AbstractSingleBeanDefinitionParser { - - @Override - protected Class getBeanClass(Element element) { - - if (isSubRegion(element)) { - return SubRegionFactoryBean.class; - } - else { - return getRegionFactoryClass(); - } - } - - protected abstract Class getRegionFactoryClass(); - - @Override - protected final void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { - doParseInternal(element, parserContext, builder); - } - - protected boolean isSubRegion(Element element) { - return element.getParentNode().getLocalName().endsWith("region"); - } - - protected abstract void doParseInternal(Element element, ParserContext parserContext, BeanDefinitionBuilder builder); - -} diff --git a/src/main/java/org/springframework/data/gemfire/config/ClientRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/ClientRegionParser.java index 620d2692..7e61d11b 100644 --- a/src/main/java/org/springframework/data/gemfire/config/ClientRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/ClientRegionParser.java @@ -39,15 +39,17 @@ import com.gemstone.gemfire.cache.DataPolicy; * * @author Costin Leau * @author David Turanski + * @author John Blum */ -class ClientRegionParser extends AliasReplacingBeanDefinitionParser { +class ClientRegionParser extends AbstractRegionParser { + @Override protected Class getRegionFactoryClass() { return ClientRegionFactoryBean.class; } @Override - protected void doParseInternal(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { + protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { super.doParse(element, builder); // set scope @@ -131,6 +133,14 @@ class ClientRegionParser extends AliasReplacingBeanDefinitionParser { } } + @Override + protected void doParseRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, + boolean subRegion) { + throw new UnsupportedOperationException(String.format( + "doParseRegion(:Element, :ParserContext, :BeanDefinitionBuilder, subRegion:boolean) is not supported on %1$s", + getClass().getName())); + } + private Object parseCacheListener(ParserContext parserContext, Element subElement, BeanDefinitionBuilder builder) { return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder); } @@ -159,4 +169,4 @@ class ClientRegionParser extends AliasReplacingBeanDefinitionParser { ParsingUtils.setPropertyValue(element, builder, "result-policy", "policy"); ParsingUtils.setPropertyValue(element, builder, "receive-values", "receiveValues"); } -} \ No newline at end of file +} From 408c385aa902e19468036b18c9e85feca5902c2a Mon Sep 17 00:00:00 2001 From: jxblum Date: Fri, 27 Sep 2013 15:16:29 -0700 Subject: [PATCH 5/5] Added copyright information and corrected version, setting to 1.3.3. --- .../ColocatedRegionIntegrationTest.java | 18 +++++++++++++++++- .../PartitionAttributesFactoryBeanTest.java | 18 +++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/springframework/data/gemfire/ColocatedRegionIntegrationTest.java b/src/test/java/org/springframework/data/gemfire/ColocatedRegionIntegrationTest.java index e8d11248..eed5bed4 100644 --- a/src/test/java/org/springframework/data/gemfire/ColocatedRegionIntegrationTest.java +++ b/src/test/java/org/springframework/data/gemfire/ColocatedRegionIntegrationTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.data.gemfire; import static org.junit.Assert.*; @@ -21,7 +37,7 @@ import com.gemstone.gemfire.cache.Region; * @see org.junit.runner.RunWith * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner - * @since 1.3.2 + * @since 1.3.3 */ @ContextConfiguration("/org/springframework/data/gemfire/colocated-region.xml") @RunWith(SpringJUnit4ClassRunner.class) diff --git a/src/test/java/org/springframework/data/gemfire/PartitionAttributesFactoryBeanTest.java b/src/test/java/org/springframework/data/gemfire/PartitionAttributesFactoryBeanTest.java index 7c71005b..b562a588 100644 --- a/src/test/java/org/springframework/data/gemfire/PartitionAttributesFactoryBeanTest.java +++ b/src/test/java/org/springframework/data/gemfire/PartitionAttributesFactoryBeanTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.data.gemfire; import static org.junit.Assert.*; @@ -15,7 +31,7 @@ import com.gemstone.gemfire.cache.PartitionResolver; * @author John Blum * @see org.junit.Test * @see org.springframework.data.gemfire.PartitionAttributesFactoryBean - * @since 1.3.2 + * @since 1.3.3 */ @SuppressWarnings("unused") public class PartitionAttributesFactoryBeanTest {