SGF-51
+ first draft of namespace support for indexes
This commit is contained in:
@@ -13,10 +13,10 @@
|
||||
<classpathentry kind="lib" path="C:/Users/costin/.gradle/cache/antlr/antlr/jars/antlr-2.7.7.jar" exported="true"/>
|
||||
<classpathentry sourcepath="C:/Users/costin/.gradle/cache/log4j/log4j/sources/log4j-1.2.16-sources.jar" kind="lib" path="C:/Users/costin/.gradle/cache/log4j/log4j/bundles/log4j-1.2.16.jar" exported="true"/>
|
||||
<classpathentry sourcepath="C:/Users/costin/.gradle/cache/org.springframework/spring-beans/sources/spring-beans-3.1.0.M2-sources.jar" kind="lib" path="C:/Users/costin/.gradle/cache/org.springframework/spring-beans/jars/spring-beans-3.1.0.M2.jar" exported="true"/>
|
||||
<classpathentry kind="lib" path="C:/Users/costin/.gradle/cache/com.gemstone.gemfire/gemfire/jars/gemfire-6.6.jar" exported="true"/>
|
||||
<classpathentry sourcepath="C:/Users/costin/.gradle/cache/org.springframework/spring-asm/sources/spring-asm-3.1.0.M2-sources.jar" kind="lib" path="C:/Users/costin/.gradle/cache/org.springframework/spring-asm/jars/spring-asm-3.1.0.M2.jar" exported="true"/>
|
||||
<classpathentry sourcepath="C:/Users/costin/.gradle/cache/org.springframework/spring-context-support/sources/spring-context-support-3.1.0.M2-sources.jar" kind="lib" path="C:/Users/costin/.gradle/cache/org.springframework/spring-context-support/jars/spring-context-support-3.1.0.M2.jar" exported="true"/>
|
||||
<classpathentry sourcepath="C:/Users/costin/.gradle/cache/org.hamcrest/hamcrest-core/sources/hamcrest-core-1.1-sources.jar" kind="lib" path="C:/Users/costin/.gradle/cache/org.hamcrest/hamcrest-core/jars/hamcrest-core-1.1.jar" exported="true"/>
|
||||
<classpathentry kind="lib" path="C:/Users/costin/.gradle/cache/com.gemstone.gemfire/gemfire/jars/gemfire-6.6.RC.jar" exported="true"/>
|
||||
<classpathentry sourcepath="C:/Users/costin/.gradle/cache/org.springframework/spring-expression/sources/spring-expression-3.1.0.M2-sources.jar" kind="lib" path="C:/Users/costin/.gradle/cache/org.springframework/spring-expression/jars/spring-expression-3.1.0.M2.jar" exported="true"/>
|
||||
<classpathentry sourcepath="C:/Users/costin/.gradle/cache/org.objenesis/objenesis/sources/objenesis-1.0-sources.jar" kind="lib" path="C:/Users/costin/.gradle/cache/org.objenesis/objenesis/jars/objenesis-1.0.jar" exported="true"/>
|
||||
<classpathentry sourcepath="C:/Users/costin/.gradle/cache/org.springframework/spring-test/sources/spring-test-3.1.0.M2-sources.jar" kind="lib" path="C:/Users/costin/.gradle/cache/org.springframework/spring-test/jars/spring-test-3.1.0.M2.jar" exported="true"/>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
#Fri Aug 19 11:36:57 EEST 2011
|
||||
#Fri Sep 16 13:59:45 EEST 2011
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.compliance=1.5
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.RegionService;
|
||||
import com.gemstone.gemfire.cache.client.Pool;
|
||||
import com.gemstone.gemfire.cache.client.PoolManager;
|
||||
import com.gemstone.gemfire.cache.query.Index;
|
||||
import com.gemstone.gemfire.cache.query.IndexType;
|
||||
import com.gemstone.gemfire.cache.query.QueryService;
|
||||
|
||||
/**
|
||||
* Factory bean for easy declarative creation of GemFire Indexes.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class IndexFactoryBean implements InitializingBean, BeanNameAware, FactoryBean<Index> {
|
||||
|
||||
private Index index;
|
||||
private QueryService queryService;
|
||||
private String poolName;
|
||||
private RegionService cache;
|
||||
private String beanName;
|
||||
private String name, expression, from, imports;
|
||||
private IndexType type;
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (queryService == null) {
|
||||
if (cache != null) {
|
||||
queryService = cache.getQueryService();
|
||||
}
|
||||
}
|
||||
|
||||
if (queryService != null && StringUtils.hasText(poolName)) {
|
||||
Pool pool = PoolManager.find(poolName);
|
||||
Assert.notNull(pool, "No pool named [" + poolName + "] found");
|
||||
queryService = pool.getQueryService();
|
||||
}
|
||||
|
||||
Assert.notNull(queryService, "Query service required for index creation");
|
||||
|
||||
String indexName = StringUtils.hasText(name) ? name : beanName;
|
||||
index = createIndex(queryService, indexName);
|
||||
}
|
||||
|
||||
private Index createIndex(QueryService queryService, String indexName) throws Exception {
|
||||
Collection<Index> indexes = queryService.getIndexes();
|
||||
for (Index index : indexes) {
|
||||
if (indexName.equals(index.getName())) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
Index index = null;
|
||||
|
||||
if (StringUtils.hasText(imports)) {
|
||||
index = queryService.createIndex(indexName, type, expression, from, imports);
|
||||
}
|
||||
else {
|
||||
index = queryService.createIndex(indexName, type, expression, from);
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
public Index getObject() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public Class<?> getObjectType() {
|
||||
return (index != null ? index.getClass() : Index.class);
|
||||
}
|
||||
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the underlying cache used for creating indexes.
|
||||
*
|
||||
* @param cache cache used for creating indexes.
|
||||
*/
|
||||
public void setCache(RegionService cache) {
|
||||
this.queryService = cache.getQueryService();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the query service used for creating indexes.
|
||||
*
|
||||
* @param service query service used for creating indexes.
|
||||
*/
|
||||
public void setQueryService(QueryService service) {
|
||||
this.queryService = service;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the beanName of the {@link Pool} used for used for creating indexes.
|
||||
*
|
||||
* @param poolName the beanName of the pool used for creating indexes.
|
||||
*/
|
||||
public void setPoolName(String poolName) {
|
||||
this.poolName = poolName;
|
||||
}
|
||||
|
||||
public void setBeanName(String name) {
|
||||
this.beanName = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param expression the expression to set
|
||||
*/
|
||||
public void setExpression(String expression) {
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param from the from to set
|
||||
*/
|
||||
public void setFrom(String from) {
|
||||
this.from = from;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param imports the imports to set
|
||||
*/
|
||||
public void setImports(String imports) {
|
||||
this.imports = imports;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type the type to set
|
||||
*/
|
||||
public void setType(IndexType type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
@@ -1138,4 +1138,43 @@ Whether the resulting GemFire continuous query is durable or not.
|
||||
</xsd:attribute>
|
||||
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:element name="index">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation source="org.springframework.data.gemfire.IndexFactoryBean"><![CDATA[
|
||||
Defines a GemFire index.
|
||||
]]></xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation>
|
||||
<tool:exports type="com.gemstone.gemfire.cache.query.Index" />
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="id" type="xsd:ID">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The name of the bean index definition. If property 'name' is not set, it will be used as the index name as well.]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="type" use="optional" default="FUNCTIONAL">
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="FUNCTIONAL"/>
|
||||
<xsd:enumeration value="PRIMARY_KEY"/>
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="name" use="optional" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The name of the index.]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<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:complexType>
|
||||
</xsd:element>
|
||||
|
||||
</xsd:schema>
|
||||
Reference in New Issue
Block a user