本文整理汇总了Java中javax.jdo.Query.setOrdering方法的典型用法代码示例。如果您正苦于以下问题:Java Query.setOrdering方法的具体用法?Java Query.setOrdering怎么用?Java Query.setOrdering使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.jdo.Query
的用法示例。
在下文中一共展示了Query.setOrdering方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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));
}
示例2: 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;
}
示例3: getOrderApprovalMapping
import javax.jdo.Query; //导入方法依赖的package包/类
public IOrderApprovalMapping getOrderApprovalMapping(Long orderId, Integer approvalType) {
IOrderApprovalMapping orderApprovalMapping = null;
List<IOrderApprovalMapping> results = 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("orderId == orderIdParam && approvalType == approvalTypeParam");
query.declareParameters("Long orderIdParam, Integer approvalTypeParam");
query.setOrdering("createdAt desc");
query.setRange(0, 1);
params.put(ORDER_ID_PARAM, orderId);
params.put(APPROVAL_TYPE_PARAM, approvalType);
results = (List<IOrderApprovalMapping>) query.executeWithMap(params);
if (results != null && !results.isEmpty()) {
orderApprovalMapping = results.get(0);
}
} catch (Exception e) {
xLogger.warn("Failed to get order approval mapping for order: {0}",
orderId, e);
} finally {
if (query != null) {
try {
query.closeAll();
} catch (Exception ignored) {
xLogger.warn("Exception while closing query", ignored);
}
}
if (pm != null) {
pm.close();
}
}
}
return orderApprovalMapping;
}
示例4: getTotalOrderApprovalMapping
import javax.jdo.Query; //导入方法依赖的package包/类
/**
* returns the total approvals against that order
*/
public List<IOrderApprovalMapping> getTotalOrderApprovalMapping(Long orderId) {
List<IOrderApprovalMapping> results = 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("orderId == orderIdParam");
query.declareParameters("Long orderIdParam");
query.setOrdering("createdAt desc");
params.put(ORDER_ID_PARAM, orderId);
results = (List<IOrderApprovalMapping>) query.executeWithMap(params);
results = (List<IOrderApprovalMapping>) pm.detachCopyAll(results);
} catch (Exception e) {
xLogger.warn("Failed to get order approval mapping for order: {0}",
orderId, e);
} finally {
if (query != null) {
try {
query.closeAll();
} catch (Exception ignored) {
xLogger.warn("Exception while closing query", ignored);
}
}
if (pm != null) {
pm.close();
}
}
}
return results;
}
示例5: getLdapUsers
import javax.jdo.Query; //导入方法依赖的package包/类
/**
* Returns a complete list of all LdapUser objects, in ascending order by username.
* @return a list of LdapUsers
* @since 1.0.0
*/
@SuppressWarnings("unchecked")
public List<LdapUser> getLdapUsers() {
final Query query = pm.newQuery(LdapUser.class);
query.setOrdering("username asc");
return (List<LdapUser>) query.execute();
}
示例6: getTeams
import javax.jdo.Query; //导入方法依赖的package包/类
/**
* Returns a complete list of all Team objects, in ascending order by name.
* @return a List of Teams
* @since 1.0.0
*/
@SuppressWarnings("unchecked")
public List<Team> getTeams() {
pm.getFetchPlan().addGroup(Team.FetchGroup.ALL.name());
final Query query = pm.newQuery(Team.class);
query.setOrdering("name asc");
return (List<Team>) query.execute();
}
示例7: getLatestEventServiceLog
import javax.jdo.Query; //导入方法依赖的package包/类
/**
* Returns the most recent log entry for the specified Subscriber.
* If no log entries are found, this method will return null.
* @param clazz The LoggableSubscriber class to query on
* @return a EventServiceLog
* @since 1.0.0
*/
@SuppressWarnings("unchecked")
public EventServiceLog getLatestEventServiceLog(final Class<LoggableSubscriber> clazz) {
final Query query = pm.newQuery(EventServiceLog.class, "eventClass == :clazz");
query.setOrdering("completed desc");
final List<EventServiceLog> result = (List<EventServiceLog>) query.execute(clazz);
return result.size() == 0 ? null : result.get(0);
}
示例8: getAllHandlingUnits
import javax.jdo.Query; //导入方法依赖的package包/类
@Override
public Results getAllHandlingUnits(Long domainId, PageParams pageParams) throws ServiceException {
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
List<IHandlingUnit> hUnits = new ArrayList<>();
String filters = "dId.contains(domainIdParam)";
String declaration = "Long domainIdParam";
Map<String, Object> params = new HashMap<>();
params.put("domainIdParam", domainId);
Query query = pm.newQuery(JDOUtils.getImplClass(IHandlingUnit.class));
query.setFilter(filters);
query.declareParameters(declaration);
query.setOrdering("nName asc");
String cursor = null;
try {
if (pageParams != null) {
QueryUtil.setPageParams(query, pageParams);
}
hUnits = (List<IHandlingUnit>) query.executeWithMap(params);
hUnits.size();
cursor = QueryUtil.getCursor(hUnits);
hUnits = (List<IHandlingUnit>) pm.detachCopyAll(hUnits);
} finally {
query.closeAll();
}
return new Results(hUnits, cursor);
} finally {
pm.close();
}
}
示例9: getLatestUpload
import javax.jdo.Query; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public IUploaded getLatestUpload(String filename, String locale) throws ServiceException {
if (filename == null || filename.isEmpty() || locale == null || locale.isEmpty()) {
throw new ServiceException("Invalid arguments - filename or locale not specified");
}
IUploaded u = null;
PersistenceManager pm = PMF.get().getPersistenceManager();
Query q = pm.newQuery(JDOUtils.getImplClass(IUploaded.class));
q.setFilter("fn == fnParam && l == lParam");
q.declareParameters("String fnParam, String lParam");
q.setOrdering("t desc");
q.setRange(0, 1); // get the latest single entry
try {
List<IUploaded> results = (List<IUploaded>) q.execute(filename, locale);
if (results != null && results.size() > 0) {
u = results.get(0);
u = pm.detachCopy(u);
}
} finally {
try {
q.closeAll();
} catch (Exception ignored) {
xLogger.warn("Exception while closing query", ignored);
}
pm.close();
}
return u;
}
示例10: getRecentJobs
import javax.jdo.Query; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static Results getRecentJobs(String type, String createdBy, Long domainId,
PageParams pageParams) throws ServiceException {
if (domainId == null || type == null) {
throw new ServiceException("Invalid input parameters while getting recent jobs.");
}
Results results = null;
PersistenceManager pm = PMF.get().getPersistenceManager();
Query q = pm.newQuery(JDOUtils.getImplClass(IJobStatus.class));
StringBuilder filter = new StringBuilder();
StringBuilder declaration = new StringBuilder();
filter.append("ty == typeParam");
declaration.append("String typeParam");
filter.append(QueryConstants.AND);
filter.append("dId == dIdParam");
declaration.append(CharacterConstants.COMMA).append("Long dIdParam");
if (createdBy != null && !createdBy.isEmpty()) {
filter.append(QueryConstants.AND);
filter.append("crBy == crByParam");
declaration.append(CharacterConstants.COMMA).append("String crByParam");
}
Map<String, Object> params = new HashMap<>();
if (createdBy != null && !createdBy.isEmpty()) {
params.put("crByParam", createdBy);
}
params.put("dIdParam", domainId);
params.put("typeParam", type);
q.setFilter(filter.toString());
q.declareParameters(declaration.toString());
q.setOrdering("stt desc");
if (pageParams != null) {
QueryUtil.setPageParams(q, pageParams);
}
try {
List<IJobStatus> jobs = (List<IJobStatus>) q.executeWithMap(params);
String cursor = null;
if (jobs != null) {
jobs.size();
cursor = QueryUtil.getCursor(jobs);
jobs = (List<IJobStatus>) pm.detachCopyAll(jobs);
}
// Get the results along with cursor, if present
results = new Results(jobs, cursor);
} finally {
try {
q.closeAll();
} catch (Exception ignored) {
}
pm.close();
}
return results;
}
示例11: getManuallyUploadedTransactions
import javax.jdo.Query; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static Results getManuallyUploadedTransactions(Long domainId, Long kioskId, Date sinceDate,
Date untilDate, PageParams pageParams)
throws ServiceException {
//Now execute the query and return the results
Results results = null;
PersistenceManager pm = PMF.get().getPersistenceManager();
// Form the query
Query query = pm.newQuery(JDOUtils.getImplClass(IMnlTransaction.class));
String filter = "";
String params = "";
HashMap<String, Object> paramsMap = new HashMap<>();
if (kioskId != null) { // Add the kiosk filter, if needed
filter += "kId == kioskIdParam";
params += "Long kioskIdParam";
paramsMap.put("kioskIdParam", kioskId);
} else if (domainId != null) {
filter += "dId.contains(domainIdParam)";
params += "Long domainIdParam";
paramsMap.put("domainIdParam", domainId);
}
// From Date
if (sinceDate != null) {
if (!filter.isEmpty()) {
filter += " && ";
params += ", ";
}
filter += "rp > sinceDateParam";
params += "Date sinceDateParam";
query.declareImports("import java.util.Date");
paramsMap.put("sinceDateParam", LocalDateUtil.getOffsetDate(sinceDate, -1,
Calendar.DATE)); // we reduce this date by 1 date, so that we can avoid a >= query on time
}
if (untilDate != null) {
if (!filter.isEmpty()) {
filter += " && ";
params += ", ";
}
filter += "rp <= untilDateParam";
params += "Date untilDateParam";
query.declareImports("import java.util.Date");
paramsMap.put("untilDateParam", untilDate);
}
// Update query
query.setFilter(filter);
query.declareParameters(params);
query.setOrdering("t desc");
// Add pagination parameters, if needed
if (pageParams != null) {
QueryUtil.setPageParams(query, pageParams);
}
// Execute query
try {
xLogger.fine("Query: {0}, paramsMap: {1}", query.toString(), paramsMap.toString());
List<IMnlTransaction> iList = (List<IMnlTransaction>) query.executeWithMap(paramsMap);
iList
.size(); // this is to force retrieval before closing PM; TODO change this later to be more efficient
// Get the cursor of the next element in the result set (for future iteration, efficiently)
String cursorStr = QueryUtil.getCursor(iList);
iList = (List<IMnlTransaction>) pm.detachCopyAll(iList);
// Create the result set
results = new Results(iList, cursorStr);
} catch (Exception e) {
xLogger.warn("Exception: {0}", e.getMessage());
throw new ServiceException(e.getMessage());
} finally {
try {
query.closeAll();
} catch (Exception ignored) {
}
pm.close();
}
return results;
}
示例12: getNotifactionLogs
import javax.jdo.Query; //导入方法依赖的package包/类
public static Results getNotifactionLogs(Long domainId, Date startDate, Date endDate,
PageParams pageParams) throws MessageHandlingException {
xLogger.fine("Entered getLogs");
if (domainId == null) {
throw new MessageHandlingException("No domainId specified");
}
Map<String, Object> params = new HashMap<>();
List<IMessageLog> mlogs = null;
String cursor = null;
PersistenceManager pm = PMF.get().getPersistenceManager();
Query q = pm.newQuery(JDOUtils.getImplClass(IMessageLog.class));
boolean imports = false;
params.put("dIdParam", domainId);
params.put("notifParam", 1);
String filter = "dId == dIdParam && notif == notifParam ";
String declaration = "Long dIdParam , Integer notifParam ";
if (startDate != null) {
//offset date with less 1 milli second
params
.put("startDateParam", LocalDateUtil.getOffsetDate(startDate, -1, Calendar.MILLISECOND));
filter += "&& t >= startDateParam ";
declaration += ",Date startDateParam ";
imports = true;
}
if (endDate != null) {
//offset date with one day increase to get inclusive end date
params.put("endDateParam", LocalDateUtil.getOffsetDate(endDate, +1, Calendar.DATE));
filter += " && t < endDateParam ";
declaration += ",Date endDateParam ";
imports = true;
}
q.setFilter(filter);
q.declareParameters(declaration);
if (imports) {
q.declareImports("import java.util.Date");
}
q.setOrdering("t desc");
if (pageParams != null) {
QueryUtil.setPageParams(q, pageParams);
}
try {
mlogs = (List<IMessageLog>) q.executeWithMap(params);
if (mlogs != null) {
mlogs.size(); // TODO: to ensure all objects are retrieved before closing object manager
cursor = QueryUtil.getCursor(mlogs);
mlogs = (List<IMessageLog>) pm.detachCopyAll(mlogs);
mlogs = sortByTime(mlogs);
}
} finally {
try {
q.closeAll();
} catch (Exception ignored) {
}
pm.close();
}
return new Results(mlogs, cursor);
}
示例13: getAllMaterials
import javax.jdo.Query; //导入方法依赖的package包/类
@Override
public Results getAllMaterials(Long domainId, String tag, PageParams pageParams) {
xLogger.fine("Entering getAllMaterials");
PersistenceManager pm = PMF.get().getPersistenceManager();
List<IMaterial> materials = new ArrayList<IMaterial>();
// Formulate query
String filters = "dId.contains(domainIdParam)";
String declaration = "Long domainIdParam";
Map<String, Object> params = new HashMap<String, Object>();
params.put("domainIdParam", domainId);
if (tag != null) {
filters += " && tgs.contains(tagsParam)";
declaration += ", Long tagsParam";
params.put("tagsParam", tagDao.getTagFilter(tag, ITag.MATERIAL_TAG));
}
Query query = pm.newQuery(Material.class);
query.setFilter(filters);
query.declareParameters(declaration);
query.setOrdering("uName asc");
if (pageParams != null) {
QueryUtil.setPageParams(query, pageParams);
}
String cursor = null;
try {
materials = (List<IMaterial>) query.executeWithMap(params);
materials
.size(); // TODO - fix to avoid "object manager closed" exception; find some other method to do this without retrieving all entities
cursor = QueryUtil.getCursor(materials);
materials = (List<IMaterial>) pm.detachCopyAll(materials);
} finally {
try {
query.closeAll();
} catch (Exception ignored) {
xLogger.warn("Exception while closing query", ignored);
}
pm.close();
}
xLogger.fine("Exiting getAllMaterials");
return new Results(materials, cursor);
}
示例14: getItems
import javax.jdo.Query; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static Results getItems(Long domainId, Date start, PageParams pageParams) {
xLogger.fine("Entered getItems");
List<IBBoard> items = null;
String cursor = null;
PersistenceManager pm = PMF.get().getPersistenceManager();
Query q = pm.newQuery(JDOUtils.getImplClass(IBBoard.class));
String filter = "dId.contains(dIdParam)";
String declaration = "Long dIdParam";
String importStr = null;
if (start != null) {
filter += "&& t > startParam";
declaration += ", Date startParam";
importStr = " import java.util.Date;";
}
q.setFilter(filter);
q.declareParameters(declaration);
if (importStr != null) {
q.declareImports(importStr);
}
q.setOrdering("t desc");
if (pageParams != null) {
QueryUtil.setPageParams(q, pageParams);
}
try {
if (start != null) {
items =
(List<IBBoard>) q
.execute(domainId, LocalDateUtil.getOffsetDate(start, -1, Calendar.MILLISECOND));
} else {
items = (List<IBBoard>) q.execute(domainId);
}
if (items != null) {
items.size();
cursor = QueryUtil.getCursor(items);
items = (List<IBBoard>) pm.detachCopyAll(items);
}
} finally {
try {
q.closeAll();
} catch (Exception ignored) {
xLogger.warn("Exception while closing query", ignored);
}
pm.close();
}
xLogger.fine("Exiting getItems");
return new Results(items, cursor);
}
示例15: getFilteredEntity
import javax.jdo.Query; //导入方法依赖的package包/类
@RequestMapping(value = "/filter", method = RequestMethod.GET)
public
@ResponseBody
Results getFilteredEntity(@RequestParam String text,
@RequestParam(required = false, defaultValue = "false") boolean sdOnly,
HttpServletRequest request) {
SecureUserDetails sUser = SecurityUtils.getUserDetails(request);
Long domainId = SessionMgr.getCurrentDomain(request.getSession(), sUser.getUsername());
if (text == null) {
text = "";
}
text = text.toLowerCase();
List<IKiosk> kiosks = new ArrayList<IKiosk>();
PersistenceManager pm = null;
try {
UsersService as =
Services.getService(UsersServiceImpl.class, sUser.getLocale());
IUserAccount user = as.getUserAccount(sUser.getUsername());
EntitiesService entitiesService = Services
.getService(EntitiesServiceImpl.class, sUser.getLocale());
if (SecurityUtil.compareRoles(user.getRole(), SecurityConstants.ROLE_DOMAINOWNER) < 0) {
Results results = entitiesService.getKiosksForUser(user, null, null);
if(results.getResults() != null) {
for (Object kiosk : results.getResults()) {
if (((IKiosk) kiosk).getName().toLowerCase().startsWith(text)) {
kiosks.add(((IKiosk) kiosk));
}
}
}
} else {
pm = PMF.get().getPersistenceManager();
String filter = "dId.contains(domainIdParam)";
if (sdOnly) {
filter = "sdId == domainIdParam";
}
String declaration = "Long domainIdParam";
Map<String, Object> params = new HashMap<String, Object>();
params.put("domainIdParam", domainId);
if (!text.isEmpty()) {
filter += " && nName.startsWith(txtParam)";
declaration += ", String txtParam";
params.put("txtParam", text);
}
Query query = pm.newQuery(JDOUtils.getImplClass(IKiosk.class));
query.setFilter(filter);
query.declareParameters(declaration);
query.setOrdering("nName asc");
PageParams pageParams = new PageParams(null, 0, 10);
QueryUtil.setPageParams(query, pageParams);
try {
kiosks = (List<IKiosk>) query.executeWithMap(params);
kiosks = (List<IKiosk>) pm.detachCopyAll(kiosks);
} finally {
query.closeAll();
}
}
} catch (Exception e) {
xLogger.warn("Exception: {0}", e.getMessage());
} finally {
if (pm != null) {
pm.close();
}
}
return new Results(builder.buildFilterModelList(kiosks), QueryUtil.getCursor(kiosks));
}