spring-projects / spring-projects/spring-data-couchbase
Allow for using @TypeAlias annotations [DATACOUCH-399]
@davidkelly is already working on this.
Since Dec 31, 2020.
- Dominant language
- Java
- Stars
- 284
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
Marcelo Grossi opened DATACOUCH-399 and commented
IndexManager is not respecting the configured TypeMapper in MappingCouchbaseConverter when creating secondary indices and views. It simply uses the classes fully qualified name (as below).
String typeKey = couchbaseOperations.getConverter().getTypeKey();
final String type = metadata.getDomainType().getName();
If one has a TypeMapper that makes use of the @TypeAlias annotation this will make the implementation unusable as the converter will correctly use the type mapper to identify the type, but (in case of no-primary-key deployments) won't have a proper index to query on your entity.
package com.sample;
@Document
@TypeAlias("my-document")
public class MyDocument {
}
@Repository
@N1qlSecondaryIndexed(indexName = "my-document-index")
public interface MyDocumentRepository extends CouchbaseRepository<MyDocument, String> {
}
The example document/repository above expects documents created in Couchbase to have a "_class" field with the value "my-document" and a secondary index like:
CREATE INDEX `my-document-index` ON `my-bucket`(`_class`) WHERE (`_class` = "my-document")
But instead, the secondary index is created as:
CREATE INDEX `my-document-index` ON `my-bucket`(`_class`) WHERE (`_class` = "com.sample.MyDocument")
In deployments where there is no primary index available your data becomes unsearchable. Which makes the generated repository unusable.
I believe that exposing the TypeMapper on MappingCouchbaseConverter via simple getter should be enough to implement this. The code in IndexManager would look like:
CouchbaseDocument tempTypeHolder = new CouchbaseDocument();
couchbaseOperations.getConverter().getTypeMapper().writeType(metadata.getDomainType(), tempTypeHolder);
final String type = tempTypeHolder.get(typeKey).toString();
1 votes, 3 watchers
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.