本文整理汇总了Java中javax.jdo.PersistenceManager.detachCopyAll方法的典型用法代码示例。如果您正苦于以下问题:Java PersistenceManager.detachCopyAll方法的具体用法?Java PersistenceManager.detachCopyAll怎么用?Java PersistenceManager.detachCopyAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.jdo.PersistenceManager
的用法示例。
在下文中一共展示了PersistenceManager.detachCopyAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAll
import javax.jdo.PersistenceManager; //导入方法依赖的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;
}
示例2: getInventoryTransactionsByTrackingId
import javax.jdo.PersistenceManager; //导入方法依赖的package包/类
/**
* Get inventory transactions by tracking-id
*/
@SuppressWarnings("unchecked")
public Results getInventoryTransactionsByTrackingId(Long trackingId) throws ServiceException {
xLogger.fine("Entered getInventoryTransactionsByTrackingId");
List<ITransaction> trans = null;
// Get PM
PersistenceManager pm = PMF.get().getPersistenceManager();
Query q = pm.newQuery(JDOUtils.getImplClass(ITransaction.class));
q.setFilter("tid == tidParam");
q.declareParameters("Long tidParam");
try {
trans = (List<ITransaction>) q.execute(trackingId);
trans = (List<ITransaction>) pm.detachCopyAll(trans);
trans.size();
} finally {
try {
q.closeAll();
} catch (Exception ignored) {
xLogger.warn("Exception while closing query", ignored);
}
pm.close();
}
Results r = new Results(trans, null);
xLogger.fine("Exiting getInventoryTransactionsByTrackingId");
return r;
}
示例3: getLogs
import javax.jdo.PersistenceManager; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static Results getLogs(String senderId, PageParams pageParams)
throws MessageHandlingException {
if (senderId == null) {
throw new MessageHandlingException("No userId specified");
}
List<IMessageLog> mlogs = null;
String cursor = null;
PersistenceManager pm = PMF.get().getPersistenceManager();
Query q = pm.newQuery(JDOUtils.getImplClass(IMessageLog.class));
q.setFilter("suId == suIdParam");
q.declareParameters("String suIdParam");
q.setOrdering("t desc");
if (pageParams != null) {
QueryUtil.setPageParams(q, pageParams);
}
try {
mlogs = (List<IMessageLog>) q.execute(senderId);
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);
}
} finally {
try {
q.closeAll();
} catch (Exception ignored) {
}
pm.close();
}
return new Results(mlogs, cursor);
}
示例4: getDomains
import javax.jdo.PersistenceManager; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public List<IDomain> getDomains(String q, PageParams pageParams)
throws ServiceException, ObjectNotFoundException {
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = pm.newQuery(JDOUtils.getImplClass(IDomain.class));
Map<String, Object> params = new HashMap<>();
if (!q.isEmpty()) {
query.declareParameters("String txtParam");
query.setFilter("nNm.startsWith(txtParam)");
params.put("txtParam", q.toLowerCase());
}
List<IDomain> domains;
QueryUtil.setPageParams(query, pageParams);
try {
domains = (List<IDomain>) query.executeWithMap(params);
domains = (List<IDomain>) pm.detachCopyAll(domains);
if (domains != null) {
domains.size();
}
} catch (Exception e) {
xLogger.severe("Error in fetching list of 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;
}
示例5: getAllDomains
import javax.jdo.PersistenceManager; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public Results getAllDomains(PageParams pageParams) throws ServiceException {
xLogger.fine("Entering getAllDomains");
PersistenceManager pm = PMF.get().getPersistenceManager();
String errMsg = null;
Query query = pm.newQuery(JDOUtils.getImplClass(IDomain.class));
query.setOrdering("nNm asc");
if (pageParams != null) {
QueryUtil.setPageParams(query, pageParams);
}
List<IDomain> domains = null;
String cursor = null;
try {
domains = (List<IDomain>) query.execute();
domains = (List<IDomain>) pm.detachCopyAll(domains);
if (domains != null) {
domains.size(); // to retrieve the results before closing the PM
cursor = QueryUtil.getCursor(domains);
}
} catch (Exception e) {
errMsg = e.getMessage();
} finally {
try {
query.closeAll();
} catch (Exception ignored) {
xLogger.warn("Exception while closing query", ignored);
}
pm.close();
}
if (errMsg != null) {
throw new ServiceException(errMsg);
}
xLogger.fine("Exiting getAllDomains");
return new Results(domains, cursor);
}
示例6: getDomainLinks
import javax.jdo.PersistenceManager; //导入方法依赖的package包/类
/**
* Get the domain links for a given
*/
@SuppressWarnings("unchecked")
public Results getDomainLinks(Long domainId, int linkType, PageParams pageParams)
throws ServiceException {
xLogger.fine("Entered getLinkedDomains");
if (domainId == null) {
throw new IllegalArgumentException("Invalid domain Id");
}
int type = linkType;
String cursor = null;
List<IDomainLink> links = null;
PersistenceManager pm = PMF.get().getPersistenceManager();
String
queryStr =
"SELECT FROM " + JDOUtils.getImplClass(IDomainLink.class).getName()
+ " WHERE dId == dIdParam && ty == tyParam PARAMETERS Long dIdParam, Integer tyParam ORDER BY nldnm ASC"; // sorted by linked domain name
Query q = pm.newQuery(queryStr);
if (pageParams != null) {
QueryUtil.setPageParams(q, pageParams);
}
try {
links = (List<IDomainLink>) q.execute(domainId, new Integer(type));
links = (List<IDomainLink>) pm.detachCopyAll(links);
if (links != null && !links.isEmpty()) {
links.size(); // ensure retrieval
cursor = QueryUtil.getCursor(links); // get cursor
}
} finally {
try {
q.closeAll();
} catch (Exception ignored) {
xLogger.warn("Exception while closing query", ignored);
}
pm.close();
}
xLogger.fine("Exiting getLinkedDomains");
return new Results(links, cursor);
}
示例7: getUsersByIds
import javax.jdo.PersistenceManager; //导入方法依赖的package包/类
/**
* Method to fetch the user account details for the given userIds
*
* @param userIds User Id list
* @return List<IUserAccount>
*/
public List<IUserAccount> getUsersByIds(List<String> userIds) {
if (userIds == null || userIds.isEmpty()) {
return null;
}
List<IUserAccount> results = null;
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = null;
try {
StringBuilder queryBuilder = new StringBuilder("SELECT * FROM `USERACCOUNT` ");
queryBuilder.append("WHERE USERID IN (");
for (String userId : userIds) {
queryBuilder.append("'").append(userId).append("'").append(CharacterConstants.COMMA);
}
queryBuilder.setLength(queryBuilder.length() - 1);
queryBuilder.append(" )");
query = pm.newQuery("javax.jdo.query.SQL", queryBuilder.toString());
query.setClass(JDOUtils.getImplClass(IUserAccount.class));
results = (List<IUserAccount>) query.execute();
results = (List<IUserAccount>) pm.detachCopyAll(results);
} catch (Exception e) {
xLogger.warn("Exception while fetching approval status", e);
} finally {
if (query != null) {
try {
query.closeAll();
} catch (Exception ignored) {
xLogger.warn("Exception while closing query", ignored);
}
}
pm.close();
}
return results;
}
示例8: getAssetRelationByAsset
import javax.jdo.PersistenceManager; //导入方法依赖的package包/类
@Override
public IAssetRelation getAssetRelationByAsset(Long assetId) throws ServiceException {
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
Query query = pm.newQuery(JDOUtils.getImplClass(IAssetRelation.class));
query.setFilter("assetId == assetIdParam");
query.declareParameters("Long assetIdParam");
List<IAssetRelation> assetRelations = null;
try {
assetRelations = (List<IAssetRelation>) query.execute(assetId);
assetRelations = (List<IAssetRelation>) pm.detachCopyAll(assetRelations);
} catch (Exception ignored) {
//do nothing
} finally {
query.closeAll();
}
if (assetRelations != null && assetRelations.size() == 1) {
return assetRelations.get(0);
}
} catch (Exception e) {
xLogger
.warn("{0} while getting asset relationship for the asset {1}", e.getMessage(), assetId,
e);
throw new ServiceException(e.getMessage());
} finally {
pm.close();
}
return null;
}
示例9: getApprovers
import javax.jdo.PersistenceManager; //导入方法依赖的package包/类
/**
* Get all the approvers for a given kioskId and order type and approver type
* @param kioskId
* @param type
* @param orderType
* @return
*/
public List<IApprover> getApprovers(Long kioskId, int type, String orderType) {
List<IApprover> appList = null;
if(kioskId != null) {
PersistenceManager pm = null;
Query query = null;
try {
pm = PMF.get().getPersistenceManager();
Map<String, Object> params = new HashMap<>();
query = pm.newQuery(JDOUtils.getImplClass(IApprover.class));
query.setFilter("kid == kioskIdParam && type == typeParam && otype == orderTypeParam");
query.declareParameters("Long kioskIdParam, int typeParam, String orderTypeParam");
params.put("kioskIdParam", kioskId);
params.put("typeParam", type);
params.put("orderTypeParam", orderType);
List<IApprover> approversList = (List<IApprover>) query.executeWithMap(params);
appList = (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);
}
}
if (pm != null) {
pm.close();
}
}
}
return appList;
}
示例10: getAssetsByKiosk
import javax.jdo.PersistenceManager; //导入方法依赖的package包/类
@Override
public List<IAsset> getAssetsByKiosk(Long kioskId, Integer assetType) throws ServiceException {
if (kioskId == null || assetType == null) {
throw new ServiceException(
backendMessages.getString("kiosk") + " and AssetType are mandatory");
}
List<IAsset> assets = null;
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
Query query = pm.newQuery(JDOUtils.getImplClass(IAsset.class));
query.setFilter("kId == kioskIdParam && type == assetTypeParam");
query.declareParameters("Long kioskIdParam, Integer assetTypeParam");
try {
assets = (List<IAsset>) query.execute(kioskId, assetType);
assets = (List<IAsset>) pm.detachCopyAll(assets);
} finally {
query.closeAll();
}
} catch (Exception e) {
xLogger.severe("{0} while getting assets for the kiosk {1}", e.getMessage(), kioskId, e);
throw new ServiceException(e.getMessage());
} finally {
pm.close();
}
return assets;
}
示例11: getUsers
import javax.jdo.PersistenceManager; //导入方法依赖的package包/类
/**
* Get users given the offset and size
*
* @param offset Offset
* @param size Number of users
*/
public List<IUserAccount> getUsers(int offset, int size) {
PersistenceManager pm = null;
Query query = null;
List<IUserAccount> users = null;
try {
pm = PMF.get().getPersistenceManager();
String
queryStr =
"SELECT * FROM USERACCOUNT ORDER BY USERID ASC limit " + offset + CharacterConstants.COMMA
+ size;
query = pm.newQuery("javax.jdo.query.SQL", queryStr);
query.setClass(UserAccount.class);
users = (List<IUserAccount>) query.execute();
users = (List<IUserAccount>) pm.detachCopyAll(users);
} catch (Exception e) {
xLogger.warn("Error encountered during user id migrations", e);
} finally {
if (query != null) {
query.closeAll();
}
if (pm != null) {
pm.close();
}
}
return users;
}
示例12: getInventoryTransactionsByUser
import javax.jdo.PersistenceManager; //导入方法依赖的package包/类
/**
* Get inventory transactions by a given user
*/
@SuppressWarnings("unchecked")
public Results getInventoryTransactionsByUser(String userId, Date fromDate, Date toDate,
PageParams pageParams) throws ServiceException {
xLogger.fine("Entered getInventoryTransactionsByUser");
if (userId == null || fromDate == null) {
throw new IllegalArgumentException("User ID and from date are not supplied");
}
// Get the query and params
String
query =
"SELECT FROM " + JDOUtils.getImplClass(ITransaction.class).getName()
+ " WHERE uId == uIdParam && t > fromParam";
Map<String, Object> params = new HashMap<String, Object>();
params.put("uIdParam", userId);
params.put("fromParam", LocalDateUtil.getOffsetDate(fromDate, -1, Calendar.MILLISECOND));
if (toDate != null) {
query += " && t < toParam";
params.put("toParam", toDate);
}
query += " PARAMETERS String uIdParam, Date fromParam";
if (toDate != null) {
query += ", Date toParam";
}
query += " import java.util.Date; ORDER BY t desc";
PersistenceManager pm = PMF.get().getPersistenceManager();
Query q = pm.newQuery(query);
if (pageParams != null) {
QueryUtil.setPageParams(q, pageParams);
}
// Execute query
List<ITransaction> transactions = null;
String cursor = null;
try {
transactions = (List<ITransaction>) q.executeWithMap(params);
if (transactions != null) {
transactions.size();
cursor = QueryUtil.getCursor(transactions);
transactions = (List<ITransaction>) pm.detachCopyAll(transactions);
}
} finally {
try {
q.closeAll();
} catch (Exception ignored) {
xLogger.warn("Exception while closing query", ignored);
}
pm.close();
}
xLogger.fine("Exiting getInventoryTransactionsByUser");
return new Results(transactions, cursor);
}
示例13: getItems
import javax.jdo.PersistenceManager; //导入方法依赖的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);
}
示例14: getDomainsAsResult
import javax.jdo.PersistenceManager; //导入方法依赖的package包/类
@RequestMapping(value = "/domains/all", method = RequestMethod.GET)
public
@ResponseBody
Results getDomainsAsResult(
@RequestParam(required = false, defaultValue = PageParams.DEFAULT_SIZE_STR) String s,
@RequestParam(required = false, defaultValue = PageParams.DEFAULT_OFFSET_STR) String o,
@RequestParam(required = false) String q,
HttpServletRequest request) {
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = pm.newQuery(JDOUtils.getImplClass(IDomain.class));
Map<String, Object> params = new HashMap<>();
Navigator navigator;
String filter;
if (q != null && !q.isEmpty()) {
filter = "nNm.startsWith(txtParam)";
query.setFilter(filter);
query.declareParameters("String txtParam");
params.put("txtParam", q.toLowerCase());
} else {
filter = "hasParent==false";
query.setFilter(filter);
query.setOrdering("nNm asc");
}
if (o != null) {
int off = Integer.parseInt(o);
int sz = Integer.parseInt(s);
navigator =
new Navigator(request.getSession(), "DomainConfigController.getDomains", off, sz, "dummy",
0);
PageParams pageParams = new PageParams(navigator.getCursor(off), off, sz);
QueryUtil.setPageParams(query, pageParams);
}
List<IDomain> domains = null;
SecureUserDetails sUser = getUserDetails();
Locale locale = sUser.getLocale();
ResourceBundle backendMessages = Resources.get().getBundle("BackendMessages", locale);
try {
if (q != null && !q.isEmpty()) {
domains = (List<IDomain>) query.executeWithMap(params);
} else {
domains = (List<IDomain>) query.execute();
}
domains = (List<IDomain>) pm.detachCopyAll(domains);
if (domains != null) {
domains.size(); // to retrieve the results before closing the PM
}
} catch (Exception e) {
xLogger.severe("Error in fetching list of 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 new Results(domains, null, -1, Integer.parseInt(o));
}
示例15: getReportData
import javax.jdo.PersistenceManager; //导入方法依赖的package包/类
/**
* Get stock levels over time
*/
@SuppressWarnings("unchecked")
@Override
public ReportData getReportData(Date from, Date until, String frequency,
Map<String, Object> filters, Locale locale, String timezone,
PageParams pageParams, DomainConfig dc, String sourceUserId)
throws ReportingDataException {
xLogger.fine("Entered getReportData");
// Validate the required filters
if (from == null || until == null) {
throw new ReportingDataException("Both from and until dates are required");
}
if (filters == null || filters.size() == 0) {
throw new ReportingDataException("No material and kiosk filter were specified");
}
// Get the Ids
Long materialId = (Long) filters.get(ReportsConstants.FILTER_MATERIAL);
Long kioskId = (Long) filters.get(ReportsConstants.FILTER_KIOSK);
if (materialId == null || kioskId == null) {
throw new ReportingDataException(
"Either the material and/or kiosk filter were not specified");
}
// Offset the from date
Date modFrom = LocalDateUtil.getOffsetDate(from, -1, Calendar.MILLISECOND);
// Get PM
PersistenceManager pm = PMF.get().getPersistenceManager();
// Form the query
Query q = pm.newQuery(JDOUtils.getImplClass(IInvntryLog.class));
q.setFilter("mId == mIdParam && kId == kIdParam && t > fromParam && t < untilParam");
q.declareParameters("Long mIdParam, Long kIdParam, Date fromParam, Date untilParam");
q.declareImports("import java.util.Date;");
q.setOrdering("t asc"); // NOTE: indexes are defined on asc
if (pageParams != null) {
QueryUtil.setPageParams(q, pageParams);
}
// Get the param map
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("mIdParam", materialId);
paramMap.put("kIdParam", kioskId);
paramMap.put("fromParam", modFrom);
paramMap.put("untilParam", until);
List<IInvntryLog> results = null;
String cursor = null;
try {
// Execute query
results = (List<IInvntryLog>) q.executeWithMap(paramMap);
if (results != null) {
results.size();
cursor = QueryUtil.getCursor(results);
results = (List<IInvntryLog>) pm.detachCopyAll(results);
}
} finally {
try {
q.closeAll();
} catch (Exception ignored) {
xLogger.warn("Exception while closing query", ignored);
}
pm.close();
}
// Get the re-order level
BigDecimal reorderLevel = BigDecimal.ZERO;
try {
InventoryManagementService
ims =
Services.getService(InventoryManagementServiceImpl.class);
IInvntry inv = ims.getInventory(kioskId, materialId);
if (inv != null) {
reorderLevel = inv.getReorderLevel();
}
} catch (ServiceException e) {
xLogger.warn("ServiceException when getting inventory re-order level: {0}", e.getMessage());
}
xLogger.fine("Exiting getReportData");
return new StockLevelData(from, until, filters, locale, timezone, results, cursor,
reorderLevel);
}