Skip to content

Allow id to be type other than String. #1533

New issue

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

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

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public CouchbaseDocument encodeEntity(final Object entityToEncode) {
}

@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
Expand Down Expand Up @@ -146,7 +146,7 @@ public <T> T decodeEntity(String id, String source, Long cas, Class<T> entityCla
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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Mono<CouchbaseDocument> encodeEntity(Object entityToEncode) {
}

@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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public Mono<CouchbaseDocument> encodeEntity(final Object entityToEncode) {
}

@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
Expand Down Expand Up @@ -118,7 +118,7 @@ public <T> Mono<T> decodeEntity(String id, String source, Long cas, Class<T> ent
+ 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
Expand Down Expand Up @@ -146,7 +146,7 @@ public <T> Mono<T> decodeEntity(String id, String source, Long cas, Class<T> ent
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();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Mono<T> one(T object) {
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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Mono<T> one(T object) {
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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Mono<T> one(T object) {
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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -68,7 +68,7 @@ public CouchbaseDocument() {
*
* @param id the document ID.
*/
public CouchbaseDocument(final String id) {
public CouchbaseDocument(final Object id) {
this(id, DEFAULT_EXPIRATION_TIME);
}

Expand All @@ -78,7 +78,7 @@ public CouchbaseDocument(final String id) {
* @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<>();
Expand Down Expand Up @@ -245,7 +245,7 @@ public CouchbaseDocument setExpiration(int expiration) {
*
* @return the ID of the document.
*/
public String getId() {
public Object getId() {
return id;
}

Expand All @@ -255,7 +255,7 @@ public String getId() {
* @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;
}
Expand Down