Example #1
0
  protected void generateView(Map<String, org.ektorp.support.DesignDocument.View> views, Field f) {
    DocumentReferences referenceMetaData = f.getAnnotation(DocumentReferences.class);
    if (referenceMetaData == null) {
      LOG.warn("No DocumentReferences annotation found in field: ", f.getName());
      return;
    }

    if (referenceMetaData.view().length() > 0) {
      LOG.debug("Skipping view generation for field {} as view is already specified", f.getName());
      return;
    }

    if (Set.class.isAssignableFrom(f.getType())) {
      generateSetBasedDocRefView(views, f, referenceMetaData);
    } else {
      throw new ViewGenerationException(
          String.format(
              "The type of the field: %s in %s annotated with DocumentReferences is not supported. (Must be assignable from java.util.Set)",
              f.getName(), f.getDeclaringClass()));
    }
  }
Example #2
0
  private void generateSetBasedDocRefView(
      Map<String, org.ektorp.support.DesignDocument.View> views,
      Member me,
      DocumentReferences referenceMetaData) {
    String fieldName = firstCharToLowerCase(me.getName());
    String orderBy = referenceMetaData.orderBy();
    String backRef = referenceMetaData.backReference();
    if (backRef.length() == 0) {
      throw new ViewGenerationException(
          String.format(
              "The DocumentReferences annotation in %s must specify a backReference",
              me.getDeclaringClass()));
    }
    String viewName = NameConventions.backReferenceViewName(fieldName);
    String typeDiscriminator = resolveTypeDiscriminatorForBackReference(me);
    if (orderBy.length() > 0) {

      views.put(
          viewName,
          generateDocRefsAsSetWithOrderByView(backRef, fieldName, orderBy, typeDiscriminator));
    } else {
      views.put(viewName, generateDocRefsAsSetView(backRef, fieldName, typeDiscriminator));
    }
  }