當前位置: 首頁>>代碼示例>>Java>>正文


Java Query.declareImports方法代碼示例

本文整理匯總了Java中javax.jdo.Query.declareImports方法的典型用法代碼示例。如果您正苦於以下問題:Java Query.declareImports方法的具體用法?Java Query.declareImports怎麽用?Java Query.declareImports使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.jdo.Query的用法示例。


在下文中一共展示了Query.declareImports方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getItems

import javax.jdo.Query; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static Results getItems(Long domainId, Date start, PageParams pageParams) {
  xLogger.fine("Entered getItems");
  List<IBBoard> items = null;
  String cursor = null;
  PersistenceManager pm = PMF.get().getPersistenceManager();
  Query q = pm.newQuery(JDOUtils.getImplClass(IBBoard.class));
  String filter = "dId.contains(dIdParam)";
  String declaration = "Long dIdParam";
  String importStr = null;
  if (start != null) {
    filter += "&& t > startParam";
    declaration += ", Date startParam";
    importStr = " import java.util.Date;";
  }
  q.setFilter(filter);
  q.declareParameters(declaration);
  if (importStr != null) {
    q.declareImports(importStr);
  }
  q.setOrdering("t desc");
  if (pageParams != null) {
    QueryUtil.setPageParams(q, pageParams);
  }
  try {
    if (start != null) {
      items =
          (List<IBBoard>) q
              .execute(domainId, LocalDateUtil.getOffsetDate(start, -1, Calendar.MILLISECOND));
    } else {
      items = (List<IBBoard>) q.execute(domainId);
    }
    if (items != null) {
      items.size();
      cursor = QueryUtil.getCursor(items);
      items = (List<IBBoard>) pm.detachCopyAll(items);
    }
  } finally {
    try {
      q.closeAll();
    } catch (Exception ignored) {
      xLogger.warn("Exception while closing query", ignored);
    }
    pm.close();
  }
  xLogger.fine("Exiting getItems");
  return new Results(items, cursor);
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:49,代碼來源:BBHandler.java

示例2: getReportData

import javax.jdo.Query; //導入方法依賴的package包/類
/**
 * Get stock levels over time
 */
@SuppressWarnings("unchecked")
@Override
public ReportData getReportData(Date from, Date until, String frequency,
                                Map<String, Object> filters, Locale locale, String timezone,
                                PageParams pageParams, DomainConfig dc, String sourceUserId)
    throws ReportingDataException {
  xLogger.fine("Entered getReportData");
  // Validate the required filters
  if (from == null || until == null) {
    throw new ReportingDataException("Both from and until dates are required");
  }
  if (filters == null || filters.size() == 0) {
    throw new ReportingDataException("No material and kiosk filter were specified");
  }
  // Get the Ids
  Long materialId = (Long) filters.get(ReportsConstants.FILTER_MATERIAL);
  Long kioskId = (Long) filters.get(ReportsConstants.FILTER_KIOSK);
  if (materialId == null || kioskId == null) {
    throw new ReportingDataException(
        "Either the material and/or kiosk filter were not specified");
  }
  // Offset the from date
  Date modFrom = LocalDateUtil.getOffsetDate(from, -1, Calendar.MILLISECOND);
  // Get PM
  PersistenceManager pm = PMF.get().getPersistenceManager();
  // Form the query
  Query q = pm.newQuery(JDOUtils.getImplClass(IInvntryLog.class));
  q.setFilter("mId == mIdParam && kId == kIdParam && t > fromParam && t < untilParam");
  q.declareParameters("Long mIdParam, Long kIdParam, Date fromParam, Date untilParam");
  q.declareImports("import java.util.Date;");
  q.setOrdering("t asc"); // NOTE: indexes are defined on asc
  if (pageParams != null) {
    QueryUtil.setPageParams(q, pageParams);
  }
  // Get the param map
  Map<String, Object> paramMap = new HashMap<String, Object>();
  paramMap.put("mIdParam", materialId);
  paramMap.put("kIdParam", kioskId);
  paramMap.put("fromParam", modFrom);
  paramMap.put("untilParam", until);
  List<IInvntryLog> results = null;
  String cursor = null;
  try {
    // Execute query
    results = (List<IInvntryLog>) q.executeWithMap(paramMap);
    if (results != null) {
      results.size();
      cursor = QueryUtil.getCursor(results);
      results = (List<IInvntryLog>) pm.detachCopyAll(results);
    }
  } finally {
    try {
      q.closeAll();
    } catch (Exception ignored) {
      xLogger.warn("Exception while closing query", ignored);
    }
    pm.close();
  }
  // Get the re-order level
  BigDecimal reorderLevel = BigDecimal.ZERO;
  try {
    InventoryManagementService
        ims =
        Services.getService(InventoryManagementServiceImpl.class);
    IInvntry inv = ims.getInventory(kioskId, materialId);
    if (inv != null) {
      reorderLevel = inv.getReorderLevel();
    }
  } catch (ServiceException e) {
    xLogger.warn("ServiceException when getting inventory re-order level: {0}", e.getMessage());
  }
  xLogger.fine("Exiting getReportData");
  return new StockLevelData(from, until, filters, locale, timezone, results, cursor,
      reorderLevel);
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:79,代碼來源:StockLevelDataGenerator.java

示例3: getNotifactionLogs

import javax.jdo.Query; //導入方法依賴的package包/類
public static Results getNotifactionLogs(Long domainId, Date startDate, Date endDate,
                                         PageParams pageParams) throws MessageHandlingException {
  xLogger.fine("Entered getLogs");
  if (domainId == null) {
    throw new MessageHandlingException("No domainId specified");
  }
  Map<String, Object> params = new HashMap<>();
  List<IMessageLog> mlogs = null;
  String cursor = null;
  PersistenceManager pm = PMF.get().getPersistenceManager();
  Query q = pm.newQuery(JDOUtils.getImplClass(IMessageLog.class));
  boolean imports = false;
  params.put("dIdParam", domainId);
  params.put("notifParam", 1);
  String filter = "dId == dIdParam && notif == notifParam ";
  String declaration = "Long dIdParam , Integer notifParam ";
  if (startDate != null) {
    //offset date with less 1 milli second
    params
        .put("startDateParam", LocalDateUtil.getOffsetDate(startDate, -1, Calendar.MILLISECOND));
    filter += "&& t >= startDateParam ";
    declaration += ",Date startDateParam ";
    imports = true;
  }
  if (endDate != null) {
    //offset date with one day increase to get inclusive end date
    params.put("endDateParam", LocalDateUtil.getOffsetDate(endDate, +1, Calendar.DATE));
    filter += " && t < endDateParam ";
    declaration += ",Date endDateParam ";
    imports = true;
  }
  q.setFilter(filter);
  q.declareParameters(declaration);
  if (imports) {
    q.declareImports("import java.util.Date");
  }
  q.setOrdering("t desc");
  if (pageParams != null) {
    QueryUtil.setPageParams(q, pageParams);
  }
  try {
    mlogs = (List<IMessageLog>) q.executeWithMap(params);
    if (mlogs != null) {
      mlogs.size(); // TODO: to ensure all objects are retrieved before closing object manager
      cursor = QueryUtil.getCursor(mlogs);
      mlogs = (List<IMessageLog>) pm.detachCopyAll(mlogs);
      mlogs = sortByTime(mlogs);
    }
  } finally {
    try {
      q.closeAll();
    } catch (Exception ignored) {

    }
    pm.close();
  }
  return new Results(mlogs, cursor);
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:59,代碼來源:MessageUtil.java

示例4: getManuallyUploadedTransactions

import javax.jdo.Query; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static Results getManuallyUploadedTransactions(Long domainId, Long kioskId, Date sinceDate,
                                                      Date untilDate, PageParams pageParams)
    throws ServiceException {
  //Now execute the query and return the results
  Results results = null;
  PersistenceManager pm = PMF.get().getPersistenceManager();
  // Form the query
  Query query = pm.newQuery(JDOUtils.getImplClass(IMnlTransaction.class));
  String filter = "";
  String params = "";
  HashMap<String, Object> paramsMap = new HashMap<>();
  if (kioskId != null) { // Add the kiosk filter, if needed
    filter += "kId == kioskIdParam";
    params += "Long kioskIdParam";
    paramsMap.put("kioskIdParam", kioskId);
  } else if (domainId != null) {
    filter += "dId.contains(domainIdParam)";
    params += "Long domainIdParam";
    paramsMap.put("domainIdParam", domainId);
  }
  // From Date
  if (sinceDate != null) {
    if (!filter.isEmpty()) {
      filter += " && ";
      params += ", ";
    }
    filter += "rp > sinceDateParam";
    params += "Date sinceDateParam";
    query.declareImports("import java.util.Date");
    paramsMap.put("sinceDateParam", LocalDateUtil.getOffsetDate(sinceDate, -1,
        Calendar.DATE)); // we reduce this date by 1 date, so that we can avoid a >= query on time
  }
  if (untilDate != null) {
    if (!filter.isEmpty()) {
      filter += " && ";
      params += ", ";
    }
    filter += "rp <= untilDateParam";
    params += "Date untilDateParam";
    query.declareImports("import java.util.Date");
    paramsMap.put("untilDateParam", untilDate);
  }
  // Update query
  query.setFilter(filter);
  query.declareParameters(params);
  query.setOrdering("t desc");
  // Add pagination parameters, if needed
  if (pageParams != null) {
    QueryUtil.setPageParams(query, pageParams);
  }
  // Execute query
  try {
    xLogger.fine("Query: {0}, paramsMap: {1}", query.toString(), paramsMap.toString());
    List<IMnlTransaction> iList = (List<IMnlTransaction>) query.executeWithMap(paramsMap);
    iList
        .size(); // this is to force retrieval before closing PM; TODO change this later to be more efficient
    // Get the cursor of the next element in the result set (for future iteration, efficiently)
    String cursorStr = QueryUtil.getCursor(iList);
    iList = (List<IMnlTransaction>) pm.detachCopyAll(iList);
    // Create the result set
    results = new Results(iList, cursorStr);
  } catch (Exception e) {
    xLogger.warn("Exception: {0}", e.getMessage());
    throw new ServiceException(e.getMessage());
  } finally {
    try {
      query.closeAll();
    } catch (Exception ignored) {

    }
    pm.close();
  }
  return results;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:76,代碼來源:MnlTransactionUtil.java


注:本文中的javax.jdo.Query.declareImports方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。