Compare commits

...

37 Commits

Author SHA1 Message Date
Oliver Gierke
51ca555470 DATAES-304 - Release version 2.0.6 (Hopper SR6). 2016-12-21 19:04:47 +01:00
Oliver Gierke
bc4891907e DATAES-304 - Prepare 2.0.6 (Hopper SR6). 2016-12-21 19:03:40 +01:00
Oliver Gierke
96934676ae DATAES-304 - Updated changelog. 2016-12-21 19:03:36 +01:00
Oliver Gierke
90348459e7 DATAES-275 - Updated changelog. 2016-12-21 18:43:08 +01:00
Oliver Gierke
e2a868ef97 DATAES-306 - Updated changelog. 2016-11-23 13:52:50 +01:00
Oliver Gierke
0c146bb47c DATAES-300 - After release cleanups. 2016-11-03 18:20:12 +01:00
Oliver Gierke
35ad47da4a DATAES-300 - Prepare next development iteration. 2016-11-03 18:20:10 +01:00
Oliver Gierke
fd33ad40d7 DATAES-300 - Release version 2.0.5 (Hopper SR5). 2016-11-03 17:56:33 +01:00
Oliver Gierke
ac7ee3e986 DATAES-300 - Prepare 2.0.5 (Hopper SR5). 2016-11-03 17:56:00 +01:00
Oliver Gierke
729ecb2ed9 DATAES-300 - Updated changelog. 2016-11-03 17:55:57 +01:00
Oliver Gierke
89b99c7687 DATAES-297 - After release cleanups. 2016-09-29 14:20:14 +02:00
Oliver Gierke
4498805d0d DATAES-297 - Prepare next development iteration. 2016-09-29 14:20:10 +02:00
Oliver Gierke
c781fde4b4 DATAES-297 - Release version 2.0.4 (Hopper SR4). 2016-09-29 13:54:04 +02:00
Oliver Gierke
67385a9c51 DATAES-297 - Prepare 2.0.4 (Hopper SR4). 2016-09-29 13:53:27 +02:00
Oliver Gierke
30cf3b5172 DATAES-297 - Updated changelog. 2016-09-29 13:53:23 +02:00
Oliver Gierke
baa52a82e4 DATAES-299 - Updated changelog. 2016-09-29 11:42:12 +02:00
Oliver Gierke
397d3b89f8 DATAES-296 - Updated changelog. 2016-09-21 07:28:59 +02:00
Oliver Gierke
abd6ad3536 DATAES-268 - After release cleanups. 2016-09-20 11:19:05 +02:00
Oliver Gierke
0510b06ee4 DATAES-268 - Prepare next development iteration. 2016-09-20 11:19:01 +02:00
Oliver Gierke
ff1f7676b2 DATAES-268 - Release version 2.0.3 (Hopper SR3). 2016-09-20 10:54:51 +02:00
Oliver Gierke
10a11ad22f DATAES-268 - Prepare 2.0.3 (Hopper SR3). 2016-09-20 10:54:17 +02:00
Oliver Gierke
0978c47fb9 DATAES-268 - Updated changelog. 2016-09-20 10:54:14 +02:00
Oliver Gierke
acc81f89fb DATAES-281 - Polishing.
Added unit test for change in DefaultResultMapperTests. Tweaked and simplified integration tests.

Make use of IdentifierAccessor in ElasticsearcTemplate.getPersistentEntityId(…). Added missing generics in DefaultResultMapper.

Removed unused imports, fixed copyright ranges, authors.

Original pull request: #156.
2016-08-20 10:07:59 +02:00
Young Gu
4fb2b33066 DATAES-281 - Setting identifier values now uses PersistentPropertyAccessor API.
DefaultResultMapper and ElasticsearchTemplate now use the PersistentPropertyAccessor API to set identifier values on objects instead of using reflection.

Original pull request: #156.
2016-08-20 10:04:09 +02:00
Oliver Gierke
20d8103a19 DATAES-250 - Updated changelog. 2016-07-28 08:50:39 +02:00
Artur Konczak
c799e8d1c8 DATAES-262 - added profile to build project with ES 2.3.3 2016-06-17 09:31:49 +01:00
Oliver Gierke
e4e6b09161 DATAES-251 - After release cleanups. 2016-06-15 14:17:54 +02:00
Oliver Gierke
511da0fadf DATAES-251 - Prepare next development iteration. 2016-06-15 14:17:52 +02:00
Oliver Gierke
6090f4a5db DATAES-251 - Release version 2.0.2 (Hopper SR2). 2016-06-15 13:45:53 +02:00
Oliver Gierke
c964ce5dac DATAES-251 - Prepare 2.0.2 (Hopper SR2). 2016-06-15 13:44:54 +02:00
Oliver Gierke
2f50462857 DATAES-251 - Updated changelog. 2016-06-15 13:44:49 +02:00
Oliver Gierke
eab54cb546 DATAES-249 - After release cleanups. 2016-04-06 22:51:45 +02:00
Oliver Gierke
6bdb45a0f8 DATAES-249 - Prepare next development iteration. 2016-04-06 22:51:43 +02:00
Oliver Gierke
793e6ab843 DATAES-249 - Release version 2.0.1 (Hopper SR1). 2016-04-06 22:32:15 +02:00
Oliver Gierke
182684e56c DATAES-249 - Prepare 2.0.1 (Hopper SR1). 2016-04-06 22:31:41 +02:00
Oliver Gierke
33e1611186 DATAES-249 - Updated changelog. 2016-04-06 22:31:38 +02:00
Oliver Gierke
55ccfe5c0b DATAES-245 - Prepare next development iteration. 2016-04-06 16:38:19 +02:00
22 changed files with 431 additions and 48 deletions

29
pom.xml
View File

@ -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>

View File

@ -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);
}
}
}

View File

@ -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);
}
}

View File

@ -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).

View File

@ -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").

View File

@ -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
#

View File

@ -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";
};

View File

@ -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();
}

View File

@ -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;
}
}

View File

@ -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> {}

View File

@ -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()));
}
}

View File

@ -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;
}
}

View 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>

View File

@ -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 -->

View File

@ -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">

View File

@ -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)}",