mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-08-08 10:33:31 +00:00
Compare commits
58 Commits
main
...
2.0.9.RELE
Author | SHA1 | Date | |
---|---|---|---|
|
15c5415276 | ||
|
c895ea43cf | ||
|
7d479090dc | ||
|
1422c290d9 | ||
|
38c571e49b | ||
|
e16be395ce | ||
|
0040779053 | ||
|
113cb52fbc | ||
|
388a77d51e | ||
|
78e25b8ddf | ||
|
01067d1127 | ||
|
242460df4c | ||
|
85a95219a1 | ||
|
f55e2e33f5 | ||
|
667cd84350 | ||
|
130625cd00 | ||
|
640e24821c | ||
|
52afb8d9a2 | ||
|
64bcce6784 | ||
|
78c7668681 | ||
|
634c0e8b1f | ||
|
51ca555470 | ||
|
bc4891907e | ||
|
96934676ae | ||
|
90348459e7 | ||
|
e2a868ef97 | ||
|
0c146bb47c | ||
|
35ad47da4a | ||
|
fd33ad40d7 | ||
|
ac7ee3e986 | ||
|
729ecb2ed9 | ||
|
89b99c7687 | ||
|
4498805d0d | ||
|
c781fde4b4 | ||
|
67385a9c51 | ||
|
30cf3b5172 | ||
|
baa52a82e4 | ||
|
397d3b89f8 | ||
|
abd6ad3536 | ||
|
0510b06ee4 | ||
|
ff1f7676b2 | ||
|
10a11ad22f | ||
|
0978c47fb9 | ||
|
acc81f89fb | ||
|
4fb2b33066 | ||
|
20d8103a19 | ||
|
c799e8d1c8 | ||
|
e4e6b09161 | ||
|
511da0fadf | ||
|
6090f4a5db | ||
|
c964ce5dac | ||
|
2f50462857 | ||
|
eab54cb546 | ||
|
6bdb45a0f8 | ||
|
793e6ab843 | ||
|
182684e56c | ||
|
33e1611186 | ||
|
55ccfe5c0b |
29
pom.xml
29
pom.xml
@ -4,12 +4,12 @@
|
|||||||
|
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-elasticsearch</artifactId>
|
<artifactId>spring-data-elasticsearch</artifactId>
|
||||||
<version>2.0.0.RELEASE</version>
|
<version>2.0.9.RELEASE</version>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.data.build</groupId>
|
<groupId>org.springframework.data.build</groupId>
|
||||||
<artifactId>spring-data-parent</artifactId>
|
<artifactId>spring-data-parent</artifactId>
|
||||||
<version>1.8.0.RELEASE</version>
|
<version>1.8.9.RELEASE</version>
|
||||||
<relativePath>../spring-data-build/parent/pom.xml</relativePath>
|
<relativePath>../spring-data-build/parent/pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
@ -24,7 +24,7 @@
|
|||||||
<commonscollections>3.2.1</commonscollections>
|
<commonscollections>3.2.1</commonscollections>
|
||||||
<commonslang>2.6</commonslang>
|
<commonslang>2.6</commonslang>
|
||||||
<elasticsearch>2.2.0</elasticsearch>
|
<elasticsearch>2.2.0</elasticsearch>
|
||||||
<springdata.commons>1.12.0.RELEASE</springdata.commons>
|
<springdata.commons>1.12.9.RELEASE</springdata.commons>
|
||||||
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
@ -129,7 +129,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>1.16.4</version>
|
<version>${lombok}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@ -150,9 +150,30 @@
|
|||||||
<artifactId>asciidoctor-maven-plugin</artifactId>
|
<artifactId>asciidoctor-maven-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|
||||||
|
<testResources>
|
||||||
|
<testResource>
|
||||||
|
<directory>${basedir}/src/test/resources</directory>
|
||||||
|
</testResource>
|
||||||
|
<testResource>
|
||||||
|
<targetPath>${basedir}/target/test-home-dir</targetPath>
|
||||||
|
<directory>${basedir}/src/test/es-modules/${elasticsearch}</directory>
|
||||||
|
<includes>
|
||||||
|
<include>**/*</include>
|
||||||
|
</includes>
|
||||||
|
</testResource>
|
||||||
|
</testResources>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<profiles>
|
<profiles>
|
||||||
|
|
||||||
|
<profile>
|
||||||
|
<id>es2.3.3</id>
|
||||||
|
<properties>
|
||||||
|
<elasticsearch>2.3.3</elasticsearch>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
|
||||||
<profile>
|
<profile>
|
||||||
<id>release</id>
|
<id>release</id>
|
||||||
<build>
|
<build>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -18,7 +18,6 @@ package org.springframework.data.elasticsearch.core;
|
|||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -48,6 +47,8 @@ import org.springframework.data.mapping.context.MappingContext;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
|
* @author Young Gu
|
||||||
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
public class DefaultResultMapper extends AbstractResultMapper {
|
public class DefaultResultMapper extends AbstractResultMapper {
|
||||||
|
|
||||||
@ -169,18 +170,15 @@ public class DefaultResultMapper extends AbstractResultMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private <T> void setPersistentEntityId(T result, String id, Class<T> clazz) {
|
private <T> void setPersistentEntityId(T result, String id, Class<T> clazz) {
|
||||||
|
|
||||||
if (mappingContext != null && clazz.isAnnotationPresent(Document.class)) {
|
if (mappingContext != null && clazz.isAnnotationPresent(Document.class)) {
|
||||||
PersistentProperty<ElasticsearchPersistentProperty> idProperty = mappingContext.getPersistentEntity(clazz).getIdProperty();
|
|
||||||
|
ElasticsearchPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(clazz);
|
||||||
|
PersistentProperty<?> idProperty = persistentEntity.getIdProperty();
|
||||||
|
|
||||||
// Only deal with String because ES generated Ids are strings !
|
// Only deal with String because ES generated Ids are strings !
|
||||||
if (idProperty != null && idProperty.getType().isAssignableFrom(String.class)) {
|
if (idProperty != null && idProperty.getType().isAssignableFrom(String.class)) {
|
||||||
Method setter = idProperty.getSetter();
|
persistentEntity.getPropertyAccessor(result).setProperty(idProperty, id);
|
||||||
if (setter != null) {
|
|
||||||
try {
|
|
||||||
setter.invoke(result, id);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
t.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,6 @@ import static org.springframework.util.CollectionUtils.isEmpty;
|
|||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.elasticsearch.action.ListenableActionFuture;
|
import org.elasticsearch.action.ListenableActionFuture;
|
||||||
@ -98,6 +97,8 @@ import org.springframework.util.Assert;
|
|||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
* @author Kevin Leturc
|
* @author Kevin Leturc
|
||||||
* @author Mason Chan
|
* @author Mason Chan
|
||||||
|
* @author Young Gu
|
||||||
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class ElasticsearchTemplate implements ElasticsearchOperations, ApplicationContextAware {
|
public class ElasticsearchTemplate implements ElasticsearchOperations, ApplicationContextAware {
|
||||||
@ -1081,35 +1082,21 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getPersistentEntityId(Object entity) {
|
private String getPersistentEntityId(Object entity) {
|
||||||
PersistentProperty idProperty = getPersistentEntityFor(entity.getClass()).getIdProperty();
|
|
||||||
if (idProperty != null) {
|
ElasticsearchPersistentEntity<?> persistentEntity = getPersistentEntityFor(entity.getClass());
|
||||||
Method getter = idProperty.getGetter();
|
Object identifier = persistentEntity.getIdentifierAccessor(entity).getIdentifier();
|
||||||
if (getter != null) {
|
|
||||||
try {
|
return identifier == null ? null : String.valueOf(identifier);
|
||||||
Object id = getter.invoke(entity);
|
|
||||||
if (id != null) {
|
|
||||||
return String.valueOf(id);
|
|
||||||
}
|
|
||||||
} catch (Throwable t) {
|
|
||||||
t.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setPersistentEntityId(Object entity, String id) {
|
private void setPersistentEntityId(Object entity, String id) {
|
||||||
PersistentProperty idProperty = getPersistentEntityFor(entity.getClass()).getIdProperty();
|
|
||||||
|
ElasticsearchPersistentEntity<?> persistentEntity = getPersistentEntityFor(entity.getClass());
|
||||||
|
PersistentProperty<?> idProperty = persistentEntity.getIdProperty();
|
||||||
|
|
||||||
// Only deal with String because ES generated Ids are strings !
|
// Only deal with String because ES generated Ids are strings !
|
||||||
if (idProperty != null && idProperty.getType().isAssignableFrom(String.class)) {
|
if (idProperty != null && idProperty.getType().isAssignableFrom(String.class)) {
|
||||||
Method setter = idProperty.getSetter();
|
persistentEntity.getPropertyAccessor(entity).setProperty(idProperty,id);
|
||||||
if (setter != null) {
|
|
||||||
try {
|
|
||||||
setter.invoke(entity, id);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
t.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2016 the original author or authors.
|
* Copyright 2014-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -28,7 +28,7 @@ import java.util.Map;
|
|||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.lang.math.NumberUtils;
|
import org.apache.commons.lang.math.NumberUtils;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.springframework.core.GenericCollectionTypeResolver;
|
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;
|
||||||
import org.springframework.data.elasticsearch.annotations.*;
|
import org.springframework.data.elasticsearch.annotations.*;
|
||||||
@ -45,8 +45,8 @@ import org.springframework.data.util.TypeInformation;
|
|||||||
* @author Kevin Leturc
|
* @author Kevin Leturc
|
||||||
* @author Alexander Volz
|
* @author Alexander Volz
|
||||||
* @author Dennis Maaß
|
* @author Dennis Maaß
|
||||||
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class MappingBuilder {
|
class MappingBuilder {
|
||||||
|
|
||||||
public static final String FIELD_STORE = "store";
|
public static final String FIELD_STORE = "store";
|
||||||
@ -313,12 +313,20 @@ class MappingBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected static Class<?> getFieldType(java.lang.reflect.Field field) {
|
protected static Class<?> getFieldType(java.lang.reflect.Field field) {
|
||||||
Class<?> clazz = field.getType();
|
|
||||||
TypeInformation typeInformation = ClassTypeInformation.from(clazz);
|
ResolvableType resolvableType = ResolvableType.forField(field);
|
||||||
if (typeInformation.isCollectionLike()) {
|
|
||||||
clazz = GenericCollectionTypeResolver.getCollectionFieldType(field) != null ? GenericCollectionTypeResolver.getCollectionFieldType(field) : typeInformation.getComponentType().getType();
|
if (resolvableType.isArray()) {
|
||||||
|
return resolvableType.getComponentType().getRawClass();
|
||||||
}
|
}
|
||||||
return clazz;
|
|
||||||
|
ResolvableType componentType = resolvableType.getGeneric(0);
|
||||||
|
if (Iterable.class.isAssignableFrom(field.getType())
|
||||||
|
&& componentType != ResolvableType.NONE) {
|
||||||
|
return componentType.getRawClass();
|
||||||
|
}
|
||||||
|
|
||||||
|
return resolvableType.getRawClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isAnyPropertyAnnotatedAsField(java.lang.reflect.Field[] fields) {
|
private static boolean isAnyPropertyAnnotatedAsField(java.lang.reflect.Field[] fields) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -31,8 +31,8 @@ import org.springframework.util.Assert;
|
|||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class MappingElasticsearchConverter implements ElasticsearchConverter, ApplicationContextAware {
|
public class MappingElasticsearchConverter implements ElasticsearchConverter, ApplicationContextAware {
|
||||||
|
|
||||||
private final MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext;
|
private final MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext;
|
||||||
@ -43,7 +43,9 @@ public class MappingElasticsearchConverter implements ElasticsearchConverter, Ap
|
|||||||
|
|
||||||
public MappingElasticsearchConverter(
|
public MappingElasticsearchConverter(
|
||||||
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext) {
|
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext) {
|
||||||
Assert.notNull(mappingContext);
|
|
||||||
|
Assert.notNull(mappingContext, "MappingContext must not be null!");
|
||||||
|
|
||||||
this.mappingContext = mappingContext;
|
this.mappingContext = mappingContext;
|
||||||
this.conversionService = new DefaultConversionService();
|
this.conversionService = new DefaultConversionService();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2016 the original author or authors.
|
* Copyright 2013-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -29,6 +29,7 @@ import org.springframework.util.Assert;
|
|||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
abstract class AbstractQuery implements Query {
|
abstract class AbstractQuery implements Query {
|
||||||
|
|
||||||
@ -55,7 +56,9 @@ abstract class AbstractQuery implements Query {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final <T extends Query> T setPageable(Pageable pageable) {
|
public final <T extends Query> T setPageable(Pageable pageable) {
|
||||||
Assert.notNull(pageable);
|
|
||||||
|
Assert.notNull(pageable, "Pageable must not be null!");
|
||||||
|
|
||||||
this.pageable = pageable;
|
this.pageable = pageable;
|
||||||
return (T) this.addSort(pageable.getSort());
|
return (T) this.addSort(pageable.getSort());
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2016 the original author or authors.
|
* Copyright 2013-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -43,6 +43,7 @@ import org.springframework.util.Assert;
|
|||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Ryan Henszey
|
* @author Ryan Henszey
|
||||||
* @author Kevin Leturc
|
* @author Kevin Leturc
|
||||||
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractElasticsearchRepository<T, ID extends Serializable> implements
|
public abstract class AbstractElasticsearchRepository<T, ID extends Serializable> implements
|
||||||
ElasticsearchRepository<T, ID> {
|
ElasticsearchRepository<T, ID> {
|
||||||
@ -56,14 +57,18 @@ public abstract class AbstractElasticsearchRepository<T, ID extends Serializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
public AbstractElasticsearchRepository(ElasticsearchOperations elasticsearchOperations) {
|
public AbstractElasticsearchRepository(ElasticsearchOperations elasticsearchOperations) {
|
||||||
Assert.notNull(elasticsearchOperations);
|
|
||||||
|
Assert.notNull(elasticsearchOperations, "ElasticsearchOperations must not be null!");
|
||||||
|
|
||||||
this.setElasticsearchOperations(elasticsearchOperations);
|
this.setElasticsearchOperations(elasticsearchOperations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractElasticsearchRepository(ElasticsearchEntityInformation<T, ID> metadata,
|
public AbstractElasticsearchRepository(ElasticsearchEntityInformation<T, ID> metadata,
|
||||||
ElasticsearchOperations elasticsearchOperations) {
|
ElasticsearchOperations elasticsearchOperations) {
|
||||||
this(elasticsearchOperations);
|
this(elasticsearchOperations);
|
||||||
Assert.notNull(metadata);
|
|
||||||
|
Assert.notNull(metadata, "ElasticsearchEntityInformation must not be null!");
|
||||||
|
|
||||||
this.entityInformation = metadata;
|
this.entityInformation = metadata;
|
||||||
setEntityClass(this.entityInformation.getJavaType());
|
setEntityClass(this.entityInformation.getJavaType());
|
||||||
try {
|
try {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2013-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -28,6 +28,7 @@ import org.springframework.util.Assert;
|
|||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
public class ElasticsearchEntityInformationCreatorImpl implements ElasticsearchEntityInformationCreator {
|
public class ElasticsearchEntityInformationCreatorImpl implements ElasticsearchEntityInformationCreator {
|
||||||
|
|
||||||
@ -35,7 +36,9 @@ public class ElasticsearchEntityInformationCreatorImpl implements ElasticsearchE
|
|||||||
|
|
||||||
public ElasticsearchEntityInformationCreatorImpl(
|
public ElasticsearchEntityInformationCreatorImpl(
|
||||||
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext) {
|
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext) {
|
||||||
Assert.notNull(mappingContext);
|
|
||||||
|
Assert.notNull(mappingContext, "MappingContext must not be null!");
|
||||||
|
|
||||||
this.mappingContext = mappingContext;
|
this.mappingContext = mappingContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -41,6 +41,8 @@ import org.springframework.util.Assert;
|
|||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Ryan Henszey
|
* @author Ryan Henszey
|
||||||
|
* @author Gad Akuka
|
||||||
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
public class ElasticsearchRepositoryFactory extends RepositoryFactorySupport {
|
public class ElasticsearchRepositoryFactory extends RepositoryFactorySupport {
|
||||||
|
|
||||||
@ -48,7 +50,9 @@ public class ElasticsearchRepositoryFactory extends RepositoryFactorySupport {
|
|||||||
private final ElasticsearchEntityInformationCreator entityInformationCreator;
|
private final ElasticsearchEntityInformationCreator entityInformationCreator;
|
||||||
|
|
||||||
public ElasticsearchRepositoryFactory(ElasticsearchOperations elasticsearchOperations) {
|
public ElasticsearchRepositoryFactory(ElasticsearchOperations elasticsearchOperations) {
|
||||||
Assert.notNull(elasticsearchOperations);
|
|
||||||
|
Assert.notNull(elasticsearchOperations, "ElasticsearchOperations must not be null!");
|
||||||
|
|
||||||
this.elasticsearchOperations = elasticsearchOperations;
|
this.elasticsearchOperations = elasticsearchOperations;
|
||||||
this.entityInformationCreator = new ElasticsearchEntityInformationCreatorImpl(elasticsearchOperations
|
this.entityInformationCreator = new ElasticsearchEntityInformationCreatorImpl(elasticsearchOperations
|
||||||
.getElasticsearchConverter().getMappingContext());
|
.getElasticsearchConverter().getMappingContext());
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -29,6 +29,7 @@ import org.springframework.util.Assert;
|
|||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
public class ElasticsearchRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable> extends
|
public class ElasticsearchRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable> extends
|
||||||
RepositoryFactoryBeanSupport<T, S, ID> {
|
RepositoryFactoryBeanSupport<T, S, ID> {
|
||||||
@ -41,7 +42,9 @@ public class ElasticsearchRepositoryFactoryBean<T extends Repository<S, ID>, S,
|
|||||||
* @param operations the operations to set
|
* @param operations the operations to set
|
||||||
*/
|
*/
|
||||||
public void setElasticsearchOperations(ElasticsearchOperations operations) {
|
public void setElasticsearchOperations(ElasticsearchOperations operations) {
|
||||||
Assert.notNull(operations);
|
|
||||||
|
Assert.notNull(operations, "ElasticsearchOperations must not be null!");
|
||||||
|
|
||||||
setMappingContext(operations.getElasticsearchConverter().getMappingContext());
|
setMappingContext(operations.getElasticsearchConverter().getMappingContext());
|
||||||
this.operations = operations;
|
this.operations = operations;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,115 @@
|
|||||||
Spring Data Elasticsearch Changelog
|
Spring Data Elasticsearch Changelog
|
||||||
===================================
|
===================================
|
||||||
|
|
||||||
|
Changes in version 2.0.9.RELEASE (2017-04-19)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-336 - Release 2.0.9 (Hopper SR9).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.1.2.RELEASE (2017-04-19)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-335 - Release 2.1.2 (Ingalls SR2).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.0.0.M2 (2017-04-04)
|
||||||
|
----------------------------------------
|
||||||
|
* DATAES-342 - Adapt to API changes in RepositoryConfigurationExtensionSupport.
|
||||||
|
* DATAES-329 - Remove references to single-argument assertion methods of Spring.
|
||||||
|
* DATAES-328 - Integrate Data Commons Java 8 upgrade branch.
|
||||||
|
* DATAES-325 - Remove references to GenericCollectionTypeResolver in favor of ResolvableType.
|
||||||
|
* DATAES-322 - Update project documentation with the CLA tool integration.
|
||||||
|
* DATAES-315 - Adapt API in RepositoryFactoryBeanSupport implementation.
|
||||||
|
* DATAES-313 - Register repository factory in spring.factories for multi-store support.
|
||||||
|
* DATAES-311 - Release 3.0 M2 (Kay).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.0.8.RELEASE (2017-03-02)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-329 - Remove references to single-argument assertion methods of Spring.
|
||||||
|
* DATAES-326 - Release 2.0.8 (Hopper SR8).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.1.1.RELEASE (2017-03-02)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-329 - Remove references to single-argument assertion methods of Spring.
|
||||||
|
* DATAES-327 - Release 2.1.1 (Ingalls SR1).
|
||||||
|
* DATAES-325 - Remove references to GenericCollectionTypeResolver in favor of ResolvableType.
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.0.7.RELEASE (2017-01-26)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-319 - Release 2.0.7 (Hopper SR7).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.1.0.RELEASE (2017-01-26)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-322 - Update project documentation with the CLA tool integration.
|
||||||
|
* DATAES-320 - Release 2.1 GA (Ingalls).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.0.6.RELEASE (2016-12-21)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-304 - Release 2.0.6 (Hopper SR6).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.1.0.RC1 (2016-12-21)
|
||||||
|
-----------------------------------------
|
||||||
|
* DATAES-315 - Adapt API in RepositoryFactoryBeanSupport implementation.
|
||||||
|
* DATAES-313 - Register repository factory in spring.factories for multi-store support.
|
||||||
|
* DATAES-289 - Upgrade to Elasticsearch 2.4.
|
||||||
|
* DATAES-284 - Downgrade to Jackson 2.7.5 until Elasticsearch is compatible with 2.8.
|
||||||
|
* DATAES-281 - Can't save entity without id setter.
|
||||||
|
* DATAES-275 - Release 2.1 RC1 (Ingalls).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.0.0.M1 (2016-11-23)
|
||||||
|
----------------------------------------
|
||||||
|
* DATAES-307 - Set up 3.0 development.
|
||||||
|
* DATAES-306 - Release 3.0 M1 (Kay).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.0.5.RELEASE (2016-11-03)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-300 - Release 2.0.5 (Hopper SR5).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.0.4.RELEASE (2016-09-29)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-297 - Release 2.0.4 (Hopper SR4).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 1.3.6.RELEASE (2016-09-29)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-299 - Release 1.3.6 (Gosling SR6).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 1.3.5.RELEASE (2016-09-20)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-296 - Release 1.3.5 (Gosling SR5).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.0.3.RELEASE (2016-09-20)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-281 - Can't save entity without id setter.
|
||||||
|
* DATAES-268 - Release 2.0.3 (Hopper SR3).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.1.0.M1 (2016-07-27)
|
||||||
|
----------------------------------------
|
||||||
|
* DATAES-262 - Upgrade Elasticsearch to 2.3.3.
|
||||||
|
* DATAES-250 - Release 2.1 M1 (Ingalls).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.0.2.RELEASE (2016-06-15)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-251 - Release 2.0.2 (Hopper SR2).
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 2.0.1.RELEASE (2016-04-06)
|
||||||
|
---------------------------------------------
|
||||||
|
* DATAES-249 - Release 2.0.1 (Hopper SR1).
|
||||||
|
|
||||||
|
|
||||||
Changes in version 2.0.0.RELEASE (2016-04-06)
|
Changes in version 2.0.0.RELEASE (2016-04-06)
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
* DATAES-245 - Release 2.0 GA (Hopper).
|
* DATAES-245 - Release 2.0 GA (Hopper).
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
Spring Data Elasticsearch 2.0 GA
|
Spring Data Elasticsearch 2.0.9
|
||||||
Copyright (c) [2013-2016] Pivotal Software, Inc.
|
Copyright (c) [2013-2016] Pivotal Software, Inc.
|
||||||
|
|
||||||
This product is licensed to you under the Apache License, Version 2.0 (the "License").
|
This product is licensed to you under the Apache License, Version 2.0 (the "License").
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1,80 @@
|
|||||||
|
# Elasticsearch plugin descriptor file
|
||||||
|
# This file must exist as 'plugin-descriptor.properties' at
|
||||||
|
# the root directory of all plugins.
|
||||||
|
#
|
||||||
|
# A plugin can be 'site', 'jvm', or both.
|
||||||
|
#
|
||||||
|
### example site plugin for "foo":
|
||||||
|
#
|
||||||
|
# foo.zip <-- zip file for the plugin, with this structure:
|
||||||
|
# _site/ <-- the contents that will be served
|
||||||
|
# plugin-descriptor.properties <-- example contents below:
|
||||||
|
#
|
||||||
|
# site=true
|
||||||
|
# description=My cool plugin
|
||||||
|
# version=1.0
|
||||||
|
#
|
||||||
|
### example jvm plugin for "foo"
|
||||||
|
#
|
||||||
|
# foo.zip <-- zip file for the plugin, with this structure:
|
||||||
|
# <arbitrary name1>.jar <-- classes, resources, dependencies
|
||||||
|
# <arbitrary nameN>.jar <-- any number of jars
|
||||||
|
# plugin-descriptor.properties <-- example contents below:
|
||||||
|
#
|
||||||
|
# jvm=true
|
||||||
|
# classname=foo.bar.BazPlugin
|
||||||
|
# description=My cool plugin
|
||||||
|
# version=2.0.0-rc1
|
||||||
|
# elasticsearch.version=2.0
|
||||||
|
# java.version=1.7
|
||||||
|
#
|
||||||
|
### mandatory elements for all plugins:
|
||||||
|
#
|
||||||
|
# 'description': simple summary of the plugin
|
||||||
|
description=Groovy scripting integration for Elasticsearch
|
||||||
|
#
|
||||||
|
# 'version': plugin's version
|
||||||
|
version=2.3.3
|
||||||
|
#
|
||||||
|
# 'name': the plugin name
|
||||||
|
name=lang-groovy
|
||||||
|
|
||||||
|
### mandatory elements for site plugins:
|
||||||
|
#
|
||||||
|
# 'site': set to true to indicate contents of the _site/
|
||||||
|
# directory in the root of the plugin should be served.
|
||||||
|
site=false
|
||||||
|
#
|
||||||
|
### mandatory elements for jvm plugins :
|
||||||
|
#
|
||||||
|
# 'jvm': true if the 'classname' class should be loaded
|
||||||
|
# from jar files in the root directory of the plugin.
|
||||||
|
# Note that only jar files in the root directory are
|
||||||
|
# added to the classpath for the plugin! If you need
|
||||||
|
# other resources, package them into a resources jar.
|
||||||
|
jvm=true
|
||||||
|
#
|
||||||
|
# 'classname': the name of the class to load, fully-qualified.
|
||||||
|
classname=org.elasticsearch.script.groovy.GroovyPlugin
|
||||||
|
#
|
||||||
|
# 'java.version' version of java the code is built against
|
||||||
|
# use the system property java.specification.version
|
||||||
|
# version string must be a sequence of nonnegative decimal integers
|
||||||
|
# separated by "."'s and may have leading zeros
|
||||||
|
java.version=1.7
|
||||||
|
#
|
||||||
|
# 'elasticsearch.version' version of elasticsearch compiled against
|
||||||
|
# You will have to release a new version of the plugin for each new
|
||||||
|
# elasticsearch release. This version is checked when the plugin
|
||||||
|
# is loaded so Elasticsearch will refuse to start in the presence of
|
||||||
|
# plugins with the incorrect elasticsearch.version.
|
||||||
|
elasticsearch.version=2.3.3
|
||||||
|
#
|
||||||
|
### deprecated elements for jvm plugins :
|
||||||
|
#
|
||||||
|
# 'isolated': true if the plugin should have its own classloader.
|
||||||
|
# passing false is deprecated, and only intended to support plugins
|
||||||
|
# that have hard dependencies against each other. If this is
|
||||||
|
# not specified, then the plugin is isolated by default.
|
||||||
|
isolated=true
|
||||||
|
#
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to Elasticsearch under one or more contributor
|
||||||
|
* license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright
|
||||||
|
* ownership. Elasticsearch licenses this file to you 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
grant {
|
||||||
|
// needed to generate runtime classes
|
||||||
|
permission java.lang.RuntimePermission "createClassLoader";
|
||||||
|
// needed by IndyInterface
|
||||||
|
permission java.lang.RuntimePermission "getClassLoader";
|
||||||
|
// needed by groovy engine
|
||||||
|
permission java.lang.RuntimePermission "accessClassInPackage.sun.reflect";
|
||||||
|
// needed by GroovyScriptEngineService to close its classloader (why?)
|
||||||
|
permission java.lang.RuntimePermission "closeClassLoader";
|
||||||
|
// Allow executing groovy scripts with codesource of /untrusted
|
||||||
|
permission groovy.security.GroovyCodeSourcePermission "/untrusted";
|
||||||
|
|
||||||
|
// Standard set of classes
|
||||||
|
permission org.elasticsearch.script.ClassPermission "<<STANDARD>>";
|
||||||
|
// groovy runtime (TODO: clean these up if possible)
|
||||||
|
permission org.elasticsearch.script.ClassPermission "groovy.grape.GrabAnnotationTransformation";
|
||||||
|
permission org.elasticsearch.script.ClassPermission "groovy.json.JsonOutput";
|
||||||
|
permission org.elasticsearch.script.ClassPermission "groovy.lang.Binding";
|
||||||
|
permission org.elasticsearch.script.ClassPermission "groovy.lang.GroovyObject";
|
||||||
|
permission org.elasticsearch.script.ClassPermission "groovy.lang.GString";
|
||||||
|
permission org.elasticsearch.script.ClassPermission "groovy.lang.Script";
|
||||||
|
permission org.elasticsearch.script.ClassPermission "groovy.util.GroovyCollections";
|
||||||
|
permission org.elasticsearch.script.ClassPermission "org.codehaus.groovy.ast.builder.AstBuilderTransformation";
|
||||||
|
permission org.elasticsearch.script.ClassPermission "org.codehaus.groovy.reflection.ClassInfo";
|
||||||
|
permission org.elasticsearch.script.ClassPermission "org.codehaus.groovy.runtime.GStringImpl";
|
||||||
|
permission org.elasticsearch.script.ClassPermission "org.codehaus.groovy.runtime.powerassert.ValueRecorder";
|
||||||
|
permission org.elasticsearch.script.ClassPermission "org.codehaus.groovy.runtime.powerassert.AssertionRenderer";
|
||||||
|
permission org.elasticsearch.script.ClassPermission "org.codehaus.groovy.runtime.ScriptBytecodeAdapter";
|
||||||
|
permission org.elasticsearch.script.ClassPermission "org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation";
|
||||||
|
permission org.elasticsearch.script.ClassPermission "org.codehaus.groovy.vmplugin.v7.IndyInterface";
|
||||||
|
permission org.elasticsearch.script.ClassPermission "sun.reflect.ConstructorAccessorImpl";
|
||||||
|
permission org.elasticsearch.script.ClassPermission "sun.reflect.MethodAccessorImpl";
|
||||||
|
|
||||||
|
permission org.elasticsearch.script.ClassPermission "groovy.lang.Closure";
|
||||||
|
permission org.elasticsearch.script.ClassPermission "org.codehaus.groovy.runtime.GeneratedClosure";
|
||||||
|
permission org.elasticsearch.script.ClassPermission "groovy.lang.MetaClass";
|
||||||
|
permission org.elasticsearch.script.ClassPermission "groovy.lang.Range";
|
||||||
|
permission org.elasticsearch.script.ClassPermission "groovy.lang.Reference";
|
||||||
|
};
|
@ -31,7 +31,7 @@ public class Utils {
|
|||||||
return (NodeClient) nodeBuilder().settings(Settings.builder()
|
return (NodeClient) nodeBuilder().settings(Settings.builder()
|
||||||
.put("http.enabled", "false")
|
.put("http.enabled", "false")
|
||||||
.put("path.data", "target/elasticsearchTestData")
|
.put("path.data", "target/elasticsearchTestData")
|
||||||
.put("path.home", "src/test/resources/test-home-dir"))
|
.put("path.home", "target/test-home-dir"))
|
||||||
.clusterName(UUID.randomUUID().toString()).local(true).node()
|
.clusterName(UUID.randomUUID().toString()).local(true).node()
|
||||||
.client();
|
.client();
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,13 @@ import static org.hamcrest.Matchers.*;
|
|||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.util.ArrayIterator;
|
|
||||||
import org.elasticsearch.action.get.GetResponse;
|
import org.elasticsearch.action.get.GetResponse;
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.search.SearchHit;
|
import org.elasticsearch.search.SearchHit;
|
||||||
@ -35,8 +37,12 @@ import org.junit.Test;
|
|||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
|
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
||||||
import org.springframework.data.elasticsearch.entities.Car;
|
import org.springframework.data.elasticsearch.entities.Car;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.util.ArrayIterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
@ -51,7 +57,7 @@ public class DefaultResultMapperTests {
|
|||||||
@Before
|
@Before
|
||||||
public void init() {
|
public void init() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
resultMapper = new DefaultResultMapper();
|
resultMapper = new DefaultResultMapper(new SimpleElasticsearchMappingContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -105,6 +111,22 @@ public class DefaultResultMapperTests {
|
|||||||
assertThat(result.getName(), is("Ford"));
|
assertThat(result.getName(), is("Ford"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAES-281.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void setsIdentifierOnImmutableType() {
|
||||||
|
|
||||||
|
GetResponse response = mock(GetResponse.class);
|
||||||
|
when(response.getSourceAsString()).thenReturn("{}");
|
||||||
|
when(response.getId()).thenReturn("identifier");
|
||||||
|
|
||||||
|
ImmutableEntity result = resultMapper.mapResult(response, ImmutableEntity.class);
|
||||||
|
|
||||||
|
assertThat(result, is(notNullValue()));
|
||||||
|
assertThat(result.getId(), is("identifier"));
|
||||||
|
}
|
||||||
|
|
||||||
private SearchHit createCarHit(String name, String model) {
|
private SearchHit createCarHit(String name, String model) {
|
||||||
SearchHit hit = mock(SearchHit.class);
|
SearchHit hit = mock(SearchHit.class);
|
||||||
when(hit.sourceAsString()).thenReturn(createJsonCar(name, model));
|
when(hit.sourceAsString()).thenReturn(createJsonCar(name, model));
|
||||||
@ -132,4 +154,12 @@ public class DefaultResultMapperTests {
|
|||||||
result.put("model", new InternalSearchHitField("model", Arrays.<Object>asList(model)));
|
result.put("model", new InternalSearchHitField("model", Arrays.<Object>asList(model)));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Document(indexName = "someIndex")
|
||||||
|
@NoArgsConstructor(force = true)
|
||||||
|
@Getter
|
||||||
|
static class ImmutableEntity {
|
||||||
|
|
||||||
|
private final String id, name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 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.immutable;
|
||||||
|
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Young Gu
|
||||||
|
* @author Oliver Gierke
|
||||||
|
*/
|
||||||
|
public interface ImmutableElasticsearchRepository extends CrudRepository<ImmutableEntity, String> {}
|
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 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.immutable;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.*;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Young Gu
|
||||||
|
* @author Oliver Gierke
|
||||||
|
*/
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration("classpath:immutable-repository-test.xml")
|
||||||
|
public class ImmutableElasticsearchRepositoryTests {
|
||||||
|
|
||||||
|
@Autowired ImmutableElasticsearchRepository repository;
|
||||||
|
@Autowired ElasticsearchOperations operations;
|
||||||
|
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void before() {
|
||||||
|
|
||||||
|
operations.deleteIndex(ImmutableEntity.class);
|
||||||
|
operations.createIndex(ImmutableEntity.class);
|
||||||
|
operations.refresh(ImmutableEntity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAES-281
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void shouldSaveAndFindImmutableDocument() {
|
||||||
|
|
||||||
|
// when
|
||||||
|
ImmutableEntity entity = repository.save(new ImmutableEntity("test name"));
|
||||||
|
assertThat(entity.getId(), is(notNullValue()));
|
||||||
|
|
||||||
|
// then
|
||||||
|
ImmutableEntity entityFromElasticSearch = repository.findOne(entity.getId());
|
||||||
|
|
||||||
|
assertThat(entityFromElasticSearch.getName(), is("test name"));
|
||||||
|
assertThat(entityFromElasticSearch.getId(), is(entity.getId()));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* 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.immutable;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Young Gu
|
||||||
|
* @author Oliver Gierke
|
||||||
|
*/
|
||||||
|
@Document(indexName = "test-index")
|
||||||
|
@NoArgsConstructor(force = true)
|
||||||
|
@Getter
|
||||||
|
public class ImmutableEntity {
|
||||||
|
private final String id, name;
|
||||||
|
|
||||||
|
public ImmutableEntity(String name) {
|
||||||
|
|
||||||
|
this.id = null;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
19
src/test/resources/immutable-repository-test.xml
Normal file
19
src/test/resources/immutable-repository-test.xml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd
|
||||||
|
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
||||||
|
|
||||||
|
<import resource="infrastructure.xml"/>
|
||||||
|
|
||||||
|
<bean name="elasticsearchTemplate"
|
||||||
|
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
||||||
|
<constructor-arg name="client" ref="client"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
|
<elasticsearch:repositories
|
||||||
|
base-package="org.springframework.data.elasticsearch.immutable"/>
|
||||||
|
|
||||||
|
</beans>
|
@ -6,7 +6,7 @@
|
|||||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||||
|
|
||||||
<elasticsearch:node-client id="client" local="true" cluster-name="#{T(java.util.UUID).randomUUID().toString()}"
|
<elasticsearch:node-client id="client" local="true" cluster-name="#{T(java.util.UUID).randomUUID().toString()}"
|
||||||
http-enabled="false" path-data="target/elasticsearchTestData" path-home="src/test/resources/test-home-dir"
|
http-enabled="false" path-data="target/elasticsearchTestData" path-home="target/test-home-dir"
|
||||||
path-configuration="node-client-configuration.yml"/>
|
path-configuration="node-client-configuration.yml"/>
|
||||||
|
|
||||||
<!-- ip4 -->
|
<!-- ip4 -->
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
<elasticsearch:node-client id="client" local="true"
|
<elasticsearch:node-client id="client" local="true"
|
||||||
cluster-name="#{T(java.util.UUID).randomUUID().toString()}" http-enabled="false"
|
cluster-name="#{T(java.util.UUID).randomUUID().toString()}" http-enabled="false"
|
||||||
path-data="target/elasticsearchTestData" path-home="src/test/resources/test-home-dir"/>
|
path-data="target/elasticsearchTestData" path-home="target/test-home-dir"/>
|
||||||
|
|
||||||
<bean name="elasticsearchTemplate"
|
<bean name="elasticsearchTemplate"
|
||||||
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
||||||
|
@ -10,8 +10,8 @@ Import-Template:
|
|||||||
javax.enterprise.*;version="${cdi:[=.=.=,+1.0.0)}";resolution:=optional,
|
javax.enterprise.*;version="${cdi:[=.=.=,+1.0.0)}";resolution:=optional,
|
||||||
org.apache.commons.lang.*;version="${commonslang:[=.=.=,+1.0.0)}",
|
org.apache.commons.lang.*;version="${commonslang:[=.=.=,+1.0.0)}",
|
||||||
com.fasterxml.jackson.*;version="${jackson:[=.=.=,+1.0.0)}";resolution:=optional,
|
com.fasterxml.jackson.*;version="${jackson:[=.=.=,+1.0.0)}";resolution:=optional,
|
||||||
org.elasticsearch.*;version="${elasticsearch:[=.=.=,2.2.0)}",
|
org.elasticsearch.*;version="${elasticsearch:[=.=.=,+2.2.0)}",
|
||||||
org.apache.lucene.*;version="5.4.1",
|
org.apache.lucene.*;version="[5.4.1,+5.4.1)",
|
||||||
org.joda.time.*;version="${jodatime:[=.=.=,+1.0.0)}",
|
org.joda.time.*;version="${jodatime:[=.=.=,+1.0.0)}",
|
||||||
org.slf4j.*;version="${slf4j:[=.=.=,+1.0.0)}",
|
org.slf4j.*;version="${slf4j:[=.=.=,+1.0.0)}",
|
||||||
org.springframework.*;version="${spring:[=.=.=.=,+1.0.0)}",
|
org.springframework.*;version="${spring:[=.=.=.=,+1.0.0)}",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user