Ejemplo n.º 1
0
  private void interpretPagingAndSorting(
      InterpretationContext context, ObjectQuery query, boolean countingObjects)
      throws QueryException {
    RootHibernateQuery hibernateQuery = context.getHibernateQuery();
    String rootAlias = hibernateQuery.getPrimaryEntityAlias();

    if (query != null && query.getPaging() instanceof ObjectPagingAfterOid) {
      ObjectPagingAfterOid paging = (ObjectPagingAfterOid) query.getPaging();
      if (paging.getOidGreaterThan() != null) {
        Condition c =
            hibernateQuery.createSimpleComparisonCondition(
                rootAlias + ".oid", paging.getOidGreaterThan(), ">");
        hibernateQuery.addCondition(c);
      }
    }

    if (!countingObjects && query != null && query.getPaging() != null) {
      if (query.getPaging() instanceof ObjectPagingAfterOid) {
        updatePagingAndSortingByOid(
            hibernateQuery,
            (ObjectPagingAfterOid)
                query.getPaging()); // very special case - ascending ordering by OID (nothing more)
      } else {
        updatePagingAndSorting(context, query.getPaging());
      }
    }
  }
Ejemplo n.º 2
0
 protected void updatePagingAndSortingByOid(
     RootHibernateQuery hibernateQuery, ObjectPagingAfterOid paging) {
   String rootAlias = hibernateQuery.getPrimaryEntityAlias();
   if (paging.getOrderBy() != null
       || paging.getDirection() != null
       || paging.getOffset() != null) {
     throw new IllegalArgumentException(
         "orderBy, direction nor offset is allowed on ObjectPagingAfterOid");
   }
   hibernateQuery.addOrdering(rootAlias + ".oid", OrderDirection.ASCENDING);
   if (paging.getMaxSize() != null) {
     hibernateQuery.setMaxResults(paging.getMaxSize());
   }
 }