mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-20 02:52:12 +00:00
DATAES-536 - Polishing
* remove unused field xContentBuilder * add missing generics * add XContentType to rawValue * organize imports
This commit is contained in:
parent
365b0c47d8
commit
ab7458d7d7
@ -15,12 +15,17 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core;
|
package org.springframework.data.elasticsearch.core;
|
||||||
|
|
||||||
|
import static org.elasticsearch.common.xcontent.XContentFactory.*;
|
||||||
|
import static org.springframework.util.StringUtils.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
import org.springframework.core.ResolvableType;
|
import org.springframework.core.ResolvableType;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.data.annotation.Transient;
|
import org.springframework.data.annotation.Transient;
|
||||||
@ -40,9 +45,6 @@ import org.springframework.data.util.ClassTypeInformation;
|
|||||||
import org.springframework.data.util.TypeInformation;
|
import org.springframework.data.util.TypeInformation;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import static org.elasticsearch.common.xcontent.XContentFactory.*;
|
|
||||||
import static org.springframework.util.StringUtils.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
@ -85,9 +87,8 @@ class MappingBuilder {
|
|||||||
public static final String TYPE_VALUE_GEO_HASH_PRECISION = "geohash_precision";
|
public static final String TYPE_VALUE_GEO_HASH_PRECISION = "geohash_precision";
|
||||||
|
|
||||||
private static SimpleTypeHolder SIMPLE_TYPE_HOLDER = SimpleTypeHolder.DEFAULT;
|
private static SimpleTypeHolder SIMPLE_TYPE_HOLDER = SimpleTypeHolder.DEFAULT;
|
||||||
private XContentBuilder xContentBuilder;
|
|
||||||
|
|
||||||
static XContentBuilder buildMapping(Class clazz, String indexType, String idFieldName, String parentType) throws IOException {
|
static XContentBuilder buildMapping(Class<?> clazz, String indexType, String idFieldName, String parentType) throws IOException {
|
||||||
|
|
||||||
XContentBuilder mapping = jsonBuilder().startObject().startObject(indexType);
|
XContentBuilder mapping = jsonBuilder().startObject().startObject(indexType);
|
||||||
// Parent
|
// Parent
|
||||||
@ -103,7 +104,7 @@ class MappingBuilder {
|
|||||||
return xContentBuilder.endObject().endObject().endObject();
|
return xContentBuilder.endObject().endObject().endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void mapEntity(XContentBuilder xContentBuilder, Class clazz, boolean isRootObject, String idFieldName,
|
private static void mapEntity(XContentBuilder xContentBuilder, Class<?> clazz, boolean isRootObject, String idFieldName,
|
||||||
String nestedObjectFieldName, boolean nestedOrObjectField, FieldType fieldType, Field fieldAnnotation) throws IOException {
|
String nestedObjectFieldName, boolean nestedOrObjectField, FieldType fieldType, Field fieldAnnotation) throws IOException {
|
||||||
|
|
||||||
java.lang.reflect.Field[] fields = retrieveFields(clazz);
|
java.lang.reflect.Field[] fields = retrieveFields(clazz);
|
||||||
@ -132,7 +133,7 @@ class MappingBuilder {
|
|||||||
if (!StringUtils.isEmpty(mappingPath)) {
|
if (!StringUtils.isEmpty(mappingPath)) {
|
||||||
ClassPathResource mappings = new ClassPathResource(mappingPath);
|
ClassPathResource mappings = new ClassPathResource(mappingPath);
|
||||||
if (mappings.exists()) {
|
if (mappings.exists()) {
|
||||||
xContentBuilder.rawField(field.getName(), mappings.getInputStream());
|
xContentBuilder.rawField(field.getName(), mappings.getInputStream(), XContentType.JSON);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,12 +179,12 @@ class MappingBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static java.lang.reflect.Field[] retrieveFields(Class clazz) {
|
private static java.lang.reflect.Field[] retrieveFields(Class<?> clazz) {
|
||||||
// Create list of fields.
|
// Create list of fields.
|
||||||
List<java.lang.reflect.Field> fields = new ArrayList<>();
|
List<java.lang.reflect.Field> fields = new ArrayList<>();
|
||||||
|
|
||||||
// Keep backing up the inheritance hierarchy.
|
// Keep backing up the inheritance hierarchy.
|
||||||
Class targetClass = clazz;
|
Class<?> targetClass = clazz;
|
||||||
do {
|
do {
|
||||||
fields.addAll(Arrays.asList(targetClass.getDeclaredFields()));
|
fields.addAll(Arrays.asList(targetClass.getDeclaredFields()));
|
||||||
targetClass = targetClass.getSuperclass();
|
targetClass = targetClass.getSuperclass();
|
||||||
@ -355,7 +356,7 @@ class MappingBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected static boolean isEntity(java.lang.reflect.Field field) {
|
protected static boolean isEntity(java.lang.reflect.Field field) {
|
||||||
TypeInformation typeInformation = ClassTypeInformation.from(field.getType());
|
TypeInformation<?> typeInformation = ClassTypeInformation.from(field.getType());
|
||||||
Class<?> clazz = getFieldType(field);
|
Class<?> clazz = getFieldType(field);
|
||||||
boolean isComplexType = !SIMPLE_TYPE_HOLDER.isSimpleType(clazz);
|
boolean isComplexType = !SIMPLE_TYPE_HOLDER.isSimpleType(clazz);
|
||||||
return isComplexType && !Map.class.isAssignableFrom(typeInformation.getType());
|
return isComplexType && !Map.class.isAssignableFrom(typeInformation.getType());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user