Skip to content

Commit 95f4b6a

Browse files
authored
Snippet fix (Azure#17174)
* Snippet fix * README fixes
1 parent 21bd526 commit 95f4b6a

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

sdk/cosmos/azure-spring-data-cosmos/README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ Azure spring data cosmos supports specifying annotated queries in the repositori
297297
```java
298298
public interface AnnotatedQueriesUserRepositoryCodeSnippet extends CosmosRepository<User, String> {
299299
@Query(value = "select * from c where c.firstName = @firstName and c.lastName = @lastName")
300-
List<User> getUsersByTitleAndValue(@Param("firstName") int firstName, @Param("lastName") String lastName);
300+
List<User> getUsersByFirstNameAndLastName(@Param("firstName") String firstName, @Param("lastName") String lastName);
301301

302302
@Query(value = "select * from c offset @offset limit @limit")
303303
List<User> getUsersWithOffsetLimit(@Param("offset") int offset, @Param("limit") int limit);
@@ -515,7 +515,7 @@ azure.cosmos.secondary.populateQueryMetrics=if-populate-query-metrics
515515
- The `@EnableReactiveCosmosRepositories` or `@EnableCosmosRepositories` support user-define the cosmos template, use `reactiveCosmosTemplateRef` or `cosmosTemplateRef` to config the name of the `ReactiveCosmosTemplate` or `CosmosTemplate` bean to be used with the repositories detected.
516516
- If you have multiple cosmos database accounts, you can define multiple `CosmosAsyncClient`. If the single cosmos account has multiple databases, you can use the same `CosmosAsyncClient` to initialize the cosmos template.
517517

518-
<!-- embedme src/samples/java/com/azure/spring/data/cosmos/multidatasource/PrimaryDatabaseConfiguration.java#L23-L62 -->
518+
<!-- embedme src/samples/java/com/azure/spring/data/cosmos/multidatasource/PrimaryDatasourceConfiguration.java#L23-L62 -->
519519
```java
520520
@Configuration
521521
public class PrimaryDatasourceConfiguration {
@@ -559,7 +559,7 @@ public class PrimaryDatasourceConfiguration {
559559
}
560560
```
561561

562-
<!-- embedme src/samples/java/com/azure/spring/data/cosmos/multidatasource/SecondaryDatabaseConfiguration.java#L28-L84 -->
562+
<!-- embedme src/samples/java/com/azure/spring/data/cosmos/multidatasource/SecondaryDatasourceConfiguration.java#L28-L84 -->
563563
```java
564564
@Configuration
565565
public class SecondaryDatasourceConfiguration {
@@ -622,19 +622,29 @@ public class SecondaryDatasourceConfiguration {
622622

623623
- In the above example, we have two cosmos account, each account has two databases. For each account, we can use the same Cosmos Client. You can create the `CosmosAsyncClient` like this:
624624

625-
<!-- embedme src/samples/java/com/azure/spring/data/cosmos/multidatasource/SecondaryDatabaseConfiguration.java#L41-L56 -->
625+
<!-- embedme src/samples/java/com/azure/spring/data/cosmos/multidatasource/SecondaryDatasourceConfiguration.java#L41-L56 -->
626626
```java
627627
@Bean("secondaryCosmosClient")
628628
public CosmosAsyncClient getCosmosAsyncClient(@Qualifier("secondary") CosmosProperties secondaryProperties) {
629629
return CosmosFactory.createCosmosAsyncClient(new CosmosClientBuilder()
630630
.key(secondaryProperties.getKey())
631631
.endpoint(secondaryProperties.getUri()));
632632
}
633+
634+
@Bean("secondaryCosmosConfig")
635+
public CosmosConfig getCosmosConfig() {
636+
return CosmosConfig.builder()
637+
.enableQueryMetrics(true)
638+
.responseDiagnosticsProcessor(new ResponseDiagnosticsProcessorImplementation())
639+
.build();
640+
}
641+
642+
@EnableCosmosRepositories(basePackages = "com.azure.cosmos.multidatasource.secondary.database3",
633643
```
634644

635645
- Besides, if you want to define `queryMetricsEnabled` or `ResponseDiagnosticsProcessor` , you can create the `CosmosConfig` for your cosmos template.
636646

637-
<!-- embedme src/samples/java/com/azure/spring/data/cosmos/multidatasource/SecondaryDatabaseConfiguration.java#L48-L54-->
647+
<!-- embedme src/samples/java/com/azure/spring/data/cosmos/multidatasource/SecondaryDatasourceConfiguration.java#L48-L54-->
638648
```java
639649
@Bean("secondaryCosmosConfig")
640650
public CosmosConfig getCosmosConfig() {

sdk/cosmos/azure-spring-data-cosmos/src/samples/java/com/azure/spring/data/cosmos/AnnotatedQueriesUserRepositoryCodeSnippet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
public interface AnnotatedQueriesUserRepositoryCodeSnippet extends CosmosRepository<User, String> {
1212
@Query(value = "select * from c where c.firstName = @firstName and c.lastName = @lastName")
13-
List<User> getUsersByTitleAndValue(@Param("firstName") int firstName, @Param("lastName") String lastName);
13+
List<User> getUsersByFirstNameAndLastName(@Param("firstName") String firstName, @Param("lastName") String lastName);
1414

1515
@Query(value = "select * from c offset @offset limit @limit")
1616
List<User> getUsersWithOffsetLimit(@Param("offset") int offset, @Param("limit") int limit);

0 commit comments

Comments
 (0)