DATACOUCH-309 Convert IDs as well if custom conversions are available in Simple Repository

Original pull request: #146.
This commit is contained in:
Subhashni Balakrishnan
2017-06-06 15:15:04 -07:00
parent c7e4801305
commit 047921956b
5 changed files with 160 additions and 4 deletions

View File

@@ -103,19 +103,19 @@ public class SimpleCouchbaseRepository<T, ID extends Serializable> implements Co
@Override
public Optional<T> findById(ID id) {
Assert.notNull(id, "The given id must not be null!");
return Optional.ofNullable(couchbaseOperations.findById(id.toString(), entityInformation.getJavaType()));
return Optional.ofNullable(couchbaseOperations.findById(couchbaseOperations.getConverter().convertForWriteIfNeeded(id).toString(), entityInformation.getJavaType()));
}
@Override
public boolean existsById(ID id) {
Assert.notNull(id, "The given id must not be null!");
return couchbaseOperations.exists(id.toString());
return couchbaseOperations.exists(couchbaseOperations.getConverter().convertForWriteIfNeeded(id).toString());
}
@Override
public void deleteById(ID id) {
Assert.notNull(id, "The given id must not be null!");
couchbaseOperations.remove(id.toString());
couchbaseOperations.remove(couchbaseOperations.getConverter().convertForWriteIfNeeded(id).toString());
}
@Override
@@ -149,7 +149,7 @@ public class SimpleCouchbaseRepository<T, ID extends Serializable> implements Co
query.stale(getCouchbaseOperations().getDefaultConsistency().viewConsistency());
JsonArray keys = JsonArray.create();
for (ID id : ids) {
keys.add(id);
keys.add(couchbaseOperations.getConverter().convertForWriteIfNeeded(id));
}
query.keys(keys);