| 1 | /* |
| 2 | * Copyright 2013 the original author or authors. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.springframework.data.elasticsearch.core.mapping; |
| 17 | |
| 18 | import org.springframework.data.elasticsearch.annotations.Version; |
| 19 | import org.springframework.data.mapping.Association; |
| 20 | import org.springframework.data.mapping.PersistentEntity; |
| 21 | import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty; |
| 22 | import org.springframework.data.mapping.model.SimpleTypeHolder; |
| 23 | |
| 24 | import java.beans.PropertyDescriptor; |
| 25 | import java.lang.reflect.Field; |
| 26 | import java.util.HashSet; |
| 27 | import java.util.Set; |
| 28 | |
| 29 | /** |
| 30 | * Elasticsearch specific {@link org.springframework.data.mapping.PersistentProperty} implementation processing |
| 31 | * |
| 32 | * @author Rizwan Idrees |
| 33 | * @author Mohsin Husen |
| 34 | */ |
| 35 | public class SimpleElasticsearchPersistentProperty extends AnnotationBasedPersistentProperty<ElasticsearchPersistentProperty> implements |
| 36 | ElasticsearchPersistentProperty { |
| 37 | |
| 38 | private static final Set<Class<?>> SUPPORTED_ID_TYPES = new HashSet<Class<?>>(); |
| 39 | private static final Set<String> SUPPORTED_ID_PROPERTY_NAMES = new HashSet<String>(); |
| 40 | |
| 41 | static { |
| 42 | SUPPORTED_ID_TYPES.add(String.class); |
| 43 | SUPPORTED_ID_PROPERTY_NAMES.add("id"); |
| 44 | SUPPORTED_ID_PROPERTY_NAMES.add("documentId"); |
| 45 | } |
| 46 | |
| 47 | public SimpleElasticsearchPersistentProperty(Field field, PropertyDescriptor propertyDescriptor, |
| 48 | PersistentEntity<?, ElasticsearchPersistentProperty> owner, SimpleTypeHolder simpleTypeHolder) { |
| 49 | super(field, propertyDescriptor, owner, simpleTypeHolder); |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public String getFieldName() { |
| 54 | return field.getName(); |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public boolean isIdProperty() { |
| 59 | return super.isIdProperty() || SUPPORTED_ID_PROPERTY_NAMES.contains(getFieldName()); |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public boolean isVersionProperty(){ |
| 64 | return field.isAnnotationPresent(Version.class); |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | protected Association<ElasticsearchPersistentProperty> createAssociation() { |
| 69 | return null; |
| 70 | } |
| 71 | |
| 72 | } |