Example #1
0
 S3ObjectSummary findAndQueueObjects(AmazonS3Source.S3Offset s3offset, boolean checkCurrent)
     throws AmazonClientException {
   List<S3ObjectSummary> s3ObjectSummaries;
   ObjectOrdering objectOrdering = s3ConfigBean.s3FileConfig.objectOrdering;
   switch (objectOrdering) {
     case TIMESTAMP:
       s3ObjectSummaries =
           AmazonS3Util.listObjectsChronologically(
               s3Client, s3ConfigBean, pathMatcher, s3offset, objectQueue.remainingCapacity());
       break;
     case LEXICOGRAPHICAL:
       s3ObjectSummaries =
           AmazonS3Util.listObjectsLexicographically(
               s3Client, s3ConfigBean, pathMatcher, s3offset, objectQueue.remainingCapacity());
       break;
     default:
       throw new IllegalArgumentException("Unknown ordering: " + objectOrdering.getLabel());
   }
   for (S3ObjectSummary objectSummary : s3ObjectSummaries) {
     addObjectToQueue(objectSummary, checkCurrent);
   }
   spoolQueueMeter.mark(objectQueue.size());
   LOG.debug("Found '{}' files", objectQueue.size());
   return (s3ObjectSummaries.isEmpty())
       ? null
       : s3ObjectSummaries.get(s3ObjectSummaries.size() - 1);
 }
Example #2
0
  private void addOrdering(InterpretationContext context, ObjectOrdering ordering)
      throws QueryException {

    ItemPath orderByPath = ordering.getOrderBy();

    // TODO if we'd like to have order-by extension properties, we'd need to provide itemDefinition
    // for them
    ProperDataSearchResult<JpaDataNodeDefinition> result =
        context
            .getItemPathResolver()
            .findProperDataDefinition(
                context.getRootEntityDefinition(), orderByPath, null, JpaDataNodeDefinition.class);
    if (result == null) {
      LOGGER.error(
          "Unknown path '"
              + orderByPath
              + "', couldn't find definition for it, "
              + "list will not be ordered by it.");
      return;
    }
    JpaDataNodeDefinition targetDefinition = result.getLinkDefinition().getTargetDefinition();
    if (targetDefinition instanceof JpaAnyContainerDefinition) {
      throw new QueryException(
          "Sorting based on extension item or attribute is not supported yet: " + orderByPath);
    } else if (targetDefinition instanceof JpaReferenceDefinition) {
      throw new QueryException("Sorting based on reference is not supported: " + orderByPath);
    } else if (result.getLinkDefinition().isMultivalued()) {
      throw new QueryException(
          "Sorting based on multi-valued item is not supported: " + orderByPath);
    } else if (targetDefinition instanceof JpaEntityDefinition) {
      throw new QueryException("Sorting based on entity is not supported: " + orderByPath);
    } else if (!(targetDefinition instanceof JpaPropertyDefinition)) {
      throw new IllegalStateException("Unknown item definition type: " + result.getClass());
    }

    JpaEntityDefinition baseEntityDefinition = result.getEntityDefinition();
    JpaPropertyDefinition orderByDefinition = (JpaPropertyDefinition) targetDefinition;
    String hqlPropertyPath =
        context
            .getItemPathResolver()
            .resolveItemPath(
                orderByPath, null, context.getPrimaryEntityAlias(), baseEntityDefinition, true)
            .getHqlPath();
    if (RPolyString.class.equals(orderByDefinition.getJpaClass())) {
      hqlPropertyPath += ".orig";
    }

    RootHibernateQuery hibernateQuery = context.getHibernateQuery();
    if (ordering.getDirection() != null) {
      switch (ordering.getDirection()) {
        case ASCENDING:
          hibernateQuery.addOrdering(hqlPropertyPath, OrderDirection.ASCENDING);
          break;
        case DESCENDING:
          hibernateQuery.addOrdering(hqlPropertyPath, OrderDirection.DESCENDING);
          break;
      }
    } else {
      hibernateQuery.addOrdering(hqlPropertyPath, OrderDirection.ASCENDING);
    }
  }