本文整理匯總了Java中javax.jdo.PersistenceManager.close方法的典型用法代碼示例。如果您正苦於以下問題:Java PersistenceManager.close方法的具體用法?Java PersistenceManager.close怎麽用?Java PersistenceManager.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jdo.PersistenceManager
的用法示例。
在下文中一共展示了PersistenceManager.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updateUserDetails
import javax.jdo.PersistenceManager; //導入方法依賴的package包/類
private static void updateUserDetails(SecureUserDetails userDetails, String ipAddress,
String userAgent) {
PersistenceManager pm = null;
try {
pm = PMF.get().getPersistenceManager();
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");
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 ignored) {
// do nothing
} finally {
if (pm != null) {
pm.close();
}
}
}
示例2: 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");
}
示例3: 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();
}
}
}
示例4: getMaterial
import javax.jdo.PersistenceManager; //導入方法依賴的package包/類
public IMaterial getMaterial(Long materialId) throws ServiceException {
xLogger.fine("Entering getMaterial");
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
//Get the material object from the database
IMaterial material = JDOUtils.getObjectById(IMaterial.class, materialId, pm);
//If we get here, it means the material exists
material = pm.detachCopy(material);
xLogger.fine("Exiting getMaterial");
return material;
} catch (JDOObjectNotFoundException e) {
xLogger.warn("getMaterial: FAILED!!! Material {0} does not exist in the database", materialId,
e);
throw new ServiceException(
messages.getString("material") + " " + materialId + " " + backendMessages
.getString("error.notfound"));
} finally {
pm.close();
}
}
示例5: resetRelatedEntitiesOrdering
import javax.jdo.PersistenceManager; //導入方法依賴的package包/類
public void resetRelatedEntitiesOrdering(Long kioskId, String linkType) throws ServiceException {
xLogger.fine("Entering resetRelatedEntitiesOrdering");
// Update the Kiosk to set the route enabled flag
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
IKiosk k = JDOUtils.getObjectById(IKiosk.class, kioskId, pm);
k.setRouteEnabled(linkType, false);
} catch (Exception e) {
xLogger.severe("{0} when trying to set the routeEnabled flag for kiosk {1}. Message: {2}",
e.getClass().getName(), kioskId, e.getMessage());
} finally {
pm.close();
}
xLogger.fine("Exiting resetRelatedEntitiesOrdering");
}
示例6: getHandlingUnitByName
import javax.jdo.PersistenceManager; //導入方法依賴的package包/類
@Override
public IHandlingUnit getHandlingUnitByName(Long domainId, String handlingUnitName)
throws ServiceException {
if (domainId == null || StringUtils.isEmpty(handlingUnitName)) {
throw new ServiceException("Invalid parameters");
}
IHandlingUnit hu = null;
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
// Form the query
Query huQuery = pm.newQuery(JDOUtils.getImplClass(IHandlingUnit.class));
huQuery.setFilter("dId.contains(dIdParam) && nName == nameParam");
huQuery.declareParameters("Long dIdParam, String nameParam");
try {
List<IHandlingUnit>
results =
(List<IHandlingUnit>) huQuery.execute(domainId, handlingUnitName.toLowerCase());
if (results != null && !results.isEmpty()) {
hu = results.get(0);
hu = pm.detachCopy(hu);
}
} finally {
huQuery.closeAll();
}
} catch (Exception e) {
xLogger.severe("Error while trying to get handling unit by name {0}", handlingUnitName, e);
} finally {
pm.close();
}
return hu;
}
示例7: getById
import javax.jdo.PersistenceManager; //導入方法依賴的package包/類
public IInvntry getById(String id) {
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
return getById(id, pm);
} finally {
pm.close();
}
}
示例8: getEnabledUserIdsWithTags
import javax.jdo.PersistenceManager; //導入方法依賴的package包/類
/**
* Get the list of enabled userIds from the given tagNames
*/
public List<String> getEnabledUserIdsWithTags(List<String> tagNames, Long domainId) {
List<String> uIds = null;
if (tagNames != null && tagNames.size() > 0) {
PersistenceManager pm = PMF.get().getPersistenceManager();
String tagName = MessageUtil.getCSVWithEnclose(tagNames);
String query = "SELECT UA.USERID FROM USERACCOUNT UA,USER_TAGS UT WHERE "
+ "UT.ID IN (SELECT ID FROM TAG WHERE NAME IN (" + tagName + ") AND TYPE=4)"
+ " AND UT.USERID = UA.USERID AND UA.ISENABLED = 1 AND UA.SDID = ?";
Query q = pm.newQuery("javax.jdo.query.SQL", query);
try {
List l = (List) q.executeWithArray(domainId);
uIds = new ArrayList<>(l.size());
for (Object o : l) {
uIds.add((String) o);
}
} catch (Exception e) {
xLogger.warn("Error while getting enabled user by tags {0}", tagName, e);
} finally {
try {
q.closeAll();
} catch (Exception ignored) {
xLogger.warn("Exception while closing query", ignored);
}
pm.close();
}
}
return uIds;
}
示例9: deleteAssetRelationByRelatedAsset
import javax.jdo.PersistenceManager; //導入方法依賴的package包/類
public void deleteAssetRelationByRelatedAsset(Long relatedAssetId) throws ServiceException {
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
Query query = pm.newQuery(JDOUtils.getImplClass(IAssetRelation.class));
query.setFilter("relatedAssetId == relatedAssetIdParam");
query.declareParameters("Long relatedAssetIdParam");
List<IAssetRelation> assetRelations = null;
try {
assetRelations = (List<IAssetRelation>) query.execute(relatedAssetId);
assetRelations = (List<IAssetRelation>) pm.detachCopyAll(assetRelations);
} catch (Exception ignored) {
//do nothing
} finally {
query.closeAll();
}
if (assetRelations != null && assetRelations.size() == 1) {
IAssetRelation assetRelationTmp = assetRelations.get(0);
pm.deletePersistent(assetRelationTmp);
}
} catch (Exception e) {
xLogger.warn("{0} while deleting asset relationship for the asset {1}", e.getMessage(),
relatedAssetId, e);
throw new ServiceException(e.getMessage());
} finally {
pm.close();
}
}
示例10: getAssetsByKiosk
import javax.jdo.PersistenceManager; //導入方法依賴的package包/類
@Override
public List<IAsset> getAssetsByKiosk(Long kioskId) throws ServiceException {
if (kioskId == null) {
throw new ServiceException("");//TODO
}
List<IAsset> assets = null;
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
Query query = pm.newQuery(JDOUtils.getImplClass(IAsset.class));
query.setFilter("kId == kioskIdParam");
query.declareParameters("Long kioskIdParam");
try {
assets = (List<IAsset>) query.execute(kioskId);
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: getAssetRelationByRelatedAsset
import javax.jdo.PersistenceManager; //導入方法依賴的package包/類
@Override
public IAssetRelation getAssetRelationByRelatedAsset(Long relatedAssetId)
throws ServiceException {
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
Query query = pm.newQuery(JDOUtils.getImplClass(IAssetRelation.class));
query.setFilter("relatedAssetId == relatedAssetIdParam");
query.declareParameters("Long relatedAssetIdParam");
List<IAssetRelation> assetRelations = null;
try {
assetRelations = (List<IAssetRelation>) query.execute(relatedAssetId);
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 deleting asset relationship for the asset {1}", e.getMessage(),
relatedAssetId, e);
throw new ServiceException(e.getMessage());
} finally {
pm.close();
}
return null;
}
示例12: getAllCountries
import javax.jdo.PersistenceManager; //導入方法依賴的package包/類
@Override
public List<String> getAllCountries(Long domainId) {
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = null;
List<String> districts = new ArrayList<>(1);
try {
query =
pm.newQuery("javax.jdo.query.SQL",
"SELECT DISTINCT COUNTRY FROM KIOSK WHERE KIOSKID IN " +
"( SELECT KIOSKID_OID IN KIOSK_DOMAINS WHERE DOMAIN_ID=" + domainId + ")");
List dsts = (List) query.execute();
for (Object dst : dsts) {
String district = (String) dst;
if (district != null) {
districts.add(district);
}
}
return districts;
} catch (Exception e) {
xLogger.severe("Error while fetching material ids from domain {0} and query {1}", domainId,
query, e);
} finally {
if (query != null) {
try {
query.closeAll();
} catch (Exception ignored) {
xLogger.warn("Exception while closing query", ignored);
}
}
pm.close();
}
return null;
}
示例13: getAllMaterialsIds
import javax.jdo.PersistenceManager; //導入方法依賴的package包/類
@Override
public List<Long> getAllMaterialsIds(Long domainId) {
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = null;
List<Long> materialIds = new ArrayList<>(1);
try {
query =
pm.newQuery("javax.jdo.query.SQL",
"SELECT MATERIALID FROM MATERIAL M, MATERIAL_DOMAINS MD WHERE " +
"MD.MATERIALID_OID = M.MATERIALID AND MD.DOMAIN_ID=" + domainId);
List matIds = (List) query.execute();
for (Object matId : matIds) {
Long matIdL = (Long) matId;
if (matIdL != null) {
materialIds.add(matIdL);
}
}
return materialIds;
} catch (Exception e) {
xLogger.severe("Error while fetching material ids from domain {0} and query {1}", domainId,
query, e);
} finally {
if (query != null) {
try {
query.closeAll();
} catch (Exception ignored) {
xLogger.warn("Exception while closing query", ignored);
}
}
pm.close();
}
return null;
}
示例14: addHandlingUnit
import javax.jdo.PersistenceManager; //導入方法依賴的package包/類
@Override
public Long addHandlingUnit(Long domainId, IHandlingUnit handlingUnit) throws ServiceException {
Date now = new Date();
handlingUnit.setTimeStamp(now);
handlingUnit.setLastUpdated(now);
handlingUnit.setDomainId(domainId);
IHandlingUnit handlingUnitByName = getHandlingUnitByName(domainId, handlingUnit.getName());
if (handlingUnitByName != null) {
xLogger.warn("add: Handling unit with name {0} already exists", handlingUnit.getName());
throw new ServiceException(
backendMessages.getString("error.cannotadd") + ". '" + handlingUnit.getName() + "' "
+ backendMessages.getString("error.alreadyexists") + ".");
}
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
DomainsUtil.addToDomain(handlingUnit, domainId, pm);
} finally {
pm.close();
}
/*
//todo: This code already modified to handle notification. Need to enable this when we enable notification for handing units.
EventGenerator eg = EventGeneratorFactory.getEventGenerator(domainId, JDOUtils.getImplClass(IHandlingUnit.class).getName());
try {
eg.generate( IEvent.CREATED, null, String.valueOf(handlingUnit.getId()), null );
} catch (EventHandlingException e) {
xLogger.warn( "Exception when generating event for handling unit-creation for handling unit {0} in domain {1}", handlingUnit.getId(), domainId,e );
}*/
return handlingUnit.getId();
}
示例15: removeMultipartMsg
import javax.jdo.PersistenceManager; //導入方法依賴的package包/類
public static void removeMultipartMsg(IMultipartMsg mmsg) throws MessageHandlingException {
if (mmsg == null) {
throw new MessageHandlingException("Invalid message object");
}
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
pm.deletePersistent(mmsg);
} finally {
pm.close();
}
}