SGF-53
+ add some integration tests (still unfinished) and improve parsing
This commit is contained in:
@@ -44,7 +44,7 @@ public class IndexFactoryBean implements InitializingBean, BeanNameAware, Factor
|
||||
private RegionService cache;
|
||||
private String beanName;
|
||||
private String name, expression, from, imports;
|
||||
private IndexType type;
|
||||
private IndexType type = IndexType.FUNCTIONAL;
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (queryService == null) {
|
||||
@@ -60,8 +60,13 @@ public class IndexFactoryBean implements InitializingBean, BeanNameAware, Factor
|
||||
}
|
||||
|
||||
Assert.notNull(queryService, "Query service required for index creation");
|
||||
Assert.hasText(expression, "Index expression is required");
|
||||
Assert.hasText(from, "Index from clause is required");
|
||||
|
||||
String indexName = StringUtils.hasText(name) ? name : beanName;
|
||||
|
||||
Assert.hasText(indexName, "Index bean id or name is required");
|
||||
|
||||
index = createIndex(queryService, indexName);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ class GemfireNamespaceHandler extends NamespaceHandlerSupport {
|
||||
registerBeanDefinitionParser("partitioned-region", new PartitionedRegionParser());
|
||||
registerBeanDefinitionParser("client-region", new ClientRegionParser());
|
||||
registerBeanDefinitionParser("pool", new PoolParser());
|
||||
registerBeanDefinitionParser("index", new IndexParser());
|
||||
registerBeanDefinitionParser("cache-server", new CacheServerParser());
|
||||
|
||||
registerBeanDefinitionParser("transaction-manager", new TransactionManagerParser());
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2011 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.AbstractSimpleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.data.gemfire.IndexFactoryBean;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for <index;gt; definitions.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
class IndexParser extends AbstractSimpleBeanDefinitionParser {
|
||||
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return IndexFactoryBean.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
ParsingUtils.setPropertyReference(element, builder, "cache-ref", "cache");
|
||||
super.doParse(element, parserContext, builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEligibleAttribute(String attributeName) {
|
||||
if ("cache-ref".equals(attributeName)) {
|
||||
return false;
|
||||
}
|
||||
return super.isEligibleAttribute(attributeName);
|
||||
}
|
||||
}
|
||||
@@ -1174,6 +1174,21 @@ The name of the index.]]></xsd:documentation>
|
||||
<xsd:attribute name="expression" use="required" type="xsd:string"/>
|
||||
<xsd:attribute name="from" use="required" type="xsd:string"/>
|
||||
<xsd:attribute name="imports" use="optional" type="xsd:string"/>
|
||||
|
||||
<xsd:attribute name="cache-ref" type="xsd:string" default="gemfire-cache" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The name of the bean defining the GemFire cache (by default 'gemfire-cache').
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="pool-name" use="optional" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The name of the pool used by the index. Used usually in client scenarios.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2011 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.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.gemfire.IndexFactoryBean;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("index-ns.xml")
|
||||
public class IndexNamespaceTest {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void testBasicIndex() throws Exception {
|
||||
IndexFactoryBean ifb = null;
|
||||
|
||||
ifb = (IndexFactoryBean) context.getBean("&simple");
|
||||
System.out.println("Ifb is " + ifb);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComplexIndex() throws Exception {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:gfe="http://www.springframework.org/schema/gemfire"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.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 -->
|
||||
|
||||
|
||||
<gfe:index id="simple" expression="status" from="/portfolios"/>
|
||||
|
||||
<gfe:cache />
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user