Skip to content

Commit 0ee7990

Browse files
committed
update comments
1 parent b8f00d3 commit 0ee7990

File tree

1 file changed

+70
-13
lines changed

1 file changed

+70
-13
lines changed

articles/cosmos-db/nosql/quickstart-java-spring-data.md

Lines changed: 70 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ This step is optional. If you're interested in learning how the database resourc
9393

9494
## [Passwordless (Recommended)](#tab/passwordless)
9595

96+
In this section, neither the configurations nor the code have any authentication operations. However, connecting to Azure service requires authentication. To complete the authentication, you need to use Azure Identity. Spring Cloud Azure uses `DefaultAzureCredential`, which is provided by Azure Identity to help you get credentials without any code changes.
97+
98+
`DefaultAzureCredential` supports multiple authentication methods and determines which method should be used at runtime. This approach enables your app to use different authentication methods in different environments (local vs. production) without implementing environment-specific code. For more information, see the [Default Azure credential](/azure/developer/java/sdk/identity-azure-hosted-auth#default-azure-credential) section of [Authenticate Azure-hosted Java applications](/azure/developer/java/sdk/identity-azure-hosted-auth).
99+
100+
To use Azure CLI, Visual Studio Code, PowerShell or other methods to complete the authentication in local development environments, see [Azure authentication in Java development environments](/azure/developer/java/sdk/identity-dev-env-auth). To complete the authentication in Azure hosting environments, we recommend using managed identity. For more information, see [What are managed identities for Azure resources?](/azure/active-directory/managed-identities-azure-resources/overview)
101+
102+
[!INCLUDE [cosmos-nosql-create-assign-roles](../../../includes/passwordless/cosmos-nosql/cosmos-nosql-create-assign-roles.md)]
103+
96104
### Application configuration file
97105

98106
Configure the Azure Database for MySQL credentials in the `application.yml` configuration file in the `cosmos/spring-cloud-azure-starter-data-cosmos/spring-cloud-azure-data-cosmos-sample` directory. Replace the values of `${AZURE_COSMOS_ENDPOINT}` and `${COSMOS_DATABASE}`.
@@ -108,17 +116,40 @@ spring:
108116
109117
After creating the Azure Cosmos DB account, database and container, Spring Boot/Spring Data will connect to the database and container for `delete`, `add` and `find` operations.
110118

111-
> [!TIP]
112-
> In this section, neither the configurations nor the code have any authentication operations. However, connecting to Azure service requires authentication. To complete the authentication, you need to use Azure Identity. Spring Cloud Azure uses `DefaultAzureCredential`, which is provided by Azure Identity to help you get credentials without any code changes.
113-
>
114-
> `DefaultAzureCredential` supports multiple authentication methods and determines which method should be used at runtime. This approach enables your app to use different authentication methods in different environments (local vs. production) without implementing environment-specific code. For more information, see the [Default Azure credential](/azure/developer/java/sdk/identity-azure-hosted-auth#default-azure-credential) section of [Authenticate Azure-hosted Java applications](/azure/developer/java/sdk/identity-azure-hosted-auth).
115-
>
116-
> To use Azure CLI, Visual Studio Code, PowerShell or other methods to complete the authentication in local development environments, see [Azure authentication in Java development environments](/azure/developer/java/sdk/identity-dev-env-auth). To complete the authentication in Azure hosting environments, we recommend using managed identity. For more information, see [What are managed identities for Azure resources?](/azure/active-directory/managed-identities-azure-resources/overview)
117-
118119
### Java source
119120

120-
The sample code has already been added, you don't need to add any code.
121+
The Spring Data value-add also comes from its simple, clean, standardized and platform-independent interface for operating on datastores. Building on the Spring Data GitHub sample linked above, below are CRUD and query samples for manipulating Azure Cosmos DB documents with Spring Datan Azure Cosmos DB.
122+
123+
* Item creation and updates by using the `save` method.
124+
125+
```java
126+
// Save the User class to Azure Cosmos DB database.
127+
final Mono<User> saveUserMono = repository.save(testUser);
128+
```
129+
130+
* Point-reads using the derived query method defined in the repository. The `findById` performs point-reads for `repository`. The fields mentioned in the method name cause Spring Data to execute a point-read defined by the `id` field:
131+
132+
```java
133+
// Nothing happens until we subscribe to these Monos.
134+
// findById will not return the user as user is not present.
135+
final Mono<User> findByIdMono = repository.findById(testUser.getId());
136+
final User findByIdUser = findByIdMono.block();
137+
Assert.isNull(findByIdUser, "User must be null");
138+
```
139+
140+
* Item deletes using `deleteAll`:
141+
142+
```java
143+
repository.deleteAll().block();
144+
LOGGER.info("Deleted all data in container.");
145+
```
146+
147+
* Derived query based on repository method name. Spring Data implements the `repository` `findByFirstName` method as a Java SDK SQL query on the `firstName` field (this query could not be implemented as a point-read):
121148

149+
```java
150+
final Flux<User> firstNameUserFlux = repository.findByFirstName("testFirstName");
151+
```
152+
122153
## [Password](#tab/password)
123154

124155
### Application configuration file
@@ -139,18 +170,44 @@ Once you create an Azure Cosmos DB account, database, and container, just fill-i
139170

140171
### Java source
141172

142-
The sample code has already been added, you don't need to add any code.
173+
The Spring Data value-add also comes from its simple, clean, standardized and platform-independent interface for operating on datastores. Building on the Spring Data GitHub sample linked above, below are CRUD and query samples for manipulating Azure Cosmos DB documents with Spring Datan Azure Cosmos DB.
143174

144-
---
175+
* Item creation and updates by using the `save` method.
176+
177+
```java
178+
// Save the User class to Azure Cosmos DB database.
179+
final Mono<User> saveUserMono = repository.save(testUser);
180+
```
181+
182+
* Point-reads using the derived query method defined in the repository. The `findById` performs point-reads for `repository`. The fields mentioned in the method name cause Spring Data to execute a point-read defined by the `id` field:
183+
184+
```java
185+
// Nothing happens until we subscribe to these Monos.
186+
// findById will not return the user as user is not present.
187+
final Mono<User> findByIdMono = repository.findById(testUser.getId());
188+
final User findByIdUser = findByIdMono.block();
189+
Assert.isNull(findByIdUser, "User must be null");
190+
```
145191

192+
* Item deletes using `deleteAll`:
193+
194+
```java
195+
repository.deleteAll().block();
196+
LOGGER.info("Deleted all data in container.");
197+
```
198+
199+
* Derived query based on repository method name. Spring Data implements the `repository` `findByFirstName` method as a Java SDK SQL query on the `firstName` field (this query could not be implemented as a point-read):
200+
201+
```java
202+
final Flux<User> firstNameUserFlux = repository.findByFirstName("testFirstName");
203+
```
204+
205+
---
146206

147207
## Run the app
148208

149209
Now go back to the Azure portal to get your connection string information and launch the app with your endpoint information. This enables your app to communicate with your hosted database.
150210

151-
>[!TIP]
152-
> Before starting the following sections, replace the variables in *application.yml* with real values. If you use Passwordless authentication, [create the custom role](/azure/cosmos-db/nosql/quickstart-java?tabs=passwordlesssync%2Csign-in-azure-cli#create-the-custom-role) and use Azure CLI, Visual Studio Code, PowerShell, or other methods to complete the authentication.
153-
154211
1. In the git terminal window, `cd` to the sample code folder.
155212

156213
```bash

0 commit comments

Comments
 (0)