Skip to content

Commit 48742b1

Browse files
authored
Allow id to be type other than String. (#1533)
Closes #1529.
1 parent f76a645 commit 48742b1

9 files changed

+16
-16
lines changed

src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplateSupport.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public CouchbaseDocument encodeEntity(final Object entityToEncode) {
8787
}
8888

8989
@Override
90-
public <T> T decodeEntity(String id, String source, Long cas, Class<T> entityClass, String scope, String collection) {
90+
public <T> T decodeEntity(Object id, String source, Long cas, Class<T> entityClass, String scope, String collection) {
9191

9292
// this is the entity class defined for the repository. It may not be the class of the document that was read
9393
// we will reset it after reading the document
@@ -146,7 +146,7 @@ public <T> T decodeEntity(String id, String source, Long cas, Class<T> entityCla
146146
if (cas != null && cas != 0 && persistentEntity.getVersionProperty() != null) {
147147
accessor.setProperty(persistentEntity.getVersionProperty(), cas);
148148
}
149-
N1qlJoinResolver.handleProperties(persistentEntity, accessor, template.reactive(), id, scope, collection);
149+
N1qlJoinResolver.handleProperties(persistentEntity, accessor, template.reactive(), id.toString(), scope, collection);
150150
return accessor.getBean();
151151
}
152152

src/main/java/org/springframework/data/couchbase/core/NonReactiveSupportWrapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public Mono<CouchbaseDocument> encodeEntity(Object entityToEncode) {
4040
}
4141

4242
@Override
43-
public <T> Mono<T> decodeEntity(String id, String source, Long cas, Class<T> entityClass, String scope,
43+
public <T> Mono<T> decodeEntity(Object id, String source, Long cas, Class<T> entityClass, String scope,
4444
String collection) {
4545
return Mono.fromSupplier(() -> support.decodeEntity(id, source, cas, entityClass, scope, collection));
4646
}

src/main/java/org/springframework/data/couchbase/core/ReactiveCouchbaseTemplateSupport.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public Mono<CouchbaseDocument> encodeEntity(final Object entityToEncode) {
8686
}
8787

8888
@Override
89-
public <T> Mono<T> decodeEntity(String id, String source, Long cas, Class<T> entityClass, String scope,
89+
public <T> Mono<T> decodeEntity(Object id, String source, Long cas, Class<T> entityClass, String scope,
9090
String collection) {
9191
return Mono.fromSupplier(() -> {
9292
// 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 @@ public <T> Mono<T> decodeEntity(String id, String source, Long cas, Class<T> ent
118118
+ TemplateUtils.SELECT_ID);
119119
}
120120

121-
final CouchbaseDocument converted = new CouchbaseDocument(id);
121+
final CouchbaseDocument converted = new CouchbaseDocument(id.toString());
122122

123123
// if possible, set the version property in the source so that if the constructor has a long version argument,
124124
// 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 @@ public <T> Mono<T> decodeEntity(String id, String source, Long cas, Class<T> ent
146146
if (cas != null && cas != 0 && persistentEntity.getVersionProperty() != null) {
147147
accessor.setProperty(persistentEntity.getVersionProperty(), cas);
148148
}
149-
N1qlJoinResolver.handleProperties(persistentEntity, accessor, template, id, scope, collection);
149+
N1qlJoinResolver.handleProperties(persistentEntity, accessor, template, id.toString(), scope, collection);
150150
return accessor.getBean();
151151
});
152152
}

src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperationSupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public Mono<T> one(T object) {
8484
return Mono.just(object).flatMap(support::encodeEntity)
8585
.flatMap(converted -> template.getCouchbaseClientFactory().withScope(pArgs.getScope())
8686
.getCollection(pArgs.getCollection()).reactive()
87-
.insert(converted.getId(), converted.export(), buildOptions(pArgs.getOptions(), converted))
87+
.insert(converted.getId().toString(), converted.export(), buildOptions(pArgs.getOptions(), converted))
8888
.flatMap(result -> support.applyUpdatedId(object, converted.getId())
8989
.flatMap(updatedObject -> support.applyUpdatedCas(updatedObject, converted, result.cas()))))
9090
.onErrorMap(throwable -> {

src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperationSupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public Mono<T> one(T object) {
8484
return Mono.just(object).flatMap(support::encodeEntity)
8585
.flatMap(converted -> template.getCouchbaseClientFactory().withScope(pArgs.getScope())
8686
.getCollection(pArgs.getCollection()).reactive()
87-
.replace(converted.getId(), converted.export(),
87+
.replace(converted.getId().toString(), converted.export(),
8888
buildReplaceOptions(pArgs.getOptions(), object, converted))
8989
.flatMap(result -> support.applyUpdatedCas(object, converted, result.cas())))
9090
.onErrorMap(throwable -> {

src/main/java/org/springframework/data/couchbase/core/ReactiveTemplateSupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public interface ReactiveTemplateSupport {
2727

2828
Mono<CouchbaseDocument> encodeEntity(Object entityToEncode);
2929

30-
<T> Mono<T> decodeEntity(String id, String source, Long cas, Class<T> entityClass, String scope, String collection);
30+
<T> Mono<T> decodeEntity(Object id, String source, Long cas, Class<T> entityClass, String scope, String collection);
3131

3232
<T> Mono<T> applyUpdatedCas(T entity, CouchbaseDocument converted, long cas);
3333

src/main/java/org/springframework/data/couchbase/core/ReactiveUpsertByIdOperationSupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public Mono<T> one(T object) {
8484
return Mono.just(object).flatMap(support::encodeEntity)
8585
.flatMap(converted -> template.getCouchbaseClientFactory().withScope(pArgs.getScope())
8686
.getCollection(pArgs.getCollection()).reactive()
87-
.upsert(converted.getId(), converted.export(), buildUpsertOptions(pArgs.getOptions(), converted))
87+
.upsert(converted.getId().toString(), converted.export(), buildUpsertOptions(pArgs.getOptions(), converted))
8888
.flatMap(result -> support.applyUpdatedId(object, converted.getId())
8989
.flatMap(updatedObject -> support.applyUpdatedCas(updatedObject, converted, result.cas()))))
9090
.onErrorMap(throwable -> {

src/main/java/org/springframework/data/couchbase/core/TemplateSupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public interface TemplateSupport {
2626

2727
CouchbaseDocument encodeEntity(Object entityToEncode);
2828

29-
<T> T decodeEntity(String id, String source, Long cas, Class<T> entityClass, String scope, String collection);
29+
<T> T decodeEntity(Object id, String source, Long cas, Class<T> entityClass, String scope, String collection);
3030

3131
<T> T applyUpdatedCas(T entity, CouchbaseDocument converted, long cas);
3232

src/main/java/org/springframework/data/couchbase/core/mapping/CouchbaseDocument.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class CouchbaseDocument implements CouchbaseStorable {
4949
/**
5050
* Represents the document ID used to identify the document in the bucket.
5151
*/
52-
private String id;
52+
private Object id;
5353

5454
/**
5555
* Contains the expiration time of the document.
@@ -68,7 +68,7 @@ public CouchbaseDocument() {
6868
*
6969
* @param id the document ID.
7070
*/
71-
public CouchbaseDocument(final String id) {
71+
public CouchbaseDocument(final Object id) {
7272
this(id, DEFAULT_EXPIRATION_TIME);
7373
}
7474

@@ -78,7 +78,7 @@ public CouchbaseDocument(final String id) {
7878
* @param id the document ID.
7979
* @param expiration the expiration time of the document.
8080
*/
81-
public CouchbaseDocument(final String id, final int expiration) {
81+
public CouchbaseDocument(final Object id, final int expiration) {
8282
this.id = id;
8383
this.expiration = expiration;
8484
content = new TreeMap<>();
@@ -245,7 +245,7 @@ public CouchbaseDocument setExpiration(int expiration) {
245245
*
246246
* @return the ID of the document.
247247
*/
248-
public String getId() {
248+
public Object getId() {
249249
return id;
250250
}
251251

@@ -255,7 +255,7 @@ public String getId() {
255255
* @param id the ID of the document.
256256
* @return the {@link CouchbaseDocument} for chaining.
257257
*/
258-
public CouchbaseDocument setId(String id) {
258+
public CouchbaseDocument setId(Object id) {
259259
this.id = id;
260260
return this;
261261
}

0 commit comments

Comments
 (0)