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


Java Query.setFilter方法代碼示例

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


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

示例1: checkCustomIdExists

import javax.jdo.Query; //導入方法依賴的package包/類
@Override
public boolean checkCustomIdExists(Long domainId, String customId) {
  PersistenceManager pm = PMF.get().getPersistenceManager();
  // Check if another material by the same custom ID exists in the database
  Query query = pm.newQuery(Material.class);
  query.setFilter("dId.contains(domainIdParam) && cId == cidParam");
  query.declareParameters("Long domainIdParam, String cidParam");
  boolean customIdExists = false;
  try {
    @SuppressWarnings("unchecked")
    List<IMaterial> results = (List<IMaterial>) query.execute(domainId, customId);
    if (results != null && results.size() == 1) {
      // Material with this name already exists in the database!
      customIdExists = true;
    }
  } finally {
    try {
      query.closeAll();
    } catch (Exception ignored) {
      xLogger.warn("Exception while closing query", ignored);
    }
    pm.close();
  }
  xLogger.fine("Exiting checkIfCustomIdExists");
  return customIdExists;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:27,代碼來源:MaterialDao.java

示例2: updateOrderApprovalStatus

import javax.jdo.Query; //導入方法依賴的package包/類
public void updateOrderApprovalStatus(Long orderId, String approvalId, String status) {
  if (orderId != null && StringUtils.isNotEmpty(approvalId)) {
    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 && approvalId == approvalIdParam ");
      query.declareParameters("Long orderIdParam, String approvalIdParam");
      params.put("orderIdParam", orderId);
      params.put(APPROVAL_ID_PARAM, approvalId);
      query.setUnique(true);
      IOrderApprovalMapping orderApprovalMapping = (IOrderApprovalMapping) query
          .executeWithMap(params);
      if (orderApprovalMapping != null) {
        orderApprovalMapping.setStatus(status);
        orderApprovalMapping.setUpdatedAt(new Date());
        pm.makePersistent(orderApprovalMapping);
      }
    } catch (Exception e) {
      xLogger.warn("Failed to get order approval mapping for order: {0} with approval: {1}",
          orderId, approvalId, e);
    } finally {
      if (query != null) {
        try {
          query.closeAll();
        } catch (Exception ignored) {
          xLogger.warn(ignored.getMessage(), ignored);
        }
      }
      if (pm != null) {
        pm.close();
      }
    }
  }
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:38,代碼來源:ApprovalsDao.java

示例3: findId

import javax.jdo.Query; //導入方法依賴的package包/類
public IInvntry findId(Long kioskId, Long materialId, PersistenceManager pm) {
  Query q = pm.newQuery(Invntry.class);
  try {
    q.setFilter("kId == " + kioskId.toString() + " && mId == " + materialId.toString());
    Object results = q.execute();
    if (results instanceof IInvntry) {
      results = pm.detachCopy(results);
      return (Invntry) results;
    } else if (results instanceof List) {
      if (!((List) results).isEmpty()) {
        Invntry result = ((List<Invntry>) results).get(0);
        result = pm.detachCopy(result);
        return result;
      }
    }
    return null;
  } finally {
    if (q != null) {
      q.closeAll();
    }
  }
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:23,代碼來源:InvntryDao.java

示例4: getShortId

import javax.jdo.Query; //導入方法依賴的package包/類
public Long getShortId(Long kioskId) {
  PersistenceManager pm = PMF.get().getPersistenceManager();
  Query q = null;
  try {
    q = pm.newQuery(JDOUtils.getImplClass(IInvntry.class));
    q.setResult("max(sId)");
    q.setFilter("kId == " + kioskId);
    Long count = (Long) q.execute();
    return count == null ? -1 : count;
  } catch (Exception e) {
    xLogger.warn("Error while getting short id for kiosk {0}", kioskId, e);
    return null;
  } finally {
    if (q != null) {
      try {
        q.closeAll();
      } catch (Exception ignored) {
        xLogger.warn("Exception while closing query", ignored);
      }
    }
    if (pm != null) {
      pm.close();
    }
  }
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:26,代碼來源:InventoryManagementServiceImpl.java

示例5: 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

示例6: findShortId

import javax.jdo.Query; //導入方法依賴的package包/類
public IInvntry findShortId(Long kioskId, Long shortId, PersistenceManager pm) {
  Query q = pm.newQuery(Invntry.class);
  try {
    q.setFilter("kId == " + kioskId.toString() + " && sId == " + shortId.toString());
    Object results = q.execute();
    if (results instanceof IInvntry) {
      results = pm.detachCopy(results);
      return (Invntry) results;
    } else if (results instanceof List) {
      if (!((List) results).isEmpty()) {
        Invntry result = ((List<Invntry>) results).get(0);
        result = pm.detachCopy(result);
        return result;
      }
    }
    return null;
  } finally {
    if (q != null) {
      q.closeAll();
    }
  }
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:23,代碼來源:InvntryDao.java

示例7: checkIfCustomIdExists

import javax.jdo.Query; //導入方法依賴的package包/類
private boolean checkIfCustomIdExists(IUserAccount userAccount) {
  xLogger.fine("Entering checkIfCustomIdExists");
  boolean customIdExists = false;
  xLogger.fine("object is an instance of UserAccount");
  Long domainId = userAccount.getDomainId();
  PersistenceManager pm = PMF.get().getPersistenceManager();
  // Check if another user by the same custom ID exists in the database
  Query query = pm.newQuery(JDOUtils.getImplClass(IUserAccount.class));
  query.setFilter("dId.contains(domainIdParam) && cId == cidParam");
  query.declareParameters("Long domainIdParam, String cidParam");
  try {
    @SuppressWarnings("unchecked")
    List<IUserAccount>
        results =
        (List<IUserAccount>) query.execute(domainId, userAccount.getCustomId());
    if (results != null && results.size() == 1) {
      // UserAccount with this custom id already exists in the database!
      xLogger.warn(
          "Error while adding or updating user Account {0}: Custom ID {1} already exists.",
          userAccount.getUserId(), userAccount.getCustomId());
      customIdExists = true;
    }
  } finally {
    try {
      query.closeAll();
    } catch (Exception ignored) {
      xLogger.warn("Exception while closing query", ignored);
    }
    pm.close();
  }
  return customIdExists;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:33,代碼來源:UsersServiceImpl.java

示例8: getKioskByName

import javax.jdo.Query; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public IKiosk getKioskByName(Long domainId, String kioskName) throws ServiceException {
  xLogger.fine("Entering getKiosk");
  if (domainId == null || kioskName == null || kioskName.isEmpty()) {
    throw new ServiceException("Invalid parameters");
  }
  IKiosk k = null;
  // Form query
  PersistenceManager pm = PMF.get().getPersistenceManager();
  // Update the UserAccount to set the route enabled flag
  try {
    // Form the query
    Query kioskQuery = pm.newQuery(JDOUtils.getImplClass(IKiosk.class));
    kioskQuery.setFilter("dId.contains(dIdParam) && nName == nameParam");
    kioskQuery.declareParameters("Long dIdParam, String nameParam");
    // Execute the query
    try {
      List<IKiosk> results = (List<IKiosk>) kioskQuery.execute(domainId, kioskName.toLowerCase());
      if (results != null && !results.isEmpty()) {
        k = results.get(0);
        k = pm.detachCopy(k);
      }
    } finally {
      kioskQuery.closeAll();
    }
  } catch (Exception e) {
    xLogger.severe("{0} when trying to get Kiosk for kiosk Name {1}. Message: {2}",
        e.getClass().getName(), kioskName, e.getMessage());
  } finally {
    pm.close();
  }
  xLogger.fine("Exiting getKiosk");
  return k;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:35,代碼來源:EntitiesServiceImpl.java

示例9: 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

示例10: getTagByName

import javax.jdo.Query; //導入方法依賴的package包/類
@Override
public ITag getTagByName(String name, int type) {
  PersistenceManager pm = PMF.get().getPersistenceManager();
  Query query = pm.newQuery(Tag.class);
  query.setFilter("name == nameParam && type == typeParam");
  query.declareParameters("String nameParam,Integer typeParam");
  ITag result = null;
  try {
    List<ITag> results = (List<ITag>) query.execute(name, type);
    if (results != null && results.size() > 0) {
      result = results.get(0);
      result = pm.detachCopy(result);
    } else {
      ITag tag = new Tag(type, name);
      tag = pm.makePersistent(tag);
      return pm.detachCopy(tag);
    }
  } catch (Exception e) {
    xLogger.warn("Error while fetching tag with name {0} and type {1}", name, type, e);
  } finally {
    try {
      query.closeAll();
    } catch (Exception ignored) {
      xLogger.warn("Exception while closing query", ignored);
    }
    pm.close();
  }
  return result;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:30,代碼來源:TagDao.java

示例11: isAnApprover

import javax.jdo.Query; //導入方法依賴的package包/類
/**
 * Checks whether a given user is an approver for purchase/sales/transfer orders in a given domain
 * @param userId
 * @param domainId
 * @return
 */
public boolean isAnApprover(String userId, Long domainId) {
  if(StringUtils.isNotEmpty(userId) && domainId != null) {
    PersistenceManager pm = null;
    Query query = null;
    try {
      pm = PMF.get().getPersistenceManager();
      Map<String, Object> params = new HashMap<>();
      query = pm.newQuery(JDOUtils.getImplClass(IApprover.class));
      query.setFilter("uid == userIdParam && sdid == domainIdParam");
      query.declareParameters("String userIdParam, Long domainIdParam");
      params.put("userIdParam", userId);
      params.put("domainIdParam", domainId);
      IApprover approvers = (IApprover) query.executeWithMap(params);
      if(approvers != null) {
        return true;
      }
    } catch (Exception e) {
      xLogger.fine("Failed to get approvals for user: {0} in domain : {1}", userId, domainId, e);
    } finally {
      if (query != null) {
        try {
          query.closeAll();
        } catch (Exception ignored) {
          xLogger.warn("Exception while closing query", ignored);
        }
      }
      if (pm != null) {
        pm.close();
      }
    }
  }

  return true;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:41,代碼來源:EntitiesServiceImpl.java

示例12: getSuperusers

import javax.jdo.Query; //導入方法依賴的package包/類
/**
 * Get all the super users (across domains)
 */
@SuppressWarnings("unchecked")
public List<IUserAccount> getSuperusers() throws ServiceException {
  xLogger.fine("Entering getSuperusers");
  List<IUserAccount> superUsers = null;
  PersistenceManager pm = PMF.get().getPersistenceManager();
  Query q = pm.newQuery(JDOUtils.getImplClass(IUserAccount.class));
  String roleParam = SecurityConstants.ROLE_SUPERUSER;
  String declaration = " String roleParam";
  q.setFilter("role == roleParam");
  q.declareParameters(declaration);
  try {
    superUsers = (List<IUserAccount>) q.execute(roleParam);
    if (superUsers != null) {
      superUsers.size(); // This is done so that pm can be closed without throwing an exception.
      superUsers = (List<IUserAccount>) pm.detachCopyAll(superUsers);
    }
  } finally {
    try {
      q.closeAll();
    } catch (Exception ignored) {
      xLogger.warn("Exception while closing query", ignored);
    }
    pm.close();
  }
  xLogger.fine("Exiting getSuperusers");
  return superUsers;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:31,代碼來源:UsersServiceImpl.java

示例13: getApprovers

import javax.jdo.Query; //導入方法依賴的package包/類
/**
 * Get all the approvers for a given kioskId and approver type
 * @param kioskId
 * @return
 */
public List<IApprover> getApprovers(Long kioskId, int type) {
  List<IApprover> appList = null;
  if(kioskId != null) {
    PersistenceManager pm = null;
    Query query = null;
    try {
      pm = PMF.get().getPersistenceManager();
      Map<String, Object> params = new HashMap<>();
      query = pm.newQuery(JDOUtils.getImplClass(IApprover.class));
      query.setFilter("kid == kioskIdParam && type == typeParam");
      query.declareParameters("Long kioskIdParam, int typeParam");
      params.put("kioskIdParam", kioskId);
      params.put("typeParam", type);
      List<IApprover> approversList = (List<IApprover>) query.executeWithMap(params);
      appList = (List<IApprover>) pm.detachCopyAll(approversList);
    } catch (Exception e) {
      xLogger.warn("Failed to get approvers for Entity: {0}", kioskId, e);
    } finally {
      if (query != null) {
        try {
          query.closeAll();
        } catch (Exception ignored) {
          xLogger.warn("Exception while closing query", ignored);
        }
      }
      if (pm != null) {
        pm.close();
      }
    }
  }
  return appList;

}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:39,代碼來源:EntitiesServiceImpl.java

示例14: deleteAssetRelation

import javax.jdo.Query; //導入方法依賴的package包/類
public void deleteAssetRelation(Long assetId, Long domainId, IAsset asset, PersistenceManager pm) throws ServiceException {
  try {
    Query query = pm.newQuery(JDOUtils.getImplClass(IAssetRelation.class));
    query.setFilter("assetId == assetIdParam");
    query.declareParameters("Long assetIdParam");
    List<IAssetRelation> assetRelations = null;
    try {
      assetRelations = (List<IAssetRelation>) query.execute(assetId);
      assetRelations = (List<IAssetRelation>) pm.detachCopyAll(assetRelations);
    } catch (Exception ignored) {
      //do nothing
    } finally {
      query.closeAll();
    }

    if (assetRelations != null && assetRelations.size() == 1) {
      IAssetRelation assetRelationTmp = assetRelations.get(0);
      for(IAssetRelation assetRelation: assetRelations){
        EventPublisher.generate(domainId, IEvent.DELETED, null,
            JDOUtils.getImplClassName(IAssetRelation.class), String.valueOf(assetRelation.getId()), null, assetRelation);
      }
      pm.deletePersistent(assetRelationTmp);
    }
  } catch (Exception e) {
    xLogger
        .warn("{0} while deleting asset relationship for the asset {1}", e.getMessage(), assetId,
            e);
    throw new ServiceException(e.getMessage());
  }
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:31,代碼來源:AssetManagementServiceImpl.java

示例15: setManagedEntityRouteInfo

import javax.jdo.Query; //導入方法依賴的package包/類
/**
 * Set ManagedEntitiesRouteInfo
 */
@SuppressWarnings("unchecked")
public void setManagedEntityRouteInfo(Long domainId, String userId, Long kioskId, String routeTag,
                                      Integer routeIndex) throws ServiceException {
  // Get the UserToKiosk object for the userId and kioskId
  // Set the routeTag to routeTag
  // Do not set the routeIndex because it is already set to Default Route Index
  xLogger.fine("Entering setManagedEntityRouteInfo");

  if (domainId == null || userId == null || userId.isEmpty() || kioskId == null) {
    xLogger.warn("Invalid parameters. domainId: {0}, userId: {1}, kioskId: {2}", domainId, userId,
        kioskId);
    throw new ServiceException("Invalid parameters");
  }

  PersistenceManager pm = PMF.get().getPersistenceManager();
  // Update the UserAccount to set the route enabled flag
  try {
    // Form the query
    Query userToKioskQuery = pm.newQuery(JDOUtils.getImplClass(IUserToKiosk.class));
    userToKioskQuery.setFilter("kioskId == kioskIdParam");
    userToKioskQuery.declareParameters("Long kioskIdParam");
    // Execute the query
    try {
      List<IUserToKiosk> results = (List<IUserToKiosk>) userToKioskQuery.execute(kioskId);
      if (results != null && !results.isEmpty()) {
        // Iterate through the results
        // Check if userId of the UserToKiosk object matches with the userId that is passed
        // If it matches, then set the routeTag and routeIndex for that UserToKiosk object
        for (IUserToKiosk u2k : results) {
          if (u2k.getUserId().equals(userId)) {
            u2k.setTag(routeTag);
            if (routeIndex != null) {
              u2k.setRouteIndex(routeIndex);
            }
            break;
          }
        }
      }
    } finally {
      userToKioskQuery.closeAll();
    }
  } catch (Exception e) {
    xLogger.severe(
        "{0} when trying to set the route info for managed entities for user {1}. Message: {2}",
        e.getClass().getName(), userId, e.getMessage());
  } finally {
    pm.close();
  }

  xLogger.fine("Exiting updateManagedEntityRouteInfo");
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:55,代碼來源:EntitiesServiceImpl.java


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