#562 - Polishing.

Reformat code. Remove superfluous @Repository annotation.

Original pull request: #564.
This commit is contained in:
Mark Paluch
2020-05-14 09:40:14 +02:00
parent fd52cea0e4
commit 005aa56d5d
17 changed files with 77 additions and 181 deletions

View File

@@ -4,7 +4,7 @@ This project contains samples of data access features with Spring Data (Couchbas
## Prerequisites
The examples require a running [Couchbase Server](https://www.couchbase.com/downloads) server with the travel sample bucket imported. We assume you're running Couchbase 6.5 and we have updated the `CouchbaseConfig` class accordingly to adapt RBAC authentication.
The examples require a running [Couchbase Server](https://www.couchbase.com/downloads) server with the travel sample bucket imported. We assume you're running Couchbase 6.5 and we have updated the `application.properties` class accordingly to adapt RBAC authentication.
For more information, see the [official documentation](https://docs.spring.io/spring-data/couchbase/docs/current/reference/html/#reference).

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2018 the original author or authors.
* Copyright 2017-2020 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,14 +15,13 @@
*/
package example.springdata.couchbase.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Version;
import org.springframework.data.couchbase.core.mapping.Document;
import org.springframework.data.couchbase.core.mapping.Field;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
/**
* A domain object representing an Airline
@@ -34,21 +33,15 @@ import org.springframework.data.couchbase.core.mapping.Field;
@JsonIgnoreProperties(ignoreUnknown = true)
public class Airline {
@Id
private String id;
private @Id String id;
@Field
private String name;
@Field
private String iata;
@Field
private String icao;
@Field
private String callsign;
@Field
private String country;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2018 the original author or authors.
* Copyright 2017-2020 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,6 +18,7 @@ package example.springdata.couchbase.repository;
import example.springdata.couchbase.model.Airline;
import java.util.List;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@@ -28,7 +29,6 @@ import org.springframework.stereotype.Repository;
* @author Mark Paluch
* @author Denis Rosa
*/
@Repository
public interface AirlineRepository extends CrudRepository<Airline, String> {
/**

View File

@@ -1,55 +0,0 @@
/*
* Copyright 2020 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 example.springdata.couchbase.repository;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration;
/**
* @author Denis Rosa
* Configuration class to connnect with couchbase
*/
@Configuration
public class CouchbaseConfig extends AbstractCouchbaseConfiguration {
@Override
public String getConnectionString() {
return "couchbase://127.0.0.1";
}
@Override
public String getUserName() {
return "Administrator";
}
@Override
public String getPassword() {
return "password";
}
@Override
public String getBucketName() {
return "travel-sample";
}
@Override
protected boolean autoIndexCreation() {
return true;
}
}

View File

@@ -15,16 +15,17 @@
*/
package example.springdata.couchbase.repository;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.manager.query.CreatePrimaryQueryIndexOptions;
import example.springdata.couchbase.model.Airline;
import lombok.RequiredArgsConstructor;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.couchbase.core.CouchbaseTemplate;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.manager.query.CreatePrimaryQueryIndexOptions;
/**
* Main Class of this module
@@ -33,14 +34,11 @@ import org.springframework.data.couchbase.core.CouchbaseTemplate;
*/
@SpringBootApplication
@RequiredArgsConstructor
public class CouchbaseMain {
@Autowired
private final CouchbaseTemplate couchbaseTemplate;
@Autowired private final CouchbaseTemplate couchbaseTemplate;
@Autowired
private Cluster cluster;
@Autowired private Cluster cluster;
/**
* Add the _class field to all Airline documents
@@ -51,7 +49,6 @@ public class CouchbaseMain {
CreatePrimaryQueryIndexOptions.createPrimaryQueryIndexOptions().ignoreIfExists(true));
// Need to post-process travel data to add _class attribute
cluster.query("update `travel-sample` set _class='"+Airline.class.getName()+"' where type = 'airline'");
cluster.query("update `travel-sample` set _class='" + Airline.class.getName() + "' where type = 'airline'");
}
}

View File

@@ -1,4 +1,8 @@
# Increased timeout to fit slower environments like TravisCI
spring.couchbase.env.timeouts.view=15000
spring.couchbase.env.timeouts.query=15000
spring.couchbase.connection-string=couchbase://127.0.0.1
spring.couchbase.username=Administrator
spring.couchbase.password=password
spring.data.couchbase.bucket-name=travel-sample
spring.data.couchbase.auto-index=true

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2018 the original author or authors.
* Copyright 2017-2020 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.
@@ -43,21 +43,17 @@ public class AirlineRepositoryIntegrationTests {
@ClassRule //
public static CouchbaseAvailableRule COUCHBASE = CouchbaseAvailableRule.onLocalhost();
@Autowired
AirlineRepository airlineRepository;
@Autowired AirlineRepository airlineRepository;
@Autowired CouchbaseOperations couchbaseOperations;
@Before
public void before() {
if( couchbaseOperations.existsById().one("LH")) {
if (couchbaseOperations.existsById().one("LH")) {
couchbaseOperations.removeById().one("LH");
}
}
/**
* The derived query executes a N1QL query emitting a single element.
*/
@@ -88,7 +84,7 @@ public class AirlineRepositoryIntegrationTests {
List<Airline> airlines = airlineRepository.findAllBy();
assertThat(airlines).hasSize(374);
assertThat(airlines).hasSizeGreaterThan(100);
}
/**

View File

@@ -21,11 +21,13 @@
<module>util</module>
</modules>
<dependencies>
<dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-couchbase</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -8,7 +8,6 @@ This project contains samples of reactive data access features with Spring Data
Spring Data Couchbase provides reactive repository support with Project Reactor:
```java
@Repository
public interface ReactiveAirlineRepository extends ReactiveCrudRepository<Airline, String> {
Mono<Airline> findByIata(String code);

View File

@@ -15,19 +15,18 @@
*/
package example.springdata.couchbase;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.manager.query.CreatePrimaryQueryIndexOptions;
import example.springdata.couchbase.model.Airline;
import lombok.RequiredArgsConstructor;
import java.util.List;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.couchbase.core.CouchbaseTemplate;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.manager.query.CreatePrimaryQueryIndexOptions;
/**
* Main Class of the module
*
@@ -37,12 +36,9 @@ import org.springframework.data.couchbase.core.CouchbaseTemplate;
@RequiredArgsConstructor
public class CouchbaseMain {
@Autowired
private final CouchbaseTemplate couchbaseTemplate;
@Autowired
private Cluster cluster;
@Autowired CouchbaseTemplate couchbaseTemplate;
@Autowired Cluster cluster;
@PostConstruct
private void postConstruct() {
@@ -51,7 +47,7 @@ public class CouchbaseMain {
CreatePrimaryQueryIndexOptions.createPrimaryQueryIndexOptions().ignoreIfExists(true));
// Need to post-process travel data to add _class attribute
cluster.query("update `travel-sample` set _class='"+Airline.class.getName()+"' where type = 'airline'");
cluster.query("update `travel-sample` set _class='" + Airline.class.getName() + "' where type = 'airline'");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2018 the original author or authors.
* Copyright 2017-2020 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.
@@ -19,8 +19,6 @@ import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.couchbase.core.mapping.Document;
import org.springframework.data.couchbase.core.mapping.Field;
/**
* A domain object representing an Airline
@@ -35,15 +33,15 @@ public class Airline {
@Id private String id;
@Field private String type;
private String type;
@Field private String name;
private String name;
@Field private String iata;
private String iata;
@Field private String icao;
private String icao;
@Field private String callsign;
private String callsign;
@Field private String country;
private String country;
}

View File

@@ -1,55 +0,0 @@
/*
* Copyright 2020 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 example.springdata.couchbase.repository;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration;
/**
* @author Denis Rosa
* Configuration class to connnect with couchbase
*/
@Configuration
public class CouchbaseConfig extends AbstractCouchbaseConfiguration {
@Override
public String getConnectionString() {
return "couchbase://127.0.0.1";
}
@Override
public String getUserName() {
return "Administrator";
}
@Override
public String getPassword() {
return "password";
}
@Override
public String getBucketName() {
return "travel-sample";
}
@Override
protected boolean autoIndexCreation() {
return true;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2018 the original author or authors.
* Copyright 2017-2020 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.

View File

@@ -1,3 +1,8 @@
# Increased timeout to fit slower environments like TravisCI
spring.couchbase.env.timeouts.view=15000
spring.couchbase.env.timeouts.query=15000
spring.couchbase.connection-string=couchbase://127.0.0.1
spring.couchbase.username=Administrator
spring.couchbase.password=password
spring.data.couchbase.bucket-name=travel-sample
spring.data.couchbase.auto-index=true

View File

@@ -60,9 +60,11 @@ public class ReactiveAirlineRepositoryIntegrationTests {
@Test
public void shouldFindAirlineN1ql() {
StepVerifier.create(airlineRepository.findByIata("TQ")).assertNext(it -> {
assertThat(it.getCallsign()).isEqualTo("TXW");
}).verifyComplete();
airlineRepository.findByIata("TQ") //
.as(StepVerifier::create) //
.assertNext(it -> {
assertThat(it.getCallsign()).isEqualTo("TXW");
}).verifyComplete();
}
/**
@@ -77,10 +79,11 @@ public class ReactiveAirlineRepositoryIntegrationTests {
.map(Airline::getId) //
.flatMap(airlineRepository::findById);
StepVerifier.create(airline).assertNext(it -> {
airline.as(StepVerifier::create) //
.assertNext(it -> {
assertThat(it.getCallsign()).isEqualTo("TXW");
}).verifyComplete();
assertThat(it.getCallsign()).isEqualTo("TXW");
}).verifyComplete();
}
@@ -89,7 +92,12 @@ public class ReactiveAirlineRepositoryIntegrationTests {
*/
@Test
public void shouldFindAll() {
StepVerifier.create(airlineRepository.findAllBy()).expectNextCount(374).verifyComplete();
airlineRepository.findAllBy().count() //
.as(StepVerifier::create) //
.assertNext(count -> {
assertThat(count).isGreaterThan(100);
}).verifyComplete();
}
/**
@@ -112,6 +120,8 @@ public class ReactiveAirlineRepositoryIntegrationTests {
.map(Airline::getId) //
.flatMap(airlineRepository::findById);
StepVerifier.create(airlineMono).expectNext(airline).verifyComplete();
airlineMono.as(StepVerifier::create) //
.expectNext(airline) //
.verifyComplete();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2018 the original author or authors.
* Copyright 2017-2020 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.
@@ -19,20 +19,18 @@ import static org.assertj.core.api.Assertions.*;
import example.springdata.couchbase.model.Airline;
import example.springdata.couchbase.util.CouchbaseAvailableRule;
import org.springframework.data.couchbase.core.CouchbaseOperations;
import org.springframework.data.couchbase.core.ReactiveCouchbaseOperations;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import rx.Observable;
import rx.observers.AssertableSubscriber;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.couchbase.core.CouchbaseOperations;
import org.springframework.data.couchbase.core.ReactiveCouchbaseOperations;
import org.springframework.test.context.junit4.SpringRunner;
/**
@@ -67,7 +65,14 @@ public class ReactiveJavaCouchbaseOperationsIntegrationTests {
*/
@Test
public void shouldFindByAll() {
StepVerifier.create( operations.findByQuery( Airline.class).all()).expectNextCount(374).verifyComplete();
operations.findByQuery(Airline.class).all() //
.count() //
.as(StepVerifier::create) //
.assertNext(count -> {
assertThat(count).isGreaterThan(100);
}) //
.verifyComplete();
}
/**
@@ -89,6 +94,7 @@ public class ReactiveJavaCouchbaseOperationsIntegrationTests {
.map(Airline::getId) //
.flatMap(id -> operations.findById(Airline.class).one(id));
StepVerifier.create(airlineMono).expectNext(airline).verifyComplete();
airlineMono.as(StepVerifier::create) //
.expectNext(airline).verifyComplete();
}
}

View File

@@ -18,7 +18,7 @@
<modules>
<module>bom</module>
<module>couchbase</module>
<module>couchbase</module>
<module>elasticsearch</module>
<module>jdbc</module>
<module>jpa</module>