DATACOUCH-203 - Use Set to store qualifiers in CDI extension.
Qualifiers are now stored in their original set instead of using the toString representation.
This commit is contained in:
@@ -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.
|
||||
@@ -28,6 +28,11 @@ class CdiRepositoryClient {
|
||||
@Inject
|
||||
private CdiPersonRepository cdiPersonRepository;
|
||||
|
||||
@Inject
|
||||
@OtherQualifier
|
||||
@PersonDB
|
||||
private QualifiedPersonRepository qualifiedPersonRepository;
|
||||
|
||||
@Inject
|
||||
private Bucket couchbaseClient;
|
||||
|
||||
@@ -35,6 +40,10 @@ class CdiRepositoryClient {
|
||||
return cdiPersonRepository;
|
||||
}
|
||||
|
||||
public QualifiedPersonRepository getQualifiedPersonRepository() {
|
||||
return qualifiedPersonRepository;
|
||||
}
|
||||
|
||||
public Bucket getCouchbaseClient() {
|
||||
return couchbaseClient;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -39,6 +39,7 @@ public class CdiRepositoryTests {
|
||||
|
||||
private static CdiTestContainer cdiContainer;
|
||||
private CdiPersonRepository repository;
|
||||
private QualifiedPersonRepository qualifiedPersonRepository;
|
||||
private Bucket couchbaseClient;
|
||||
|
||||
@BeforeClass
|
||||
@@ -58,6 +59,7 @@ public class CdiRepositoryTests {
|
||||
public void setUp() {
|
||||
CdiRepositoryClient repositoryClient = cdiContainer.getInstance(CdiRepositoryClient.class);
|
||||
repository = repositoryClient.getCdiPersonRepository();
|
||||
qualifiedPersonRepository = repositoryClient.getQualifiedPersonRepository();
|
||||
|
||||
couchbaseClient = repositoryClient.getCouchbaseClient();
|
||||
createAndWaitForDesignDocs(couchbaseClient);
|
||||
@@ -91,7 +93,26 @@ public class CdiRepositoryTests {
|
||||
assertNotNull(retrieved);
|
||||
assertEquals(bean.getName(), retrieved.getName());
|
||||
assertEquals(bean.getId(), retrieved.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACOUCH-203
|
||||
*/
|
||||
@Test
|
||||
public void testQualifiedCdiRepository() {
|
||||
assertNotNull(qualifiedPersonRepository);
|
||||
qualifiedPersonRepository.deleteAll();
|
||||
|
||||
Person bean = new Person("key", "username");
|
||||
|
||||
qualifiedPersonRepository.save(bean);
|
||||
|
||||
assertTrue(qualifiedPersonRepository.exists(bean.getId()));
|
||||
|
||||
Person retrieved = qualifiedPersonRepository.findOne(bean.getId());
|
||||
assertNotNull(retrieved);
|
||||
assertEquals(bean.getName(), retrieved.getName());
|
||||
assertEquals(bean.getId(), retrieved.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.
|
||||
@@ -16,10 +16,12 @@
|
||||
|
||||
package org.springframework.data.couchbase.repository.cdi;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.enterprise.inject.Disposes;
|
||||
import javax.enterprise.inject.Produces;
|
||||
|
||||
import com.couchbase.client.java.Bucket;
|
||||
import com.couchbase.client.java.Cluster;
|
||||
import com.couchbase.client.java.CouchbaseCluster;
|
||||
|
||||
import org.springframework.data.couchbase.config.CouchbaseBucketFactoryBean;
|
||||
@@ -34,10 +36,14 @@ import org.springframework.data.couchbase.config.CouchbaseBucketFactoryBean;
|
||||
class CouchbaseClientProducer {
|
||||
|
||||
@Produces
|
||||
public Bucket createCouchbaseClient() throws Exception {
|
||||
//FIXME produce a Cluster and close it properly?
|
||||
CouchbaseBucketFactoryBean couchbaseFactoryBean = new CouchbaseBucketFactoryBean(
|
||||
CouchbaseCluster.create(), "default");
|
||||
@ApplicationScoped
|
||||
public Cluster cluster() {
|
||||
return CouchbaseCluster.create();
|
||||
}
|
||||
|
||||
@Produces
|
||||
public Bucket createCouchbaseClient(Cluster cluster) throws Exception {
|
||||
CouchbaseBucketFactoryBean couchbaseFactoryBean = new CouchbaseBucketFactoryBean(cluster, "default");
|
||||
couchbaseFactoryBean.afterPropertiesSet();
|
||||
return couchbaseFactoryBean.getObject();
|
||||
}
|
||||
@@ -45,4 +51,8 @@ class CouchbaseClientProducer {
|
||||
public void close(@Disposes Bucket couchbaseClient) {
|
||||
couchbaseClient.close();
|
||||
}
|
||||
|
||||
public void close(@Disposes Cluster cluster) {
|
||||
cluster.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -30,12 +30,12 @@ import org.springframework.data.couchbase.core.CouchbaseTemplate;
|
||||
* Produces a {@link ClusterInfo} instance for test usage.
|
||||
*
|
||||
* @author Simon Baslé
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
class CouchbaseClusterInfoProducer {
|
||||
|
||||
@Produces
|
||||
public ClusterInfo createClusterInfo() throws Exception {
|
||||
Cluster cluster = CouchbaseCluster.create();
|
||||
public ClusterInfo createClusterInfo(Cluster cluster) throws Exception {
|
||||
return cluster.clusterManager("default", "").info();
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -33,10 +33,14 @@ class CouchbaseOperationsProducer {
|
||||
|
||||
@Produces
|
||||
public CouchbaseOperations createCouchbaseOperations(Bucket couchbaseClient, ClusterInfo clusterInfo) throws Exception {
|
||||
|
||||
CouchbaseTemplate couchbaseTemplate = new CouchbaseTemplate(clusterInfo, couchbaseClient);
|
||||
|
||||
return couchbaseTemplate;
|
||||
return new CouchbaseTemplate(clusterInfo, couchbaseClient);
|
||||
}
|
||||
|
||||
@Produces
|
||||
@OtherQualifier
|
||||
@PersonDB
|
||||
public CouchbaseOperations createQualifiedCouchbaseOperations(Bucket couchbaseClient, ClusterInfo clusterInfo) throws Exception {
|
||||
return new CouchbaseTemplate(clusterInfo, couchbaseClient);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.couchbase.repository.cdi;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
* @see DATACOUCH-203
|
||||
*/
|
||||
@Qualifier
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
|
||||
@interface OtherQualifier {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.couchbase.repository.cdi;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
* @see DATACOUCH-203
|
||||
*/
|
||||
@Qualifier
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
|
||||
@interface PersonDB {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.couchbase.repository.cdi;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
* @see DATACOUCH-203
|
||||
*/
|
||||
@PersonDB
|
||||
@OtherQualifier
|
||||
public interface QualifiedPersonRepository extends CrudRepository<Person, String> {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user