Skip to content

Combinig cosmos db samples #708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ az acr create --resource-group cosmosdb-springboot-aks-rg --location eastus \
```bash
git clone https://github.com/Azure-Samples/azure-spring-boot-samples.git

cd cosmos/spring-cloud-azure-starter-data-cosmos/spring-cloud-azure-data-cosmos-aks-sample
cd cosmos/spring-cloud-azure-starter-data-cosmos/spring-cloud-azure-data-cosmos-sample
```

1. Use Maven to build the application.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.spring.sample.cosmos;
package spring.cloud.azure.starter.data.cosmos.sample;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -9,47 +9,32 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.util.Assert;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.Optional;

@SpringBootApplication
public class CosmosSampleApplication implements CommandLineRunner {

private static final Logger LOGGER = LoggerFactory.getLogger(CosmosSampleApplication.class);
public class CosmosDBSpringApplication implements CommandLineRunner {
private static final Logger LOGGER = LoggerFactory.getLogger(CosmosDBSpringApplication.class);

@Autowired
private UserRepository repository;

public static void main(String[] args) {
SpringApplication.run(CosmosSampleApplication.class, args);
SpringApplication.run(CosmosDBSpringApplication.class, args);
}

@Override
public void run(String... var1) {
this.repository.deleteAll().block();
this.repository.deleteAll();
LOGGER.info("Deleted all data in container.");

final User testUser = new User("testId", "testFirstName", "testLastName", "test address line one");

// Save the User class to Azure Cosmos DB database.
final Mono<User> saveUserMono = repository.save(testUser);

final Flux<User> firstNameUserFlux = repository.findByFirstName("testFirstName");
final User savedUser = repository.save(testUser);

// Nothing happens until we subscribe to these Monos.
// findById will not return the user as user is not present.
final Mono<User> findByIdMono = repository.findById(testUser.getId());
final User findByIdUser = findByIdMono.block();
Assert.isNull(findByIdUser, "User must be null");

final User savedUser = saveUserMono.block();
Assert.state(savedUser != null, "Saved user must not be null");
Assert.state(savedUser.getFirstName().equals(testUser.getFirstName()), "Saved user first name doesn't match");

firstNameUserFlux.collectList().block();

final Optional<User> optionalUserResult = repository.findById(testUser.getId()).blockOptional();
final Optional<User> optionalUserResult = repository.findById(testUser.getEmail());
Assert.isTrue(optionalUserResult.isPresent(), "Cannot find user.");

final User result = optionalUserResult.get();
Expand All @@ -60,3 +45,4 @@ public void run(String... var1) {
LOGGER.info("spring-cloud-azure-data-cosmos-sample successfully run.");
}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package spring.cloud.azure.starter.data.cosmos.sample.aks;
package spring.cloud.azure.starter.data.cosmos.sample;

import com.azure.cosmos.CosmosException;
import org.springframework.core.Ordered;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package spring.cloud.azure.starter.data.cosmos.sample.aks;
package spring.cloud.azure.starter.data.cosmos.sample;

import org.springframework.boot.context.properties.ConfigurationProperties;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package spring.cloud.azure.starter.data.cosmos.sample.aks;
package spring.cloud.azure.starter.data.cosmos.sample;

import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.DirectConnectionConfig;
Expand All @@ -16,7 +16,6 @@
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.lang.Nullable;

@Configuration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package spring.cloud.azure.starter.data.cosmos.sample.aks;
package spring.cloud.azure.starter.data.cosmos.sample;

import com.azure.spring.data.cosmos.core.mapping.Container;
import com.azure.spring.data.cosmos.core.mapping.PartitionKey;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package spring.cloud.azure.starter.data.cosmos.sample.aks;
package spring.cloud.azure.starter.data.cosmos.sample;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package spring.cloud.azure.starter.data.cosmos.sample.aks;
package spring.cloud.azure.starter.data.cosmos.sample;

import com.azure.spring.data.cosmos.repository.CosmosRepository;
import org.springframework.stereotype.Repository;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.