本文整理汇总了Java中javax.jdo.Query.execute方法的典型用法代码示例。如果您正苦于以下问题:Java Query.execute方法的具体用法?Java Query.execute怎么用?Java Query.execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.jdo.Query
的用法示例。
在下文中一共展示了Query.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkCustomIdExists
import javax.jdo.Query; //导入方法依赖的package包/类
@Override
public boolean checkCustomIdExists(Long domainId, String customId) {
PersistenceManager pm = PMF.get().getPersistenceManager();
// Check if another material by the same custom ID exists in the database
Query query = pm.newQuery(Material.class);
query.setFilter("dId.contains(domainIdParam) && cId == cidParam");
query.declareParameters("Long domainIdParam, String cidParam");
boolean customIdExists = false;
try {
@SuppressWarnings("unchecked")
List<IMaterial> results = (List<IMaterial>) query.execute(domainId, customId);
if (results != null && results.size() == 1) {
// Material with this name already exists in the database!
customIdExists = true;
}
} finally {
try {
query.closeAll();
} catch (Exception ignored) {
xLogger.warn("Exception while closing query", ignored);
}
pm.close();
}
xLogger.fine("Exiting checkIfCustomIdExists");
return customIdExists;
}
示例2: getCnt
import javax.jdo.Query; //导入方法依赖的package包/类
private static int getCnt(Query query, Object o1, Object o2, Map map) {
if (query == null) {
return -1;
}
query.setResult(QueryConstants.COUNT);
query.setRange(null);
query.setOrdering(null);
Long cnt;
if (map != null) {
cnt = (Long) query.executeWithMap(map);
} else {
cnt = (Long) query.execute(o1, o2);
}
return Integer.parseInt(String.valueOf(cnt));
}
示例3: findId
import javax.jdo.Query; //导入方法依赖的package包/类
public IInvntry findId(Long kioskId, Long materialId, PersistenceManager pm) {
Query q = pm.newQuery(Invntry.class);
try {
q.setFilter("kId == " + kioskId.toString() + " && mId == " + materialId.toString());
Object results = q.execute();
if (results instanceof IInvntry) {
results = pm.detachCopy(results);
return (Invntry) results;
} else if (results instanceof List) {
if (!((List) results).isEmpty()) {
Invntry result = ((List<Invntry>) results).get(0);
result = pm.detachCopy(result);
return result;
}
}
return null;
} finally {
if (q != null) {
q.closeAll();
}
}
}
示例4: getInventoryTransactionsByTrackingId
import javax.jdo.Query; //导入方法依赖的package包/类
/**
* Get inventory transactions by tracking-id
*/
@SuppressWarnings("unchecked")
public Results getInventoryTransactionsByTrackingId(Long trackingId) throws ServiceException {
xLogger.fine("Entered getInventoryTransactionsByTrackingId");
List<ITransaction> trans = null;
// Get PM
PersistenceManager pm = PMF.get().getPersistenceManager();
Query q = pm.newQuery(JDOUtils.getImplClass(ITransaction.class));
q.setFilter("tid == tidParam");
q.declareParameters("Long tidParam");
try {
trans = (List<ITransaction>) q.execute(trackingId);
trans = (List<ITransaction>) pm.detachCopyAll(trans);
trans.size();
} finally {
try {
q.closeAll();
} catch (Exception ignored) {
xLogger.warn("Exception while closing query", ignored);
}
pm.close();
}
Results r = new Results(trans, null);
xLogger.fine("Exiting getInventoryTransactionsByTrackingId");
return r;
}
示例5: getAllRootDomains
import javax.jdo.Query; //导入方法依赖的package包/类
@Override
public List<IDomain> getAllRootDomains() {
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = pm.newQuery(JDOUtils.getImplClass(IDomain.class));
query.setFilter("hasParent == false");
query.setOrdering("nNm asc");
List<IDomain> domains;
try {
domains = (List<IDomain>) query.execute();
domains = (List<IDomain>) pm.detachCopyAll(domains);
} catch (Exception e) {
xLogger.severe("Error while fetching root domains", e);
throw new InvalidServiceException(backendMessages.getString("domains.fetch.error"));
} finally {
try {
query.closeAll();
} catch (Exception ignored) {
xLogger.warn("Exception while closing query", ignored);
}
pm.close();
}
return domains;
}
示例6: hasDomainLinks
import javax.jdo.Query; //导入方法依赖的package包/类
/**
* Check if links of a certain type exist
*/
@SuppressWarnings("unchecked")
public boolean hasDomainLinks(Long domainId, int linkType) throws ServiceException {
xLogger.fine("Entered hasLinkedDomains");
if (domainId == null) {
throw new IllegalArgumentException("Invalid domain ID");
}
boolean has = false;
PersistenceManager pm = PMF.get().getPersistenceManager();
String
queryStr =
"SELECT key FROM " + JDOUtils.getImplClass(IDomainLink.class).getName()
+ " WHERE dId == dIdParam && ty == tyParam PARAMETERS Long dIdParam, Integer tyParam ORDER BY nldnm ASC";
Query q = pm.newQuery(queryStr);
QueryUtil.setPageParams(q, new PageParams(null, 1));
try {
List<String> keys = (List<String>) q.execute(domainId, new Integer(linkType));
xLogger.fine("Got keys: {0}", keys);
has = keys != null && !keys.isEmpty();
} finally {
try {
q.closeAll();
} catch (Exception ignored) {
xLogger.warn("Exception while closing query", ignored);
}
pm.close();
}
xLogger.fine("Exiting hasLinkedDomains");
return has;
}
示例7: getApiKey
import javax.jdo.Query; //导入方法依赖的package包/类
/**
* Returns an API key.
* @param key the key to return
* @return an ApiKey
* @since 1.0.0
*/
@SuppressWarnings("unchecked")
public ApiKey getApiKey(final String key) {
final Query query = pm.newQuery(ApiKey.class, "key == :key");
final List<ApiKey> result = (List<ApiKey>) query.execute(key);
return result.size() == 0 ? null : result.get(0);
}
示例8: getResults
import javax.jdo.Query; //导入方法依赖的package包/类
private static Object getResults(QueryParams qp, Query q) {
Object results;
if (qp.params != null && !qp.params.isEmpty()) {
results = q.executeWithMap(qp.params);
} else if (qp.listParams != null && !qp.listParams.isEmpty()) {
results = q.executeWithArray(qp.listParams.toArray());
} else {
results = q.execute();
}
return results;
}
示例9: getAssetsByKiosk
import javax.jdo.Query; //导入方法依赖的package包/类
@Override
public List<IAsset> getAssetsByKiosk(Long kioskId, Integer assetType) throws ServiceException {
if (kioskId == null || assetType == null) {
throw new ServiceException(
backendMessages.getString("kiosk") + " and AssetType are mandatory");
}
List<IAsset> assets = null;
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
Query query = pm.newQuery(JDOUtils.getImplClass(IAsset.class));
query.setFilter("kId == kioskIdParam && type == assetTypeParam");
query.declareParameters("Long kioskIdParam, Integer assetTypeParam");
try {
assets = (List<IAsset>) query.execute(kioskId, assetType);
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;
}
示例10: getManagedUsers
import javax.jdo.Query; //导入方法依赖的package包/类
/**
* Returns a complete list of all ManagedUser objects, in ascending order by username.
* @return a List of ManagedUsers
* @since 1.0.0
*/
@SuppressWarnings("unchecked")
public List<ManagedUser> getManagedUsers() {
final Query query = pm.newQuery(ManagedUser.class);
query.setOrdering("username asc");
return (List<ManagedUser>) query.execute();
}
示例11: getTeams
import javax.jdo.Query; //导入方法依赖的package包/类
/**
* Returns a complete list of all Team objects, in ascending order by name.
* @return a List of Teams
* @since 1.0.0
*/
@SuppressWarnings("unchecked")
public List<Team> getTeams() {
pm.getFetchPlan().addGroup(Team.FetchGroup.ALL.name());
final Query query = pm.newQuery(Team.class);
query.setOrdering("name asc");
return (List<Team>) query.execute();
}
示例12: 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;
}
示例13: getUsersForKiosk
import javax.jdo.Query; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public Results getUsersForKiosk(Long kioskId, PageParams pageParams, PersistenceManager pm)
throws ServiceException {
xLogger.fine("Entered getUsersForKiosk");
List<IUserAccount> users = null;
String cursor = null;
Query userToKioskQuery = pm.newQuery(UserToKiosk.class);
userToKioskQuery.setFilter("kioskId == kioskIdParam");
userToKioskQuery.declareParameters("Long kioskIdParam");
if (pageParams != null) {
QueryUtil.setPageParams(userToKioskQuery, pageParams);
}
// Get the list of users associated with this kiosk
try {
List<IUserToKiosk> results = (List<IUserToKiosk>) userToKioskQuery.execute(kioskId);
if (results != null && !results.isEmpty()) {
cursor = QueryUtil.getCursor(results);
users = new ArrayList<>();
Iterator<IUserToKiosk> it = results.iterator();
while (it.hasNext()) {
IUserToKiosk u2k = it.next();
try {
IUserAccount user = JDOUtils.getObjectById(IUserAccount.class, u2k.getUserId(), pm);
user = pm.detachCopy(user);
users.add(user);
} catch (JDOObjectNotFoundException e) {
xLogger.warn("User {0} not found when getting users for kiosk {1}", u2k.getUserId(),
kioskId);
}
}
}
} finally {
userToKioskQuery.closeAll();
}
xLogger.fine("Exiting getUsersForKiosk");
return new Results(users, cursor);
}
示例14: getAssets
import javax.jdo.Query; //导入方法依赖的package包/类
public List<IAsset> getAssets(Long domainId, Long kId, String q, String assetType, Boolean all)
throws ServiceException {
PersistenceManager pm = PMF.get().getPersistenceManager();
List<IAsset> assets = new ArrayList<>();
try {
StringBuilder sqlQuery = new StringBuilder("SELECT * FROM ASSET WHERE");
if (all) {
sqlQuery.append(" ID IN (SELECT ID_OID FROM ASSET_DOMAINS WHERE DOMAIN_ID = ")
.append(domainId).append(")");
} else {
sqlQuery.append(" ID NOT IN (SELECT RELATEDASSETID FROM ASSETRELATION where RELATEDASSETID is not NULL) AND SDID = ")
.append(domainId);
}
if (kId != null) {
sqlQuery.append(" AND KID = ").append(kId);
}
if (!q.isEmpty()) {
sqlQuery.append(" AND nsId like '").append(q).append("%'");
}
if (assetType != null) {
sqlQuery.append(" AND type = ").append(assetType);
}
sqlQuery.append(" ORDER BY nsId asc LIMIT 0, 10");
Query query = pm.newQuery("javax.jdo.query.SQL", sqlQuery.toString());
query.setClass(JDOUtils.getImplClass(IAsset.class));
try {
assets = (List<IAsset>) query.execute();
assets = (List<IAsset>) pm.detachCopyAll(assets);
} finally {
query.closeAll();
}
} catch (Exception e) {
throw new ServiceException(e.getMessage());
} finally {
pm.close();
}
return assets;
}
示例15: getKioskLinksInDomain
import javax.jdo.Query; //导入方法依赖的package包/类
public List<EntityLinkModel> getKioskLinksInDomain(Long domainId, String user, String role) {
PersistenceManager pm = null;
Query query = null;
try {
pm = PMF.get().getPersistenceManager();
StringBuilder
sqlQuery =
new StringBuilder(
"SELECT K.NAME,K.KIOSKID,KL.LINKTYPE,KL.LINKEDKIOSKID,KL.LKNM FROM KIOSK K LEFT JOIN KIOSKLINK KL ON K.KIOSKID = KL.KIOSKID WHERE K.KIOSKID IN(");
if (SecurityConstants.ROLE_SERVICEMANAGER.equalsIgnoreCase(role)) {
sqlQuery.append("SELECT KIOSKID FROM USERTOKIOSK WHERE USERID=");
sqlQuery.append("'");
sqlQuery.append(user);
sqlQuery.append("' AND DID= ");
} else {
sqlQuery.append("SELECT KIOSKID_OID FROM KIOSK_DOMAINS WHERE DOMAIN_ID=");
}
sqlQuery.append(domainId);
sqlQuery.append(") AND IFNULL(KL.LINKTYPE,'c') = 'c'");
query = pm.newQuery("javax.jdo.query.SQL", sqlQuery.toString());
List data = (List) query.execute();
if (data != null && !data.isEmpty()) {
List<EntityLinkModel> models = new ArrayList<>();
for (Object aData : data) {
EntityLinkModel nvm = new EntityLinkModel();
Object[] kLinks = (Object[]) aData;
nvm.kioskName = (String) kLinks[0];
nvm.kioskId = (Long) kLinks[1];
nvm.linkType = (String) kLinks[2];
nvm.linkedKioskId = (Long) kLinks[3];
nvm.linkedKioskName = (String) kLinks[4];
models.add(nvm);
}
return models;
}
} catch (Exception e) {
xLogger.warn("Exception while fetching kiosk links", e);
} finally {
if (query != null) {
try {
query.closeAll();
} catch (Exception ignored) {
xLogger.warn("Exception while closing query", ignored);
}
}
if (pm != null) {
pm.close();
}
}
xLogger.fine("Exiting getKioskLinks");
return null;
}