本文整理汇总了Java中javax.jdo.Query.declareParameters方法的典型用法代码示例。如果您正苦于以下问题:Java Query.declareParameters方法的具体用法?Java Query.declareParameters怎么用?Java Query.declareParameters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.jdo.Query
的用法示例。
在下文中一共展示了Query.declareParameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateOrderApprovalStatus
import javax.jdo.Query; //导入方法依赖的package包/类
public void updateOrderApprovalStatus(Long orderId, String approvalId, String status) {
if (orderId != null && StringUtils.isNotEmpty(approvalId)) {
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 && approvalId == approvalIdParam ");
query.declareParameters("Long orderIdParam, String approvalIdParam");
params.put("orderIdParam", orderId);
params.put(APPROVAL_ID_PARAM, approvalId);
query.setUnique(true);
IOrderApprovalMapping orderApprovalMapping = (IOrderApprovalMapping) query
.executeWithMap(params);
if (orderApprovalMapping != null) {
orderApprovalMapping.setStatus(status);
orderApprovalMapping.setUpdatedAt(new Date());
pm.makePersistent(orderApprovalMapping);
}
} catch (Exception e) {
xLogger.warn("Failed to get order approval mapping for order: {0} with approval: {1}",
orderId, approvalId, e);
} finally {
if (query != null) {
try {
query.closeAll();
} catch (Exception ignored) {
xLogger.warn(ignored.getMessage(), ignored);
}
}
if (pm != null) {
pm.close();
}
}
}
}
示例2: getAll
import javax.jdo.Query; //导入方法依赖的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;
}
示例3: getUserDevice
import javax.jdo.Query; //导入方法依赖的package包/类
@Override
public IUserDevice getUserDevice(String userid, String appname) throws ServiceException {
IUserDevice userDevice = null;
PersistenceManager pm = null;
try {
pm = PMF.get().getPersistenceManager();
Query query = pm.newQuery(JDOUtils.getImplClass(IUserDevice.class));
query.setFilter("userId == userIdParam && appname == appnameParam");
query.declareParameters("String userIdParam, String appnameParam");
//Query query = pm.newQuery("javax.jdo.query.SQL",q);
query.setUnique(true);
userDevice = (IUserDevice) query.execute(userid, appname);
userDevice = pm.detachCopy(userDevice);
return userDevice;
} catch (Exception e) {
xLogger.severe("{0} while getting user device {1}", e.getMessage(), userid, e);
throw new ServiceException("Issue with getting user device for user :" + userid);
} finally {
if (pm != null) {
pm.close();
}
}
}
示例4: getKioskByName
import javax.jdo.Query; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public IKiosk getKioskByName(Long domainId, String kioskName) throws ServiceException {
xLogger.fine("Entering getKiosk");
if (domainId == null || kioskName == null || kioskName.isEmpty()) {
throw new ServiceException("Invalid parameters");
}
IKiosk k = null;
// Form query
PersistenceManager pm = PMF.get().getPersistenceManager();
// Update the UserAccount to set the route enabled flag
try {
// Form the query
Query kioskQuery = pm.newQuery(JDOUtils.getImplClass(IKiosk.class));
kioskQuery.setFilter("dId.contains(dIdParam) && nName == nameParam");
kioskQuery.declareParameters("Long dIdParam, String nameParam");
// Execute the query
try {
List<IKiosk> results = (List<IKiosk>) kioskQuery.execute(domainId, kioskName.toLowerCase());
if (results != null && !results.isEmpty()) {
k = results.get(0);
k = pm.detachCopy(k);
}
} finally {
kioskQuery.closeAll();
}
} catch (Exception e) {
xLogger.severe("{0} when trying to get Kiosk for kiosk Name {1}. Message: {2}",
e.getClass().getName(), kioskName, e.getMessage());
} finally {
pm.close();
}
xLogger.fine("Exiting getKiosk");
return k;
}
示例5: getMaterialByName
import javax.jdo.Query; //导入方法依赖的package包/类
@SuppressWarnings({"unchecked"})
public IMaterial getMaterialByName(Long domainId, String materialName) throws ServiceException {
xLogger.fine("Entering getMaterialByName");
if (domainId == null || materialName == null || materialName.isEmpty()) {
throw new ServiceException("Invalid parameters");
}
IMaterial m = null;
// Form query
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
// Form the query
Query materialQuery = pm.newQuery(JDOUtils.getImplClass(IMaterial.class));
materialQuery.setFilter("dId.contains(dIdParam) && uName == nameParam");
materialQuery.declareParameters("Long dIdParam, String nameParam");
// Execute the query
try {
List<IMaterial>
results =
(List<IMaterial>) materialQuery.execute(domainId, materialName.toLowerCase());
if (results != null && !results.isEmpty()) {
m = results.get(0);
m = pm.detachCopy(m);
}
} finally {
materialQuery.closeAll();
}
} catch (Exception e) {
xLogger.severe("{0} when trying to get Material for Material Name {1}. Message: {2}",
e.getClass().getName(), materialName, e.getMessage());
} finally {
pm.close();
}
xLogger.fine("Exiting getMaterial");
return m;
}
示例6: getHandlingUnitByName
import javax.jdo.Query; //导入方法依赖的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: 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();
}
}
示例8: getAssetRelationByAsset
import javax.jdo.Query; //导入方法依赖的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: 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;
}
示例10: getUploadMsgLog
import javax.jdo.Query; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private List<IUploadedMsgLog> getUploadMsgLog(String uploadedKey, PersistenceManager pm) {
Query query = pm.newQuery(JDOUtils.getImplClass(IUploadedMsgLog.class));
try {
query.setFilter("uploadedId == uploadedIdParam");
query.declareParameters("String uploadedIdParam");
List<IUploadedMsgLog> results = (List<IUploadedMsgLog>) query.execute(uploadedKey);
return (List<IUploadedMsgLog>) pm.detachCopyAll(results);
} finally {
if (query != null) {
query.closeAll();
}
}
}
示例11: createOrUpdateAssetRelation
import javax.jdo.Query; //导入方法依赖的package包/类
@Override
public IAssetRelation createOrUpdateAssetRelation(Long domainId, IAssetRelation assetRelation)
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(assetRelation.getAssetId());
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);
assetRelationTmp.setRelatedAssetId(assetRelation.getRelatedAssetId());
assetRelationTmp.setType(assetRelation.getType());
pm.makePersistent(assetRelationTmp);
return assetRelationTmp;
} else {
pm.makePersistent(assetRelation);
EventPublisher.generate(domainId, IEvent.CREATED, null,
JDOUtils.getImplClassName(IAssetRelation.class), String.valueOf(assetRelation.getId()), null);
return assetRelation;
}
} catch (Exception e) {
xLogger.warn("{0} while updating asset relationship for the asset {1}", e.getMessage(),
assetRelation.getAssetId(), e);
throw new ServiceException(e.getMessage());
} finally {
pm.close();
}
}
示例12: getTagById
import javax.jdo.Query; //导入方法依赖的package包/类
@Override
public ITag getTagById(long id, int type) {
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = pm.newQuery(Tag.class);
query.setFilter("id == idParam && type == typeParam");
query.declareParameters("Long idParam,Integer typeParam");
ITag result = null;
try {
List<ITag> results = (List<ITag>) query.execute(id, type);
if (results != null && results.size() > 0) {
result = results.get(0);
result = pm.detachCopy(result);
} else {
ITag tag = new Tag(type, id);
tag = pm.makePersistent(tag);
return pm.detachCopy(tag);
}
} catch (Exception e) {
xLogger.warn("Error while fetching tag with name {0} and type {1}", id, type, e);
} finally {
try {
query.closeAll();
} catch (Exception ignored) {
xLogger.warn("Exception while closing query", ignored);
}
pm.close();
}
return result;
}
示例13: testJdoSafeFilter2
import javax.jdo.Query; //导入方法依赖的package包/类
public void testJdoSafeFilter2(String filterValue) {
PersistenceManager pm = getPM();
Query q = pm.newQuery(UserEntity.class);
q.setFilter("id == userId");
q.declareParameters("int userId");
}
示例14: setManagedEntityRouteInfo
import javax.jdo.Query; //导入方法依赖的package包/类
/**
* Set ManagedEntitiesRouteInfo
*/
@SuppressWarnings("unchecked")
public void setManagedEntityRouteInfo(Long domainId, String userId, Long kioskId, String routeTag,
Integer routeIndex) throws ServiceException {
// Get the UserToKiosk object for the userId and kioskId
// Set the routeTag to routeTag
// Do not set the routeIndex because it is already set to Default Route Index
xLogger.fine("Entering setManagedEntityRouteInfo");
if (domainId == null || userId == null || userId.isEmpty() || kioskId == null) {
xLogger.warn("Invalid parameters. domainId: {0}, userId: {1}, kioskId: {2}", domainId, userId,
kioskId);
throw new ServiceException("Invalid parameters");
}
PersistenceManager pm = PMF.get().getPersistenceManager();
// Update the UserAccount to set the route enabled flag
try {
// Form the query
Query userToKioskQuery = pm.newQuery(JDOUtils.getImplClass(IUserToKiosk.class));
userToKioskQuery.setFilter("kioskId == kioskIdParam");
userToKioskQuery.declareParameters("Long kioskIdParam");
// Execute the query
try {
List<IUserToKiosk> results = (List<IUserToKiosk>) userToKioskQuery.execute(kioskId);
if (results != null && !results.isEmpty()) {
// Iterate through the results
// Check if userId of the UserToKiosk object matches with the userId that is passed
// If it matches, then set the routeTag and routeIndex for that UserToKiosk object
for (IUserToKiosk u2k : results) {
if (u2k.getUserId().equals(userId)) {
u2k.setTag(routeTag);
if (routeIndex != null) {
u2k.setRouteIndex(routeIndex);
}
break;
}
}
}
} finally {
userToKioskQuery.closeAll();
}
} catch (Exception e) {
xLogger.severe(
"{0} when trying to set the route info for managed entities for user {1}. Message: {2}",
e.getClass().getName(), userId, e.getMessage());
} finally {
pm.close();
}
xLogger.fine("Exiting updateManagedEntityRouteInfo");
}
示例15: 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);
}