DATACOUCH-196 - Fix ViewIndexed generated map and improve usability
The generated view's default map function now emits meta.id so that CRUD findAll(ids) works. The default value for the view name is now "all". The ViewIndexed isn't documented as applicable to METHODs (deferred feature).
This commit is contained in:
@@ -29,24 +29,25 @@ import java.lang.annotation.Target;
|
||||
* The view must at least be described as a design document name and view name. Default map function
|
||||
* will filter documents on the type associated to the repository, and default reduce function is "_count".
|
||||
* <p/>
|
||||
* One can specify a custom reduce function as well as a non-default map function. This can be done on methods,
|
||||
* allowing for multiple views per repository to be created.
|
||||
* One can specify a custom reduce function as well as a non-default map function.
|
||||
*
|
||||
* @author Simon Baslé
|
||||
*/
|
||||
@Target({ElementType.TYPE, ElementType.METHOD})
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ViewIndexed {
|
||||
|
||||
/**
|
||||
* The design document in which to create/look for the view.
|
||||
* The design document in which to create/look for the view. Usually to create the backing view for CRUD
|
||||
* methods, the expected designDoc value is the entity's simple class name, with a lowercase first letter
|
||||
* (eg. a UserInfo repository would expect a design document named "userInfo").
|
||||
*/
|
||||
String designDoc();
|
||||
|
||||
/**
|
||||
* The name of the view.
|
||||
* The name of the view, defaults to "all" (which is what CRUD methods expect by default).
|
||||
*/
|
||||
String viewName();
|
||||
String viewName() default "all";
|
||||
|
||||
/**
|
||||
* The map function to use (default is empty, which will trigger a default map function filtering on the
|
||||
|
||||
@@ -56,7 +56,7 @@ public class IndexManager {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(IndexManager.class);
|
||||
|
||||
private static final String TEMPLATE_MAP_FUNCTION = "function (doc, meta) { if(doc.%s == \"%s\") { emit(null, null); } }";
|
||||
private static final String TEMPLATE_MAP_FUNCTION = "function (doc, meta) { if(doc.%s == \"%s\") { emit(meta.id, null); } }";
|
||||
|
||||
private static final JsonObject SUCCESS_MARKER = JsonObject.empty();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user