SGF-102 Enable JavaConfig for repositories
This commit is contained in:
@@ -216,21 +216,21 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
|
||||
|
||||
protected final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
private GemFireCache cache;
|
||||
protected GemFireCache cache;
|
||||
|
||||
private Resource cacheXml;
|
||||
protected Resource cacheXml;
|
||||
|
||||
private Properties properties;
|
||||
protected Properties properties;
|
||||
|
||||
private ClassLoader beanClassLoader;
|
||||
protected ClassLoader beanClassLoader;
|
||||
|
||||
private GemfireBeanFactoryLocator factoryLocator;
|
||||
protected GemfireBeanFactoryLocator factoryLocator;
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
protected BeanFactory beanFactory;
|
||||
|
||||
private String beanName;
|
||||
protected String beanName;
|
||||
|
||||
private boolean useBeanFactoryLocator = true;
|
||||
protected boolean useBeanFactoryLocator = true;
|
||||
|
||||
// PDX options
|
||||
protected Object pdxSerializer;
|
||||
|
||||
@@ -17,18 +17,23 @@
|
||||
package org.springframework.data.gemfire.config;
|
||||
|
||||
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
|
||||
import org.springframework.data.gemfire.repository.config.GemfireRepositoryParser;
|
||||
import org.springframework.data.gemfire.repository.config.GemfireRepositoryConfigurationExtension;
|
||||
import org.springframework.data.repository.config.RepositoryBeanDefinitionParser;
|
||||
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
|
||||
|
||||
/**
|
||||
* Namespace handler for GemFire definitions.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
class GemfireDataNamespaceHandler extends NamespaceHandlerSupport {
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
registerBeanDefinitionParser("repositories", new GemfireRepositoryParser());
|
||||
// Repository namespace
|
||||
RepositoryConfigurationExtension extension = new GemfireRepositoryConfigurationExtension();
|
||||
registerBeanDefinitionParser("repositories", new RepositoryBeanDefinitionParser(extension));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* 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.repository.config;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.data.gemfire.mapping.GemfireMappingContext;
|
||||
import org.springframework.data.gemfire.repository.support.GemfireRepositoryFactoryBean;
|
||||
import org.springframework.data.repository.query.QueryLookupStrategy;
|
||||
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
|
||||
|
||||
/**
|
||||
* Annotation to enable Gemfire repositories.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Import(GemfireRepositoriesRegistrar.class)
|
||||
public @interface EnableGemfireRepositories {
|
||||
|
||||
/**
|
||||
* Alias for the {@link #basePackages()} attribute. Allows for more concise
|
||||
* annotation declarations e.g.:
|
||||
* {@code @EnableGemfireRepositories("org.my.pkg")} instead of
|
||||
* {@code @EnableGemfireRepositories(basePackages="org.my.pkg")}.
|
||||
*/
|
||||
String[] value() default {};
|
||||
|
||||
/**
|
||||
* Base packages to scan for annotated components. {@link #value()} is an
|
||||
* alias for (and mutually exclusive with) this attribute. Use
|
||||
* {@link #basePackageClasses()} for a type-safe alternative to String-based
|
||||
* package names.
|
||||
*/
|
||||
String[] basePackages() default {};
|
||||
|
||||
/**
|
||||
* Type-safe alternative to {@link #basePackages()} for specifying the
|
||||
* packages to scan for annotated components. The package of each class
|
||||
* specified will be scanned. Consider creating a special no-op marker class
|
||||
* or interface in each package that serves no purpose other than being
|
||||
* referenced by this attribute.
|
||||
*/
|
||||
Class<?>[] basePackageClasses() default {};
|
||||
|
||||
/**
|
||||
* Specifies which types are eligible for component scanning. Further
|
||||
* narrows the set of candidate components from everything in
|
||||
* {@link #basePackages()} to everything in the base packages that matches
|
||||
* the given filter or filters.
|
||||
*/
|
||||
Filter[] includeFilters() default {};
|
||||
|
||||
/**
|
||||
* Specifies which types are not eligible for component scanning.
|
||||
*/
|
||||
Filter[] excludeFilters() default {};
|
||||
|
||||
/**
|
||||
* Returns the postfix to be used when looking up custom repository
|
||||
* implementations. Defaults to {@literal Impl}. So for a repository named
|
||||
* {@code PersonRepository} the corresponding implementation class will be
|
||||
* looked up scanning for {@code PersonRepositoryImpl}.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String repositoryImplementationPostfix() default "Impl";
|
||||
|
||||
/**
|
||||
* Configures the location of where to find the Spring Data named queries
|
||||
* properties file. Will default to
|
||||
* {@code META-INFO/jpa-named-queries.properties}.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String namedQueriesLocation() default "";
|
||||
|
||||
/**
|
||||
* Returns the key of the {@link QueryLookupStrategy} to be used for lookup
|
||||
* queries for query methods. Defaults to {@link Key#CREATE_IF_NOT_FOUND}.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Key queryLookupStrategy() default Key.CREATE_IF_NOT_FOUND;
|
||||
|
||||
/**
|
||||
* Returns the {@link FactoryBean} class to be used for each repository
|
||||
* instance. Defaults to {@link GemfireRepositoryFactoryBean}.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Class<?> repositoryFactoryBeanClass() default GemfireRepositoryFactoryBean.class;
|
||||
|
||||
// Gemfire specific configuration
|
||||
/**
|
||||
* Configures the name of the {@link GemfireMappingContext} bean definition
|
||||
* to be used to create repositories discovered through this annotation. If
|
||||
* not configured a default one will be created.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String mappingContextRef() default "";
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.repository.config;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
|
||||
import org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport;
|
||||
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
|
||||
|
||||
/**
|
||||
* {@link ImportBeanDefinitionRegistrar} to setup Gemfire repositories via
|
||||
* {@link EnableGemfireRepositories}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class GemfireRepositoriesRegistrar extends RepositoryBeanDefinitionRegistrarSupport {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.data.repository.config.
|
||||
* RepositoryBeanDefinitionRegistrarSupport#getAnnotation()
|
||||
*/
|
||||
@Override
|
||||
protected Class<? extends Annotation> getAnnotation() {
|
||||
return EnableGemfireRepositories.class;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.data.repository.config.
|
||||
* RepositoryBeanDefinitionRegistrarSupport#getExtension()
|
||||
*/
|
||||
@Override
|
||||
protected RepositoryConfigurationExtension getExtension() {
|
||||
return new GemfireRepositoryConfigurationExtension();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.repository.config;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.data.gemfire.repository.support.GemfireRepositoryFactoryBean;
|
||||
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
|
||||
import org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport;
|
||||
import org.springframework.data.repository.config.XmlRepositoryConfigurationSource;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* {@link RepositoryConfigurationExtension} implementation to add Gemfire
|
||||
* specific extensions to the repository XML namespace and annotation based
|
||||
* configuration.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class GemfireRepositoryConfigurationExtension extends RepositoryConfigurationExtensionSupport {
|
||||
|
||||
private static final String MAPPING_CONTEXT_REF = "mapping-context-ref";
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.data.repository.config.RepositoryConfigurationExtension
|
||||
* #getRepositoryFactoryClassName()
|
||||
*/
|
||||
@Override
|
||||
public String getRepositoryFactoryClassName() {
|
||||
return GemfireRepositoryFactoryBean.class.getName();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.data.repository.config.
|
||||
* RepositoryConfigurationExtensionSupport#getModulePrefix()
|
||||
*/
|
||||
@Override
|
||||
protected String getModulePrefix() {
|
||||
return "gemfire";
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.data.repository.config.
|
||||
* RepositoryConfigurationExtensionSupport
|
||||
* #postProcess(org.springframework.beans
|
||||
* .factory.support.BeanDefinitionBuilder,
|
||||
* org.springframework.data.repository
|
||||
* .config.XmlRepositoryConfigurationSource)
|
||||
*/
|
||||
@Override
|
||||
public void postProcess(BeanDefinitionBuilder builder, XmlRepositoryConfigurationSource config) {
|
||||
|
||||
Element element = config.getElement();
|
||||
String mappingContextRef = element.getAttribute(MAPPING_CONTEXT_REF);
|
||||
|
||||
if (StringUtils.hasText(mappingContextRef)) {
|
||||
builder.addPropertyReference("mappingContext", mappingContextRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +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.repository.config;
|
||||
|
||||
import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
||||
import org.springframework.data.gemfire.repository.config.SimpleGemfireRepositoryConfiguration.GemfireRepositoryConfiguration;
|
||||
import org.springframework.data.gemfire.repository.support.GemfireRepositoryFactoryBean;
|
||||
import org.springframework.data.repository.config.AbstractRepositoryConfigDefinitionParser;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* {@link BeanDefinitionParser} to create {@link GemfireRepositoryFactoryBean}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class GemfireRepositoryParser extends
|
||||
AbstractRepositoryConfigDefinitionParser<SimpleGemfireRepositoryConfiguration, GemfireRepositoryConfiguration> {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.config.AbstractRepositoryConfigDefinitionParser#getGlobalRepositoryConfigInformation(org.w3c.dom.Element)
|
||||
*/
|
||||
@Override
|
||||
protected SimpleGemfireRepositoryConfiguration getGlobalRepositoryConfigInformation(Element element) {
|
||||
return new SimpleGemfireRepositoryConfiguration(element);
|
||||
}
|
||||
}
|
||||
@@ -1,135 +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.repository.config;
|
||||
|
||||
import org.springframework.data.gemfire.GemfireTemplate;
|
||||
import org.springframework.data.gemfire.repository.config.SimpleGemfireRepositoryConfiguration.GemfireRepositoryConfiguration;
|
||||
import org.springframework.data.gemfire.repository.support.GemfireRepositoryFactoryBean;
|
||||
import org.springframework.data.repository.config.AutomaticRepositoryConfigInformation;
|
||||
import org.springframework.data.repository.config.ManualRepositoryConfigInformation;
|
||||
import org.springframework.data.repository.config.RepositoryConfig;
|
||||
import org.springframework.data.repository.config.SingleRepositoryConfigInformation;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Repository configuration implementation.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
class SimpleGemfireRepositoryConfiguration extends
|
||||
RepositoryConfig<GemfireRepositoryConfiguration, SimpleGemfireRepositoryConfiguration> {
|
||||
|
||||
private static final String GEMFIRE_TEMPLATE_REF = "gemfire-template-ref";
|
||||
|
||||
/**
|
||||
* Creates a new {@link SimpleGemfireRepositoryConfiguration} for the given {@link Element}.
|
||||
*
|
||||
* @param repositoriesElement must not be {@literal null}.
|
||||
*/
|
||||
protected SimpleGemfireRepositoryConfiguration(Element repositoriesElement) {
|
||||
super(repositoriesElement, GemfireRepositoryFactoryBean.class.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bean name of the {@link GemfireTemplate} to be used.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getGemfireTemplateRef() {
|
||||
|
||||
String attribute = getSource().getAttribute(GEMFIRE_TEMPLATE_REF);
|
||||
return StringUtils.hasText(attribute) ? attribute : null;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.config.GlobalRepositoryConfigInformation#getAutoconfigRepositoryInformation(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public GemfireRepositoryConfiguration getAutoconfigRepositoryInformation(String interfaceName) {
|
||||
return new AutomaticGemfireRepositoryConfiguration(interfaceName, this);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.config.CommonRepositoryConfigInformation#getNamedQueriesLocation()
|
||||
*/
|
||||
@Override
|
||||
public String getNamedQueriesLocation() {
|
||||
return "classpath*:META-INF/gemfire-named-queries.properties";
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.config.RepositoryConfig#createSingleRepositoryConfigInformationFor(org.w3c.dom.Element)
|
||||
*/
|
||||
@Override
|
||||
protected GemfireRepositoryConfiguration createSingleRepositoryConfigInformationFor(Element element) {
|
||||
return new ManualGemfireRepositoryConfiguration(element, this);
|
||||
}
|
||||
|
||||
public interface GemfireRepositoryConfiguration extends
|
||||
SingleRepositoryConfigInformation<SimpleGemfireRepositoryConfiguration> {
|
||||
|
||||
String getGemfireTemplateRef();
|
||||
}
|
||||
|
||||
static class ManualGemfireRepositoryConfiguration extends
|
||||
ManualRepositoryConfigInformation<SimpleGemfireRepositoryConfiguration> implements GemfireRepositoryConfiguration {
|
||||
|
||||
/**
|
||||
* @param element
|
||||
* @param parent
|
||||
*/
|
||||
public ManualGemfireRepositoryConfiguration(Element element, SimpleGemfireRepositoryConfiguration parent) {
|
||||
super(element, parent);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.gemfire.config.GemfireRepositoryParser.SimpleGemfireRepositoryConfiguration.GemfireRepositoryConfiguration#getGemfireTemplateRef()
|
||||
*/
|
||||
@Override
|
||||
public String getGemfireTemplateRef() {
|
||||
return getAttribute(GEMFIRE_TEMPLATE_REF);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class AutomaticGemfireRepositoryConfiguration extends
|
||||
AutomaticRepositoryConfigInformation<SimpleGemfireRepositoryConfiguration> implements
|
||||
GemfireRepositoryConfiguration {
|
||||
|
||||
/**
|
||||
* @param interfaceName
|
||||
* @param parent
|
||||
*/
|
||||
public AutomaticGemfireRepositoryConfiguration(String interfaceName, SimpleGemfireRepositoryConfiguration parent) {
|
||||
super(interfaceName, parent);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.gemfire.config.GemfireRepositoryParser.SimpleGemfireRepositoryConfiguration.GemfireRepositoryConfiguration#getGemfireTemplateRef()
|
||||
*/
|
||||
@Override
|
||||
public String getGemfireTemplateRef() {
|
||||
|
||||
return getParent().getGemfireTemplateRef();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user