本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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();
}
}
}
示例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();
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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));
}
示例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;
}