当前位置: 首页>>代码示例>>Java>>正文


Java Query.setRange方法代码示例

本文整理汇总了Java中javax.jdo.Query.setRange方法的典型用法代码示例。如果您正苦于以下问题:Java Query.setRange方法的具体用法?Java Query.setRange怎么用?Java Query.setRange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.jdo.Query的用法示例。


在下文中一共展示了Query.setRange方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: decorate

import javax.jdo.Query; //导入方法依赖的package包/类
/**
 * Given a query, this method will decorate that query with pagination, ordering,
 * and sorting direction. Specific checks are performed to ensure the execution
 * of the query is capable of being paged and that ordering can be securely performed.
 * @param query the JDO Query object to execute
 * @return a Collection of objects
 * @since 1.0.0
 */
public Query decorate(final Query query) {
    // Clear the result to fetch if previously specified (i.e. by getting count)
    query.setResult(null);
    if (pagination != null && pagination.isPaginated()) {
        final long begin = pagination.getOffset();
        final long end = begin + pagination.getLimit();
        query.setRange(begin, end);
    }
    if (orderBy != null && RegexSequence.Pattern.ALPHA_NUMERIC.matcher(orderBy).matches() && orderDirection != OrderDirection.UNSPECIFIED) {
        // Check to see if the specified orderBy field is defined in the class being queried.
        boolean found = false;
        final org.datanucleus.store.query.Query iq = ((JDOQuery) query).getInternalQuery();
        for (Field field: iq.getCandidateClass().getDeclaredFields()) {
            if (orderBy.equals(field.getName())) {
                found = true;
                break;
            }
        }
        if (found) {
            query.setOrdering(orderBy + " " + orderDirection.name().toLowerCase());
        }
    }
    return query;
}
 
开发者ID:stevespringett,项目名称:Alpine,代码行数:33,代码来源:AbstractAlpineQueryManager.java

示例2: getInvntryEvntLog

import javax.jdo.Query; //导入方法依赖的package包/类
@Override
public List<IInvntryEvntLog> getInvntryEvntLog(Long invId, int size, int offset) {
  PersistenceManager pm = PMF.get().getPersistenceManager();
  List<IInvntryEvntLog> results;
  try {
    Query q = pm.newQuery(InvntryEvntLog.class);
    q.setFilter("invId == invIdParam");
    Map<String, Object> params = new HashMap<>();
    params.put("invIdParam", invId);
    q.declareParameters("Long invIdParam");
    q.setOrdering("sd desc");
    q.setRange(offset, offset + size);
    results = (List<IInvntryEvntLog>) q.executeWithMap(params);
    results = (List<IInvntryEvntLog>) pm.detachCopyAll(results);
  } finally {
    pm.close();
  }
  return results;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:20,代码来源:InvntryDao.java

示例3: getCnt

import javax.jdo.Query; //导入方法依赖的package包/类
private static int getCnt(Query query, Object o1, Object o2, Map map) {
  if (query == null) {
    return -1;
  }
  query.setResult(QueryConstants.COUNT);
  query.setRange(null);
  query.setOrdering(null);
  Long cnt;
  if (map != null) {
    cnt = (Long) query.executeWithMap(map);
  } else {
    cnt = (Long) query.execute(o1, o2);
  }
  return Integer.parseInt(String.valueOf(cnt));

}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:17,代码来源:Counter.java

示例4: setPageParams

import javax.jdo.Query; //导入方法依赖的package包/类
public static void setPageParams(Query q, PageParams pageParams) {
  // Add pagination parameters, if needed
  if (q != null && pageParams != null) {
    String cursorStr = pageParams.getCursor();
    boolean hasCursor = (cursorStr != null && !cursorStr.isEmpty());
    int size = pageParams.getSize();
    int startOffset = pageParams.getOffset();
    int endOffset = startOffset + size;
    if (hasCursor) {
      daoUtil.setCursorExtensions(cursorStr, q);
      startOffset =
          0; // ensure that the offset is always zero, when cursor is present (given the range is starting from this cursor)
      endOffset =
          size; // ensure that end offset is size (and does not include startOffset within)
    }
    // Set the range
    if (endOffset > 0) {
      q.setRange(startOffset, endOffset);
    }
  }
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:22,代码来源:QueryUtil.java

示例5: getOrderApprovalMapping

import javax.jdo.Query; //导入方法依赖的package包/类
public IOrderApprovalMapping getOrderApprovalMapping(Long orderId, Integer approvalType) {
  IOrderApprovalMapping orderApprovalMapping = null;
  List<IOrderApprovalMapping> results = null;
  if (orderId != null) {
    PersistenceManager pm = null;
    Query query = null;
    try {
      pm = PMF.get().getPersistenceManager();
      Map<String, Object> params = new HashMap<>();
      query = pm.newQuery(JDOUtils.getImplClass(IOrderApprovalMapping.class));
      query.setFilter("orderId == orderIdParam && approvalType == approvalTypeParam");
      query.declareParameters("Long orderIdParam, Integer approvalTypeParam");
      query.setOrdering("createdAt desc");
      query.setRange(0, 1);
      params.put(ORDER_ID_PARAM, orderId);
      params.put(APPROVAL_TYPE_PARAM, approvalType);
      results = (List<IOrderApprovalMapping>) query.executeWithMap(params);
      if (results != null && !results.isEmpty()) {
        orderApprovalMapping = results.get(0);
      }
    } catch (Exception e) {
      xLogger.warn("Failed to get order approval mapping for order: {0}",
          orderId, e);
    } finally {
      if (query != null) {
        try {
          query.closeAll();
        } catch (Exception ignored) {
          xLogger.warn("Exception while closing query", ignored);
        }
      }
      if (pm != null) {
        pm.close();
      }
    }
  }
  return orderApprovalMapping;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:39,代码来源:ApprovalsDao.java

示例6: getConversationId

import javax.jdo.Query; //导入方法依赖的package包/类
@Override
public String getConversationId(String objectType, String objectId, PersistenceManager pm) {
  Query query = pm.newQuery(Conversation.class);
  query.setFilter("objectId == objIdParam && objectType == objTypeParam");
  query.declareParameters("String objIdParam, String objTypeParam");
  Map<String, Object> params = new HashMap<>(2);
  params.put("objIdParam", objectId);
  params.put("objTypeParam", objectType);
  query.setRange(0, 1);
  List<Conversation> results = (List<Conversation>) query.executeWithMap(params);
  if (results != null && !results.isEmpty()) {
    return results.get(0).getId();
  }
  return null;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:16,代码来源:MessageDao.java

示例7: getLatestUpload

import javax.jdo.Query; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public IUploaded getLatestUpload(String filename, String locale) throws ServiceException {
  if (filename == null || filename.isEmpty() || locale == null || locale.isEmpty()) {
    throw new ServiceException("Invalid arguments - filename or locale not specified");
  }
  IUploaded u = null;
  PersistenceManager pm = PMF.get().getPersistenceManager();
  Query q = pm.newQuery(JDOUtils.getImplClass(IUploaded.class));
  q.setFilter("fn == fnParam && l == lParam");
  q.declareParameters("String fnParam, String lParam");
  q.setOrdering("t desc");
  q.setRange(0, 1); // get the latest single entry
  try {
    List<IUploaded> results = (List<IUploaded>) q.execute(filename, locale);
    if (results != null && results.size() > 0) {
      u = results.get(0);
      u = pm.detachCopy(u);
    }
  } finally {
    try {
      q.closeAll();
    } catch (Exception ignored) {
      xLogger.warn("Exception while closing query", ignored);
    }
    pm.close();
  }

  return u;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:30,代码来源:UploadServiceImpl.java


注:本文中的javax.jdo.Query.setRange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。