Updated term collection name, collection keyword with container name and container keyword

This commit is contained in:
Kushagra Thapar 2020-02-24 18:11:53 -08:00
Родитель 54a45fd5d7
Коммит 51ea47cd60
60 изменённых файлов: 429 добавлений и 335 удалений

Просмотреть файл

@ -45,7 +45,7 @@ spring-data-cosmosdb | [![Maven Central][Branch master Badge]][Branch master Lin
- annotate a field in domain class with `@Id`, this field will be mapped to document `id` in Cosmos DB.
- set name of this field to `id`, this field will be mapped to document `id` in Azure Cosmos DB.
- Custom collection Name.
By default, collection name will be class name of user domain class. To customize it, add the `@Document(collection="myCustomCollectionName")` annotation to the domain class. The collection field also supports SpEL expressions (eg. `collection = "${dynamic.collection.name}"` or `collection = "#{@someBean.getCollectionName()}"`) in order to provide collection names programmatically/via configuration properties.
By default, collection name will be class name of user domain class. To customize it, add the `@Document(collection="myCustomCollectionName")` annotation to the domain class. The collection field also supports SpEL expressions (eg. `collection = "${dynamic.collection.name}"` or `collection = "#{@someBean.getContainerName()}"`) in order to provide collection names programmatically/via configuration properties.
- Custom IndexingPolicy
By default, IndexingPolicy will be set by azure service. To customize it add annotation `@DocumentIndexingPolicy` to domain class. This annotation has 4 attributes to customize, see following:
```java

Просмотреть файл

@ -58,7 +58,7 @@
<gson.version>2.8.4</gson.version>
<project.reactor.test.version>3.3.0.RELEASE</project.reactor.test.version>
<azure.cosmos.version>3.6.0</azure.cosmos.version>
<azure.cosmos.version>3.7.0</azure.cosmos.version>
<azure.test.resourcegroup>spring-data-cosmosdb-test</azure.test.resourcegroup>
<azure.test.dbname>testdb-${maven.build.timestamp}</azure.test.dbname>
<skip.integration.tests>true</skip.integration.tests>

Просмотреть файл

@ -18,7 +18,7 @@ public class Constants {
public static final IndexingMode DEFAULT_INDEXINGPOLICY_MODE = IndexingMode.CONSISTENT;
public static final String DEFAULT_REPOSITORY_IMPLEMENT_POSTFIX = "Impl";
public static final int DEFAULT_TIME_TO_LIVE = -1; // Indicates never expire
public static final boolean DEFAULT_AUTO_CREATE_COLLECTION = true;
public static final boolean DEFAULT_AUTO_CREATE_CONTAINER = true;
public static final String ID_PROPERTY_NAME = "id";

Просмотреть файл

@ -11,8 +11,6 @@ import java.util.function.Function;
/**
* Memoize function computation results
* @author Domenico Sibilio
*
*/
public class Memoizer<I, O> {

Просмотреть файл

@ -18,49 +18,72 @@ import java.util.List;
public interface CosmosOperations {
/**
* Use getContainerName() instead
* @param domainType class type
* @return container name
*/
@Deprecated
String getCollectionName(Class<?> domainType);
String getContainerName(Class<?> domainType);
/**
* Use createContainerIfNotExists() instead
* @param information cosmos entity information
* @return created container properties
*/
@Deprecated
CosmosContainerProperties createCollectionIfNotExists(CosmosEntityInformation<?, ?> information);
CosmosContainerProperties createContainerIfNotExists(CosmosEntityInformation<?, ?> information);
<T> List<T> findAll(Class<T> domainType);
<T> List<T> findAll(String collectionName, Class<T> domainType);
<T> List<T> findAll(String containerName, Class<T> domainType);
<T> T findById(Object id, Class<T> domainType);
<T> T findById(String collectionName, Object id, Class<T> domainType);
<T> T findById(String containerName, Object id, Class<T> domainType);
<T> T findById(Object id, Class<T> domainType, PartitionKey partitionKey);
<T> T insert(T objectToSave, PartitionKey partitionKey);
<T> T insert(String collectionName, T objectToSave, PartitionKey partitionKey);
<T> T insert(String containerName, T objectToSave, PartitionKey partitionKey);
<T> void upsert(T object, PartitionKey partitionKey);
<T> void upsert(String collectionName, T object, PartitionKey partitionKey);
<T> void upsert(String containerName, T object, PartitionKey partitionKey);
void deleteById(String collectionName, Object id, PartitionKey partitionKey);
void deleteById(String containerName, Object id, PartitionKey partitionKey);
void deleteAll(String collectionName, Class<?> domainType);
void deleteAll(String containerName, Class<?> domainType);
void deleteCollection(String collectionName);
/**
* Use deleteContainer() instead
* @param containerName container name
*/
@Deprecated
void deleteCollection(String containerName);
<T> List<T> delete(DocumentQuery query, Class<T> domainType, String collectionName);
void deleteContainer(String containerName);
<T> List<T> find(DocumentQuery query, Class<T> domainType, String collectionName);
<T> List<T> delete(DocumentQuery query, Class<T> domainType, String containerName);
<T, ID> List<T> findByIds(Iterable<ID> ids, Class<T> domainType, String collectionName);
<T> List<T> find(DocumentQuery query, Class<T> domainType, String containerName);
<T> Boolean exists(DocumentQuery query, Class<T> domainType, String collectionName);
<T, ID> List<T> findByIds(Iterable<ID> ids, Class<T> domainType, String containerName);
<T> Page<T> findAll(Pageable pageable, Class<T> domainType, String collectionName);
<T> Boolean exists(DocumentQuery query, Class<T> domainType, String containerName);
<T> Page<T> paginationQuery(DocumentQuery query, Class<T> domainType, String collectionName);
<T> Page<T> findAll(Pageable pageable, Class<T> domainType, String containerName);
long count(String collectionName);
<T> Page<T> paginationQuery(DocumentQuery query, Class<T> domainType, String containerName);
<T> long count(DocumentQuery query, Class<T> domainType, String collectionName);
long count(String containerName);
<T> long count(DocumentQuery query, Class<T> domainType, String containerName);
MappingCosmosConverter getConverter();
}

Просмотреть файл

@ -86,16 +86,16 @@ public class CosmosTemplate implements CosmosOperations, ApplicationContextAware
public <T> T insert(T objectToSave, PartitionKey partitionKey) {
Assert.notNull(objectToSave, "domainType should not be null");
return insert(getCollectionName(objectToSave.getClass()), objectToSave, partitionKey);
return insert(getContainerName(objectToSave.getClass()), objectToSave, partitionKey);
}
public <T> T insert(String collectionName, T objectToSave, PartitionKey partitionKey) {
Assert.hasText(collectionName, "collectionName should not be null, empty or only whitespaces");
public <T> T insert(String containerName, T objectToSave, PartitionKey partitionKey) {
Assert.hasText(containerName, "containerName should not be null, empty or only whitespaces");
Assert.notNull(objectToSave, "objectToSave should not be null");
final CosmosItemProperties originalItem = mappingCosmosConverter.writeCosmosItemProperties(objectToSave);
log.debug("execute createItem in database {} collection {}", this.databaseName, collectionName);
log.debug("execute createItem in database {} container {}", this.databaseName, containerName);
final CosmosItemRequestOptions options = new CosmosItemRequestOptions();
options.partitionKey(partitionKey);
@ -105,7 +105,7 @@ public class CosmosTemplate implements CosmosOperations, ApplicationContextAware
final CosmosItemResponse response = cosmosClient
.getDatabase(this.databaseName)
.getContainer(collectionName)
.getContainer(containerName)
.createItem(originalItem, options)
.doOnNext(cosmosItemResponse -> fillAndProcessResponseDiagnostics(responseDiagnosticsProcessor,
cosmosItemResponse, null))
@ -120,7 +120,7 @@ public class CosmosTemplate implements CosmosOperations, ApplicationContextAware
public <T> T findById(Object id, Class<T> domainType) {
Assert.notNull(domainType, "domainType should not be null");
return findById(getCollectionName(domainType), id, domainType);
return findById(getContainerName(domainType), id, domainType);
}
@Override
@ -129,10 +129,10 @@ public class CosmosTemplate implements CosmosOperations, ApplicationContextAware
Assert.notNull(partitionKey, "partitionKey should not be null");
assertValidId(id);
final String collectionName = getCollectionName(domainType);
final String containerName = getContainerName(domainType);
return cosmosClient
.getDatabase(databaseName)
.getContainer(collectionName)
.getContainer(containerName)
.getItem(id.toString(), partitionKey)
.read()
.flatMap(cosmosItemResponse -> {
@ -146,8 +146,8 @@ public class CosmosTemplate implements CosmosOperations, ApplicationContextAware
.block();
}
public <T> T findById(String collectionName, Object id, Class<T> domainType) {
Assert.hasText(collectionName, "collectionName should not be null, empty or only whitespaces");
public <T> T findById(String containerName, Object id, Class<T> domainType) {
Assert.hasText(containerName, "containerName should not be null, empty or only whitespaces");
Assert.notNull(domainType, "domainType should not be null");
assertValidId(id);
@ -157,7 +157,7 @@ public class CosmosTemplate implements CosmosOperations, ApplicationContextAware
options.populateQueryMetrics(isPopulateQueryMetrics);
return cosmosClient
.getDatabase(databaseName)
.getContainer(collectionName)
.getContainer(containerName)
.queryItems(query, options)
.flatMap(cosmosItemFeedResponse -> {
fillAndProcessResponseDiagnostics(responseDiagnosticsProcessor,
@ -176,16 +176,16 @@ public class CosmosTemplate implements CosmosOperations, ApplicationContextAware
public <T> void upsert(T object, PartitionKey partitionKey) {
Assert.notNull(object, "Upsert object should not be null");
upsert(getCollectionName(object.getClass()), object, partitionKey);
upsert(getContainerName(object.getClass()), object, partitionKey);
}
public <T> void upsert(String collectionName, T object, PartitionKey partitionKey) {
Assert.hasText(collectionName, "collectionName should not be null, empty or only whitespaces");
public <T> void upsert(String containerName, T object, PartitionKey partitionKey) {
Assert.hasText(containerName, "containerName should not be null, empty or only whitespaces");
Assert.notNull(object, "Upsert object should not be null");
final CosmosItemProperties originalItem = mappingCosmosConverter.writeCosmosItemProperties(object);
log.debug("execute upsert item in database {} collection {}", this.databaseName, collectionName);
log.debug("execute upsert item in database {} container {}", this.databaseName, containerName);
final CosmosItemRequestOptions options = new CosmosItemRequestOptions();
options.partitionKey(partitionKey);
@ -193,7 +193,7 @@ public class CosmosTemplate implements CosmosOperations, ApplicationContextAware
final CosmosItemResponse cosmosItemResponse = cosmosClient
.getDatabase(this.databaseName)
.getContainer(collectionName)
.getContainer(containerName)
.upsertItem(originalItem, options)
.doOnNext(response -> fillAndProcessResponseDiagnostics(responseDiagnosticsProcessor,
response, null))
@ -206,77 +206,92 @@ public class CosmosTemplate implements CosmosOperations, ApplicationContextAware
public <T> List<T> findAll(Class<T> domainType) {
Assert.notNull(domainType, "domainType should not be null");
return findAll(getCollectionName(domainType), domainType);
return findAll(getContainerName(domainType), domainType);
}
public <T> List<T> findAll(String collectionName, final Class<T> domainType) {
Assert.hasText(collectionName, "collectionName should not be null, empty or only whitespaces");
public <T> List<T> findAll(String containerName, final Class<T> domainType) {
Assert.hasText(containerName, "containerName should not be null, empty or only whitespaces");
Assert.notNull(domainType, "domainType should not be null");
final DocumentQuery query = new DocumentQuery(Criteria.getInstance(CriteriaType.ALL));
final List<CosmosItemProperties> items = findItems(query, domainType, collectionName);
final List<CosmosItemProperties> items = findItems(query, domainType, containerName);
return items.stream()
.map(d -> getConverter().read(domainType, d))
.collect(Collectors.toList());
}
public void deleteAll(@NonNull String collectionName, @NonNull Class<?> domainType) {
Assert.hasText(collectionName, "collectionName should not be null, empty or only whitespaces");
public void deleteAll(@NonNull String containerName, @NonNull Class<?> domainType) {
Assert.hasText(containerName, "containerName should not be null, empty or only whitespaces");
final DocumentQuery query = new DocumentQuery(Criteria.getInstance(CriteriaType.ALL));
this.delete(query, domainType, collectionName);
this.delete(query, domainType, containerName);
}
@Override
public void deleteCollection(@NonNull String collectionName) {
Assert.hasText(collectionName, "collectionName should have text.");
public void deleteCollection(@NonNull String containerName) {
deleteContainer(containerName);
}
@Override
public void deleteContainer(@NonNull String containerName) {
Assert.hasText(containerName, "containerName should have text.");
cosmosClient.getDatabase(this.databaseName)
.getContainer(collectionName)
.getContainer(containerName)
.delete()
.doOnNext(response -> fillAndProcessResponseDiagnostics(responseDiagnosticsProcessor,
response, null))
.onErrorResume(throwable ->
exceptionHandler("Failed to delete collection", throwable))
exceptionHandler("Failed to delete container", throwable))
.block();
}
public String getCollectionName(Class<?> domainType) {
return getContainerName(domainType);
}
@Override
public String getContainerName(Class<?> domainType) {
Assert.notNull(domainType, "domainType should not be null");
return entityInfoCreator.apply(domainType).getCollectionName();
return entityInfoCreator.apply(domainType).getContainerName();
}
@Override
public CosmosContainerProperties createCollectionIfNotExists(@NonNull CosmosEntityInformation<?, ?> information) {
return createContainerIfNotExists(information);
}
@Override
public CosmosContainerProperties createContainerIfNotExists(CosmosEntityInformation<?, ?> information) {
final CosmosContainerResponse response = cosmosClient
.createDatabaseIfNotExists(this.databaseName)
.onErrorResume(throwable ->
exceptionHandler("Failed to create database", throwable))
.flatMap(cosmosDatabaseResponse -> {
fillAndProcessResponseDiagnostics(responseDiagnosticsProcessor,
cosmosDatabaseResponse, null);
return cosmosDatabaseResponse
.database()
.createContainerIfNotExists(information.getCollectionName(),
"/" + information.getPartitionKeyFieldName(), information.getRequestUnit())
.onErrorResume(throwable ->
exceptionHandler("Failed to create container", throwable))
.doOnNext(cosmosContainerResponse ->
fillAndProcessResponseDiagnostics(responseDiagnosticsProcessor,
cosmosContainerResponse, null));
})
.block();
.createDatabaseIfNotExists(this.databaseName)
.onErrorResume(throwable ->
exceptionHandler("Failed to create database", throwable))
.flatMap(cosmosDatabaseResponse -> {
fillAndProcessResponseDiagnostics(responseDiagnosticsProcessor,
cosmosDatabaseResponse, null);
return cosmosDatabaseResponse
.database()
.createContainerIfNotExists(information.getContainerName(),
"/" + information.getPartitionKeyFieldName(), information.getRequestUnit())
.onErrorResume(throwable ->
exceptionHandler("Failed to create container", throwable))
.doOnNext(cosmosContainerResponse ->
fillAndProcessResponseDiagnostics(responseDiagnosticsProcessor,
cosmosContainerResponse, null));
})
.block();
assert response != null;
return response.properties();
}
public void deleteById(String collectionName, Object id, PartitionKey partitionKey) {
Assert.hasText(collectionName, "collectionName should not be null, empty or only whitespaces");
public void deleteById(String containerName, Object id, PartitionKey partitionKey) {
Assert.hasText(containerName, "containerName should not be null, empty or only whitespaces");
assertValidId(id);
log.debug("execute deleteById in database {} container {}", this.databaseName, collectionName);
log.debug("execute deleteById in database {} container {}", this.databaseName, containerName);
if (partitionKey == null) {
partitionKey = PartitionKey.None;
@ -284,7 +299,7 @@ public class CosmosTemplate implements CosmosOperations, ApplicationContextAware
final CosmosItemRequestOptions options = new CosmosItemRequestOptions();
options.partitionKey(partitionKey);
cosmosClient.getDatabase(this.databaseName)
.getContainer(collectionName)
.getContainer(containerName)
.getItem(id.toString(), partitionKey)
.delete(options)
.doOnNext(response -> fillAndProcessResponseDiagnostics(responseDiagnosticsProcessor,
@ -295,29 +310,29 @@ public class CosmosTemplate implements CosmosOperations, ApplicationContextAware
}
@Override
public <T, ID> List<T> findByIds(Iterable<ID> ids, Class<T> domainType, String collectionName) {
public <T, ID> List<T> findByIds(Iterable<ID> ids, Class<T> domainType, String containerName) {
Assert.notNull(ids, "Id list should not be null");
Assert.notNull(domainType, "domainType should not be null.");
Assert.hasText(collectionName, "collection should not be null, empty or only whitespaces");
Assert.hasText(containerName, "container should not be null, empty or only whitespaces");
final DocumentQuery query = new DocumentQuery(Criteria.getInstance(CriteriaType.IN, "id",
Collections.singletonList(ids)));
return find(query, domainType, collectionName);
return find(query, domainType, containerName);
}
public <T> List<T> find(@NonNull DocumentQuery query, @NonNull Class<T> domainType, String collectionName) {
public <T> List<T> find(@NonNull DocumentQuery query, @NonNull Class<T> domainType, String containerName) {
Assert.notNull(query, "DocumentQuery should not be null.");
Assert.notNull(domainType, "domainType should not be null.");
Assert.hasText(collectionName, "container should not be null, empty or only whitespaces");
Assert.hasText(containerName, "container should not be null, empty or only whitespaces");
return findItems(query, domainType, collectionName)
return findItems(query, domainType, containerName)
.stream()
.map(cosmosItemProperties -> toDomainObject(domainType, cosmosItemProperties))
.collect(Collectors.toList());
}
public <T> Boolean exists(@NonNull DocumentQuery query, @NonNull Class<T> domainType, String collectionName) {
return this.find(query, domainType, collectionName).size() > 0;
public <T> Boolean exists(@NonNull DocumentQuery query, @NonNull Class<T> domainType, String containerName) {
return this.find(query, domainType, containerName).size() > 0;
}
/**
@ -327,41 +342,41 @@ public class CosmosTemplate implements CosmosOperations, ApplicationContextAware
*
* @param query The representation for query method.
* @param domainType Class of domain
* @param collectionName Container name of database
* @param containerName Container name of database
* @param <T>
* @return All the deleted items as List.
*/
@Override
public <T> List<T> delete(@NonNull DocumentQuery query, @NonNull Class<T> domainType,
@NonNull String collectionName) {
@NonNull String containerName) {
Assert.notNull(query, "DocumentQuery should not be null.");
Assert.notNull(domainType, "domainType should not be null.");
Assert.hasText(collectionName, "container should not be null, empty or only whitespaces");
Assert.hasText(containerName, "container should not be null, empty or only whitespaces");
final List<CosmosItemProperties> results = findItems(query, domainType, collectionName);
final List<CosmosItemProperties> results = findItems(query, domainType, containerName);
final List<String> partitionKeyName = getPartitionKeyNames(domainType);
return results.stream().map(cosmosItemProperties -> {
final CosmosItemResponse cosmosItemResponse = deleteItem(cosmosItemProperties,
partitionKeyName, collectionName, domainType);
partitionKeyName, containerName, domainType);
return getConverter().read(domainType, cosmosItemResponse.properties());
}).collect(Collectors.toList());
}
@Override
public <T> Page<T> findAll(Pageable pageable, Class<T> domainType, String collectionName) {
public <T> Page<T> findAll(Pageable pageable, Class<T> domainType, String containerName) {
final DocumentQuery query = new DocumentQuery(Criteria.getInstance(CriteriaType.ALL)).with(pageable);
if (pageable.getSort().isSorted()) {
query.with(pageable.getSort());
}
return paginationQuery(query, domainType, collectionName);
return paginationQuery(query, domainType, containerName);
}
@Override
public <T> Page<T> paginationQuery(DocumentQuery query, Class<T> domainType, String collectionName) {
public <T> Page<T> paginationQuery(DocumentQuery query, Class<T> domainType, String containerName) {
Assert.isTrue(query.getPageable().getPageSize() > 0, "pageable should have page size larger than 0");
Assert.hasText(collectionName, "container should not be null, empty or only whitespaces");
Assert.hasText(containerName, "container should not be null, empty or only whitespaces");
final Pageable pageable = query.getPageable();
final FeedOptions feedOptions = new FeedOptions();
@ -376,7 +391,7 @@ public class CosmosTemplate implements CosmosOperations, ApplicationContextAware
final SqlQuerySpec sqlQuerySpec = new FindQuerySpecGenerator().generateCosmos(query);
final FeedResponse<CosmosItemProperties> feedResponse = cosmosClient
.getDatabase(this.databaseName)
.getContainer(collectionName)
.getContainer(containerName)
.queryItems(sqlQuerySpec, feedOptions)
.doOnNext(propertiesFeedResponse -> fillAndProcessResponseDiagnostics(responseDiagnosticsProcessor,
null, propertiesFeedResponse))
@ -400,7 +415,7 @@ public class CosmosTemplate implements CosmosOperations, ApplicationContextAware
result.add(entity);
}
final long total = count(query, domainType, collectionName);
final long total = count(query, domainType, containerName);
final int contentSize = result.size();
int pageSize;
@ -426,23 +441,23 @@ public class CosmosTemplate implements CosmosOperations, ApplicationContextAware
}
@Override
public long count(String collectionName) {
Assert.hasText(collectionName, "container name should not be empty");
public long count(String containerName) {
Assert.hasText(containerName, "container name should not be empty");
final DocumentQuery query = new DocumentQuery(Criteria.getInstance(CriteriaType.ALL));
final Long count = getCountValue(query, true, collectionName);
final Long count = getCountValue(query, true, containerName);
assert count != null;
return count;
}
@Override
public <T> long count(DocumentQuery query, Class<T> domainType, String collectionName) {
public <T> long count(DocumentQuery query, Class<T> domainType, String containerName) {
Assert.notNull(domainType, "domainType should not be null");
Assert.hasText(collectionName, "container name should not be empty");
Assert.hasText(containerName, "container name should not be empty");
final boolean isCrossPartitionQuery =
query.isCrossPartitionQuery(getPartitionKeyNames(domainType));
final Long count = getCountValue(query, isCrossPartitionQuery, collectionName);
final Long count = getCountValue(query, isCrossPartitionQuery, containerName);
assert count != null;
return count;
}
@ -469,10 +484,10 @@ public class CosmosTemplate implements CosmosOperations, ApplicationContextAware
.block();
}
private Flux<FeedResponse<CosmosItemProperties>> executeQuery(SqlQuerySpec sqlQuerySpec, String collectionName,
private Flux<FeedResponse<CosmosItemProperties>> executeQuery(SqlQuerySpec sqlQuerySpec, String containerName,
FeedOptions options) {
return cosmosClient.getDatabase(this.databaseName)
.getContainer(collectionName)
.getContainer(containerName)
.queryItems(sqlQuerySpec, options)
.onErrorResume(throwable ->
exceptionHandler("Failed to execute query", throwable));

Просмотреть файл

@ -18,41 +18,49 @@ public interface ReactiveCosmosOperations {
String getContainerName(Class<?> domainType);
/**
* Use createContainerIfNotExists() instead
* @param information cosmos entity information
* @return Mono of cosmos container response
*/
@Deprecated
Mono<CosmosContainerResponse> createCollectionIfNotExists(CosmosEntityInformation information);
<T> Flux<T> findAll(String collectionName, Class<T> domainType);
Mono<CosmosContainerResponse> createContainerIfNotExists(CosmosEntityInformation information);
<T> Flux<T> findAll(String containerName, Class<T> domainType);
<T> Flux<T> findAll(Class<T> domainType);
<T> Mono<T> findById(Object id, Class<T> domainType);
<T> Mono<T> findById(String collectionName, Object id, Class<T> domainType);
<T> Mono<T> findById(String containerName, Object id, Class<T> domainType);
<T> Mono<T> findById(Object id, Class<T> domainType, PartitionKey partitionKey);
<T> Mono<T> insert(T objectToSave, PartitionKey partitionKey);
<T> Mono<T> insert(String collectionName, Object objectToSave, PartitionKey partitionKey);
<T> Mono<T> insert(String containerName, Object objectToSave, PartitionKey partitionKey);
<T> Mono<T> upsert(T object, PartitionKey partitionKey);
<T> Mono<T> upsert(String collectionName, T object, PartitionKey partitionKey);
<T> Mono<T> upsert(String containerName, T object, PartitionKey partitionKey);
Mono<Void> deleteById(String collectionName, Object id, PartitionKey partitionKey);
Mono<Void> deleteById(String containerName, Object id, PartitionKey partitionKey);
Mono<Void> deleteAll(String collectionName, String partitionKey);
Mono<Void> deleteAll(String containerName, String partitionKey);
void deleteContainer(String collectionName);
void deleteContainer(String containerName);
<T> Flux<T> delete(DocumentQuery query, Class<T> domainType, String collectionName);
<T> Flux<T> delete(DocumentQuery query, Class<T> domainType, String containerName);
<T> Flux<T> find(DocumentQuery query, Class<T> domainType, String collectionName);
<T> Flux<T> find(DocumentQuery query, Class<T> domainType, String containerName);
Mono<Boolean> exists(DocumentQuery query, Class<?> domainType, String collectionName);
Mono<Boolean> exists(DocumentQuery query, Class<?> domainType, String containerName);
Mono<Boolean> existsById(Object id, Class<?> domainType, String containerName);
Mono<Long> count(String collectionName);
Mono<Long> count(String containerName);
Mono<Long> count(DocumentQuery query, String containerName);

Просмотреть файл

@ -58,7 +58,7 @@ public class ReactiveCosmosTemplate implements ReactiveCosmosOperations, Applica
private Function<Class<?>, CosmosEntityInformation<?, ?>> entityInfoCreator =
Memoizer.memoize(this::getCosmosEntityInformation);
private final List<String> collectionCache;
private final List<String> containerNameCache;
/**
* Constructor
@ -75,7 +75,7 @@ public class ReactiveCosmosTemplate implements ReactiveCosmosOperations, Applica
this.mappingCosmosConverter = mappingCosmosConverter;
this.databaseName = dbName;
this.collectionCache = new ArrayList<>();
this.containerNameCache = new ArrayList<>();
this.cosmosClient = cosmosDbFactory.getCosmosClient();
this.responseDiagnosticsProcessor = cosmosDbFactory.getConfig().getResponseDiagnosticsProcessor();
@ -91,13 +91,24 @@ public class ReactiveCosmosTemplate implements ReactiveCosmosOperations, Applica
}
/**
* Creates a collection if it doesn't already exist
* Creates a container if it doesn't already exist
*
* @param information the CosmosEntityInformation
* @return Mono containing CosmosContainerResponse
*/
@Override
public Mono<CosmosContainerResponse> createCollectionIfNotExists(CosmosEntityInformation information) {
return createContainerIfNotExists(information);
}
/**
* Creates a container if it doesn't already exist
*
* @param information the CosmosEntityInformation
* @return Mono containing CosmosContainerResponse
*/
@Override
public Mono<CosmosContainerResponse> createContainerIfNotExists(CosmosEntityInformation information) {
return cosmosClient
.createDatabaseIfNotExists(this.databaseName)
@ -108,16 +119,16 @@ public class ReactiveCosmosTemplate implements ReactiveCosmosOperations, Applica
cosmosDatabaseResponse, null);
return cosmosDatabaseResponse
.database()
.createContainerIfNotExists(information.getCollectionName(),
.createContainerIfNotExists(information.getContainerName(),
"/" + information.getPartitionKeyFieldName(), information.getRequestUnit())
.map(cosmosContainerResponse -> {
fillAndProcessResponseDiagnostics(responseDiagnosticsProcessor,
cosmosContainerResponse, null);
this.collectionCache.add(information.getCollectionName());
this.containerNameCache.add(information.getContainerName());
return cosmosContainerResponse;
})
.onErrorResume(throwable ->
exceptionHandler("Failed to create collection", throwable));
exceptionHandler("Failed to create container", throwable));
});
}
@ -170,7 +181,7 @@ public class ReactiveCosmosTemplate implements ReactiveCosmosOperations, Applica
*/
@Override
public <T> Mono<T> findById(String containerName, Object id, Class<T> domainType) {
Assert.hasText(containerName, "collectionName should not be null, empty or only whitespaces");
Assert.hasText(containerName, "containerName should not be null, empty or only whitespaces");
Assert.notNull(domainType, "domainType should not be null");
assertValidId(id);
@ -515,11 +526,11 @@ public class ReactiveCosmosTemplate implements ReactiveCosmosOperations, Applica
.map(r -> r.results().get(0).getLong(COUNT_VALUE_KEY));
}
private Flux<FeedResponse<CosmosItemProperties>> executeQuery(SqlQuerySpec sqlQuerySpec, String collectionName,
private Flux<FeedResponse<CosmosItemProperties>> executeQuery(SqlQuerySpec sqlQuerySpec, String containerName,
FeedOptions options) {
return cosmosClient.getDatabase(this.databaseName)
.getContainer(collectionName)
.getContainer(containerName)
.queryItems(sqlQuerySpec, options)
.onErrorResume(throwable ->
exceptionHandler("Failed to execute query", throwable));
@ -542,7 +553,7 @@ public class ReactiveCosmosTemplate implements ReactiveCosmosOperations, Applica
.onErrorResume(throwable ->
exceptionHandler("Failed to delete container", throwable))
.block();
this.collectionCache.remove(containerName);
this.containerNameCache.remove(containerName);
}
/**
@ -552,7 +563,7 @@ public class ReactiveCosmosTemplate implements ReactiveCosmosOperations, Applica
public String getContainerName(Class<?> domainType) {
Assert.notNull(domainType, "domainType should not be null");
return entityInfoCreator.apply(domainType).getCollectionName();
return entityInfoCreator.apply(domainType).getContainerName();
}
private Flux<CosmosItemProperties> findItems(@NonNull DocumentQuery query, @NonNull Class<?> domainType,

Просмотреть файл

@ -36,6 +36,11 @@ public class BasicCosmosPersistentEntity<T> extends BasicPersistentEntity<T, Cos
return "";
}
@Override
public String getContainer() {
return "";
}
@Override
public String getLanguage() {
return "";

Просмотреть файл

@ -11,7 +11,10 @@ import org.springframework.data.mapping.PersistentEntity;
public interface CosmosPersistentEntity<T> extends PersistentEntity<T, CosmosPersistentProperty> {
@Deprecated
String getCollection();
String getContainer();
String getLanguage();
}

Просмотреть файл

@ -22,5 +22,5 @@ public @interface Document {
int timeToLive() default Constants.DEFAULT_TIME_TO_LIVE;
boolean autoCreateCollection() default Constants.DEFAULT_AUTO_CREATE_COLLECTION;
boolean autoCreateCollection() default Constants.DEFAULT_AUTO_CREATE_CONTAINER;
}

Просмотреть файл

@ -25,10 +25,10 @@ public abstract class AbstractCosmosQuery implements RepositoryQuery {
final DocumentQuery query = createQuery(accessor);
final ResultProcessor processor = method.getResultProcessor().withDynamicProjection(accessor);
final String collection = ((CosmosEntityMetadata) method.getEntityInformation()).getCollectionName();
final String container = ((CosmosEntityMetadata) method.getEntityInformation()).getContainerName();
final CosmosQueryExecution execution = getExecution(accessor);
return execution.execute(query, processor.getReturnedType().getDomainType(), collection);
return execution.execute(query, processor.getReturnedType().getDomainType(), container);
}

Просмотреть файл

@ -28,11 +28,11 @@ public abstract class AbstractReactiveCosmosQuery implements RepositoryQuery {
final ResultProcessor processor =
method.getResultProcessor().withDynamicProjection(accessor);
final String collection =
((ReactiveCosmosEntityMetadata) method.getEntityInformation()).getCollectionName();
final String containerName =
((ReactiveCosmosEntityMetadata) method.getEntityInformation()).getContainerName();
final ReactiveCosmosQueryExecution execution = getExecution(accessor);
return execution.execute(query, processor.getReturnedType().getDomainType(), collection);
return execution.execute(query, processor.getReturnedType().getDomainType(), containerName);
}

Просмотреть файл

@ -7,6 +7,14 @@ package com.microsoft.azure.spring.data.cosmosdb.repository.query;
import org.springframework.data.repository.core.EntityMetadata;
public interface CosmosEntityMetadata<T> extends EntityMetadata {
public interface CosmosEntityMetadata<T> extends EntityMetadata<T> {
/**
* Use getContainerName() instead
* @return container name
*/
@Deprecated
String getCollectionName();
String getContainerName();
}

Просмотреть файл

@ -11,19 +11,19 @@ import com.microsoft.azure.spring.data.cosmosdb.core.query.DocumentQuery;
import org.springframework.data.domain.Pageable;
public interface CosmosQueryExecution {
Object execute(DocumentQuery query, Class<?> type, String collection);
Object execute(DocumentQuery query, Class<?> type, String container);
final class CollectionExecution implements CosmosQueryExecution {
final class ContainerExecution implements CosmosQueryExecution {
private final CosmosOperations operations;
public CollectionExecution(CosmosOperations operations) {
public ContainerExecution(CosmosOperations operations) {
this.operations = operations;
}
@Override
public Object execute(DocumentQuery query, Class<?> type, String collection) {
return operations.getCollectionName(type);
public Object execute(DocumentQuery query, Class<?> type, String container) {
return operations.getContainerName(type);
}
}
@ -36,8 +36,8 @@ public interface CosmosQueryExecution {
}
@Override
public Object execute(DocumentQuery query, Class<?> type, String collection) {
return operations.find(query, type, collection);
public Object execute(DocumentQuery query, Class<?> type, String container) {
return operations.find(query, type, container);
}
}
@ -50,8 +50,8 @@ public interface CosmosQueryExecution {
}
@Override
public Object execute(DocumentQuery query, Class<?> type, String collection) {
return operations.exists(query, type, collection);
public Object execute(DocumentQuery query, Class<?> type, String container) {
return operations.exists(query, type, container);
}
}
@ -64,8 +64,8 @@ public interface CosmosQueryExecution {
}
@Override
public Object execute(DocumentQuery query, Class<?> type, String collection) {
return operations.delete(query, type, collection);
public Object execute(DocumentQuery query, Class<?> type, String container) {
return operations.delete(query, type, container);
}
}
@ -79,7 +79,7 @@ public interface CosmosQueryExecution {
}
@Override
public Object execute(DocumentQuery query, Class<?> type, String collection) {
public Object execute(DocumentQuery query, Class<?> type, String container) {
if (pageable.getPageNumber() != 0 && !(pageable instanceof CosmosPageRequest)) {
throw new IllegalStateException("Not the first page but Pageable is not a valid " +
"CosmosPageRequest, requestContinuation is required for non first page request");
@ -87,7 +87,7 @@ public interface CosmosQueryExecution {
query.with(pageable);
return operations.paginationQuery(query, type, collection);
return operations.paginationQuery(query, type, container);
}
}
}

Просмотреть файл

@ -8,5 +8,8 @@ package com.microsoft.azure.spring.data.cosmosdb.repository.query;
import org.springframework.data.repository.core.EntityMetadata;
public interface ReactiveCosmosEntityMetadata<T> extends EntityMetadata {
@Deprecated
String getCollectionName();
String getContainerName();
}

Просмотреть файл

@ -9,18 +9,18 @@ import com.microsoft.azure.spring.data.cosmosdb.core.ReactiveCosmosOperations;
import com.microsoft.azure.spring.data.cosmosdb.core.query.DocumentQuery;
public interface ReactiveCosmosQueryExecution {
Object execute(DocumentQuery query, Class<?> type, String collection);
Object execute(DocumentQuery query, Class<?> type, String container);
final class CollectionExecution implements ReactiveCosmosQueryExecution {
final class ContainerExecution implements ReactiveCosmosQueryExecution {
private final ReactiveCosmosOperations operations;
public CollectionExecution(ReactiveCosmosOperations operations) {
public ContainerExecution(ReactiveCosmosOperations operations) {
this.operations = operations;
}
@Override
public Object execute(DocumentQuery query, Class<?> type, String collection) {
public Object execute(DocumentQuery query, Class<?> type, String container) {
return operations.getContainerName(type);
}
}
@ -34,8 +34,8 @@ public interface ReactiveCosmosQueryExecution {
}
@Override
public Object execute(DocumentQuery query, Class<?> type, String collection) {
return operations.find(query, type, collection);
public Object execute(DocumentQuery query, Class<?> type, String container) {
return operations.find(query, type, container);
}
}
@ -48,8 +48,8 @@ public interface ReactiveCosmosQueryExecution {
}
@Override
public Object execute(DocumentQuery query, Class<?> type, String collection) {
return operations.exists(query, type, collection);
public Object execute(DocumentQuery query, Class<?> type, String container) {
return operations.exists(query, type, container);
}
}
@ -62,8 +62,8 @@ public interface ReactiveCosmosQueryExecution {
}
@Override
public Object execute(DocumentQuery query, Class<?> type, String collection) {
return operations.delete(query, type, collection);
public Object execute(DocumentQuery query, Class<?> type, String container) {
return operations.delete(query, type, container);
}
}
}

Просмотреть файл

@ -26,6 +26,10 @@ public class SimpleCosmosEntityMetadata<T> implements CosmosEntityMetadata<T> {
}
public String getCollectionName() {
return entityInformation.getCollectionName();
return entityInformation.getContainerName();
}
public String getContainerName() {
return entityInformation.getContainerName();
}
}

Просмотреть файл

@ -25,8 +25,13 @@ public class SimpleReactiveCosmosEntityMetadata<T> implements ReactiveCosmosEnti
public Class<T> getJavaType() {
return type;
}
public String getCollectionName() {
return entityInformation.getCollectionName();
return entityInformation.getContainerName();
}
@Override
public String getContainerName() {
return entityInformation.getContainerName();
}
}

Просмотреть файл

@ -35,12 +35,12 @@ public class CosmosEntityInformation<T, ID> extends AbstractEntityInformation<T,
private static final String ETAG = "_etag";
private Field id;
private Field partitionKeyField;
private String collectionName;
private String containerName;
private Integer requestUnit;
private Integer timeToLive;
private IndexingPolicy indexingPolicy;
private boolean isVersioned;
private boolean autoCreateCollection;
private boolean autoCreateContainer;
public CosmosEntityInformation(Class<T> domainType) {
super(domainType);
@ -48,7 +48,7 @@ public class CosmosEntityInformation<T, ID> extends AbstractEntityInformation<T,
this.id = getIdField(domainType);
ReflectionUtils.makeAccessible(this.id);
this.collectionName = getCollectionName(domainType);
this.containerName = getContainerName(domainType);
this.partitionKeyField = getPartitionKeyField(domainType);
if (this.partitionKeyField != null) {
ReflectionUtils.makeAccessible(this.partitionKeyField);
@ -58,7 +58,7 @@ public class CosmosEntityInformation<T, ID> extends AbstractEntityInformation<T,
this.timeToLive = getTimeToLive(domainType);
this.indexingPolicy = getIndexingPolicy(domainType);
this.isVersioned = getIsVersioned(domainType);
this.autoCreateCollection = getIsAutoCreateCollection(domainType);
this.autoCreateContainer = getIsAutoCreateContainer(domainType);
}
@SuppressWarnings("unchecked")
@ -75,8 +75,13 @@ public class CosmosEntityInformation<T, ID> extends AbstractEntityInformation<T,
return (Class<ID>) id.getType();
}
@Deprecated
public String getCollectionName() {
return this.collectionName;
return this.containerName;
}
public String getContainerName() {
return this.containerName;
}
public Integer getRequestUnit() {
@ -109,8 +114,13 @@ public class CosmosEntityInformation<T, ID> extends AbstractEntityInformation<T,
return partitionKeyField == null ? null : (String) ReflectionUtils.getField(partitionKeyField, entity);
}
@Deprecated
public boolean isAutoCreateCollection() {
return autoCreateCollection;
return autoCreateContainer;
}
public boolean isAutoCreateContainer() {
return autoCreateContainer;
}
private IndexingPolicy getIndexingPolicy(Class<?> domainType) {
@ -146,16 +156,16 @@ public class CosmosEntityInformation<T, ID> extends AbstractEntityInformation<T,
return idField;
}
private String getCollectionName(Class<?> domainType) {
String customCollectionName = domainType.getSimpleName();
private String getContainerName(Class<?> domainType) {
String customContainerName = domainType.getSimpleName();
final Document annotation = domainType.getAnnotation(Document.class);
if (annotation != null && annotation.collection() != null && !annotation.collection().isEmpty()) {
customCollectionName = resolveExpression(annotation.collection());
customContainerName = resolveExpression(annotation.collection());
}
return customCollectionName;
return customContainerName;
}
private Field getPartitionKeyField(Class<?> domainType) {
@ -261,15 +271,15 @@ public class CosmosEntityInformation<T, ID> extends AbstractEntityInformation<T,
&& findField.isAnnotationPresent(Version.class);
}
private boolean getIsAutoCreateCollection(Class<T> domainType) {
private boolean getIsAutoCreateContainer(Class<T> domainType) {
final Document annotation = domainType.getAnnotation(Document.class);
boolean autoCreateCollection = Constants.DEFAULT_AUTO_CREATE_COLLECTION;
boolean autoCreateContainer = Constants.DEFAULT_AUTO_CREATE_CONTAINER;
if (annotation != null) {
autoCreateCollection = annotation.autoCreateCollection();
autoCreateContainer = annotation.autoCreateCollection();
}
return autoCreateCollection;
return autoCreateContainer;
}
}

Просмотреть файл

@ -36,8 +36,8 @@ public class SimpleCosmosRepository<T, ID extends Serializable> implements Cosmo
this.operation = applicationContext.getBean(CosmosOperations.class);
this.information = metadata;
if (this.information.isAutoCreateCollection()) {
createCollectionIfNotExists();
if (this.information.isAutoCreateContainer()) {
createContainerIfNotExists();
}
}
@ -46,13 +46,13 @@ public class SimpleCosmosRepository<T, ID extends Serializable> implements Cosmo
this.operation = dbOperations;
this.information = metadata;
if (this.information.isAutoCreateCollection()) {
createCollectionIfNotExists();
if (this.information.isAutoCreateContainer()) {
createContainerIfNotExists();
}
}
private CosmosContainerProperties createCollectionIfNotExists() {
return this.operation.createCollectionIfNotExists(this.information);
private CosmosContainerProperties createContainerIfNotExists() {
return this.operation.createContainerIfNotExists(this.information);
}
/**
@ -68,11 +68,11 @@ public class SimpleCosmosRepository<T, ID extends Serializable> implements Cosmo
// save entity
if (information.isNew(entity)) {
return operation.insert(information.getCollectionName(),
return operation.insert(information.getContainerName(),
entity,
createKey(information.getPartitionKeyFieldValue(entity)));
} else {
operation.upsert(information.getCollectionName(),
operation.upsert(information.getContainerName(),
entity, createKey(information.getPartitionKeyFieldValue(entity)));
}
@ -104,17 +104,17 @@ public class SimpleCosmosRepository<T, ID extends Serializable> implements Cosmo
}
/**
* find all entities from one collection without configuring partition key value
* find all entities from one container without configuring partition key value
*
* @return
*/
@Override
public Iterable<T> findAll() {
return operation.findAll(information.getCollectionName(), information.getJavaType());
return operation.findAll(information.getContainerName(), information.getJavaType());
}
/**
* find entities based on id list from one collection without partitions
* find entities based on id list from one container without partitions
*
* @param ids
* @return
@ -123,7 +123,7 @@ public class SimpleCosmosRepository<T, ID extends Serializable> implements Cosmo
public List<T> findAllById(Iterable<ID> ids) {
Assert.notNull(ids, "Iterable ids should not be null");
return operation.findByIds(ids, information.getJavaType(), information.getCollectionName());
return operation.findByIds(ids, information.getJavaType(), information.getContainerName());
}
/**
@ -140,7 +140,7 @@ public class SimpleCosmosRepository<T, ID extends Serializable> implements Cosmo
return Optional.empty();
}
return Optional.ofNullable(operation.findById(information.getCollectionName(), id, information.getJavaType()));
return Optional.ofNullable(operation.findById(information.getContainerName(), id, information.getJavaType()));
}
@Override
@ -155,13 +155,13 @@ public class SimpleCosmosRepository<T, ID extends Serializable> implements Cosmo
}
/**
* return count of documents in one collection without partitions
* return count of documents in one container without partitions
*
* @return
*/
@Override
public long count() {
return operation.count(information.getCollectionName());
return operation.count(information.getContainerName());
}
/**
@ -173,7 +173,7 @@ public class SimpleCosmosRepository<T, ID extends Serializable> implements Cosmo
public void deleteById(ID id) {
Assert.notNull(id, "id to be deleted should not be null");
operation.deleteById(information.getCollectionName(), id, null);
operation.deleteById(information.getContainerName(), id, null);
}
@Override
@ -181,7 +181,7 @@ public class SimpleCosmosRepository<T, ID extends Serializable> implements Cosmo
Assert.notNull(id, "id to be deleted should not be null");
Assert.notNull(partitionKey, "partitionKey to be deleted should not be null");
operation.deleteById(information.getCollectionName(), id, partitionKey);
operation.deleteById(information.getContainerName(), id, partitionKey);
}
/**
@ -195,17 +195,17 @@ public class SimpleCosmosRepository<T, ID extends Serializable> implements Cosmo
final String partitionKeyValue = information.getPartitionKeyFieldValue(entity);
operation.deleteById(information.getCollectionName(),
operation.deleteById(information.getContainerName(),
information.getId(entity),
partitionKeyValue == null ? null : new PartitionKey(partitionKeyValue));
}
/**
* delete all the domains of a collection
* delete all the domains of a container
*/
@Override
public void deleteAll() {
operation.deleteAll(information.getCollectionName(), information.getJavaType());
operation.deleteAll(information.getContainerName(), information.getJavaType());
}
/**
@ -244,7 +244,7 @@ public class SimpleCosmosRepository<T, ID extends Serializable> implements Cosmo
Assert.notNull(sort, "sort of findAll should not be null");
final DocumentQuery query = new DocumentQuery(Criteria.getInstance(CriteriaType.ALL)).with(sort);
return operation.find(query, information.getJavaType(), information.getCollectionName());
return operation.find(query, information.getJavaType(), information.getContainerName());
}
/**
@ -258,6 +258,6 @@ public class SimpleCosmosRepository<T, ID extends Serializable> implements Cosmo
public Page<T> findAll(Pageable pageable) {
Assert.notNull(pageable, "pageable should not be null");
return operation.findAll(pageable, information.getJavaType(), information.getCollectionName());
return operation.findAll(pageable, information.getJavaType(), information.getContainerName());
}
}

Просмотреть файл

@ -33,7 +33,7 @@ public class SimpleReactiveCosmosRepository<T, K extends Serializable> implement
this.cosmosOperations = applicationContext.getBean(ReactiveCosmosOperations.class);
this.entityInformation = metadata;
createCollectionIfNotExists();
createContainerIfNotExists();
}
public SimpleReactiveCosmosRepository(CosmosEntityInformation<T, K> metadata,
@ -41,11 +41,11 @@ public class SimpleReactiveCosmosRepository<T, K extends Serializable> implement
this.cosmosOperations = reactiveCosmosOperations;
this.entityInformation = metadata;
createCollectionIfNotExists();
createContainerIfNotExists();
}
private CosmosContainerResponse createCollectionIfNotExists() {
return this.cosmosOperations.createCollectionIfNotExists(this.entityInformation).block();
private CosmosContainerResponse createContainerIfNotExists() {
return this.cosmosOperations.createContainerIfNotExists(this.entityInformation).block();
}
@Override
@ -56,7 +56,7 @@ public class SimpleReactiveCosmosRepository<T, K extends Serializable> implement
new DocumentQuery(Criteria.getInstance(CriteriaType.ALL)).with(sort);
return cosmosOperations.find(query, entityInformation.getJavaType(),
entityInformation.getCollectionName());
entityInformation.getContainerName());
}
@Override
@ -65,11 +65,11 @@ public class SimpleReactiveCosmosRepository<T, K extends Serializable> implement
Assert.notNull(entity, "Entity must not be null!");
if (entityInformation.isNew(entity)) {
return cosmosOperations.insert(entityInformation.getCollectionName(),
return cosmosOperations.insert(entityInformation.getContainerName(),
entity,
createKey(entityInformation.getPartitionKeyFieldValue(entity)));
} else {
return cosmosOperations.upsert(entityInformation.getCollectionName(),
return cosmosOperations.upsert(entityInformation.getContainerName(),
entity, createKey(entityInformation.getPartitionKeyFieldValue(entity)));
}
}
@ -93,7 +93,7 @@ public class SimpleReactiveCosmosRepository<T, K extends Serializable> implement
@Override
public Mono<T> findById(K id) {
Assert.notNull(id, "The given id must not be null!");
return cosmosOperations.findById(entityInformation.getCollectionName(), id,
return cosmosOperations.findById(entityInformation.getContainerName(), id,
entityInformation.getJavaType());
}
@ -102,7 +102,7 @@ public class SimpleReactiveCosmosRepository<T, K extends Serializable> implement
Assert.notNull(publisher, "The given id must not be null!");
return Mono.from(publisher).flatMap(
id -> cosmosOperations.findById(entityInformation.getCollectionName(),
id -> cosmosOperations.findById(entityInformation.getContainerName(),
id, entityInformation.getJavaType()));
}
@ -118,7 +118,7 @@ public class SimpleReactiveCosmosRepository<T, K extends Serializable> implement
Assert.notNull(id, "The given id must not be null!");
return cosmosOperations.existsById(id, entityInformation.getJavaType(),
entityInformation.getCollectionName());
entityInformation.getContainerName());
}
@Override
@ -127,12 +127,12 @@ public class SimpleReactiveCosmosRepository<T, K extends Serializable> implement
return Mono.from(publisher).flatMap(id -> cosmosOperations.existsById(id,
entityInformation.getJavaType(),
entityInformation.getCollectionName()));
entityInformation.getContainerName()));
}
@Override
public Flux<T> findAll() {
return cosmosOperations.findAll(entityInformation.getCollectionName(),
return cosmosOperations.findAll(entityInformation.getContainerName(),
entityInformation.getJavaType());
}
@ -150,21 +150,21 @@ public class SimpleReactiveCosmosRepository<T, K extends Serializable> implement
@Override
public Mono<Long> count() {
return cosmosOperations.count(entityInformation.getCollectionName());
return cosmosOperations.count(entityInformation.getContainerName());
}
@Override
public Mono<Void> deleteById(K id) {
Assert.notNull(id, "The given id must not be null!");
return cosmosOperations.deleteById(entityInformation.getCollectionName(), id, null);
return cosmosOperations.deleteById(entityInformation.getContainerName(), id, null);
}
@Override
public Mono<Void> deleteById(Publisher<K> publisher) {
Assert.notNull(publisher, "Id must not be null!");
return Mono.from(publisher).flatMap(id -> cosmosOperations.deleteById(entityInformation.getCollectionName(),
return Mono.from(publisher).flatMap(id -> cosmosOperations.deleteById(entityInformation.getContainerName(),
id, null)).then();
}
@ -173,7 +173,7 @@ public class SimpleReactiveCosmosRepository<T, K extends Serializable> implement
Assert.notNull(id, "Id must not be null!");
Assert.notNull(partitionKey, "PartitionKey must not be null!");
return cosmosOperations.deleteById(entityInformation.getCollectionName(), id, partitionKey);
return cosmosOperations.deleteById(entityInformation.getContainerName(), id, partitionKey);
}
@ -182,7 +182,7 @@ public class SimpleReactiveCosmosRepository<T, K extends Serializable> implement
Assert.notNull(entity, "entity to be deleted must not be null!");
final Object id = entityInformation.getId(entity);
return cosmosOperations.deleteById(entityInformation.getCollectionName(),
return cosmosOperations.deleteById(entityInformation.getContainerName(),
id,
createKey(entityInformation.getPartitionKeyFieldValue(entity)));
}
@ -207,7 +207,7 @@ public class SimpleReactiveCosmosRepository<T, K extends Serializable> implement
@Override
public Mono<Void> deleteAll() {
return cosmosOperations.deleteAll(entityInformation.getCollectionName(),
return cosmosOperations.deleteAll(entityInformation.getContainerName(),
entityInformation.getPartitionKeyFieldName());
}

Просмотреть файл

@ -39,9 +39,9 @@ public class TestConstants {
};
public static final String ROLE_COLLECTION_NAME = "RoleCollectionName";
public static final int REQUEST_UNIT = 1000;
public static final int REQUEST_UNIT = 4000;
public static final int TIME_TO_LIVE = 5;
public static final String REQUEST_UNIT_STRING = "1000";
public static final String REQUEST_UNIT_STRING = "4000";
public static final boolean INDEXINGPOLICY_AUTOMATIC = false;
public static final IndexingMode INDEXINGPOLICY_MODE = IndexingMode.LAZY;
public static final String INCLUDEDPATH_0 = "{\"path\":\"/*\",\"indexes\":[" +

Просмотреть файл

@ -80,7 +80,7 @@ public class CosmosTemplateIT {
private static CosmosTemplate cosmosTemplate;
private static CosmosEntityInformation<Person, String> personInfo;
private static String collectionName;
private static String containerName;
private static boolean initialized;
private Person insertedPerson;
@ -99,14 +99,14 @@ public class CosmosTemplateIT {
final CosmosMappingContext mappingContext = new CosmosMappingContext();
personInfo = new CosmosEntityInformation<>(Person.class);
collectionName = personInfo.getCollectionName();
containerName = personInfo.getContainerName();
mappingContext.setInitialEntitySet(new EntityScanner(this.applicationContext).scan(Persistent.class));
final MappingCosmosConverter cosmosConverter = new MappingCosmosConverter(mappingContext,
null);
cosmosTemplate = new CosmosTemplate(cosmosDbFactory, cosmosConverter, dbConfig.getDatabase());
cosmosTemplate.createCollectionIfNotExists(personInfo);
cosmosTemplate.createContainerIfNotExists(personInfo);
initialized = true;
}
@ -156,7 +156,7 @@ public class CosmosTemplateIT {
new PartitionKey(personInfo.getPartitionKeyFieldValue(TEST_PERSON_3)));
final List<Object> ids = Lists.newArrayList(ID_1, ID_2, ID_3);
final List<Person> result = cosmosTemplate.findByIds(ids, Person.class, collectionName);
final List<Person> result = cosmosTemplate.findByIds(ids, Person.class, containerName);
assertThat(responseDiagnosticsTestUtils.getFeedResponseDiagnostics()).isNotNull();
assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull();
@ -261,8 +261,8 @@ public class CosmosTemplateIT {
}
@Test
public void testCountByCollection() {
final long prevCount = cosmosTemplate.count(collectionName);
public void testCountByContainer() {
final long prevCount = cosmosTemplate.count(containerName);
assertThat(prevCount).isEqualTo(1);
assertThat(responseDiagnosticsTestUtils.getFeedResponseDiagnostics()).isNotNull();
@ -274,7 +274,7 @@ public class CosmosTemplateIT {
assertThat(responseDiagnosticsTestUtils.getCosmosResponseDiagnostics()).isNotNull();
final long newCount = cosmosTemplate.count(collectionName);
final long newCount = cosmosTemplate.count(containerName);
assertThat(newCount).isEqualTo(2);
assertThat(responseDiagnosticsTestUtils.getCosmosResponseDiagnostics()).isNull();
@ -296,7 +296,7 @@ public class CosmosTemplateIT {
Collections.singletonList(TEST_PERSON_2.getFirstName()));
final DocumentQuery query = new DocumentQuery(criteria);
final long count = cosmosTemplate.count(query, Person.class, collectionName);
final long count = cosmosTemplate.count(query, Person.class, containerName);
assertThat(count).isEqualTo(1);
assertThat(responseDiagnosticsTestUtils.getFeedResponseDiagnostics()).isNotNull();
@ -314,7 +314,7 @@ public class CosmosTemplateIT {
assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull();
final CosmosPageRequest pageRequest = new CosmosPageRequest(0, PAGE_SIZE_1, null);
final Page<Person> page1 = cosmosTemplate.findAll(pageRequest, Person.class, collectionName);
final Page<Person> page1 = cosmosTemplate.findAll(pageRequest, Person.class, containerName);
assertThat(page1.getContent().size()).isEqualTo(PAGE_SIZE_1);
validateNonLastPage(page1, PAGE_SIZE_1);
@ -325,7 +325,7 @@ public class CosmosTemplateIT {
assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0);
final Page<Person> page2 = cosmosTemplate.findAll(page1.getPageable(), Person.class,
collectionName);
containerName);
assertThat(page2.getContent().size()).isEqualTo(1);
validateLastPage(page2, PAGE_SIZE_1);
@ -349,7 +349,7 @@ public class CosmosTemplateIT {
final PageRequest pageRequest = new CosmosPageRequest(0, PAGE_SIZE_2, null);
final DocumentQuery query = new DocumentQuery(criteria).with(pageRequest);
final Page<Person> page = cosmosTemplate.paginationQuery(query, Person.class, collectionName);
final Page<Person> page = cosmosTemplate.paginationQuery(query, Person.class, containerName);
assertThat(page.getContent().size()).isEqualTo(1);
validateLastPage(page, page.getContent().size());
@ -373,7 +373,7 @@ public class CosmosTemplateIT {
final Sort sort = Sort.by(Sort.Direction.DESC, "firstName");
final PageRequest pageRequest = new CosmosPageRequest(0, PAGE_SIZE_3, null, sort);
final Page<Person> page = cosmosTemplate.findAll(pageRequest, Person.class, collectionName);
final Page<Person> page = cosmosTemplate.findAll(pageRequest, Person.class, containerName);
assertThat(page.getContent().size()).isEqualTo(3);
validateLastPage(page, PAGE_SIZE_3);
@ -407,7 +407,7 @@ public class CosmosTemplateIT {
final PageRequest pageRequest = new CosmosPageRequest(0, PAGE_SIZE_3, null, sort);
final Page<Person> firstPage = cosmosTemplate.findAll(pageRequest, Person.class,
collectionName);
containerName);
assertThat(firstPage.getContent().size()).isEqualTo(3);
validateNonLastPage(firstPage, firstPage.getContent().size());
@ -418,7 +418,7 @@ public class CosmosTemplateIT {
assertThat(firstPageResults.get(2).getFirstName()).isEqualTo(testPerson5.getFirstName());
final Page<Person> secondPage = cosmosTemplate.findAll(firstPage.getPageable(), Person.class,
collectionName);
containerName);
assertThat(secondPage.getContent().size()).isEqualTo(2);
validateLastPage(secondPage, secondPage.getContent().size());

Просмотреть файл

@ -55,7 +55,7 @@ public class CosmosTemplateIllegalTest {
}
@Test
public void deleteIllegalCollectionShouldFail() throws NoSuchMethodException {
public void deleteIllegalContainerShouldFail() throws NoSuchMethodException {
final Method method = dbTemplateClass.getDeclaredMethod("deleteAll", String.class, Class.class);
checkIllegalArgument(method, NULL_STR, Person.class);
@ -68,7 +68,7 @@ public class CosmosTemplateIllegalTest {
final Method method = dbTemplateClass.getDeclaredMethod("deleteById", String.class, Object.class,
PartitionKey.class);
// Test argument collectionName
// Test argument containerName
checkIllegalArgument(method, null, DUMMY_ID, DUMMY_KEY);
checkIllegalArgument(method, EMPTY_STR, DUMMY_ID, DUMMY_KEY);
checkIllegalArgument(method, WHITESPACES_STR, DUMMY_ID, DUMMY_KEY);

Просмотреть файл

@ -23,10 +23,8 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.domain.EntityScanner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.PropertySource;
import org.springframework.data.annotation.Persistent;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
@ -55,7 +53,7 @@ public class CosmosTemplatePartitionIT {
TEST_PERSON.getLastName(), HOBBIES, ADDRESSES);
private static CosmosTemplate cosmosTemplate;
private static String collectionName;
private static String containerName;
private static CosmosEntityInformation<PartitionPerson, String> personInfo;
private static boolean initialized;
@ -76,9 +74,9 @@ public class CosmosTemplatePartitionIT {
final MappingCosmosConverter dbConverter = new MappingCosmosConverter(mappingContext, null);
cosmosTemplate = new CosmosTemplate(cosmosDbFactory, dbConverter, dbConfig.getDatabase());
collectionName = personInfo.getCollectionName();
containerName = personInfo.getContainerName();
cosmosTemplate.createCollectionIfNotExists(personInfo);
cosmosTemplate.createContainerIfNotExists(personInfo);
initialized = true;
}
@ -88,7 +86,7 @@ public class CosmosTemplatePartitionIT {
@After
public void cleanup() {
cosmosTemplate.deleteAll(personInfo.getCollectionName(), PartitionPerson.class);
cosmosTemplate.deleteAll(personInfo.getContainerName(), PartitionPerson.class);
}
@Test
@ -181,12 +179,12 @@ public class CosmosTemplatePartitionIT {
@Test
public void testCountForPartitionedCollection() {
final long prevCount = cosmosTemplate.count(collectionName);
final long prevCount = cosmosTemplate.count(containerName);
assertThat(prevCount).isEqualTo(1);
cosmosTemplate.insert(TEST_PERSON_2, new PartitionKey(TEST_PERSON_2.getLastName()));
final long newCount = cosmosTemplate.count(collectionName);
final long newCount = cosmosTemplate.count(containerName);
assertThat(newCount).isEqualTo(2);
}
@ -198,7 +196,7 @@ public class CosmosTemplatePartitionIT {
Arrays.asList(TEST_PERSON_2.getFirstName()));
final DocumentQuery query = new DocumentQuery(criteria);
final long count = cosmosTemplate.count(query, PartitionPerson.class, collectionName);
final long count = cosmosTemplate.count(query, PartitionPerson.class, containerName);
assertThat(count).isEqualTo(1);
}
@ -208,7 +206,7 @@ public class CosmosTemplatePartitionIT {
Arrays.asList("non-exist-first-name"));
final DocumentQuery query = new DocumentQuery(criteria);
final long count = cosmosTemplate.count(query, PartitionPerson.class, collectionName);
final long count = cosmosTemplate.count(query, PartitionPerson.class, containerName);
assertThat(count).isEqualTo(0);
}
@ -217,13 +215,13 @@ public class CosmosTemplatePartitionIT {
cosmosTemplate.insert(TEST_PERSON_2, new PartitionKey(TEST_PERSON_2.getLastName()));
final CosmosPageRequest pageRequest = new CosmosPageRequest(0, PAGE_SIZE_1, null);
final Page<PartitionPerson> page1 = cosmosTemplate.findAll(pageRequest, PartitionPerson.class, collectionName);
final Page<PartitionPerson> page1 = cosmosTemplate.findAll(pageRequest, PartitionPerson.class, containerName);
assertThat(page1.getContent().size()).isEqualTo(PAGE_SIZE_1);
validateNonLastPage(page1, PAGE_SIZE_1);
final Page<PartitionPerson> page2 = cosmosTemplate.findAll(page1.getPageable(),
PartitionPerson.class, collectionName);
PartitionPerson.class, containerName);
assertThat(page2.getContent().size()).isEqualTo(1);
validateLastPage(page2, PAGE_SIZE_1);
}
@ -237,7 +235,7 @@ public class CosmosTemplatePartitionIT {
final PageRequest pageRequest = new CosmosPageRequest(0, PAGE_SIZE_2, null);
final DocumentQuery query = new DocumentQuery(criteria).with(pageRequest);
final Page<PartitionPerson> page = cosmosTemplate.paginationQuery(query, PartitionPerson.class, collectionName);
final Page<PartitionPerson> page = cosmosTemplate.paginationQuery(query, PartitionPerson.class, containerName);
assertThat(page.getContent().size()).isEqualTo(1);
validateLastPage(page, page.getContent().size());
}

Просмотреть файл

@ -97,14 +97,14 @@ public class ReactiveCosmosTemplateIT {
final CosmosMappingContext mappingContext = new CosmosMappingContext();
personInfo = new CosmosEntityInformation<>(Person.class);
containerName = personInfo.getCollectionName();
containerName = personInfo.getContainerName();
mappingContext.setInitialEntitySet(new EntityScanner(this.applicationContext).scan(Persistent.class));
final MappingCosmosConverter dbConverter =
new MappingCosmosConverter(mappingContext, null);
cosmosTemplate = new ReactiveCosmosTemplate(dbFactory, dbConverter, dbConfig.getDatabase());
cosmosTemplate.createCollectionIfNotExists(personInfo).block().container();
cosmosTemplate.createContainerIfNotExists(personInfo).block().container();
initialized = true;
}
@ -210,7 +210,7 @@ public class ReactiveCosmosTemplateIT {
}
@Test
public void testInsertWithCollectionName() {
public void testInsertWithContainerName() {
StepVerifier.create(cosmosTemplate.insert(Person.class.getSimpleName(), TEST_PERSON_2,
new PartitionKey(personInfo.getPartitionKeyFieldValue(TEST_PERSON_2))))
.expectNext(TEST_PERSON_2).verifyComplete();
@ -276,7 +276,7 @@ public class ReactiveCosmosTemplateIT {
}
@Test
public void testUpsertWithCollectionName() {
public void testUpsertWithContainerName() {
final Person p = TEST_PERSON_2;
final ArrayList<String> hobbies = new ArrayList<>(p.getHobbies());
hobbies.add("more code");

Просмотреть файл

@ -21,10 +21,8 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.domain.EntityScanner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.PropertySource;
import org.springframework.data.annotation.Persistent;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ -36,7 +34,6 @@ import java.util.Arrays;
import java.util.UUID;
import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.ADDRESSES;
import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.DB_NAME;
import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.FIRST_NAME;
import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.HOBBIES;
import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.ID_1;
@ -79,14 +76,14 @@ public class ReactiveCosmosTemplatePartitionIT {
final CosmosMappingContext mappingContext = new CosmosMappingContext();
personInfo =
new CosmosEntityInformation<>(PartitionPerson.class);
containerName = personInfo.getCollectionName();
containerName = personInfo.getContainerName();
mappingContext.setInitialEntitySet(new EntityScanner(this.applicationContext).scan(Persistent.class));
final MappingCosmosConverter dbConverter = new MappingCosmosConverter(mappingContext,
null);
cosmosTemplate = new ReactiveCosmosTemplate(dbFactory, dbConverter, dbConfig.getDatabase());
cosmosTemplate.createCollectionIfNotExists(personInfo).block();
cosmosTemplate.createContainerIfNotExists(personInfo).block();
initialized = true;
}

Просмотреть файл

@ -18,7 +18,7 @@ public class BasicCosmosPersistentEntityUnitTest {
public void testGetCollection() {
final BasicCosmosPersistentEntity entity = new BasicCosmosPersistentEntity<Person>(
ClassTypeInformation.from(Person.class));
assertThat(entity.getCollection()).isEqualTo("");
assertThat(entity.getContainer()).isEqualTo("");
}
@Test

Просмотреть файл

@ -5,10 +5,12 @@
*/
package com.microsoft.azure.spring.data.cosmosdb.domain;
import com.microsoft.azure.spring.data.cosmosdb.core.mapping.Document;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.data.annotation.Id;
@Document(ru = "10000")
@Data
@AllArgsConstructor
public class Contact {

Просмотреть файл

@ -14,7 +14,7 @@ import java.util.Date;
/**
* For testing date and enum purpose
*/
@Document
@Document(ru = "100000")
@Data
@AllArgsConstructor
public class Memo {

Просмотреть файл

@ -6,12 +6,14 @@
package com.microsoft.azure.spring.data.cosmosdb.domain;
import com.microsoft.azure.spring.data.cosmosdb.core.mapping.Document;
import com.microsoft.azure.spring.data.cosmosdb.core.mapping.PartitionKey;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.util.List;
@Document(ru = "10000")
@Data
@AllArgsConstructor
public class PartitionPerson {

Просмотреть файл

@ -9,6 +9,7 @@ package com.microsoft.azure.spring.data.cosmosdb.domain;
import java.util.List;
import com.microsoft.azure.spring.data.cosmosdb.common.TestConstants;
import com.microsoft.azure.spring.data.cosmosdb.core.mapping.Document;
import com.microsoft.azure.spring.data.cosmosdb.core.mapping.DocumentIndexingPolicy;
import com.microsoft.azure.spring.data.cosmosdb.core.mapping.PartitionKey;
import lombok.Data;
@ -17,6 +18,7 @@ import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Version;
@Document(ru = "10000")
@Data
@EqualsAndHashCode(exclude = "_etag")
@NoArgsConstructor

Просмотреть файл

@ -6,12 +6,14 @@
package com.microsoft.azure.spring.data.cosmosdb.domain;
import com.microsoft.azure.spring.data.cosmosdb.common.TestConstants;
import com.microsoft.azure.spring.data.cosmosdb.core.mapping.Document;
import com.microsoft.azure.spring.data.cosmosdb.core.mapping.DocumentIndexingPolicy;
import com.microsoft.azure.spring.data.cosmosdb.core.mapping.PartitionKey;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.data.annotation.Id;
@Document(ru = "10000")
@Data
@AllArgsConstructor
@DocumentIndexingPolicy(includePaths = TestConstants.ORDER_BY_STRING_PATH)

Просмотреть файл

@ -29,7 +29,6 @@ import org.springframework.data.annotation.Id;
TestConstants.EXCLUDEDPATH_1,
})
@Document(collection = TestConstants.ROLE_COLLECTION_NAME,
ru = TestConstants.REQUEST_UNIT_STRING,
autoCreateCollection = false)
public class Role {
@Id

Просмотреть файл

@ -14,7 +14,7 @@ import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Document(collection = "#{@dynamicCollectionContainer.getCollectionName()}")
@Document(collection = "#{@dynamicCollectionContainer.getContainerName()}")
public class SpELBeanStudent {
private String id;
private String firstName;

Просмотреть файл

@ -72,9 +72,9 @@ public class PerformanceCompare {
public void setup() throws CosmosClientException {
if (!hasInit) {
DatabaseUtils.createDatabase(cosmosSyncClient, Constants.PERF_DATABASE_NAME);
DatabaseUtils.createCollection(cosmosSyncClient, Constants.PERF_DATABASE_NAME,
DatabaseUtils.createContainer(cosmosSyncClient, Constants.PERF_DATABASE_NAME,
Constants.SPRING_COLLECTION_NAME);
DatabaseUtils.createCollection(cosmosSyncClient,
DatabaseUtils.createContainer(cosmosSyncClient,
Constants.PERF_DATABASE_NAME, Constants.SDK_COLLECTION_NAME);
sdkService = new SdkService(cosmosSyncClient, Constants.PERF_DATABASE_NAME,

Просмотреть файл

@ -30,12 +30,12 @@ public class SdkService {
private final CosmosSyncClient cosmosSyncClient;
private final String dbName;
private final String collectionName;
private final String containerName;
public SdkService(CosmosSyncClient client, String dbName, String collectionName, CosmosClient asyncClient) {
public SdkService(CosmosSyncClient client, String dbName, String containerName, CosmosClient asyncClient) {
this.cosmosSyncClient = client;
this.dbName = dbName;
this.collectionName = collectionName;
this.containerName = containerName;
}
public PerfPerson save(PerfPerson person) {
@ -44,7 +44,7 @@ public class SdkService {
final CosmosItemProperties personDoc = new CosmosItemProperties(personJson);
final CosmosItemProperties doc = cosmosSyncClient.getDatabase(dbName)
.getContainer(collectionName)
.getContainer(containerName)
.createItem(personDoc)
.properties();
@ -63,11 +63,10 @@ public class SdkService {
public void delete(PerfPerson person) {
try {
final String docLink = DatabaseUtils.getDocumentLink(dbName, collectionName, person.getId());
final String docLink = DatabaseUtils.getDocumentLink(dbName, containerName, person.getId());
cosmosSyncClient.getDatabase(dbName)
.getContainer(collectionName)
.getItem(person.getId(),
PartitionKey.None)
.getContainer(containerName)
.getItem(person.getId(), PartitionKey.None)
.delete(new CosmosItemRequestOptions());
} catch (CosmosClientException e) {
@ -82,9 +81,9 @@ public class SdkService {
public CosmosItemProperties findById(String id) {
final Iterator<FeedResponse<CosmosItemProperties>> feedResponseIterator =
cosmosSyncClient.getDatabase(dbName)
.getContainer(collectionName)
.queryItems("SELECT * FROM " + collectionName + " WHERE " +
collectionName + ".id='" + id + "'", new FeedOptions());
.getContainer(containerName)
.queryItems("SELECT * FROM " + containerName + " WHERE " +
containerName + ".id='" + id + "'", new FeedOptions());
CosmosItemProperties itemProperties = null;
if (feedResponseIterator.hasNext()) {
final List<CosmosItemProperties> results = feedResponseIterator.next().results();
@ -99,16 +98,16 @@ public class SdkService {
public List<PerfPerson> findAllById(Iterable<String> ids) {
final String idsInList = String.join(",",
Arrays.asList(ids).stream().map(id -> "'" + id + "'").collect(Collectors.toList()));
final String sql = "SELECT * FROM " + collectionName + " WHERE " + collectionName + ".id IN ("
final String sql = "SELECT * FROM " + containerName + " WHERE " + containerName + ".id IN ("
+ idsInList + ")";
final FeedOptions feedOptions = new FeedOptions();
feedOptions.enableCrossPartitionQuery(true);
final List<CosmosItemProperties> docs = null;
final List<CosmosItemProperties> docs = new ArrayList<>();
final Iterator<FeedResponse<CosmosItemProperties>> feedResponseIterator = cosmosSyncClient.getDatabase(dbName)
.getContainer(collectionName)
.getContainer(containerName)
.queryItems(sql, feedOptions);
while (feedResponseIterator.hasNext()) {
final FeedResponse<CosmosItemProperties> next = feedResponseIterator.next();
@ -120,19 +119,19 @@ public class SdkService {
}
public List<PerfPerson> findAll() {
final String sql = "SELECT * FROM " + collectionName;
final String sql = "SELECT * FROM " + containerName;
final List<CosmosItemProperties> docs = getCosmosItemPropertiesList(sql);
return fromDocuments(docs);
}
public boolean deleteAll() {
final String sql = "SELECT * FROM " + collectionName;
final String sql = "SELECT * FROM " + containerName;
final List<CosmosItemProperties> documents = getCosmosItemPropertiesList(sql);
documents.forEach(document -> {
try {
cosmosSyncClient.getDatabase(dbName)
.getContainer(collectionName)
.getContainer(containerName)
.getItem(document.id(), PartitionKey.None)
.delete(new CosmosItemRequestOptions().partitionKey(PartitionKey.None));
} catch (CosmosClientException e) {
@ -147,7 +146,7 @@ public class SdkService {
final List<CosmosItemProperties> documents = new ArrayList<>();
final Iterator<FeedResponse<CosmosItemProperties>> feedResponseIterator =
cosmosSyncClient.getDatabase(dbName)
.getContainer(collectionName)
.getContainer(containerName)
.queryItems(sql, new FeedOptions().enableCrossPartitionQuery(true));
while (feedResponseIterator.hasNext()) {
final FeedResponse<CosmosItemProperties> next = feedResponseIterator.next();
@ -158,7 +157,7 @@ public class SdkService {
public List<PerfPerson> searchDocuments(Sort sort) {
final Sort.Order order = sort.iterator().next(); // Only one Order supported
final String sql = "SELECT * FROM " + collectionName + " ORDER BY " + collectionName + "."
final String sql = "SELECT * FROM " + containerName + " ORDER BY " + containerName + "."
+ order.getProperty() + " " + order.getDirection().name();
final List<CosmosItemProperties> docs = getCosmosItemPropertiesList(sql);
@ -166,9 +165,9 @@ public class SdkService {
}
public long count() {
final String sql = "SELECT VALUE COUNT(1) FROM " + collectionName;
final String sql = "SELECT VALUE COUNT(1) FROM " + containerName;
final Iterator<FeedResponse<CosmosItemProperties>> feedResponseIterator = cosmosSyncClient.getDatabase(dbName)
.getContainer(collectionName)
.getContainer(containerName)
.queryItems(sql, new FeedOptions());
final Object result = feedResponseIterator.next().results().get(0).get("_aggregate");
@ -176,7 +175,7 @@ public class SdkService {
}
public List<PerfPerson> findByName(String name) {
final String sql = "SELECT * FROM " + collectionName + " WHERE " + collectionName + ".name='"
final String sql = "SELECT * FROM " + containerName + " WHERE " + containerName + ".name='"
+ name + "'";
final Iterator<CosmosItemProperties> result = getCosmosItemPropertiesList(sql).iterator();
return fromDocuments(Lists.newArrayList(result));
@ -192,7 +191,7 @@ public class SdkService {
}
private List<PerfPerson> searchBySize(int size, FeedOptions options) {
final String sql = "SELECT * FROM " + collectionName;
final String sql = "SELECT * FROM " + containerName;
final Iterator<CosmosItemProperties> it = getCosmosItemPropertiesList(sql).iterator();
final List<PerfPerson> entities = new ArrayList<>();

Просмотреть файл

@ -30,17 +30,17 @@ public class DatabaseUtils {
documentClient.createDatabase(databaseName);
}
public static void deleteCollection(CosmosSyncClient documentClient, String databaseName, String collectionName)
public static void deleteContainer(CosmosSyncClient documentClient, String databaseName, String containerName)
throws CosmosClientException{
final RequestOptions requestOptions = new RequestOptions();
requestOptions.setOfferThroughput(1000);
documentClient.getDatabase(databaseName).getContainer(collectionName).delete();
documentClient.getDatabase(databaseName).getContainer(containerName).delete();
}
public static void createCollection(CosmosSyncClient documentClient, String databaseName, String collectionName)
public static void createContainer(CosmosSyncClient documentClient, String databaseName, String containerName)
throws CosmosClientException {
final CosmosContainerProperties containerProperties = new CosmosContainerProperties(collectionName,
final CosmosContainerProperties containerProperties = new CosmosContainerProperties(containerName,
new PartitionKeyDefinition().paths(Collections.singletonList("/mypk")));
final IndexingPolicy policy = new IndexingPolicy();
@ -50,15 +50,15 @@ public class DatabaseUtils {
documentClient.getDatabase(databaseName).createContainer(containerProperties);
}
public static String getDocumentLink(String databaseName, String collectionName, Object documentId) {
return getCollectionLink(databaseName, collectionName) + "/docs/" + documentId;
public static String getDocumentLink(String databaseName, String containerName, Object documentId) {
return getContainerLink(databaseName, containerName) + "/docs/" + documentId;
}
public static String getDatabaseLink(String databaseName) {
return "dbs/" + databaseName;
}
public static String getCollectionLink(String databaseName, String collectionName) {
return getDatabaseLink(databaseName) + "/colls/" + collectionName;
public static String getContainerLink(String databaseName, String containerName) {
return getDatabaseLink(databaseName) + "/colls/" + containerName;
}
}

Просмотреть файл

@ -40,8 +40,8 @@ public class CosmosAnnotationUnitTest {
Assert.isNull(policyAnnotation, "NoDBAnnotationPerson class should not have DocumentIndexingPolicy annotation");
Assert.notNull(policy, "NoDBAnnotationPerson class collection policy should not be null");
// CollectionName, RequestUnit, Automatic and IndexingMode
Assert.isTrue(personInfo.getCollectionName().equals(NoDBAnnotationPerson.class.getSimpleName()),
// ContainerName, RequestUnit, Automatic and IndexingMode
Assert.isTrue(personInfo.getContainerName().equals(NoDBAnnotationPerson.class.getSimpleName()),
"should be default collection name");
Assert.isTrue(personInfo.getRequestUnit() == TestConstants.DEFAULT_REQUEST_UNIT,
"should be default request unit");
@ -65,12 +65,12 @@ public class CosmosAnnotationUnitTest {
final Document documentAnnotation = Role.class.getAnnotation(Document.class);
final DocumentIndexingPolicy policyAnnotation = Role.class.getAnnotation(DocumentIndexingPolicy.class);
// CollectionName, RequestUnit, Automatic and IndexingMode
// ContainerName, RequestUnit, Automatic and IndexingMode
Assert.notNull(documentAnnotation, "NoDBAnnotationPerson class should have Document annotation");
Assert.notNull(policyAnnotation, "NoDBAnnotationPerson class should have DocumentIndexingPolicy annotation");
Assert.notNull(policy, "NoDBAnnotationPerson class collection policy should not be null");
Assert.isTrue(roleInfo.getCollectionName().equals(TestConstants.ROLE_COLLECTION_NAME),
Assert.isTrue(roleInfo.getContainerName().equals(TestConstants.ROLE_COLLECTION_NAME),
"should be Role(class) collection name");
Assert.isTrue(roleInfo.getRequestUnit() == TestConstants.REQUEST_UNIT,
"should be Role(class) request unit");
@ -86,11 +86,11 @@ public class CosmosAnnotationUnitTest {
@Test
public void testAutoCreateCollectionAnnotation() {
final boolean autoCreateCollectionRoleInfo = roleInfo.isAutoCreateCollection();
final boolean autoCreateCollectionPersonInfo = personInfo.isAutoCreateCollection();
final boolean autoCreateCollectionRoleInfo = roleInfo.isAutoCreateContainer();
final boolean autoCreateCollectionPersonInfo = personInfo.isAutoCreateContainer();
Assert.isTrue(!autoCreateCollectionRoleInfo, "autoCreateCollection in role should be false");
Assert.isTrue(autoCreateCollectionPersonInfo, "autoCreateCollection in person should be true");
Assert.isTrue(!autoCreateCollectionRoleInfo, "autoCreateContainer in role should be false");
Assert.isTrue(autoCreateCollectionPersonInfo, "autoCreateContainer in person should be true");
}
@Test

Просмотреть файл

@ -50,7 +50,7 @@ public class SimpleCosmosRepositoryUnitTest {
@Before
public void setUp() {
when(entityInformation.getJavaType()).thenReturn(Person.class);
when(entityInformation.getCollectionName()).thenReturn(Person.class.getSimpleName());
when(entityInformation.getContainerName()).thenReturn(Person.class.getSimpleName());
when(cosmosOperations.findAll(anyString(), any())).thenReturn(Arrays.asList(TEST_PERSON));
repository = new SimpleCosmosRepository<>(entityInformation, cosmosOperations);

Просмотреть файл

@ -77,14 +77,14 @@ public class TestRepositoryConfig extends AbstractCosmosConfiguration {
}
public class DynamicCollectionContainer {
private String collectionName;
private String containerName;
public DynamicCollectionContainer(String collectionName) {
this.collectionName = collectionName;
public DynamicCollectionContainer(String containerName) {
this.containerName = containerName;
}
public String getCollectionName() {
return this.collectionName;
public String getContainerName() {
return this.containerName;
}
}
}

Просмотреть файл

@ -57,7 +57,7 @@ public class AddressRepositoryIT {
@PreDestroy
public void cleanUpCollection() {
template.deleteCollection(entityInformation.getCollectionName());
template.deleteContainer(entityInformation.getContainerName());
}
@Before

Просмотреть файл

@ -46,7 +46,7 @@ public class ContactRepositoryIT {
@PreDestroy
public void cleanUpCollection() {
template.deleteCollection(entityInformation.getCollectionName());
template.deleteContainer(entityInformation.getContainerName());
}
@Before

Просмотреть файл

@ -67,17 +67,17 @@ public class CosmosAnnotationIT {
cosmosTemplate = new CosmosTemplate(cosmosDbFactory, mappingConverter, dbConfig.getDatabase());
initialized = true;
}
collectionRole = cosmosTemplate.createCollectionIfNotExists(roleInfo);
collectionRole = cosmosTemplate.createContainerIfNotExists(roleInfo);
cosmosTemplate.createCollectionIfNotExists(sampleInfo);
cosmosTemplate.createContainerIfNotExists(sampleInfo);
cosmosTemplate.insert(roleInfo.getCollectionName(), TEST_ROLE, null);
cosmosTemplate.insert(roleInfo.getContainerName(), TEST_ROLE, null);
}
@After
public void cleanUp() {
cosmosTemplate.deleteCollection(roleInfo.getCollectionName());
cosmosTemplate.deleteCollection(sampleInfo.getCollectionName());
cosmosTemplate.deleteContainer(roleInfo.getContainerName());
cosmosTemplate.deleteContainer(sampleInfo.getContainerName());
}
@Test

Просмотреть файл

@ -62,7 +62,7 @@ public class CustomerRepositoryIT {
@PreDestroy
public void cleanUpCollection() {
template.deleteCollection(entityInformation.getCollectionName());
template.deleteContainer(entityInformation.getContainerName());
}
@Before

Просмотреть файл

@ -43,7 +43,7 @@ public class IntegerIdDomainRepositoryIT {
@PreDestroy
public void cleanUpCollection() {
template.deleteCollection(entityInformation.getCollectionName());
template.deleteContainer(entityInformation.getContainerName());
}
@Before

Просмотреть файл

@ -68,7 +68,7 @@ public class MemoRepositoryIT {
@PreDestroy
public void cleanUpCollection() {
template.deleteCollection(entityInformation.getCollectionName());
template.deleteContainer(entityInformation.getContainerName());
}
@Before

Просмотреть файл

@ -77,7 +77,7 @@ public class PageableAddressRepositoryIT {
@PreDestroy
public void cleanUpCollection() {
template.deleteCollection(entityInformation.getCollectionName());
template.deleteContainer(entityInformation.getContainerName());
}
@After
@ -97,16 +97,16 @@ public class PageableAddressRepositoryIT {
final CosmosPageRequest pageRequest = new CosmosPageRequest(0, PAGE_SIZE_3, null);
final Page<Address> page = repository.findAll(pageRequest);
assertThat(page.getContent().size()).isEqualTo(PAGE_SIZE_3);
assertThat(page.getContent().size()).isLessThanOrEqualTo(PAGE_SIZE_3);
validateNonLastPage(page, PAGE_SIZE_3);
final Page<Address> nextPage = repository.findAll(page.getPageable());
assertThat(nextPage.getContent().size()).isEqualTo(1);
assertThat(nextPage.getContent().size()).isLessThanOrEqualTo(PAGE_SIZE_3);
validateLastPage(nextPage, nextPage.getContent().size());
}
@Test
public void testFindWithParitionKeySinglePage() {
public void testFindWithPartitionKeySinglePage() {
final CosmosPageRequest pageRequest = new CosmosPageRequest(0, PAGE_SIZE_3, null);
final Page<Address> page = repository.findByCity(TestConstants.CITY, pageRequest);
@ -116,7 +116,7 @@ public class PageableAddressRepositoryIT {
}
@Test
public void testFindWithParitionKeyMultiPages() {
public void testFindWithPartitionKeyMultiPages() {
final CosmosPageRequest pageRequest = new CosmosPageRequest(0, PAGE_SIZE_1, null);
final Page<Address> page = repository.findByCity(TestConstants.CITY, pageRequest);
@ -171,7 +171,7 @@ public class PageableAddressRepositoryIT {
final CosmosClient cosmosClient = applicationContext.getBean(CosmosClient.class);
final Flux<FeedResponse<CosmosItemProperties>> feedResponseFlux =
cosmosClient.getDatabase(dbConfig.getDatabase())
.getContainer(entityInformation.getCollectionName())
.getContainer(entityInformation.getContainerName())
.queryItems(query, options);
StepVerifier.create(feedResponseFlux)

Просмотреть файл

@ -90,7 +90,7 @@ public class PageableMemoRepositoryIT {
@PreDestroy
public void cleanUpCollection() {
template.deleteCollection(entityInformation.getCollectionName());
template.deleteContainer(entityInformation.getContainerName());
}
@Test
@ -142,7 +142,7 @@ public class PageableMemoRepositoryIT {
final CosmosClient cosmosClient = applicationContext.getBean(CosmosClient.class);
return cosmosClient.getDatabase(dbConfig.getDatabase())
.getContainer(entityInformation.getCollectionName())
.getContainer(entityInformation.getContainerName())
.queryItems(query, options);
}

Просмотреть файл

@ -80,7 +80,7 @@ public class PageablePersonRepositoryIT {
@PreDestroy
public void cleanUpCollection() {
template.deleteCollection(entityInformation.getCollectionName());
template.deleteContainer(entityInformation.getContainerName());
}
// Cosmos DB can return any number of documents less than or equal to requested page size

Просмотреть файл

@ -83,7 +83,7 @@ public class ProjectRepositoryIT {
@PreDestroy
public void cleanUpCollection() {
template.deleteCollection(entityInformation.getCollectionName());
template.deleteContainer(entityInformation.getContainerName());
}
@Before

Просмотреть файл

@ -84,7 +84,7 @@ public class ProjectRepositorySortIT {
@PreDestroy
public void cleanUpCollection() {
template.deleteCollection(entityInformation.getCollectionName());
template.deleteContainer(entityInformation.getContainerName());
}
@Before

Просмотреть файл

@ -50,7 +50,7 @@ public class QuestionRepositoryIT {
@PreDestroy
public void cleanUpCollection() {
template.deleteCollection(entityInformation.getCollectionName());
template.deleteContainer(entityInformation.getContainerName());
}
@Before

Просмотреть файл

@ -65,7 +65,7 @@ public class ReactiveCourseRepositoryIT {
@PreDestroy
public void cleanUpCollection() {
template.deleteContainer(entityInformation.getCollectionName());
template.deleteContainer(entityInformation.getContainerName());
}
@Before

Просмотреть файл

@ -53,7 +53,7 @@ public class RoleRepositoryCollectionIT {
@PreDestroy
public void cleanUpCollection() {
template.deleteCollection(entityInformation.getCollectionName());
template.deleteContainer(entityInformation.getContainerName());
}
@Test

Просмотреть файл

@ -58,24 +58,24 @@ public class SpELCosmosDBAnnotationIT {
@After
public void cleanUp() {
if (cosmosTemplate != null && cosmosEntityInformation != null) {
cosmosTemplate.deleteCollection(cosmosEntityInformation.getCollectionName());
cosmosTemplate.deleteContainer(cosmosEntityInformation.getContainerName());
}
}
@Test
public void testDynamicCollectionNameWithPropertySourceExpression() {
public void testDynamicContainerNameWithPropertySourceExpression() {
final CosmosEntityInformation<SpELPropertyStudent, Object> propertyStudentInfo =
new CosmosEntityInformation<>(SpELPropertyStudent.class);
assertEquals(TestConstants.DYNAMIC_PROPERTY_COLLECTION_NAME, propertyStudentInfo.getCollectionName());
assertEquals(TestConstants.DYNAMIC_PROPERTY_COLLECTION_NAME, propertyStudentInfo.getContainerName());
}
@Test
public void testDynamicCollectionNameWithBeanExpression() {
public void testDynamicContainerNameWithBeanExpression() {
final CosmosEntityInformation<SpELBeanStudent, Object> beanStudentInfo =
new CosmosEntityInformation<>(SpELBeanStudent.class);
assertEquals(TestConstants.DYNAMIC_BEAN_COLLECTION_NAME, beanStudentInfo.getCollectionName());
assertEquals(TestConstants.DYNAMIC_BEAN_COLLECTION_NAME, beanStudentInfo.getContainerName());
}
@Test
@ -91,10 +91,10 @@ public class SpELCosmosDBAnnotationIT {
final MappingCosmosConverter mappingConverter = new MappingCosmosConverter(dbContext, objectMapper);
cosmosTemplate = new CosmosTemplate(dbFactory, mappingConverter, TestConstants.DB_NAME);
cosmosTemplate.createCollectionIfNotExists(cosmosEntityInformation);
cosmosTemplate.createContainerIfNotExists(cosmosEntityInformation);
final SpELPropertyStudent insertedRecord =
cosmosTemplate.insert(cosmosEntityInformation.getCollectionName(), TEST_PROPERTY_STUDENT, null);
cosmosTemplate.insert(cosmosEntityInformation.getContainerName(), TEST_PROPERTY_STUDENT, null);
assertNotNull(insertedRecord);
final SpELPropertyStudent readRecord =

Просмотреть файл

@ -42,7 +42,7 @@ public class SquareRepositoryIT {
@PreDestroy
public void cleanUpCollection() {
template.deleteCollection(entityInformation.getCollectionName());
template.deleteContainer(entityInformation.getContainerName());
}
@Before

Просмотреть файл

@ -64,7 +64,7 @@ public class StudentRepositoryIT {
@PreDestroy
public void cleanUpCollection() {
template.deleteCollection(entityInformation.getCollectionName());
template.deleteContainer(entityInformation.getContainerName());
}
@Before

Просмотреть файл

@ -48,21 +48,21 @@ public class CosmosEntityInformationUnitTest {
}
@Test
public void testGetCollectionName() {
public void testGetContainerName() {
final CosmosEntityInformation<Person, String> entityInformation =
new CosmosEntityInformation<Person, String>(Person.class);
final String collectionName = entityInformation.getCollectionName();
assertThat(collectionName).isEqualTo(Person.class.getSimpleName());
final String containerName = entityInformation.getContainerName();
assertThat(containerName).isEqualTo(Person.class.getSimpleName());
}
@Test
public void testCustomCollectionName() {
public void testCustomContainerName() {
final CosmosEntityInformation<VersionedVolunteer, String> entityInformation =
new CosmosEntityInformation<VersionedVolunteer, String>(VersionedVolunteer.class);
final String collectionName = entityInformation.getCollectionName();
assertThat(collectionName).isEqualTo("testCollection");
final String containerName = entityInformation.getContainerName();
assertThat(containerName).isEqualTo("testCollection");
}
@Test