SGF-289 - Enumeration restrictions (xsd:enumeration) should be avoided in the XML schema.

Removed the XSD enumeration restriction on the 'index-update-type' attribute of the 'baseRegionType' element in the Spring GemFire XML Schema (XSD).
This commit is contained in:
John Blum
2014-11-21 19:48:11 -08:00
parent 74755d0654
commit 4a1a3bf64d
11 changed files with 395 additions and 25 deletions

View File

@@ -33,6 +33,7 @@ import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.core.io.Resource;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.support.PersistenceExceptionTranslator;
@@ -908,6 +909,15 @@ public class CacheFactoryBean implements BeanClassLoaderAware, BeanFactoryAware,
return lazyInitialize;
}
/* (non-Javadoc) */
private void initBeanFactory() {
if (getBeanFactory() instanceof ConfigurableBeanFactory) {
((ConfigurableBeanFactory) getBeanFactory()).registerCustomEditor(IndexMaintenanceType.class,
IndexMaintenanceTypeConverter.class);
}
}
/* (non-Javadoc) */
protected void postProcessPropertiesBeforeInitialization(Properties gemfireProperties) {
if (GemfireUtils.isGemfireVersion8OrAbove()) {
gemfireProperties.setProperty("disable-auto-reconnect", String.valueOf(
@@ -917,11 +927,13 @@ public class CacheFactoryBean implements BeanClassLoaderAware, BeanFactoryAware,
}
}
/* (non-Javadoc)
/*
* (non-Javadoc)
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
@Override
public void afterPropertiesSet() throws Exception {
initBeanFactory();
postProcessPropertiesBeforeInitialization(getProperties());
if (!isLazyInitialize()) {

View File

@@ -21,8 +21,12 @@ import org.springframework.core.convert.converter.Converter;
import com.gemstone.gemfire.cache.DataPolicy;
/**
* The DataPolicyConverter class converts String values into GemFire DataPolicy enumerated values.
*
* @author David Turanski
*
* @author John Blum
* @see org.springframework.core.convert.converter.Converter
* @see com.gemstone.gemfire.cache.DataPolicy
*/
public class DataPolicyConverter implements Converter<String, DataPolicy> {

View File

@@ -0,0 +1,81 @@
/*
* 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 com.gemstone.gemfire.cache.AttributesFactory;
import com.gemstone.gemfire.cache.RegionFactory;
/**
* The IndexMaintenanceType enum is a enumerated type of GemFire Index maintenance update options.
*
* @author John Blum
* @see com.gemstone.gemfire.cache.AttributesFactory#setIndexMaintenanceSynchronous(boolean)
* @see com.gemstone.gemfire.cache.RegionAttributes#getIndexMaintenanceSynchronous()
* @see com.gemstone.gemfire.cache.RegionFactory#setIndexMaintenanceSynchronous(boolean)
* @since 1.6.0
*/
@SuppressWarnings("unused")
public enum IndexMaintenanceType {
SYNCHRONOUS,
ASYNCHRONOUS;
/**
* Determines the appropriate IndexMaintenanceType given a String value. This method is null-safe
* and case-insensitive.
*
* @param value the String value indicating the type of Index maintenance (update).
* @return a IndexMaintenanceType enumerated value based on the given String value, or null
* if the String representation does not match a IndexMaintenanceType.
* @see java.lang.Enum#name()
* @see java.lang.String#equalsIgnoreCase(String)
*/
public static IndexMaintenanceType valueOfIgnoreCase(final String value) {
for (IndexMaintenanceType indexMaintenanceType : values()) {
if (indexMaintenanceType.name().equalsIgnoreCase(value)) {
return indexMaintenanceType;
}
}
return null;
}
/**
* Sets the GemFire AttributesFactory's 'indexMaintenanceSynchronous' property appropriately based on
* this IndexMaintenanceType.
*
* @param attributesFactory the AttributesFactory instance on which to set the indexMaintenanceProperty.
* @throws java.lang.NullPointerException if the AttributesFactory reference is null.
* @see #setIndexMaintenance(com.gemstone.gemfire.cache.RegionFactory)
*/
@SuppressWarnings("deprecation")
public void setIndexMaintenance(final AttributesFactory attributesFactory) {
attributesFactory.setIndexMaintenanceSynchronous(equals(SYNCHRONOUS));
}
/**
* Sets the GemFire RegionFactory's 'indexMaintenanceSynchronous' property appropriately based on
* this IndexMaintenanceType.
*
* @param regionFactory the RegionFactory instance on which to set the indexMaintenanceProperty.
* @throws java.lang.NullPointerException if the RegionFactory reference is null.
* @see #setIndexMaintenance(com.gemstone.gemfire.cache.AttributesFactory)
*/
public void setIndexMaintenance(final RegionFactory regionFactory) {
regionFactory.setIndexMaintenanceSynchronous(equals(SYNCHRONOUS));
}
}

View File

@@ -0,0 +1,71 @@
/*
* 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 java.beans.PropertyEditorSupport;
import org.springframework.core.convert.converter.Converter;
/**
* The IndexMaintenanceTypeConverter class...
*
* @author John Blum
* @see java.beans.PropertyEditorSupport
* @see org.springframework.core.convert.converter.Converter
* @since 1.5.0
*/
@SuppressWarnings("unused")
public class IndexMaintenanceTypeConverter extends PropertyEditorSupport implements Converter<String, IndexMaintenanceType> {
/* (non-Javadoc) */
private IndexMaintenanceType assertConverted(final String source, final IndexMaintenanceType indexMaintenanceType) {
if (indexMaintenanceType == null) {
throw new IllegalArgumentException(String.format("Source (%1$s) is not a valid IndexMaintenanceType!",
source));
}
return indexMaintenanceType;
}
/**
* Sets the IndexMaintenanceType by parsing a given String. May raise a java.lang.IllegalArgumentException
* if either the String is badly formatted or the text cannot be expressed as a IndexMaintenanceType.
*
* @param text the String value to express (convert) as a IndexMaintenanceType.
* @throws java.lang.IllegalArgumentException if the String value does not represent a valid IndexMaintenanceType.
* @see #convert(String)
* @see #setValue(Object)
*/
@Override
public void setAsText(final String text) throws IllegalArgumentException {
setValue(convert(text));
}
/**
* Converts the given String value into an appropriate IndexMaintenanceType.
*
* @param source the String value to convert into a IndexMaintenanceType.
* @return a IndexMaintenanceType for the given String value.
* @throws java.lang.IllegalArgumentException if the String value does not represent a valid IndexMaintenanceType.
* @see org.springframework.data.gemfire.IndexMaintenanceType#valueOfIgnoreCase(String)
*/
@Override
public IndexMaintenanceType convert(final String source) {
return assertConverted(source, IndexMaintenanceType.valueOfIgnoreCase(source));
}
}

View File

@@ -19,11 +19,11 @@ package org.springframework.data.gemfire;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import com.gemstone.gemfire.cache.AttributesFactory;
import com.gemstone.gemfire.cache.RegionAttributes;
/**
* Spring-friendly bean for creating {@link RegionAttributes}. Eliminates the need of using
* a XML 'factory-method' tag.
* Spring-friendly bean for creating {@link RegionAttributes}. Eliminates the need of using a XML 'factory-method' tag.
*
* @author Costin Leau
* @author John Blum
@@ -32,9 +32,9 @@ import com.gemstone.gemfire.cache.RegionAttributes;
* @see com.gemstone.gemfire.cache.AttributesFactory
* @see com.gemstone.gemfire.cache.RegionAttributes
*/
@SuppressWarnings("deprecation")
public class RegionAttributesFactoryBean extends com.gemstone.gemfire.cache.AttributesFactory
implements FactoryBean<RegionAttributes>, InitializingBean {
@SuppressWarnings({ "deprecation", "unused" })
public class RegionAttributesFactoryBean extends AttributesFactory implements FactoryBean<RegionAttributes>,
InitializingBean {
private RegionAttributes attributes;
@@ -53,6 +53,10 @@ public class RegionAttributesFactoryBean extends com.gemstone.gemfire.cache.Attr
return true;
}
public void setIndexUpdateType(final IndexMaintenanceType indexUpdateType) {
indexUpdateType.setIndexMaintenance(this);
}
@Override
public void afterPropertiesSet() throws Exception {
attributes = super.create();

View File

@@ -307,6 +307,7 @@ abstract class ParsingUtils {
setPropertyValue(element, regionAttributesBuilder, "enable-async-conflation");
setPropertyValue(element, regionAttributesBuilder, "enable-subscription-conflation");
setPropertyValue(element, regionAttributesBuilder, "ignore-jta", "ignoreJTA");
setPropertyValue(element, regionAttributesBuilder, "index-update-type");
setPropertyValue(element, regionAttributesBuilder, "initial-capacity");
setPropertyValue(element, regionAttributesBuilder, "is-lock-grantor", "lockGrantor");
setPropertyValue(element, regionAttributesBuilder, "key-constraint");
@@ -315,18 +316,11 @@ abstract class ParsingUtils {
setPropertyValue(element, regionAttributesBuilder, "publisher");
setPropertyValue(element, regionAttributesBuilder, "value-constraint");
String indexUpdateType = element.getAttribute("index-update-type");
if (StringUtils.hasText(indexUpdateType)) {
regionAttributesBuilder.addPropertyValue("indexMaintenanceSynchronous",
"synchronous".equals(indexUpdateType));
}
String concurrencyChecksEnabled = element.getAttribute("concurrency-checks-enabled");
if (StringUtils.hasText(concurrencyChecksEnabled)) {
if (!GemfireUtils.isGemfireVersion7OrAbove()) {
log.warn("Setting 'concurrency-checks-enabled' is only available in Gemfire 7.0 or above");
log.warn("Setting 'concurrency-checks-enabled' is only available in Gemfire 7.0 or above!");
}
else {
ParsingUtils.setPropertyValue(element, regionAttributesBuilder, "concurrency-checks-enabled");