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


Java Query.setUnique方法代碼示例

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


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

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

示例2: getInvTotalCount

import javax.jdo.Query; //導入方法依賴的package包/類
public Integer getInvTotalCount(Map<String, String> filter) throws SQLException{
  PersistenceManager pm = PMF.get().getPersistenceManager();
  StringBuilder
      sb =
      new StringBuilder("SELECT COUNT(1) AS COUNT FROM INVNTRY WHERE KID = " + Long.parseLong(
          filter.get(Constants.ENTITY)));
  if (filter.get(Constants.MATERIAL_TAG) != null) {
    sb.append(
        " AND MID IN (SELECT MATERIALID FROM MATERIAL_TAGS WHERE ID IN (SELECT ID FROM TAG WHERE NAME IN (")
        .append(String.valueOf(filter.get(Constants.MATERIAL_TAG))).append(")))");
  }
  Query query = pm.newQuery("javax.jdo.query.SQL",sb.toString());
  query.setUnique(true);
  Object object = query.execute();
  Integer count = ((Long) object).intValue();
  return count;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:18,代碼來源:DashboardService.java

示例3: getUserDevice

import javax.jdo.Query; //導入方法依賴的package包/類
@Override
public IUserDevice getUserDevice(String userid, String appname) throws ServiceException {

  IUserDevice userDevice = null;
  PersistenceManager pm = null;
  try {
    pm = PMF.get().getPersistenceManager();
    Query query = pm.newQuery(JDOUtils.getImplClass(IUserDevice.class));
    query.setFilter("userId == userIdParam && appname == appnameParam");
    query.declareParameters("String userIdParam, String appnameParam");
    //Query query = pm.newQuery("javax.jdo.query.SQL",q);
    query.setUnique(true);
    userDevice = (IUserDevice) query.execute(userid, appname);
    userDevice = pm.detachCopy(userDevice);
    return userDevice;
  } catch (Exception e) {
    xLogger.severe("{0} while getting user device {1}", e.getMessage(), userid, e);
    throw new ServiceException("Issue with getting user device for user :" + userid);
  } finally {
    if (pm != null) {
      pm.close();
    }
  }
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:25,代碼來源:UsersServiceImpl.java

示例4: isApprover

import javax.jdo.Query; //導入方法依賴的package包/類
@Override
public Boolean isApprover(String userId) throws SQLException {
  PersistenceManager pm = PMF.get().getPersistenceManager();
  Query query = null;
  IUserAccount userAccount;
  try {
    String
        sqlQuery =
        "SELECT 1 FROM APPROVERS WHERE UID = ? LIMIT 1";
    query = pm.newQuery(Constants.JAVAX_JDO_QUERY_SQL, sqlQuery);
    query.setUnique(true);
    if ((query.execute(userId)) != null) {
      return true;
    }
    userAccount = JDOUtils.getObjectById(IUserAccount.class, userId, pm);
    DomainConfig dc = DomainConfig.getInstance(userAccount.getDomainId());
    ApprovalsConfig.OrderConfig ac = dc.getApprovalsConfig().getOrderConfig();
    return ac != null && ac.isApprover(userId);
  } finally {
    if(query != null) {
      query.closeAll();
    }
    pm.close();
  }
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:26,代碼來源:OrderApprovalsServiceImpl.java

示例5: findInvBatch

import javax.jdo.Query; //導入方法依賴的package包/類
public IInvntryBatch findInvBatch(Long kioskId, Long materialId, String batchId,
                                  PersistenceManager pm) {
  if (batchId == null) {
    throw new IllegalArgumentException("Batch Id cannot be null");
  }
  Query
      q =
      pm.newQuery("SELECT FROM " + JDOUtils.getImplClassName(IInvntryBatch.class)
          + " WHERE kId == kIdParam && " +
          "mId == mIdParam && bid == bIdParam PARAMETERS Long kIdParam, Long mIdParam, String bIdParam");
  Map<String, Object> params = new HashMap<>();
  params.put("kIdParam", kioskId);
  params.put("mIdParam", materialId);
  params.put("bIdParam", batchId.toUpperCase());
  try {
    q.setUnique(true);
    IInvntryBatch result = (IInvntryBatch) q.executeWithMap(params);
    return pm.detachCopy(result);
  } finally {
    if (q != null) {
      q.closeAll();
    }
  }
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:25,代碼來源:InvntryDao.java

示例6: getConversationById

import javax.jdo.Query; //導入方法依賴的package包/類
public IConversation getConversationById(String convId) throws ServiceException {
  IConversation conversation = null;
  PersistenceManager pm = null;
  try {
    pm = PMF.get().getPersistenceManager();
    Query query = pm.newQuery(JDOUtils.getImplClass(IConversation.class));
    query.setFilter("id == :convIdParam");
    Map<String, String> paramValues = new HashMap<>(1);
    paramValues.put("convIdParam", convId);
    query.setUnique(true);
    conversation = (IConversation) query.executeWithMap(paramValues);
    conversation = pm.detachCopy(conversation);
  } catch (Exception e) {
    xLogger.severe("{0} while creating getting conversation {1}", e.getMessage(), convId, e);
    throw new ServiceException(e);
  } finally {
    if (pm != null) {
      pm.close();
    }
  }
  return conversation;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:23,代碼來源:ConversationServiceImpl.java

示例7: getSingle

import javax.jdo.Query; //導入方法依賴的package包/類
/**
 * Gets single result from Database
 * @param qp
 * @param pm
 * @param pageParams
 * @param <T>
 * @return
 */
public static <T> T getSingle(QueryParams qp, PersistenceManager pm,
                                  PageParams pageParams){
  T result = null;
  Query q = getQuery(qp, pm, pageParams);
  q.setUnique(true);
  try {
    result = (T) getResults(qp,q);
    if(result != null){
      result = pm.detachCopy(result);
    }
  } finally {
    q.closeAll();
  }
  return result;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:24,代碼來源:JDOUtils.java

示例8: hasAccessToKiosk

import javax.jdo.Query; //導入方法依賴的package包/類
public Integer hasAccessToKiosk(String userId, Long kioskId) {
  PersistenceManager pm = PMF.get().getPersistenceManager();
  Query query = null;
  try {
    String
        qry =
        "SELECT IF(R = 'c,v' OR R = 'v,c',GREATEST(C, V),IF(R = 'c', C, V)) Perm FROM(SELECT (SELECT GROUP_CONCAT(KL.LINKTYPE) R FROM KIOSKLINK KL WHERE KL.LINKEDKIOSKID = ?"
            +
            " AND KL.KIOSKID = K.KIOSKID) R,K.CPERM C,K.VPERM V FROM KIOSK K, (SELECT KIOSKID FROM USERTOKIOSK UK WHERE KIOSKID IN (SELECT DISTINCT KL.LINKEDKIOSKID FROM KIOSKLINK KL WHERE KIOSKID = ?)"
            +
            " AND USERID = ?) UK WHERE K.KIOSKID = UK.KIOSKID AND (K.CPERM > 0 OR K.VPERM > 0)) PERM limit 1";
    query = pm.newQuery("javax.jdo.query.SQL", qry);
    query.setUnique(true);
    Integer hasAccess = (Integer) query.executeWithArray(kioskId, kioskId, userId);
    if (hasAccess != null && hasAccess > 0) {
      return hasAccess;
    } else {
      return 0;
    }
  } finally {
    if (query != null) {
      try {
        query.closeAll();
      } catch (Exception ignored) {
        xLogger.warn("Exception while closing query", ignored);
      }
    }
    pm.close();
  }
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:31,代碼來源:EntitiesServiceImpl.java

示例9: getOrderApprovalMapping

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

示例10: validateEntityBatchManagementUpdate

import javax.jdo.Query; //導入方法依賴的package包/類
@Override
public boolean validateEntityBatchManagementUpdate(Long kioskId, PersistenceManager pm) throws ServiceException {
  if (kioskId == null) {
    throw new ServiceException("Invalid or null kioskId {0} while changing batch management on entity", kioskId);
  }
  boolean useLocalPm = false;
  if (pm == null) {
    pm = PMF.get().getPersistenceManager();
    useLocalPm = true;
  }

  Query query = null;
  List<String> parameters = new ArrayList<>(1);
  try {
    StringBuilder sqlQuery = new StringBuilder("SELECT 1 FROM INVNTRY I, MATERIAL M WHERE I.MID = M.MATERIALID AND M.BM = 1 AND I.STK > 0 AND I.KID = ").append(CharacterConstants.QUESTION);
    parameters.add(String.valueOf(kioskId));
    sqlQuery.append( " LIMIT 1");
    query = pm.newQuery("javax.jdo.query.SQL", sqlQuery.toString());
    query.setUnique(true);
    Long hasInv = (Long) query.executeWithArray(parameters.toArray());
    return (hasInv == null);
  } finally {
    if (query != null) {
      try {
        query.closeAll();
      } catch (Exception ignored) {
        xLogger.warn("Exception while closing query", ignored);
      }
    }
    if (useLocalPm) {
      pm.close();
    }
  }
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:35,代碼來源:InvntryDao.java

示例11: validateMaterialBatchManagementUpdate

import javax.jdo.Query; //導入方法依賴的package包/類
@Override
public boolean validateMaterialBatchManagementUpdate(Long materialId, PersistenceManager pm) throws ServiceException {
  if (materialId == null) {
    throw new ServiceException("Invalid or null materialId {0} while changing batch management on material", materialId);
  }
  boolean useLocalPm = false;
  if (pm == null) {
    pm = PMF.get().getPersistenceManager();
    useLocalPm = true;
  }

  Query query = null;
  List<String> parameters = new ArrayList<>(1);
  try {
    StringBuilder sqlQuery = new StringBuilder("SELECT 1 FROM INVNTRY I, MATERIAL M WHERE I.MID = M.MATERIALID AND M.MATERIALID = ").append(CharacterConstants.QUESTION);
    parameters.add(String.valueOf(materialId));
    sqlQuery.append(" AND I.STK > 0 LIMIT 1");
    query = pm.newQuery("javax.jdo.query.SQL", sqlQuery.toString());
    query.setUnique(true);
    Long hasInv = (Long) query.executeWithArray(parameters.toArray());
    return (hasInv == null);
  } finally {
    if (query != null) {
      try {
        query.closeAll();
      } catch (Exception ignored) {
        xLogger.warn("Exception while closing query", ignored);
      }
    }
    if (useLocalPm) {
      pm.close();
    }
  }
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:35,代碼來源:InvntryDao.java

示例12: closeOpenEvent

import javax.jdo.Query; //導入方法依賴的package包/類
private boolean closeOpenEvent(Long invId, PersistenceManager pm) {
  boolean useLocalPm = pm == null;
  if (useLocalPm) {
    pm = PMF.get().getPersistenceManager();
  }
  Query query = null;
  try {
    StringBuilder queryStr = new StringBuilder("SELECT * FROM INVNTRYEVNTLOG WHERE INVID = ");
    queryStr.append(invId);
    queryStr.append(" AND ED IS NULL");
    query =
        pm.newQuery("javax.jdo.query.SQL",
            queryStr.toString());
    query.setClass(JDOUtils.getImplClass(IInvntryEvntLog.class));
    query.setUnique(true);
    IInvntryEvntLog invntryEvntLog = (IInvntryEvntLog) query.execute();
    if (invntryEvntLog != null) {
      // Update the end date to now
      invntryEvntLog.setEndDate(new Date());
      pm.makePersistent(invntryEvntLog);
    }
  } catch (Exception e) {
    xLogger.warn(
        "Exception while closing open event for inventory item, invId: {0}", invId, e);
    return false;
  } finally {
    if (query != null) {
      query.closeAll();
    }
    if (useLocalPm) {
      pm.close();
    }
  }
  return true;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:36,代碼來源:InventoryManagementServiceImpl.java

示例13: getInvMaterialCount

import javax.jdo.Query; //導入方法依賴的package包/類
/**
 * Method to get the count of unique materials for a given domain id
 *
 * @param domainId Domain Id
 * @return Count of unique materials
 */
public Long getInvMaterialCount(Long domainId, Long tagId) throws ServiceException {
  if (domainId == null) {
    return 0L;
  }
  StringBuilder
      queryBuilder =
      new StringBuilder(
          "SELECT COUNT(DISTINCT(MID)) FROM INVNTRY WHERE KID IN (SELECT KIOSKID_OID FROM KIOSK_DOMAINS WHERE DOMAIN_ID=?)");
  Long count;
  try {
    List<String> parameters = new ArrayList<>(2);
    PersistenceManager pm = PMF.get().getPersistenceManager();
    Query query;
    if (tagId != null) {
      queryBuilder.append(" AND MID IN (SELECT MATERIALID FROM MATERIAL_TAGS WHERE ID=?)");
      parameters.add(String.valueOf(tagId));
    }
    query = pm.newQuery("javax.jdo.query.SQL", queryBuilder.toString());
    parameters.add(String.valueOf(domainId));
    query.setUnique(true);
    count = (Long) query.executeWithArray(parameters.toArray());
  } catch (Exception e) {
    xLogger.warn("Exception fetching the count", e);
    throw new ServiceException("Failed to fetch count");
  }
  return count;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:34,代碼來源:InventoryManagementServiceImpl.java

示例14: getMessageById

import javax.jdo.Query; //導入方法依賴的package包/類
public IMessage getMessageById(String messageId) throws ServiceException {

    IMessage message = null;
    PersistenceManager pm = null;
    Query query = null;
    try {
      pm = PMF.get().getPersistenceManager();
      query = pm.newQuery(JDOUtils.getImplClass(IMessage.class));
      query.setFilter("messageId == :messageIdParam");
      Map<String, String> paramValues = new HashMap<>();
      paramValues.put("messageIdParam", messageId);
      query.setUnique(true);
      message = (IMessage) query.executeWithMap(paramValues);
      message = pm.detachCopy(message);
    } catch (Exception e) {
      xLogger.severe("{0} while getting message {1}", e.getMessage(), messageId, e);
      throw new ServiceException(e);
    } finally {
      if (query != null) {
        try {
          query.closeAll();
        } catch (Exception ignored) {
          xLogger.warn("Exception while closing query", ignored);
        }
      }
      if (pm != null) {
        pm.close();
      }
    }
    return message;
  }
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:32,代碼來源:MessageDao.java

示例15: getApprovalType

import javax.jdo.Query; //導入方法依賴的package包/類
public Integer getApprovalType(Long orderId, String approvalId) {
  Integer type = null;
  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);
      orderApprovalMapping = pm.detachCopy(orderApprovalMapping);
      if (orderApprovalMapping != null) {
        type = orderApprovalMapping.getApprovalType();
      }
    } 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();
      }
    }
  }
  return type;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:42,代碼來源:ApprovalsDao.java


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