Polish contribution

Closes gh-3499
This commit is contained in:
Stephane Nicoll
2016-02-15 20:25:12 +01:00
parent 76f1ca4188
commit da3b49e024
15 changed files with 320 additions and 162 deletions

View File

@@ -0,0 +1,22 @@
= Spring Boot Couchbase Sample
This sample demonstrates how you can store a simple document using Spring Data Couchbase.
The sample expects couchbase to run on your machine with a bucket named `mybucket` and
`couchbase` for the password. You can customize these settings in `application.properties`.
Before you use the sample, you need _at least_ to create an `all` view for the `User`: go
to the Couchbase servers admin console and visit the Views screen, then click `Create
Development View` and name it `all` with `user` as document name. On that view, you need
to change the code to:
```java
function (doc, meta) {
if (doc._class == "sample.data.couchbase.User") {
emit(meta.id, null);
}
}
```
and the _reduce_ function to `_count`. After you've saved your changes go back to `Views`
and click on `Publish` so that the `all` view move to the `Production Views` tab.

View File

@@ -16,6 +16,8 @@
package sample.data.couchbase;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
@@ -40,8 +42,9 @@ public class SampleCouchbaseApplication implements CommandLineRunner {
private void saveUsers() {
User user = new User();
user.setFirstname("Alice");
user.setLastname("Smith");
user.setId(UUID.randomUUID().toString());
user.setFirstName("Alice");
user.setLastName("Smith");
this.userRepository.save(user);
}

View File

@@ -28,10 +28,10 @@ public class User {
private String id;
@Field
private String firstname;
private String firstName;
@Field
private String lastname;
private String lastName;
public String getId() {
return this.id;
@@ -41,28 +41,28 @@ public class User {
this.id = id;
}
public String getFirstname() {
return this.firstname;
public String getFirstName() {
return this.firstName;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastname() {
return this.lastname;
public String getLastName() {
return this.lastName;
}
public void setLastname(String lastname) {
this.lastname = lastname;
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Override
public String toString() {
return "User{" +
"id='" + this.id + '\'' +
", firstname='" + this.firstname + '\'' +
", lastname='" + this.lastname + '\'' +
", firstName='" + this.firstName + '\'' +
", lastName='" + this.lastName + '\'' +
'}';
}
}

View File

@@ -28,7 +28,7 @@ public class SampleCouchbaseApplicationTests {
}
}
String output = this.outputCapture.toString();
assertThat(output).contains("firstname='Alice', lastname='Smith'");
assertThat(output).contains("firstName='Alice', lastName='Smith'");
}
private boolean serverNotRunning(RuntimeException ex) {

View File

@@ -1,3 +1,2 @@
spring.data.couchbase.bucket-name=mybucket
spring.data.couchbase.bucket-password=couchbase
spring.data.couchbase.hosts[0]=127.0.0.1
spring.data.couchbase.bucket.name=mybucket
spring.data.couchbase.bucket.password=couchbase