本文整理匯總了Java中javax.jdo.PersistenceManager.newQuery方法的典型用法代碼示例。如果您正苦於以下問題:Java PersistenceManager.newQuery方法的具體用法?Java PersistenceManager.newQuery怎麽用?Java PersistenceManager.newQuery使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jdo.PersistenceManager
的用法示例。
在下文中一共展示了PersistenceManager.newQuery方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getInvTotalCount
import javax.jdo.PersistenceManager; //導入方法依賴的package包/類
public Integer getInvTotalCount(Map<String, String> filter) throws SQLException{
PersistenceManager pm = PMF.get().getPersistenceManager();
StringBuilder
sb =
new StringBuilder("SELECT COUNT(1) AS COUNT FROM INVNTRY WHERE KID = " + Long.parseLong(
filter.get(Constants.ENTITY)));
if (filter.get(Constants.MATERIAL_TAG) != null) {
sb.append(
" AND MID IN (SELECT MATERIALID FROM MATERIAL_TAGS WHERE ID IN (SELECT ID FROM TAG WHERE NAME IN (")
.append(String.valueOf(filter.get(Constants.MATERIAL_TAG))).append(")))");
}
Query query = pm.newQuery("javax.jdo.query.SQL",sb.toString());
query.setUnique(true);
Object object = query.execute();
Integer count = ((Long) object).intValue();
return count;
}
示例2: getFilteredRequesters
import javax.jdo.PersistenceManager; //導入方法依賴的package包/類
public Collection<String> getFilteredRequesters(String requester, Long domainId) {
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = null;
List<String> queryList = new ArrayList<>(0);
try {
if (StringUtils.isNotEmpty(requester)) {
query = pm.newQuery("javax.jdo.query.SQL",
"SELECT DISTINCT CREATED_BY FROM ORDER_APPROVAL_MAPPING WHERE "
+ "EXISTS (SELECT 1 from USERACCOUNT_DOMAINS WHERE CREATED_BY = USERID_OID "
+ "AND DOMAIN_ID = ?) "
+ "AND CREATED_BY in (SELECT USERID from USERACCOUNT WHERE NNAME like ?) limit 10");
List results = (List) query.executeWithArray(domainId, requester.toLowerCase() + "%");
if(results != null && !results.isEmpty()) {
queryList = new ArrayList<>(results.size());
for(Object o : results) {
queryList.add((String)o);
}
}
}
} finally {
if (query != null) {
query.closeAll();
}
pm.close();
}
return queryList;
}
示例3: getOutOfStockCounts
import javax.jdo.PersistenceManager; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public int getOutOfStockCounts(Long entityId) {
int count = 0;
PersistenceManager pm = null;
Query query = null;
try {
pm = PMF.get().getPersistenceManager();
Map<String, Object> params = new HashMap<String, Object>(1);
query =
pm.newQuery("select key from " + JDOUtils.getImplClass(IInvntry.class).getName()
+ " where kId == kIdParam && stk == 0f PARAMETERS Long kIdParam");
params.put("kIdParam", entityId);
List<Long> results = (List<Long>) query.executeWithMap(params);
if (results != null) {
count = results.size();
}
} catch (Exception e) {
xLogger.warn("Failed to get out of stock counts for Entity: {0}", entityId, e);
} finally {
if (query != null) {
try {
query.closeAll();
} catch (Exception ignored) {
xLogger.warn("Exception while closing query", ignored);
}
}
if (pm != null) {
pm.close();
}
}
return count;
}
示例4: getInvMaterialCount
import javax.jdo.PersistenceManager; //導入方法依賴的package包/類
/**
* Method to get the count of unique materials for a given domain id
*
* @param domainId Domain Id
* @return Count of unique materials
*/
public Long getInvMaterialCount(Long domainId, Long tagId) throws ServiceException {
if (domainId == null) {
return 0L;
}
StringBuilder
queryBuilder =
new StringBuilder(
"SELECT COUNT(DISTINCT(MID)) FROM INVNTRY WHERE KID IN (SELECT KIOSKID_OID FROM KIOSK_DOMAINS WHERE DOMAIN_ID=?)");
Long count;
try {
List<String> parameters = new ArrayList<>(2);
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query;
if (tagId != null) {
queryBuilder.append(" AND MID IN (SELECT MATERIALID FROM MATERIAL_TAGS WHERE ID=?)");
parameters.add(String.valueOf(tagId));
}
query = pm.newQuery("javax.jdo.query.SQL", queryBuilder.toString());
parameters.add(String.valueOf(domainId));
query.setUnique(true);
count = (Long) query.executeWithArray(parameters.toArray());
} catch (Exception e) {
xLogger.warn("Exception fetching the count", e);
throw new ServiceException("Failed to fetch count");
}
return count;
}
示例5: findAllPoolGroups
import javax.jdo.PersistenceManager; //導入方法依賴的package包/類
/**
* Find all pool groups with pagination, in a given domain
* TODO: Pagination
*/
@SuppressWarnings("unchecked")
public List<IPoolGroup> findAllPoolGroups(Long domainId, int pageNumber, int numOfEntries) {
xLogger.fine("Entering findAllPooLGroups");
PersistenceManager pm = PMF.get().getPersistenceManager();
List<IPoolGroup> poolGroups = new ArrayList<IPoolGroup>();
// Formulate query
Query query = pm.newQuery(JDOUtils.getImplClass(IPoolGroup.class));
query.setFilter("dId == domainIdParam");
query.declareParameters("Long domainIdParam");
query.setOrdering("name asc");
// Execute query
try {
poolGroups = (List<IPoolGroup>) query.execute(domainId);
poolGroups
.size(); // TODO - temp. fix for retrieving all obejcts and avoid "object manager closed" exception
poolGroups = (List<IPoolGroup>) pm.detachCopyAll(poolGroups);
} catch (Exception e) {
xLogger.warn("Exception: {0}", e.getMessage());
} finally {
try {
query.closeAll();
} catch (Exception ignored) {
xLogger.warn("Exception while closing query", ignored);
}
pm.close();
}
xLogger.fine("Exiting findAllPooLGroups");
return poolGroups;
}
示例6: getStateSuggestions
import javax.jdo.PersistenceManager; //導入方法依賴的package包/類
@Override
public List<LocationSuggestionModel> getStateSuggestions(Long domainId, String text) {
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = null;
List<LocationSuggestionModel> states = new ArrayList<>(8);
try {
query =
pm.newQuery("javax.jdo.query.SQL",
"SELECT DISTINCT COUNTRY,STATE FROM KIOSK WHERE STATE COLLATE UTF8_GENERAL_CI LIKE '%" + text + "%' AND KIOSKID IN " +
"( SELECT KIOSKID_OID FROM KIOSK_DOMAINS WHERE DOMAIN_ID=" + domainId
+ ") LIMIT 8");
List stateList = (List) query.execute();
for (Object st : stateList) {
String country = (String)((Object[])st)[0];
String state = (String)((Object[])st)[1];
LocationSuggestionModel model = new LocationSuggestionModel();
model.label = state;
model.country = country;
states.add(model);
}
return states;
} catch (Exception e) {
xLogger.severe("Error while fetching state suggestions from domain {0}", domainId, e);
} finally {
if (query != null) {
try {
query.closeAll();
} catch (Exception ignored) {
xLogger.warn("Exception while closing query", ignored);
}
}
pm.close();
}
return null;
}
示例7: getValidBatches
import javax.jdo.PersistenceManager; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private Results<IInvntryBatch> getValidBatches(Long materialId, Long kioskId, PageParams pageParams,
PersistenceManager pm) throws ServiceException {
xLogger.fine("Entered getValidBatches");
// Form query
String
queryStr =
"SELECT FROM " + JDOUtils.getImplClass(IInvntryBatch.class).getName()
+ " WHERE mId == mIdParam && kId == kIdParam && vld == vldParam PARAMETERS Long mIdParam, Long kIdParam, Boolean vldParam ORDER BY bexp ASC";
Query q = pm.newQuery(queryStr);
if (pageParams != null) {
QueryUtil.setPageParams(q, pageParams);
}
Map<String, Object> params = new HashMap<>();
params.put("mIdParam", materialId);
params.put("kIdParam", kioskId);
params.put("vldParam", Boolean.TRUE);
xLogger.fine("Params: {0}", params);
List<IInvntryBatch> results = null;
String cursor = null;
try {
results = (List<IInvntryBatch>) q.executeWithMap(params);
xLogger.fine("Results: {0}", results);
if (results != null) {
results.size();
cursor = QueryUtil.getCursor(results);
results = (List<IInvntryBatch>) pm.detachCopyAll(results);
}
} finally {
q.closeAll();
}
xLogger.fine("Exiting getValidBatches");
return new Results<>(results, cursor);
}
示例8: getMaterialByName
import javax.jdo.PersistenceManager; //導入方法依賴的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;
}
示例9: 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;
}
示例10: getOrderApprovalMapping
import javax.jdo.PersistenceManager; //導入方法依賴的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;
}
示例11: customIdExists
import javax.jdo.PersistenceManager; //導入方法依賴的package包/類
/**
* Check if a custom ID is available in a domain or it's child domains
*/
public boolean customIdExists(Long domainId, String customId, String userId)
throws ServiceException {
if (domainId == null || customId == null || customId.isEmpty() || userId == null || userId
.isEmpty()) {
throw new ServiceException("Invalid or null Domain ID: {0}, custom ID : {1}, user ID: {2}",
domainId, customId, userId);
}
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = pm.newQuery(JDOUtils.getImplClass(IUserAccount.class));
query.setFilter("dId.contains(domainIdParam) && cId == cidParam");
query.declareParameters("Long domainIdParam, String cidParam");
try {
List<IUserAccount> results = (List<IUserAccount>) query.execute(domainId, customId);
if (results != null && results.size() == 1) {
if (userId != null) {
IUserAccount res = results.get(0);
if (userId.equals(res.getUserId())) {
return false;
}
}
return true;
}
} finally {
try {
query.closeAll();
} catch (Exception ignored) {
xLogger.warn("Exception while closing query", ignored);
}
pm.close();
}
return false;
}
示例12: getModelSuggestion
import javax.jdo.PersistenceManager; //導入方法依賴的package包/類
@Override
public List<String> getModelSuggestion(Long domainId, String term) {
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = null;
try {
StringBuilder sqlQuery = new StringBuilder("SELECT DISTINCT MODEL FROM ASSET WHERE");
sqlQuery.append(" ID IN (SELECT ID_OID FROM ASSET_DOMAINS WHERE DOMAIN_ID = ")
.append(domainId).append(")");
if (StringUtils.isNotEmpty(term)) {
sqlQuery.append(" AND lower(MODEL) like '%").append(term.toLowerCase()).append("%'");
}
sqlQuery.append(" LIMIT 0, 10");
query = pm.newQuery("javax.jdo.query.SQL", sqlQuery.toString());
List modelList = (List) query.execute();
List<String> models = new ArrayList<>(modelList.size());
for (Object o : modelList) {
models.add((String) o);
}
return models;
} catch (Exception e) {
xLogger.warn("Error while fetching suggestions for asset models", e);
} finally {
if(query != null) {
query.closeAll();
}
pm.close();
}
return null;
}
示例13: getUploadMsgLog
import javax.jdo.PersistenceManager; //導入方法依賴的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();
}
}
}
示例14: testJdoSafeFilter2
import javax.jdo.PersistenceManager; //導入方法依賴的package包/類
public void testJdoSafeFilter2(String filterValue) {
PersistenceManager pm = getPM();
Query q = pm.newQuery(UserEntity.class);
q.setFilter("id == userId");
q.declareParameters("int userId");
}
示例15: testJdoQueriesAdditionalMethodSig
import javax.jdo.PersistenceManager; //導入方法依賴的package包/類
public void testJdoQueriesAdditionalMethodSig(String input) {
PersistenceManager pm = getPM();
pm.newQuery(UserEntity.class,new ArrayList(),"id == "+ input); //Injection?
pm.newQuery(UserEntity.class,new ArrayList(),"id == 1");
pm.newQuery(UserEntity.class,"id == "+ input); //Injection?
pm.newQuery(UserEntity.class,"id == 1");
pm.newQuery((Extent) null,"id == "+input); //Injection?
pm.newQuery((Extent) null,"id == 1");
}