1 | /* |
2 | * Copyright 2012 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.mapping.Association; |
19 | import org.springframework.data.mapping.PersistentEntity; |
20 | import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty; |
21 | import org.springframework.data.mapping.model.SimpleTypeHolder; |
22 | |
23 | import java.beans.PropertyDescriptor; |
24 | import java.lang.reflect.Field; |
25 | import java.util.HashSet; |
26 | import java.util.Set; |
27 | |
28 | /** |
29 | * Elasticsearch specific {@link org.springframework.data.mapping.PersistentProperty} implementation processing |
30 | */ |
31 | public class SimpleElasticsearchPersistentProperty extends AnnotationBasedPersistentProperty<ElasticsearchPersistentProperty> implements |
32 | ElasticsearchPersistentProperty { |
33 | |
34 | private static final Set<Class<?>> SUPPORTED_ID_TYPES = new HashSet<Class<?>>(); |
35 | private static final Set<String> SUPPORTED_ID_PROPERTY_NAMES = new HashSet<String>(); |
36 | |
37 | static { |
38 | SUPPORTED_ID_TYPES.add(String.class); |
39 | SUPPORTED_ID_PROPERTY_NAMES.add("id"); |
40 | SUPPORTED_ID_PROPERTY_NAMES.add("documentId"); |
41 | } |
42 | |
43 | public SimpleElasticsearchPersistentProperty(Field field, PropertyDescriptor propertyDescriptor, |
44 | PersistentEntity<?, ElasticsearchPersistentProperty> owner, SimpleTypeHolder simpleTypeHolder) { |
45 | super(field, propertyDescriptor, owner, simpleTypeHolder); |
46 | } |
47 | |
48 | @Override |
49 | public String getFieldName() { |
50 | return field.getName(); |
51 | } |
52 | |
53 | @Override |
54 | public boolean isIdProperty() { |
55 | return super.isIdProperty() || SUPPORTED_ID_PROPERTY_NAMES.contains(getFieldName()); |
56 | } |
57 | |
58 | @Override |
59 | protected Association<ElasticsearchPersistentProperty> createAssociation() { |
60 | return null; |
61 | } |
62 | |
63 | } |