From 2fe012e87fcd65488e508890a76e26742bf7e559 Mon Sep 17 00:00:00 2001 From: Rizwan Idrees Date: Wed, 20 Mar 2013 12:54:56 +0000 Subject: [PATCH] removed custom Version as it is available in spring-data-commons 1.5 release --- .../elasticsearch/annotations/Version.java | 31 ------------------- .../SimpleElasticsearchPersistentEntity.java | 12 ------- ...SimpleElasticsearchPersistentProperty.java | 13 ++++++-- .../data/elasticsearch/SampleEntity.java | 3 +- ...mpleElasticsearchPersistentEntityTest.java | 2 +- 5 files changed, 13 insertions(+), 48 deletions(-) delete mode 100644 src/main/java/org/springframework/data/elasticsearch/annotations/Version.java diff --git a/src/main/java/org/springframework/data/elasticsearch/annotations/Version.java b/src/main/java/org/springframework/data/elasticsearch/annotations/Version.java deleted file mode 100644 index d0065304f..000000000 --- a/src/main/java/org/springframework/data/elasticsearch/annotations/Version.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 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.elasticsearch.annotations; - -import java.lang.annotation.*; - -/** - * Version - * - * @author Rizwan Idrees - * @author Mohsin Husen - */ - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -@Documented -public @interface Version { -} diff --git a/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntity.java b/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntity.java index a02edc3a3..32d21b715 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntity.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntity.java @@ -45,7 +45,6 @@ public class SimpleElasticsearchPersistentEntity extends BasicPersistentEntit private final StandardEvaluationContext context; private String indexName; private String indexType; - private ElasticsearchPersistentProperty versionProperty; public SimpleElasticsearchPersistentEntity(TypeInformation typeInformation) { super(typeInformation); @@ -76,22 +75,11 @@ public class SimpleElasticsearchPersistentEntity extends BasicPersistentEntit return indexType; } - @Override - public ElasticsearchPersistentProperty getVersionProperty() { - return this.versionProperty; - } - @Override public void addPersistentProperty(ElasticsearchPersistentProperty property) { super.addPersistentProperty(property); if(property.isVersionProperty()){ - if (this.versionProperty != null) { - throw new MappingException(String.format( - "Attempt to add version property %s but already have property %s registered " - + "as version. Check your mapping configuration!", property.getField(), versionProperty.getField())); - } Assert.isTrue(property.getType() == Long.class, "Version property should be Long"); - this.versionProperty = property; } } } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java b/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java index d2e44df5a..f191be246 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java @@ -15,7 +15,6 @@ */ package org.springframework.data.elasticsearch.core.mapping; -import org.springframework.data.elasticsearch.annotations.Version; import org.springframework.data.mapping.Association; import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty; @@ -35,6 +34,7 @@ import java.util.Set; public class SimpleElasticsearchPersistentProperty extends AnnotationBasedPersistentProperty implements ElasticsearchPersistentProperty { + private static final Class FIELD_ANNOTATION = org.springframework.data.elasticsearch.annotations.Field.class; private static final Set> SUPPORTED_ID_TYPES = new HashSet>(); private static final Set SUPPORTED_ID_PROPERTY_NAMES = new HashSet(); @@ -60,8 +60,15 @@ public class SimpleElasticsearchPersistentProperty extends AnnotationBasedPersis } @Override - public boolean isVersionProperty(){ - return field.isAnnotationPresent(Version.class); + public String getMappingType() { + return isAnnotationPresent(FIELD_ANNOTATION)? + ((org.springframework.data.elasticsearch.annotations.Field) findAnnotation(FIELD_ANNOTATION)).type(): null; + } + + @Override + public String getAnalyzer() { + return isAnnotationPresent(FIELD_ANNOTATION)? + ((org.springframework.data.elasticsearch.annotations.Field) findAnnotation(FIELD_ANNOTATION)).analyzer(): null; } @Override diff --git a/src/test/java/org/springframework/data/elasticsearch/SampleEntity.java b/src/test/java/org/springframework/data/elasticsearch/SampleEntity.java index 1c75d7544..013b9382a 100644 --- a/src/test/java/org/springframework/data/elasticsearch/SampleEntity.java +++ b/src/test/java/org/springframework/data/elasticsearch/SampleEntity.java @@ -19,8 +19,9 @@ package org.springframework.data.elasticsearch; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.springframework.data.annotation.Id; +import org.springframework.data.annotation.Version; import org.springframework.data.elasticsearch.annotations.Document; -import org.springframework.data.elasticsearch.annotations.Version; + /** * @author Rizwan Idrees * @author Mohsin Husen diff --git a/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntityTest.java b/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntityTest.java index d4396c7f3..553b2faf2 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntityTest.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntityTest.java @@ -17,7 +17,7 @@ package org.springframework.data.elasticsearch.core.mapping; import org.junit.Test; -import org.springframework.data.elasticsearch.annotations.Version; +import org.springframework.data.annotation.Version; import org.springframework.data.mapping.model.MappingException; import org.springframework.data.mapping.model.SimpleTypeHolder; import org.springframework.data.util.ClassTypeInformation;