Ejemplo n.º 1
0
  public SqlQueryBuilder appendPathSegments(
      ProcessorManager processorManager,
      String databaseName,
      String tableName,
      ContentUri.PathSegment[] pathSegments) {
    TableDefinition tableDefinition = processorManager.getTableDefinition(databaseName, tableName);
    if (tableDefinition == null) {
      processorManager.logError(
          "Could not find table definition for %1s from %1s", tableName, databaseName);
    } else {
      for (ContentUri.PathSegment pathSegment : pathSegments) {
        ColumnDefinition columnDefinition = tableDefinition.mColumnMap.get(pathSegment.column());
        if (columnDefinition == null) {
          processorManager.logError(
              "Column %1s not found for table %1s",
              pathSegment.column(), tableDefinition.tableName);
        } else {
          append(
              String.format(
                  "\n.and(Condition.column%s(\"%1s\").is(",
                  (columnDefinition.hasTypeConverter && !columnDefinition.isBoolean) ? "Raw" : "",
                  pathSegment.column()));

          // primitive use value of
          if (columnDefinition.element.asType().getKind().isPrimitive()) {
            String name = columnDefinition.element.asType().toString();

            // handle char
            if ("char".equals(name)) {
              name = "character";
            }
            name = name.substring(0, 1).toUpperCase() + name.substring(1);
            append(
                String.format(
                    "%1s.valueOf(uri.getPathSegments().get(%1d))", name, pathSegment.segment()));
          } else {
            append(String.format("uri.getPathSegments().get(%1d)", pathSegment.segment()));
          }
          append("))");
        }
      }
    }
    return this;
  }
Ejemplo n.º 2
0
 public void putTableEndpointForProvider(TableEndpointDefinition tableEndpointDefinition) {
   ContentProviderDefinition contentProviderDefinition =
       providerMap.get(tableEndpointDefinition.contentProviderName);
   if (contentProviderDefinition == null) {
     logError(
         "Content Provider %1s was not found for the @TableEndpoint %1s",
         tableEndpointDefinition.contentProviderName, tableEndpointDefinition.elementClassName);
   } else {
     contentProviderDefinition.endpointDefinitions.add(tableEndpointDefinition);
   }
 }
Ejemplo n.º 3
0
  public TableEndpointDefinition(Element typeElement, ProcessorManager processorManager) {
    super(typeElement, processorManager);

    TableEndpoint endpoint = typeElement.getAnnotation(TableEndpoint.class);

    tableName = endpoint.name();

    contentProviderName = endpoint.contentProviderName();

    isTopLevel = typeElement.getEnclosingElement() instanceof PackageElement;

    List<? extends Element> elements =
        processorManager.getElements().getAllMembers((TypeElement) typeElement);
    for (Element innerElement : elements) {
      if (innerElement.getAnnotation(ContentUri.class) != null) {
        ContentUriDefinition contentUriDefinition =
            new ContentUriDefinition(innerElement, processorManager);
        if (!pathValidationMap.containsKey(contentUriDefinition.path)) {
          contentUriDefinitions.add(contentUriDefinition);
        } else {
          processorManager.logError(
              "There must be unique paths for the specified @ContentUri" + " %1s from %1s",
              contentUriDefinition.name, contentProviderName);
        }
      } else if (innerElement.getAnnotation(Notify.class) != null) {
        NotifyDefinition notifyDefinition = new NotifyDefinition(innerElement, processorManager);

        for (String path : notifyDefinition.paths) {
          Map<Notify.Method, List<NotifyDefinition>> methodListMap =
              notifyDefinitionPathMap.get(path);
          if (methodListMap == null) {
            methodListMap = Maps.newHashMap();
            notifyDefinitionPathMap.put(path, methodListMap);
          }

          List<NotifyDefinition> notifyDefinitionList = methodListMap.get(notifyDefinition.method);
          if (notifyDefinitionList == null) {
            notifyDefinitionList = Lists.newArrayList();
            methodListMap.put(notifyDefinition.method, notifyDefinitionList);
          }
          notifyDefinitionList.add(notifyDefinition);
        }
      }
    }
  }