本文整理匯總了Java中javax.jdo.PersistenceManager類的典型用法代碼示例。如果您正苦於以下問題:Java PersistenceManager類的具體用法?Java PersistenceManager怎麽用?Java PersistenceManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PersistenceManager類屬於javax.jdo包,在下文中一共展示了PersistenceManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getMedias
import javax.jdo.PersistenceManager; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public List<IMedia> getMedias(String domainKey) {
Query q = null;
PersistenceManager pm = null;
try {
pm = PMF.get().getPersistenceManager();
q = pm.newQuery(Media.class, "domainKey == '" + domainKey + "'");
List<IMedia> result = (List<IMedia>) q.execute();
return (List<IMedia>) pm.detachCopyAll(result);
} finally {
if (q != null) {
try {
q.closeAll();
} catch (Exception ignored) {
logger.warn("Exception while closing query", ignored);
}
}
if (pm != null) {
pm.close();
}
}
}
示例2: getQuery
import javax.jdo.PersistenceManager; //導入依賴的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;
}
示例3: getConversationById
import javax.jdo.PersistenceManager; //導入依賴的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;
}
示例4: updateWidget
import javax.jdo.PersistenceManager; //導入依賴的package包/類
@Override
public String updateWidget(Long id, String ty, String val) throws ServiceException {
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
IWidget wid = JDOUtils.getObjectById(IWidget.class, id, pm);
String name = wid.getName();
if ("nm".equals(ty)) {
wid.setName(val);
} else if ("desc".equals(ty)) {
wid.setDesc(val);
}
pm.makePersistent(wid);
return name;
} catch (Exception e) {
xLogger.severe("Error in updating widget {0}", id, e);
throw new ServiceException("Error in updating widget " + id, e);
} finally {
pm.close();
}
}
示例5: updateWidgetConfig
import javax.jdo.PersistenceManager; //導入依賴的package包/類
@Override
public void updateWidgetConfig(IWidget widget) throws ServiceException {
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
IWidget wid = JDOUtils.getObjectById(IWidget.class, widget.getwId(), pm);
wid.setTitle(widget.getTitle());
wid.setSubtitle(widget.getSubtitle());
wid.setType(widget.getType());
wid.setFreq(widget.getFreq());
wid.setNop(widget.getNop());
wid.setAggrTy(widget.getAggrTy());
wid.setAggr(widget.getAggr());
wid.setyLabel(widget.getyLabel());
wid.setExpEnabled(widget.getExpEnabled());
wid.setShowLeg(widget.getShowLeg());
pm.makePersistent(wid);
} catch (Exception e) {
xLogger.severe("Error in updating widget config for widget {0}", widget.getwId(), e);
throw new ServiceException("Error in updating widget config for widget " + widget.getwId(),
e);
} finally {
pm.close();
}
}
示例6: closePersistenceManagerAfterFailedBegin
import javax.jdo.PersistenceManager; //導入依賴的package包/類
/**
* Close the current transaction's EntityManager.
* Called after a transaction begin attempt failed.
* @param txObject the current transaction
*/
protected void closePersistenceManagerAfterFailedBegin(JdoTransactionObject txObject) {
if (txObject.isNewPersistenceManagerHolder()) {
PersistenceManager pm = txObject.getPersistenceManagerHolder().getPersistenceManager();
try {
if (pm.currentTransaction().isActive()) {
pm.currentTransaction().rollback();
}
}
catch (Throwable ex) {
logger.debug("Could not rollback PersistenceManager after failed transaction begin", ex);
}
finally {
PersistenceManagerFactoryUtils.releasePersistenceManager(pm, getPersistenceManagerFactory());
}
}
}
示例7: findInvBatch
import javax.jdo.PersistenceManager; //導入依賴的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();
}
}
}
示例8: getObject
import javax.jdo.PersistenceManager; //導入依賴的package包/類
@Override
public Object getObject(PersistenceManager pm) {
if (oty == null || oty.isEmpty() || oId == null || oId.isEmpty()) {
return null;
}
boolean closePm = false;
if (pm == null) {
pm = PMF.get().getPersistenceManager();
closePm = true;
}
try {
return pm.getObjectById(Class.forName(oty), oId);
} catch (Exception e) {
xLogger
.warn("{0} when getting object of type {1} of event with oId {2}", e.getClass().getName(),
oty, oId);
return null;
} finally {
if (closePm) {
pm.close();
}
}
}
示例9: log
import javax.jdo.PersistenceManager; //導入依賴的package包/類
public static void log(IMessageLog mlog) throws MessageHandlingException {
xLogger.fine("Entered log");
if (mlog == null) {
throw new MessageHandlingException("Invalid message log");
}
if (mlog.getKey() == null) {
throw new MessageHandlingException("Invalid key");
}
PersistenceManager pm = PMF.get().getPersistenceManager();
String msg = null;
try {
pm.makePersistent(mlog);
} catch (Exception e) {
msg = e.getMessage();
} finally {
pm.close();
}
if (msg != null) {
throw new MessageHandlingException(msg);
}
xLogger.fine("Exiting log");
}
示例10: addKioskLinks
import javax.jdo.PersistenceManager; //導入依賴的package包/類
public List<String> addKioskLinks(Long domainId, List<IKioskLink> links) throws ServiceException {
xLogger.fine("Entering addKioskLink");
if (links == null || links.isEmpty()) {
throw new ServiceException("No links to add");
}
PersistenceManager pm = PMF.get().getPersistenceManager();
// Set the timeStamp to now
List<String> linkIds = new ArrayList<>(1);
try {
for (IKioskLink link : links) {
try {
addKioskLink(domainId, link, pm);
linkIds.add(link.getId());
} catch (ServiceException e) {
xLogger.warn("ServiceException when adding kiosk link {0}: {1}", link.getId(),
e.getMessage());
}
}
} finally {
pm.close();
}
xLogger.fine("Exiting addKioskLink");
return linkIds;
}
示例11: createNewStockEvent
import javax.jdo.PersistenceManager; //導入依賴的package包/類
private boolean createNewStockEvent(IInvntry inv, int updateSource,
IInvntryEvntLog lastStockEvent, PersistenceManager pm) {
int type = inv.getStockEvent();
boolean
createNewEvent =
!(updateSource == IInvntryEvntLog.SOURCE_MINMAXUPDATE && type == IEvent.STOCKOUT) &&
(lastStockEvent == null || lastStockEvent.getType() != type || !lastStockEvent
.isOpen());
boolean
closeLastEvent =
lastStockEvent != null && lastStockEvent.getType() != type && lastStockEvent.isOpen();
if (closeLastEvent) { // close the last stock event, if different from the current event (e.g. earlier it was 0, now it is <min)
lastStockEvent.setEndDate(inv.getTimestamp());
}
if (createNewEvent) {
invntryDao.createInvntryEvntLog(type, inv);
//Required to save stock event to inventory
pm.makePersistent(inv);
return true;
}
return false;
}
示例12: updateUserDetails
import javax.jdo.PersistenceManager; //導入依賴的package包/類
private static void updateUserDetails(SecureUserDetails userDetails, String ipAddress,
String userAgent) {
xLogger.fine("Entered updateUserDetails");
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
// More efficient to get/set using PM, instead of AccountsService
IUserAccount u = JDOUtils.getObjectById(IUserAccount.class, userDetails.getUsername(), pm);
u.setLastLogin(new Date());
u.setIPAddress(ipAddress);
u.setPreviousUserAgent(u.getUserAgent());
u.setUserAgent(userAgent);
u.setAppVersion("LogiWeb");
// Generate IP Address matched event, if required
Map<String, Object> params = new HashMap<>(1);
params.put("ipaddress", u.getIPAddress());
EventPublisher.generate(u.getDomainId(), IEvent.IP_ADDRESS_MATCHED, params,
UserAccount.class.getName(), u.getKeyString(),
null);
} catch (Exception e) {
xLogger.warn("Unable to update user's last login time for user {0}: {1}",
userDetails.getUsername(), e.getMessage());
} finally {
pm.close();
}
xLogger.fine("Exitig updateUserDetails");
}
示例13: getMultiple
import javax.jdo.PersistenceManager; //導入依賴的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;
}
示例14: getShipmentsByOrderId
import javax.jdo.PersistenceManager; //導入依賴的package包/類
/**
* Get all shipment for a specific order
*
* @param orderId Order Id
* @return -
*/
@Override
@SuppressWarnings("unchecked")
public List<IShipment> getShipmentsByOrderId(Long orderId, PersistenceManager pm) {
Query query = null;
try {
query = pm.newQuery("javax.jdo.query.SQL", "SELECT * FROM SHIPMENT WHERE ORDERID = ?");
query.setClass(JDOUtils.getImplClass(IShipment.class));
List list = (List) query.executeWithArray(orderId);
List<IShipment> shipments = new ArrayList<>(list.size());
for (Object shipment : list) {
shipments.add((IShipment) shipment);
}
return shipments;
} catch (Exception e) {
xLogger.severe("Error while fetching shipments by order id: {0}", orderId, e);
} finally {
if (query != null) {
query.closeAll();
}
}
return null;
}
示例15: setJobMetaInfo
import javax.jdo.PersistenceManager; //導入依賴的package包/類
public static void setJobMetaInfo(Long jobId, Map<String, String> metadataMap) {
// Get the Job ID and update.
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
IJobStatus jobStatus = JDOUtils.getObjectById(IJobStatus.class, jobId, pm);
if (metadataMap != null && !metadataMap.isEmpty()) {
jobStatus.setMetadata(getMetadataString(metadataMap));
pm.makePersistent(jobStatus);
}
} catch (Exception e) {
xLogger
.warn("{0} when updating metadata info for job with ID {1}: {2}", e.getClass().getName(),
jobId, e.getMessage());
} finally {
pm.close();
}
}