Allow id to be type other than String. (#1533)

Closes #1529.
This commit is contained in:
Michael Reiche
2022-08-05 10:30:35 -07:00
committed by GitHub
parent f76a64563a
commit 48742b145d
9 changed files with 16 additions and 16 deletions

View File

@@ -87,7 +87,7 @@ class CouchbaseTemplateSupport implements ApplicationContextAware, TemplateSuppo
}
@Override
public <T> T decodeEntity(String id, String source, Long cas, Class<T> entityClass, String scope, String collection) {
public <T> T decodeEntity(Object id, String source, Long cas, Class<T> entityClass, String scope, String collection) {
// this is the entity class defined for the repository. It may not be the class of the document that was read
// we will reset it after reading the document
@@ -146,7 +146,7 @@ class CouchbaseTemplateSupport implements ApplicationContextAware, TemplateSuppo
if (cas != null && cas != 0 && persistentEntity.getVersionProperty() != null) {
accessor.setProperty(persistentEntity.getVersionProperty(), cas);
}
N1qlJoinResolver.handleProperties(persistentEntity, accessor, template.reactive(), id, scope, collection);
N1qlJoinResolver.handleProperties(persistentEntity, accessor, template.reactive(), id.toString(), scope, collection);
return accessor.getBean();
}

View File

@@ -40,7 +40,7 @@ public class NonReactiveSupportWrapper implements ReactiveTemplateSupport {
}
@Override
public <T> Mono<T> decodeEntity(String id, String source, Long cas, Class<T> entityClass, String scope,
public <T> Mono<T> decodeEntity(Object id, String source, Long cas, Class<T> entityClass, String scope,
String collection) {
return Mono.fromSupplier(() -> support.decodeEntity(id, source, cas, entityClass, scope, collection));
}

View File

@@ -86,7 +86,7 @@ class ReactiveCouchbaseTemplateSupport implements ApplicationContextAware, React
}
@Override
public <T> Mono<T> decodeEntity(String id, String source, Long cas, Class<T> entityClass, String scope,
public <T> Mono<T> decodeEntity(Object id, String source, Long cas, Class<T> entityClass, String scope,
String collection) {
return Mono.fromSupplier(() -> {
// this is the entity class defined for the repository. It may not be the class of the document that was read
@@ -118,7 +118,7 @@ class ReactiveCouchbaseTemplateSupport implements ApplicationContextAware, React
+ TemplateUtils.SELECT_ID);
}
final CouchbaseDocument converted = new CouchbaseDocument(id);
final CouchbaseDocument converted = new CouchbaseDocument(id.toString());
// if possible, set the version property in the source so that if the constructor has a long version argument,
// it will have a value and not fail (as null is not a valid argument for a long argument). This possible failure
@@ -146,7 +146,7 @@ class ReactiveCouchbaseTemplateSupport implements ApplicationContextAware, React
if (cas != null && cas != 0 && persistentEntity.getVersionProperty() != null) {
accessor.setProperty(persistentEntity.getVersionProperty(), cas);
}
N1qlJoinResolver.handleProperties(persistentEntity, accessor, template, id, scope, collection);
N1qlJoinResolver.handleProperties(persistentEntity, accessor, template, id.toString(), scope, collection);
return accessor.getBean();
});
}

View File

@@ -84,7 +84,7 @@ public class ReactiveInsertByIdOperationSupport implements ReactiveInsertByIdOpe
return Mono.just(object).flatMap(support::encodeEntity)
.flatMap(converted -> template.getCouchbaseClientFactory().withScope(pArgs.getScope())
.getCollection(pArgs.getCollection()).reactive()
.insert(converted.getId(), converted.export(), buildOptions(pArgs.getOptions(), converted))
.insert(converted.getId().toString(), converted.export(), buildOptions(pArgs.getOptions(), converted))
.flatMap(result -> support.applyUpdatedId(object, converted.getId())
.flatMap(updatedObject -> support.applyUpdatedCas(updatedObject, converted, result.cas()))))
.onErrorMap(throwable -> {

View File

@@ -84,7 +84,7 @@ public class ReactiveReplaceByIdOperationSupport implements ReactiveReplaceByIdO
return Mono.just(object).flatMap(support::encodeEntity)
.flatMap(converted -> template.getCouchbaseClientFactory().withScope(pArgs.getScope())
.getCollection(pArgs.getCollection()).reactive()
.replace(converted.getId(), converted.export(),
.replace(converted.getId().toString(), converted.export(),
buildReplaceOptions(pArgs.getOptions(), object, converted))
.flatMap(result -> support.applyUpdatedCas(object, converted, result.cas())))
.onErrorMap(throwable -> {

View File

@@ -27,7 +27,7 @@ public interface ReactiveTemplateSupport {
Mono<CouchbaseDocument> encodeEntity(Object entityToEncode);
<T> Mono<T> decodeEntity(String id, String source, Long cas, Class<T> entityClass, String scope, String collection);
<T> Mono<T> decodeEntity(Object id, String source, Long cas, Class<T> entityClass, String scope, String collection);
<T> Mono<T> applyUpdatedCas(T entity, CouchbaseDocument converted, long cas);

View File

@@ -84,7 +84,7 @@ public class ReactiveUpsertByIdOperationSupport implements ReactiveUpsertByIdOpe
return Mono.just(object).flatMap(support::encodeEntity)
.flatMap(converted -> template.getCouchbaseClientFactory().withScope(pArgs.getScope())
.getCollection(pArgs.getCollection()).reactive()
.upsert(converted.getId(), converted.export(), buildUpsertOptions(pArgs.getOptions(), converted))
.upsert(converted.getId().toString(), converted.export(), buildUpsertOptions(pArgs.getOptions(), converted))
.flatMap(result -> support.applyUpdatedId(object, converted.getId())
.flatMap(updatedObject -> support.applyUpdatedCas(updatedObject, converted, result.cas()))))
.onErrorMap(throwable -> {

View File

@@ -26,7 +26,7 @@ public interface TemplateSupport {
CouchbaseDocument encodeEntity(Object entityToEncode);
<T> T decodeEntity(String id, String source, Long cas, Class<T> entityClass, String scope, String collection);
<T> T decodeEntity(Object id, String source, Long cas, Class<T> entityClass, String scope, String collection);
<T> T applyUpdatedCas(T entity, CouchbaseDocument converted, long cas);

View File

@@ -49,7 +49,7 @@ public class CouchbaseDocument implements CouchbaseStorable {
/**
* Represents the document ID used to identify the document in the bucket.
*/
private String id;
private Object id;
/**
* Contains the expiration time of the document.
@@ -68,7 +68,7 @@ public class CouchbaseDocument implements CouchbaseStorable {
*
* @param id the document ID.
*/
public CouchbaseDocument(final String id) {
public CouchbaseDocument(final Object id) {
this(id, DEFAULT_EXPIRATION_TIME);
}
@@ -78,7 +78,7 @@ public class CouchbaseDocument implements CouchbaseStorable {
* @param id the document ID.
* @param expiration the expiration time of the document.
*/
public CouchbaseDocument(final String id, final int expiration) {
public CouchbaseDocument(final Object id, final int expiration) {
this.id = id;
this.expiration = expiration;
content = new TreeMap<>();
@@ -245,7 +245,7 @@ public class CouchbaseDocument implements CouchbaseStorable {
*
* @return the ID of the document.
*/
public String getId() {
public Object getId() {
return id;
}
@@ -255,7 +255,7 @@ public class CouchbaseDocument implements CouchbaseStorable {
* @param id the ID of the document.
* @return the {@link CouchbaseDocument} for chaining.
*/
public CouchbaseDocument setId(String id) {
public CouchbaseDocument setId(Object id) {
this.id = id;
return this;
}