當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。