You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+27-15Lines changed: 27 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@
5
5
Often, the first step developers take after creating their database is to create a REST API that can perform Create, Read, Update, and Delete (CRUD) operations for that database. This repo is designed to teach you and give you a starter project (in Java using Spring Data) to generate such a REST API. After you have installed the travel-sample bucket in your database, you can run this application which is a REST API with Swagger documentation so that you can learn:
6
6
7
7
1. How to create, read, update, and delete documents using Key-Value[ operations](https://docs.couchbase.com/java-sdk/current/howtos/kv-operations.html) (KV operations). KV operations are unique to Couchbase and provide super fast (think microseconds) queries.
8
-
2. How to write simple parametrized [N1QL queries](https://docs.couchbase.com/java-sdk/current/howtos/n1ql-queries-with-sdk.html) using the built-in travel-sample bucket.
8
+
2. How to write simple parametrized [SQL++ Queries](https://docs.couchbase.com/java-sdk/current/howtos/n1ql-queries-with-sdk.html) using the built-in travel-sample bucket.
9
9
10
10
Full documentation for the tutorial can be found on the [Couchbase Developer Portal](https://developer.couchbase.com/tutorial-quickstart-spring-data-java/).
11
11
@@ -17,11 +17,10 @@ To run this prebuilt project, you will need:
17
17
- To run this tutorial using a self-managed Couchbase cluster, please refer to the [appendix](#running-self-managed-couchbase-cluster).
18
18
-[Java 17 or higher](https://www.oracle.com/java/technologies/javase-downloads.html)
19
19
- Ensure that the Java version is compatible with the Couchbase SDK.
20
-
- Loading Travel Sample Bucket
21
-
If travel-sample is not loaded in your Capella cluster, you can load it by following the instructions for your Capella Cluster:
22
-
-[Load travel-sample bucket in Couchbase Capella](https://docs.couchbase.com/cloud/clusters/data-service/import-data-documents.html#import-sample-data)
23
-
- Gradle
24
-
- You can install Gradle using the [instructions](https://gradle.org/install/).
- If `travel-sample` is not loaded in your Capella cluster, you can load it by following the instructions for your Capella Cluster
22
+
-[Gradle 8.6 or higher](https://gradle.org/releases/)
23
+
25
24
## App Setup
26
25
27
26
We will walk through the different steps required to get the application running.
@@ -55,22 +54,33 @@ Specifically, you need to do the following:
55
54
56
55
All configuration for communication with the database is read from the environment variables. We have provided a convenience feature in this quickstart to read the environment variables from a local file, `application.properties` in the `src/main/resources` folder.
57
56
57
+
You can also set the environment variables directly in your environment such as:
58
+
59
+
```sh
60
+
export DB_CONN_STR=couchbases://<cluster-url>
61
+
export DB_USERNAME=Administrator
62
+
export DB_PASSWORD=password
63
+
```
64
+
65
+
The `application.properties` file should look like this:
Instead of DB_CONN_STR, DB_USERNAME, and DB_PASSWORD, you should replace these with the connection string, username, and password for your Couchbase cluster. The connection string is the URL of your cluster. For example, if you are using Capella, the connection string will look like `couchbases://cb.jnym5s9gv4ealbe.cloud.couchbase.com`. If you are using a local cluster, the connection string will be `localhost`.
69
75
70
-
> Note: The connection string expects the `couchbases://` or `couchbase://` part.
76
+
You can specify the connection string, username, and password using environment variables. The application will read these environment variables and use them to connect to the database.
77
+
78
+
Additionally, you can specify the connection string, username, and password directly in the `application.properties` file.
71
79
80
+
> Note: The connection string expects the `couchbases://` or `couchbase://` part.
72
81
73
82
## Cluster Connection Configuration
83
+
74
84
Spring Data couchbase connector can be configured by providing a `@Configuration`[bean](https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#beans-definition) that extends [`AbstractCouchbaseConfiguration`](https://docs.spring.io/spring-data/couchbase/docs/current/api/org/springframework/data/couchbase/config/AbstractCouchbaseConfiguration.html).
75
85
76
86
```java
@@ -144,7 +154,8 @@ public class CouchbaseConfiguration extends AbstractCouchbaseConfiguration {
144
154
145
155
}
146
156
```
147
-
> *from config/CouchbaseConfiguration.java*
157
+
158
+
> _from config/CouchbaseConfiguration.java_
148
159
149
160
This default configuration assumes that you have a locally running Couchbae server and uses standard administrative login and password for demonstration purpose.
150
161
Applications deployed to production or staging environments should use less privileged credentials created using [Role-Based Access Control](https://docs.couchbase.com/go-sdk/current/concept-docs/rbac.html).
@@ -212,10 +223,11 @@ For this quickstart, we use three collections, `airport`, `airline` and `routes`
212
223
213
224
If you would like to add another entity to the APIs, these are the steps to follow:
214
225
215
-
- Create the new entity (collection) in the Couchbase bucket. You can create the collection using the [SDK](https://docs.couchbase.com/sdk-api/couchbase-java-client-3.5.2/com/couchbase/client/java/Collection.html#createScope-java.lang.String-) or via the [Couchbase Server interface](https://docs.couchbase.com/cloud/n1ql/n1ql-language-reference/createcollection.html).
216
-
- Define the routes in a new file in the `controllers` folder similar to the existing routes like `AirportController.java`.
217
-
- Define the service in a new file in the `services` folder similar to the existing services like `AirportService.java`.
218
-
- Define the repository in a new file in the `repositories` folder similar to the existing repositories like `AirportRepository.java`.
226
+
- You can create the collection using the [SDK](https://docs.couchbase.com/sdk-api/couchbase-java-client-3.5.2/com/couchbase/client/java/Collection.html#createScope-java.lang.String-) or via the [Couchbase Server interface](https://docs.couchbase.com/cloud/n1ql/n1ql-language-reference/createcollection.html).
227
+
- Create a new entity class in the `models` package similar to the existing entity classes like `Airport.java`.
228
+
- Define the controller in a new file in the `controllers` folder similar to the existing classes like `AirportController.java`.
229
+
- Define the service in a new file in the `services` folder similar to the existing classes like `AirportService.java`.
230
+
- Define the repository in a new file in the `repositories` folder similar to the existing classes like `AirportRepository.java`.
@Operation(summary = "Get an airline by ID", description = "Get Airline by specified ID.\n\nThis provides an example of using Key Value operations in Couchbase to retrieve a document with a specified ID. \n\n Code: [`controllers/AirlineController.java`](https://github.com/couchbase-examples/java-springdata-quickstart/blob/main/src/main/java/org/couchbase/quickstart/springdata/controllers/AirlineController.java) \n File: `AirlineController.java` \n Method: `getAirline`", tags = {
@@ -59,8 +67,14 @@ public ResponseEntity<Airline> getAirline(@PathVariable String id) {
59
67
}
60
68
}
61
69
62
-
@Operation(summary = "Create an airline")
63
70
@PostMapping("/{id}")
71
+
@Operation(summary = "Create an airline", description = "Create an airline with the specified ID.\n\nThis provides an example of using Key Value operations in Couchbase to create a document with a specified ID. \n\n Code: [`controllers/AirlineController.java`](https://github.com/couchbase-examples/java-springdata-quickstart/blob/main/src/main/java/org/couchbase/quickstart/springdata/controllers/AirlineController.java) \n File: `AirlineController.java` \n Method: `createAirline`", tags = {
@@ -74,8 +88,14 @@ public ResponseEntity<Airline> createAirline(@Valid @RequestBody Airline airline
74
88
}
75
89
}
76
90
77
-
@Operation(summary = "Update an airline")
78
91
@PutMapping("/{id}")
92
+
@Operation(summary = "Update an airline", description = "Update an airline with the specified ID.\n\nThis provides an example of using Key Value operations in Couchbase to update a document with a specified ID. \n\n Code: [`controllers/AirlineController.java`](https://github.com/couchbase-examples/java-springdata-quickstart/blob/main/src/main/java/org/couchbase/quickstart/springdata/controllers/AirlineController.java) \n File: `AirlineController.java` \n Method: `updateAirline`", tags = {
@Operation(summary = "Delete an airline", description = "Delete an airline with the specified ID.\n\nThis provides an example of using Key Value operations in Couchbase to delete a document with a specified ID. \n\n Code: [`controllers/AirlineController.java`](https://github.com/couchbase-examples/java-springdata-quickstart/blob/main/src/main/java/org/couchbase/quickstart/springdata/controllers/AirlineController.java) \n File: `AirlineController.java` \n Method: `deleteAirline`", tags = {
@Operation(summary = "List all airlines by country")
125
-
@GetMapping("/country/{country}")
138
+
@Operation(summary = "List all airlines by country", description = "List all airlines by country.\n\nThis provides an example of using N1QL queries in Couchbase to retrieve documents with a specified field value. \n\n Code: [`controllers/AirlineController.java`](https://github.com/couchbase-examples/java-springdata-quickstart/blob/main/src/main/java/org/couchbase/quickstart/springdata/controllers/AirlineController.java) \n File: `AirlineController.java` \n Method: `listAirlinesByCountry`", tags = {
@Operation(summary = "List all airlines by desination airport")
141
-
@GetMapping("/destination/{destinationAirport}")
162
+
@GetMapping("/to-airport")
163
+
@Operation(summary = "List all airlines by desination airport", description = "List all airlines by destination airport.\n\nThis provides an example of using N1QL queries in Couchbase to retrieve documents with a specified field value. \n\n Code: [`controllers/AirlineController.java`](https://github.com/couchbase-examples/java-springdata-quickstart/blob/main/src/main/java/org/couchbase/quickstart/springdata/controllers/AirlineController.java) \n File: `AirlineController.java` \n Method: `listAirlinesByDestinationAirport`", tags = {
0 commit comments