From a33a48a8821a907a3a936a1cce34862007e5164f Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Fri, 7 Feb 2014 10:00:46 +0100 Subject: [PATCH] DATAES-45 - Prepare 1.0 M1 release. Upgraded to Spring Data Build 1.3.0 RC1 and Spring Data Commons 1.7.0.RC1. Cleaned up pom accordingly. Adapted repository setup to accommodate for changed lifecycle behavior of repository factories. Marked repositories explicitly created to check for the detection of misconfiguration as @Lazy to prevent them from being instantiated and causing the tests to fail. Added assertion in ElasticsearchEntityInformationCreatorImpl to eagerly fail in case of misconfiguration. Marked ElasticsearchCrudRepository as @NoRepositoryBean as it should never be considered to be a repository interface to be instantiated. Tweaked CDI implementation to benefit from new feature in Spring Data Commons to eagerly instantiate CDI repository beans. Fixed capitalization in CDI integration test sample repositories to let the code compile on case-sensitive file systems. --- pom.xml | 19 ++++--------------- .../ElasticsearchCrudRepository.java | 10 ++++++---- .../cdi/ElasticsearchRepositoryExtension.java | 13 ++++++++----- ...ticsearchEntityInformationCreatorImpl.java | 8 ++++++-- .../NonDocumentEntityRepository.java | 5 ++++- .../cdi/CdiProductRepository.java | 5 ++--- .../repositories/cdi/CdiRepositoryClient.java | 9 +++++---- .../repositories/cdi/CdiRepositoryTests.java | 6 +++--- template.mf | 2 +- 9 files changed, 39 insertions(+), 38 deletions(-) diff --git a/pom.xml b/pom.xml index 38986db65..88072e389 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.springframework.data.build spring-data-parent - 1.2.0.RELEASE + 1.3.0.RC1 ../spring-data-build/parent/pom.xml @@ -25,8 +25,7 @@ 3.2.1 2.6 0.90.11 - 2.2.3 - 1.6.0.BUILD-SNAPSHOT + 1.7.0.RC1 @@ -36,7 +35,6 @@ org.springframework spring-context - ${spring} commons-logging @@ -48,15 +46,6 @@ org.springframework spring-tx - ${spring} - - - - - cglib - cglib - 2.2.2 - test @@ -158,8 +147,8 @@ - spring-libs-snapshot - http://repo.springsource.org/libs-snapshot-local + spring-libs-milestone + http://repo.spring.io/libs-mileston diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchCrudRepository.java b/src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchCrudRepository.java index 1273d0b50..d2326731d 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchCrudRepository.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchCrudRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2014 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. @@ -15,10 +15,10 @@ */ package org.springframework.data.elasticsearch.repository; -import org.springframework.data.repository.PagingAndSortingRepository; - import java.io.Serializable; -import java.util.List; + +import org.springframework.data.repository.NoRepositoryBean; +import org.springframework.data.repository.PagingAndSortingRepository; /** * @param @@ -26,7 +26,9 @@ import java.util.List; * * @author Rizwan Idrees * @author Mohsin Husen + * @author Oliver Gierke */ +@NoRepositoryBean public interface ElasticsearchCrudRepository extends PagingAndSortingRepository { } diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/cdi/ElasticsearchRepositoryExtension.java b/src/main/java/org/springframework/data/elasticsearch/repository/cdi/ElasticsearchRepositoryExtension.java index 4fe639395..afd71ce37 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/cdi/ElasticsearchRepositoryExtension.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/cdi/ElasticsearchRepositoryExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2014 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. @@ -16,6 +16,7 @@ package org.springframework.data.elasticsearch.repository.cdi; import org.springframework.data.elasticsearch.core.ElasticsearchOperations; +import org.springframework.data.repository.cdi.CdiRepositoryBean; import org.springframework.data.repository.cdi.CdiRepositoryExtensionSupport; import javax.enterprise.event.Observes; @@ -36,8 +37,8 @@ import java.util.Set; * * @author Rizwan Idrees * @author Mohsin Husen + * @author Oliver Gierke */ - public class ElasticsearchRepositoryExtension extends CdiRepositoryExtensionSupport { private final Map> elasticsearchOperationsMap = new HashMap>(); @@ -58,12 +59,14 @@ public class ElasticsearchRepositoryExtension extends CdiRepositoryExtensionSupp Class repositoryType = entry.getKey(); Set qualifiers = entry.getValue(); - Bean repositoryBean = createRepositoryBean(repositoryType, qualifiers, beanManager); + CdiRepositoryBean repositoryBean = createRepositoryBean(repositoryType, qualifiers, beanManager); afterBeanDiscovery.addBean(repositoryBean); + registerBean(repositoryBean); } } - private Bean createRepositoryBean(Class repositoryType, Set qualifiers, BeanManager beanManager) { + private CdiRepositoryBean createRepositoryBean(Class repositoryType, Set qualifiers, BeanManager beanManager) { + Bean elasticsearchOperationsBean = this.elasticsearchOperationsMap.get(qualifiers .toString()); @@ -71,7 +74,7 @@ public class ElasticsearchRepositoryExtension extends CdiRepositoryExtensionSupp throw new UnsatisfiedResolutionException(String.format("Unable to resolve a bean for '%s' with qualifiers %s.", ElasticsearchOperations.class.getName(), qualifiers)); } + return new ElasticsearchRepositoryBean(elasticsearchOperationsBean, qualifiers, repositoryType, beanManager); } - } diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchEntityInformationCreatorImpl.java b/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchEntityInformationCreatorImpl.java index 07e7f3489..8a4dd443f 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchEntityInformationCreatorImpl.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchEntityInformationCreatorImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2014 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. @@ -27,6 +27,7 @@ import java.io.Serializable; * * @author Rizwan Idrees * @author Mohsin Husen + * @author Oliver Gierke */ public class ElasticsearchEntityInformationCreatorImpl implements ElasticsearchEntityInformationCreator { @@ -41,9 +42,12 @@ public class ElasticsearchEntityInformationCreatorImpl implements ElasticsearchE @Override @SuppressWarnings("unchecked") public ElasticsearchEntityInformation getEntityInformation(Class domainClass) { + ElasticsearchPersistentEntity persistentEntity = (ElasticsearchPersistentEntity) mappingContext .getPersistentEntity(domainClass); + + Assert.notNull(persistentEntity, String.format("Unable to obtain mapping metadata for %s!", domainClass)); + return new MappingElasticsearchEntityInformation(persistentEntity); } - } diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/NonDocumentEntityRepository.java b/src/test/java/org/springframework/data/elasticsearch/repositories/NonDocumentEntityRepository.java index e78f14ab3..8d911ab1f 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repositories/NonDocumentEntityRepository.java +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/NonDocumentEntityRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2014 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. @@ -15,12 +15,15 @@ */ package org.springframework.data.elasticsearch.repositories; +import org.springframework.context.annotation.Lazy; import org.springframework.data.elasticsearch.NonDocumentEntity; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; /** * @author Rizwan Idrees * @author Mohsin Husen + * @author Oliver Gierke */ +@Lazy public interface NonDocumentEntityRepository extends ElasticsearchRepository { } diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/CdiProductRepository.java b/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/CdiProductRepository.java index 236ddb5ed..b061f6048 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/CdiProductRepository.java +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/CdiProductRepository.java @@ -20,10 +20,9 @@ import org.springframework.data.repository.CrudRepository; /** * @author Mohsin Husen + * @author Oliver Gierke */ - -public interface CDIProductRepository extends CrudRepository { +public interface CdiProductRepository extends CrudRepository { Product findOne(String id); - } diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/CdiRepositoryClient.java b/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/CdiRepositoryClient.java index 9e5ed9597..cc2a6b9fa 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/CdiRepositoryClient.java +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/CdiRepositoryClient.java @@ -19,17 +19,18 @@ import javax.inject.Inject; /** * @author Mohsin Husen + * @author Oliver Gierke */ -class CDIRepositoryClient { +class CdiRepositoryClient { - private CDIProductRepository repository; + private CdiProductRepository repository; - public CDIProductRepository getRepository() { + public CdiProductRepository getRepository() { return repository; } @Inject - public void setRepository(CDIProductRepository repository) { + public void setRepository(CdiProductRepository repository) { this.repository = repository; } diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/CdiRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/CdiRepositoryTests.java index ca6c40a1d..7f2770500 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/CdiRepositoryTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/CdiRepositoryTests.java @@ -26,10 +26,10 @@ import static org.junit.Assert.*; * @author Mohsin Husen */ -public class CDIRepositoryTests { +public class CdiRepositoryTests { private static CdiTestContainer cdiContainer; - private CDIProductRepository repository; + private CdiProductRepository repository; @BeforeClass public static void init() throws Exception { @@ -46,7 +46,7 @@ public class CDIRepositoryTests { @Before public void setUp() { - CDIRepositoryClient client = cdiContainer.getInstance(CDIRepositoryClient.class); + CdiRepositoryClient client = cdiContainer.getInstance(CdiRepositoryClient.class); repository = client.getRepository(); } diff --git a/template.mf b/template.mf index 5b25ec451..f0dac7b43 100644 --- a/template.mf +++ b/template.mf @@ -14,7 +14,7 @@ Import-Template: org.elasticsearch.*;version="${elasticsearch:[=.=.=,+1.0.0)}", org.joda.time.*;version="${jodatime:[=.=.=,+1.0.0)}", org.slf4j.*;version="${slf4j:[=.=.=,+1.0.0)}", - org.springframework.*;version="${spring30:[=.=.=.=,+1.0.0)}", + org.springframework.*;version="${spring:[=.=.=.=,+1.0.0)}", org.springframework.data.*;version="${springdata.commons:[=.=.=.=,+1.0.0)}", org.w3c.*;version="0.0.0" \ No newline at end of file