当前位置: 首页>>代码示例>>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;未经允许,请勿转载。