com.googlecode.objectify.annotation.Id Java Examples

The following examples show how to use com.googlecode.objectify.annotation.Id. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ModelUtils.java    From nomulus with Apache License 2.0 5 votes vote down vote up
/** Return a string representing the persisted schema of a type or enum. */
static String getSchema(Class<?> clazz) {
  StringBuilder stringBuilder = new StringBuilder();
  Stream<?> body;
  if (clazz.isEnum()) {
    stringBuilder.append("enum ");
    body = Arrays.stream(clazz.getEnumConstants());
  } else {
    stringBuilder.append("class ");
    body =
        getAllFields(clazz)
            .values()
            .stream()
            .filter(field -> !field.isAnnotationPresent(Ignore.class))
            .map(
                field -> {
                  String annotation =
                      field.isAnnotationPresent(Id.class)
                          ? "@Id "
                          : field.isAnnotationPresent(Parent.class) ? "@Parent " : "";
                  String type =
                      field.getType().isArray()
                          ? field.getType().getComponentType().getName() + "[]"
                          : field.getGenericType().toString().replaceFirst("class ", "");
                  return String.format("%s%s %s", annotation, type, field.getName());
                });
  }
  return stringBuilder
      .append(clazz.getName())
      .append(" {\n  ")
      .append(body.map(Object::toString).sorted().collect(Collectors.joining(";\n  ")))
      .append(";\n}")
      .toString();
}