本文整理匯總了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;
}