本文整理汇总了Java中javax.jdo.Query.setResult方法的典型用法代码示例。如果您正苦于以下问题:Java Query.setResult方法的具体用法?Java Query.setResult怎么用?Java Query.setResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.jdo.Query
的用法示例。
在下文中一共展示了Query.setResult方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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();
}
}
}
示例3: 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));
}
示例4: getCount
import javax.jdo.Query; //导入方法依赖的package包/类
/**
* Returns the number of items that would have resulted from returning all object.
* This method is performant in that the objects are not actually retrieved, only
* the count.
* @param query the query to return a count from
* @return the number of items
* @since 1.0.0
*/
public long getCount(final Query query) {
//query.addExtension("datanucleus.query.resultSizeMethod", "count");
final String ordering = ((org.datanucleus.api.jdo.JDOQuery) query).getInternalQuery().getOrdering();
query.setResult("count(id)");
query.setOrdering(null);
final long count = (Long) query.execute();
query.setOrdering(ordering);
return count;
}