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


Java Query類代碼示例

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


Query類屬於javax.jdo包,在下文中一共展示了Query類的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: 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

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

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

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

示例6: getAll

import javax.jdo.Query; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private <T> List<T> getAll(Long domainId, Class<T> clz) {
  List<T> o = null;
  PersistenceManager pm = PMF.get().getPersistenceManager();
  Query q = pm.newQuery(JDOUtils.getImplClass(clz));
  String declaration = " Long dIdParam";
  q.setFilter("dId == dIdParam");
  q.declareParameters(declaration);
  try {
    o = (List<T>) q.execute(domainId);
    if (o != null) {
      o.size();
      o = (List<T>) pm.detachCopyAll(o);
    }
  } finally {
    try {
      q.closeAll();
    } catch (Exception ignored) {
      xLogger.warn("Exception while closing query", ignored);
    }
    pm.close();
  }
  return o;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:25,代碼來源:DashboardService.java

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

示例8: getMaterialByName

import javax.jdo.Query; //導入依賴的package包/類
@Override
public List<IMaterial> getMaterialByName(Long domainId, String materialName) {
  PersistenceManager pm = PMF.get().getPersistenceManager();
  Query query = pm.newQuery(Material.class);
  query.setFilter("dId.contains(domainIdParam) && uName == unameParam");
  query.declareParameters("Long domainIdParam, String unameParam");
  List<IMaterial> results = null;
  try {
    results = (List<IMaterial>) query.execute(domainId, materialName);
    if (results != null) {
      results = (List<IMaterial>) pm.detachCopyAll(results);
    }
  } catch (Exception e) {
    xLogger.warn("Error while fetching materials with name {0}", materialName, e);
  } finally {
    try {
      query.closeAll();
    } catch (Exception ignored) {
      xLogger.warn("Exception while closing query", ignored);
    }
    pm.close();
  }
  return results;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:25,代碼來源:MaterialDao.java

示例9: getQuery

import javax.jdo.Query; //導入依賴的package包/類
private static Query getQuery(QueryParams qp, PersistenceManager pm,
                              PageParams pageParams) {
  Query q;
  if (QueryParams.QTYPE.SQL.equals(qp.qType)) {
    String query = qp.query;
    if (query != null && pageParams != null && !query.contains(" LIMIT ")) {
      query +=
          " LIMIT " + pageParams.getOffset() + CharacterConstants.COMMA + pageParams
              .getSize();
    }
    q = pm.newQuery("javax.jdo.query.SQL", query);
    q.setClass(JDOUtils.getImplClass(qp.qClazz));
  } else {
    q = pm.newQuery(qp.query);
    if (pageParams != null) {
      QueryUtil.setPageParams(q, pageParams);
    }
  }
  return q;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:21,代碼來源:JDOUtils.java

示例10: getAllRootDomains

import javax.jdo.Query; //導入依賴的package包/類
@Override
public List<IDomain> getAllRootDomains() {
  PersistenceManager pm = PMF.get().getPersistenceManager();
  Query query = pm.newQuery(JDOUtils.getImplClass(IDomain.class));
  query.setFilter("hasParent == false");
  query.setOrdering("nNm asc");
  List<IDomain> domains;
  try {
    domains = (List<IDomain>) query.execute();
    domains = (List<IDomain>) pm.detachCopyAll(domains);
  } catch (Exception e) {
    xLogger.severe("Error while fetching root domains", e);
    throw new InvalidServiceException(backendMessages.getString("domains.fetch.error"));
  } finally {
    try {
      query.closeAll();
    } catch (Exception ignored) {
      xLogger.warn("Exception while closing query", ignored);
    }
    pm.close();
  }
  return domains;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:24,代碼來源:DomainsServiceImpl.java

示例11: getApprovers

import javax.jdo.Query; //導入依賴的package包/類
/**
 * Get the list of approvers for a given kiosk id
 * @param kioskId
 * @return
 */
@Override
public List<IApprover> getApprovers(Long kioskId, PersistenceManager pm) {
  if(kioskId != null) {
    Query query = null;
    try {
      query = pm.newQuery(JDOUtils.getImplClass(IApprover.class));
      query.setFilter("kid == kioskIdParam");
      query.declareParameters("Long kioskIdParam");
      List<IApprover> approversList = (List<IApprover>) query.execute(kioskId);
      return (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);
        }
      }
    }
  }
  return Collections.emptyList();

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

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

示例13: getAccess

import javax.jdo.Query; //導入依賴的package包/類
private boolean getAccess(Map<String, Object> params, String queryStr) {
  PersistenceManager pm = PMF.get().getPersistenceManager();
  boolean hasAccess = false;
  List<Long> results;
  Query q = null;
  try {
    q = pm.newQuery(queryStr);
    results = (List<Long>) q.executeWithMap(params);
    if (results != null && results.size() == 1) {
      hasAccess = true;
    }
  } finally {
    if (q != null) {
      try {
        q.closeAll();
      } catch (Exception ignored) {
        xLogger.warn("Exception while closing query", ignored);
      }
    }
    pm.close();
  }
  return hasAccess;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:24,代碼來源:EntitiesServiceImpl.java

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

示例15: getMultiple

import javax.jdo.Query; //導入依賴的package包/類
/**
 * Helper method to execute a JDO query in SQL and JQL.
 * @param qp
 * @param pm
 * @param pageParams
 * @return
 */
public static <T> List<T> getMultiple(QueryParams qp, PersistenceManager pm,
                                      PageParams pageParams){
  List<T> results = null;
  Query q = getQuery(qp, pm, pageParams);
  try {
    results = (List<T>) getResults(qp, q);
    if(results != null){
      results = (List<T>) pm.detachCopyAll(results);
    }

  } finally {
    q.closeAll();
  }
  return results;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:23,代碼來源:JDOUtils.java


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