本文整理汇总了Java中javax.jdo.PersistenceManager.currentTransaction方法的典型用法代码示例。如果您正苦于以下问题:Java PersistenceManager.currentTransaction方法的具体用法?Java PersistenceManager.currentTransaction怎么用?Java PersistenceManager.currentTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.jdo.PersistenceManager
的用法示例。
在下文中一共展示了PersistenceManager.currentTransaction方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addToExistingOrder
import javax.jdo.PersistenceManager; //导入方法依赖的package包/类
private void addToExistingOrder(List<ITransaction> kioskTransactions,
Long orderId, Locale locale)
throws LogiException {
IOrder order = orderManagementService.getOrder(orderId, true);
PersistenceManager pm = PMF.get().getPersistenceManager();
Transaction tx = null;
try {
String message = getAddMaterialsMessage(kioskTransactions, locale);
tx = pm.currentTransaction();
tx.begin();
orderManagementService.modifyOrder(order, Constants.SYSTEM_USER_ID,
kioskTransactions, new Date(), order.getDomainId(),
ITransaction.TYPE_REORDER, message, null, null,
null,
null, null,
true, null, order.getReferenceID());
orderManagementService
.updateOrder(order, SourceConstants.SYSTEM, true, true, Constants.SYSTEM_USER_ID);
LOGGER.info("Added new materials to order {0} for kiosk {1} with message {2}", orderId,
order.getKioskId(), message);
tx.commit();
} finally {
if (tx != null && tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
示例2: adjustInventoryEvents
import javax.jdo.PersistenceManager; //导入方法依赖的package包/类
@Override
public IInvntryEvntLog adjustInventoryEvents(IInvntryEvntLog iEvntLog) throws ServiceException {
PersistenceManager pm = PMF.get().getPersistenceManager();
Transaction tx = null;
try {
tx = pm.currentTransaction();
tx.begin();
List<IInvntryEvntLog> logs = invntryDao.removeInvEventLogs(iEvntLog.getKioskId(),
iEvntLog.getMaterialId(), iEvntLog.getStartDate(), iEvntLog.getEndDate(), pm);
IInvntry invntry = invntryDao.findId(iEvntLog.getKioskId(), iEvntLog.getMaterialId(), pm);
iEvntLog.setInvId(invntry.getKey());
DomainsUtil.addToDomain(iEvntLog, iEvntLog.getDomainId(), pm);
pm.makePersistent(iEvntLog);
if (iEvntLog.getKey() == null) {
pm.makePersistent(iEvntLog);
}
for (IInvntryEvntLog log : logs) {
if (Objects.equals(log.getKey(), invntry.getLastStockEvent())) {
invntry.setLastStockEvent(iEvntLog.getKey());
pm.makePersistent(invntry);
break;
}
}
tx.commit();
} catch (Exception e) {
xLogger.severe("Failed to adjust inventory log events for {0}:{1}", iEvntLog.getKioskId(),
iEvntLog.getDomainId(), e);
throw new ServiceException(e);
} finally {
if (tx != null && tx.isActive()) {
tx.rollback();
}
pm.close();
}
return iEvntLog;
}
示例3: updateHandlingUnit
import javax.jdo.PersistenceManager; //导入方法依赖的package包/类
@Override
public void updateHandlingUnit(IHandlingUnit handlingUnit, Long domainId)
throws ServiceException {
xLogger.fine("Entering update Handling unit");
PersistenceManager pm = PMF.get().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
try {
IHandlingUnit hu = JDOUtils.getObjectById(IHandlingUnit.class, handlingUnit.getId(), pm);
if (!domainId.equals(hu.getDomainId())) {
xLogger.warn("Updating of this handling unit {0} is not allowed in this domain.",
handlingUnit.getName(), handlingUnit.getDomainId());
throw new ServiceException("Handling unit does not exist");
}
List<IHandlingUnit> temp = getHandlingUnitListByName(domainId, handlingUnit.getName());
for (IHandlingUnit iHu : temp) {
if (!iHu.getId().equals(handlingUnit.getId())) {
throw new InvalidDataException("Handling unit " + hu.getName() + " " + backendMessages
.getString("error.alreadyexists"));
}
}
hu.setName(handlingUnit.getName());
hu.setDescription(handlingUnit.getDescription());
hu.setContents(handlingUnit.getContents());
hu.setLastUpdated(new Date());
hu.setUpdatedBy(handlingUnit.getUpdatedBy());
handlingUnit = pm.makePersistent(hu);
handlingUnit = pm.detachCopy(handlingUnit);
} catch (JDOObjectNotFoundException e) {
xLogger.warn("update handling unit: FAILED!! Handling unit does not exist: {0}",
handlingUnit.getId());
}
tx.commit();
/*
//todo: This code already modified to handle notification. Need to enable this when we enable notification for handing units.
EventGenerator eg = EventGeneratorFactory.getEventGenerator(handlingUnit.getDomainId(), JDOUtils.getImplClass(IHandlingUnit.class).getName());
try {
eg.generate( IEvent.MODIFIED, null, String.valueOf(handlingUnit.getId()), null );
} catch (EventHandlingException e) {
xLogger.warn( "Exception when generating event for handling unit modification for hu {0} in domain {1}", handlingUnit.getId(), handlingUnit.getDomainId(), e);
}*/
} finally {
if (tx.isActive()) {
xLogger.warn("update handling unit: Rolling back transaction");
tx.rollback();
}
xLogger.fine("Exiting update handling unit");
pm.close();
}
}
示例4: allocateQuantity
import javax.jdo.PersistenceManager; //导入方法依赖的package包/类
@RequestMapping("/allocate/")
public
@ResponseBody
boolean allocateQuantity(@RequestBody DBDRequestModel allocate, HttpServletRequest request)
throws ServiceException {
SecureUserDetails sUser = SecurityUtils.getUserDetails(request);
String userId = sUser.getUsername();
DomainConfig dc = DomainConfig.getInstance(sUser.getDomainId());
ResourceBundle
backendMessages =
Resources.get().getBundle("BackendMessages", sUser.getLocale());
if (dc.autoGI()) {
for (DemandBreakdownModel dbm : allocate.model) {
List<ShipmentItemBatchModel> sim = null;
String
tag =
IInvAllocation.Type.ORDER.toString().concat(":").concat(String.valueOf(dbm.orderId));
InventoryManagementService
ims =
Services.getService(InventoryManagementServiceImpl.class);
PersistenceManager pm = null;
Transaction tx = null;
try {
pm = PMF.get().getPersistenceManager();
tx = pm.currentTransaction();
tx.begin();
if (dbm.bid != null) {
ShipmentItemBatchModel sibm = new ShipmentItemBatchModel();
sibm.id = dbm.bid;
sibm.q = dbm.bQty;
sibm.smst = dbm.mst;
dbm.oQty = null;
sim = new ArrayList<>(1);
sim.add(sibm);
}
ims.allocate(dbm.kId, dbm.matId, IInvAllocation.Type.ORDER, String.valueOf(dbm.orderId),
tag, dbm.oQty, sim, userId, pm, dbm.mst);
tx.commit();
} catch (Exception e) {
throw new InvalidServiceException(backendMessages.getString("inv.alloc.failed"), e);
} finally {
if (tx != null && tx.isActive()) {
tx.rollback();
}
if (pm != null) {
pm.close();
}
}
}
}
return true;
}
示例5: updateShipmentStatusForMigratoryOrder
import javax.jdo.PersistenceManager; //导入方法依赖的package包/类
private boolean updateShipmentStatusForMigratoryOrder(String shipmentId, ShipmentStatus status,
String message, String userId,
PersistenceManager pm, String reason,
Date shpDate) {
boolean closePM = false;
Transaction tx = null;
if (pm == null) {
pm = PMF.get().getPersistenceManager();
tx = pm.currentTransaction();
closePM = true;
}
try {
if (closePM) {
tx.begin();
}
IShipment shipment = JDOUtils.getObjectById(IShipment.class, shipmentId, pm);
if (shipment == null) {
throw new Exception(
"Shipment is not available in db to update status. Shipment ID:" + shipmentId);
}
Date uon = null != shpDate ? shpDate : new Date();
includeShipmentItems(shipment, pm);
ShipmentStatus prevStatus = shipment.getStatus();
shipment.setStatus(status);
shipment.setUpdatedBy(userId);
shipment.setUpdatedOn(shpDate);
if (status == ShipmentStatus.SHIPPED || (prevStatus != ShipmentStatus.SHIPPED
&& status == ShipmentStatus.FULFILLED)) {
IDemandService ds = Services.getService(DemandService.class);
InventoryManagementService
ims =
Services.getService(InventoryManagementServiceImpl.class, this.getLocale());
Long orderId = extractOrderId(shipmentId);
List<IDemandItem> demandItems = ds.getDemandItems(orderId, pm);
for (IShipmentItem shipmentItem : shipment.getShipmentItems()) {
for (IDemandItem demandItem : demandItems) {
if (demandItem.getMaterialId().equals(shipmentItem.getMaterialId())) {
demandItem.setShippedQuantity(
demandItem.getShippedQuantity().add(shipmentItem.getQuantity()));
if (status == ShipmentStatus.FULFILLED) {
demandItem.setFulfilledQuantity(
demandItem.getFulfilledQuantity().add(shipmentItem.getQuantity()));
} else {
IInvntry
custInvntry =
ims.getInventory(shipment.getKioskId(), demandItem.getMaterialId(), pm);
custInvntry.setInTransitStock(
custInvntry.getInTransitStock().add(shipmentItem.getQuantity()));
pm.makePersistent(custInvntry);
}
}
}
}
pm.makePersistentAll(demandItems);
}
updateMessageAndHistory(shipmentId, message, userId, shipment.getOrderId(),
shipment.getDomainId(), prevStatus, shipment.getStatus(), shpDate, pm);
if (closePM) {
tx.commit();
}
} catch (Exception e) {
xLogger.severe("Error while getting shipment details.", e);
return false;
} finally {
if (closePM && tx.isActive()) {
tx.rollback();
}
if (closePM) {
pm.close();
}
}
return true;
}
示例6: updateConfiguration
import javax.jdo.PersistenceManager; //导入方法依赖的package包/类
/**
* Update a given configuration object.
*
* @param config The configuration object to be updated.
* @throws ServiceException Thrown if an invalid object or key was passed.
*/
public void updateConfiguration(IConfig config) throws ServiceException {
if (config == null || config.getConfig() == null) {
throw new ServiceException("Invalid configuration object - the object or its value are null");
}
if (config.getKey() == null || config.getKey().isEmpty()) {
throw new ServiceException(
"Invalid configuration key - key cannot be null or an empty string");
}
// Save the config object to data store
PersistenceManager pm = PMF.get().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
IConfig c = JDOUtils.getObjectById(IConfig.class, config.getKey(), pm);
c.setPrevConfig(c.getConfig()); // backup the current configuration before updating
c.setConfig(
getCleanString(config.getConfig())); // update the current configuration with the new one
c.setUserId(config.getUserId());
c.setDomainId(config.getDomainId());
c.setLastUpdated(new Date());
int locindex = compareLocationChange(c);
//update loc ids
if (locindex != 0) {
updateDomainConfigLocIds(c);
}
// whenever there is a change in the location configuration, re-initialize it
if (c.getKey().equals(IConfig.LOCATIONS)) {
LocationConfig.initialize();
}
//pm.makePersistent( c );
tx.commit();
} catch (Exception e) {
xLogger
.fine("Exception while updating configuration object with key {0}: {1}", config.getKey(),
e.getMessage(), e);
throw new ServiceException(e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}