mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-08-09 02:53:28 +00:00
Compare commits
37 Commits
main
...
2.0.6.RELE
Author | SHA1 | Date | |
---|---|---|---|
|
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>
|
||||
<artifactId>spring-data-elasticsearch</artifactId>
|
||||
<version>2.0.0.RELEASE</version>
|
||||
<version>2.0.6.RELEASE</version>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.data.build</groupId>
|
||||
<artifactId>spring-data-parent</artifactId>
|
||||
<version>1.8.0.RELEASE</version>
|
||||
<version>1.8.6.RELEASE</version>
|
||||
<relativePath>../spring-data-build/parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
<commonscollections>3.2.1</commonscollections>
|
||||
<commonslang>2.6</commonslang>
|
||||
<elasticsearch>2.2.0</elasticsearch>
|
||||
<springdata.commons>1.12.0.RELEASE</springdata.commons>
|
||||
<springdata.commons>1.12.6.RELEASE</springdata.commons>
|
||||
|
||||
</properties>
|
||||
|
||||
@ -129,7 +129,7 @@
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.16.4</version>
|
||||
<version>${lombok}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
@ -150,9 +150,30 @@
|
||||
<artifactId>asciidoctor-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</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>
|
||||
|
||||
<profiles>
|
||||
|
||||
<profile>
|
||||
<id>es2.3.3</id>
|
||||
<properties>
|
||||
<elasticsearch>2.3.3</elasticsearch>
|
||||
</properties>
|
||||
</profile>
|
||||
|
||||
<profile>
|
||||
<id>release</id>
|
||||
<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");
|
||||
* 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.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -48,6 +47,8 @@ import org.springframework.data.mapping.context.MappingContext;
|
||||
|
||||
/**
|
||||
* @author Artur Konczak
|
||||
* @author Young Gu
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
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) {
|
||||
|
||||
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 !
|
||||
if (idProperty != null && idProperty.getType().isAssignableFrom(String.class)) {
|
||||
Method setter = idProperty.getSetter();
|
||||
if (setter != null) {
|
||||
try {
|
||||
setter.invoke(result, id);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
persistentEntity.getPropertyAccessor(result).setProperty(idProperty, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ import static org.springframework.util.CollectionUtils.isEmpty;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
|
||||
import org.elasticsearch.action.ListenableActionFuture;
|
||||
@ -98,6 +97,8 @@ import org.springframework.util.Assert;
|
||||
* @author Artur Konczak
|
||||
* @author Kevin Leturc
|
||||
* @author Mason Chan
|
||||
* @author Young Gu
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
|
||||
public class ElasticsearchTemplate implements ElasticsearchOperations, ApplicationContextAware {
|
||||
@ -1081,35 +1082,21 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
}
|
||||
|
||||
private String getPersistentEntityId(Object entity) {
|
||||
PersistentProperty idProperty = getPersistentEntityFor(entity.getClass()).getIdProperty();
|
||||
if (idProperty != null) {
|
||||
Method getter = idProperty.getGetter();
|
||||
if (getter != null) {
|
||||
try {
|
||||
Object id = getter.invoke(entity);
|
||||
if (id != null) {
|
||||
return String.valueOf(id);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
ElasticsearchPersistentEntity<?> persistentEntity = getPersistentEntityFor(entity.getClass());
|
||||
Object identifier = persistentEntity.getIdentifierAccessor(entity).getIdentifier();
|
||||
|
||||
return identifier == null ? null : String.valueOf(identifier);
|
||||
}
|
||||
|
||||
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 !
|
||||
if (idProperty != null && idProperty.getType().isAssignableFrom(String.class)) {
|
||||
Method setter = idProperty.getSetter();
|
||||
if (setter != null) {
|
||||
try {
|
||||
setter.invoke(entity, id);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
persistentEntity.getPropertyAccessor(entity).setProperty(idProperty,id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,69 @@
|
||||
Spring Data Elasticsearch Changelog
|
||||
===================================
|
||||
|
||||
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)
|
||||
---------------------------------------------
|
||||
* DATAES-245 - Release 2.0 GA (Hopper).
|
||||
|
@ -1,4 +1,4 @@
|
||||
Spring Data Elasticsearch 2.0 GA
|
||||
Spring Data Elasticsearch 2.0.6
|
||||
Copyright (c) [2013-2016] Pivotal Software, Inc.
|
||||
|
||||
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()
|
||||
.put("http.enabled", "false")
|
||||
.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()
|
||||
.client();
|
||||
}
|
||||
|
@ -19,11 +19,13 @@ import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.databind.util.ArrayIterator;
|
||||
import org.elasticsearch.action.get.GetResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
@ -35,8 +37,12 @@ import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
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 com.fasterxml.jackson.databind.util.ArrayIterator;
|
||||
|
||||
/**
|
||||
* @author Artur Konczak
|
||||
* @author Mohsin Husen
|
||||
@ -51,7 +57,7 @@ public class DefaultResultMapperTests {
|
||||
@Before
|
||||
public void init() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
resultMapper = new DefaultResultMapper();
|
||||
resultMapper = new DefaultResultMapper(new SimpleElasticsearchMappingContext());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -104,6 +110,22 @@ public class DefaultResultMapperTests {
|
||||
assertThat(result.getModel(), is("Grat"));
|
||||
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) {
|
||||
SearchHit hit = mock(SearchHit.class);
|
||||
@ -132,4 +154,12 @@ public class DefaultResultMapperTests {
|
||||
result.put("model", new InternalSearchHitField("model", Arrays.<Object>asList(model)));
|
||||
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">
|
||||
|
||||
<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"/>
|
||||
|
||||
<!-- ip4 -->
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
<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"/>
|
||||
path-data="target/elasticsearchTestData" path-home="target/test-home-dir"/>
|
||||
|
||||
<bean name="elasticsearchTemplate"
|
||||
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
||||
|
@ -10,8 +10,8 @@ Import-Template:
|
||||
javax.enterprise.*;version="${cdi:[=.=.=,+1.0.0)}";resolution:=optional,
|
||||
org.apache.commons.lang.*;version="${commonslang:[=.=.=,+1.0.0)}",
|
||||
com.fasterxml.jackson.*;version="${jackson:[=.=.=,+1.0.0)}";resolution:=optional,
|
||||
org.elasticsearch.*;version="${elasticsearch:[=.=.=,2.2.0)}",
|
||||
org.apache.lucene.*;version="5.4.1",
|
||||
org.elasticsearch.*;version="${elasticsearch:[=.=.=,+2.2.0)}",
|
||||
org.apache.lucene.*;version="[5.4.1,+5.4.1)",
|
||||
org.joda.time.*;version="${jodatime:[=.=.=,+1.0.0)}",
|
||||
org.slf4j.*;version="${slf4j:[=.=.=,+1.0.0)}",
|
||||
org.springframework.*;version="${spring:[=.=.=.=,+1.0.0)}",
|
||||
|
Loading…
x
Reference in New Issue
Block a user