本文整理汇总了Java中javax.persistence.Query.getSingleResult方法的典型用法代码示例。如果您正苦于以下问题:Java Query.getSingleResult方法的具体用法?Java Query.getSingleResult怎么用?Java Query.getSingleResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.persistence.Query
的用法示例。
在下文中一共展示了Query.getSingleResult方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pagingQuery
import javax.persistence.Query; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void pagingQuery(String jpql,String countJpql,Page<?> page,Map<String,Object> parameter,String dataSourceName){
EntityManager em=this.getEntityManager(dataSourceName);
Query query=em.createQuery(jpql);
if(parameter!=null){
this.setParameter(query, parameter);
}
query.setFirstResult((page.getPageNo()-1)*page.getPageSize());
query.setMaxResults(page.getPageSize());
page.setEntities(query.getResultList());
Query countQuery=em.createQuery(countJpql);
if(parameter!=null){
this.setParameter(countQuery, parameter);
}
int count=0;
Object obj=countQuery.getSingleResult();
if(obj instanceof Integer){
count=(Integer)obj;
}else if(obj instanceof Long){
count=((Long)obj).intValue();
}else{
throw new IllegalArgumentException("The ql["+countJpql+"] fetch result is "+obj+",can not convert to int value");
}
page.setEntityCount(count);
}
示例2: getCountUserAssignableSubscriptions
import javax.persistence.Query; //导入方法依赖的package包/类
public Long getCountUserAssignableSubscriptions(PaginationInt pagination,
Organization owner, long userKey, Set<SubscriptionStatus> states) {
String nativeQuery = getQueryCountUserAssignableSubscriptions(
pagination);
Query q = dataManager.createNativeQuery(nativeQuery);
q.setParameter("locale", owner.getLocale());
q.setParameter("orgKey", Long.valueOf(owner.getKey()));
q.setParameter("userKey", Long.valueOf(userKey));
q.setParameter("states", getSubscriptionStatesAsString(states));
setPaginationParameters(pagination, q);
BigInteger result = (BigInteger) q.getSingleResult();
return result.longValue();
}
示例3: findSubscriptionForAsyncCallBack
import javax.persistence.Query; //导入方法依赖的package包/类
public Long findSubscriptionForAsyncCallBack(String subscriptionId,
String organizationId) {
Query query = dataManager
.createNamedQuery("ModifiedEntity.findSubscriptionKeyByOrgIdAndSubId");
query.setParameter("organizationId", organizationId);
query.setParameter("subOrgIdType",
ModifiedEntityType.SUBSCRIPTION_ORGANIZATIONID);
query.setParameter("subscriptionId", subscriptionId);
query.setParameter("subIdType",
ModifiedEntityType.SUBSCRIPTION_SUBSCRIPTIONID);
return (Long) query.getSingleResult();
}
示例4: deleteCategories
import javax.persistence.Query; //导入方法依赖的package包/类
/**
* @param toBeDeleted
* @throws OperationNotPermittedException
* @throws ObjectNotFoundException
*/
private void deleteCategories(List<VOCategory> toBeDeleted)
throws OperationNotPermittedException, ObjectNotFoundException {
final Organization currentOrg = dm.getCurrentUser().getOrganization();
final Query marketplaceQuery = dm
.createNamedQuery("Marketplace.findByBusinessKey");
for (VOCategory voCategory : toBeDeleted) {
final Category category = dm.getReference(Category.class,
voCategory.getKey());
try {
marketplaceQuery.setParameter("marketplaceId", category
.getMarketplace().getMarketplaceId());
} catch (EntityNotFoundException e) {
throw new ObjectNotFoundException(ClassEnum.MARKETPLACE,
voCategory.getMarketplaceId());
}
final Marketplace marketplace = (Marketplace) marketplaceQuery
.getSingleResult();
PermissionCheck.owns(marketplace, currentOrg, logger, null);
List<PlatformUser> usersToBeNotified = collectUsersToBeNotified(category);
prefetchRequiredObject(category);
dm.remove(category);
sendNotification(category, usersToBeNotified);
}
}
示例5: getPlatformUserByOrganization
import javax.persistence.Query; //导入方法依赖的package包/类
@Override
public PlatformUser getPlatformUserByOrganization(String userId,
String orgId) throws ObjectNotFoundException {
Query query = dm.createNamedQuery("PlatformUser.findByUserIdAndOrgId");
query.setParameter("userId", userId);
query.setParameter("organizationId", orgId);
PlatformUser platformUser = null;
try {
platformUser = (PlatformUser) query.getSingleResult();
} catch (NoResultException e) {
throwONFExcp(userId);
}
if (platformUser == null) {
throwONFExcp(userId);
}
return platformUser;
}
示例6: findCode
import javax.persistence.Query; //导入方法依赖的package包/类
public T findCode(String code) {
T entity;
String queryString = "Select c FROM " + entityClass.getSimpleName() + " c where c.code = :code1";
Query query = entityManager.createQuery(queryString).setParameter("code1", code);
try {
entity = (T) query.getSingleResult();
} catch (NoResultException | NonUniqueResultException e) {
entity = null;
LOG.log(Level.WARNING, e.getMessage());
}
return entity;
}
示例7: existsActiveSurveyWithCode
import javax.persistence.Query; //导入方法依赖的package包/类
@Override
public boolean existsActiveSurveyWithCode(String code){
Date nowDate = new Date();
Timestamp now = new Timestamp(nowDate.getTime());
Query query = entityManager.createQuery("select count(s) from survey s where s.code = :code " +
"and s.deadline > :now");
query.setParameter("code", code);
query.setParameter("now", now);
Long count = (Long) query.getSingleResult();
return count >= 1;
}
示例8: findMarketplaceRevenueShareWithinPeriod
import javax.persistence.Query; //导入方法依赖的package包/类
private RevenueShareModelHistory findMarketplaceRevenueShareWithinPeriod(
long mpKey, long endPeriod) {
Query query = dm
.createNamedQuery("RevenueShareModelHistory.findMarketplaceRevenueSharePercentage");
query.setParameter("mpKey", Long.valueOf(mpKey));
query.setParameter("modDate", new Date(endPeriod));
query.setMaxResults(1);
try {
return (RevenueShareModelHistory) query.getSingleResult();
} catch (NoResultException e) {
return null;
}
}
示例9: getOperationByInstanceId
import javax.persistence.Query; //导入方法依赖的package包/类
public Operation getOperationByInstanceId(String instanceId) {
Query query = em.createNamedQuery("Operation.getOperationByInstanceId");
query.setParameter("id", instanceId);
query.setMaxResults(1);
try {
return (Operation) query.getSingleResult();
} catch (NoResultException e) {
return null;
}
}
示例10: updateQuotePriceVolume
import javax.persistence.Query; //导入方法依赖的package包/类
@Override
public QuoteDataBean updateQuotePriceVolume(String symbol, BigDecimal changeFactor, double sharesTraded) {
if (!TradeConfig.getUpdateQuotePrices())
return new QuoteDataBean();
if (Log.doTrace())
Log.trace("TradeSLSBBean:updateQuote", symbol, changeFactor);
// QuoteDataBean quote = entityManager.find(QuoteDataBean.class, symbol);
Query q = entityManager.createNamedQuery("quoteejb.quoteForUpdate");
q.setParameter(1, symbol);
QuoteDataBean quote = (QuoteDataBean) q.getSingleResult();
BigDecimal oldPrice = quote.getPrice();
if (quote.getPrice().equals(TradeConfig.PENNY_STOCK_PRICE)) {
changeFactor = TradeConfig.PENNY_STOCK_RECOVERY_MIRACLE_MULTIPLIER;
}
BigDecimal newPrice = changeFactor.multiply(oldPrice).setScale(2, BigDecimal.ROUND_HALF_UP);
quote.setPrice(newPrice);
quote.setVolume(quote.getVolume() + sharesTraded);
entityManager.merge(quote);
// TODO find out if requires new here is really intended -- it is backwards,
// change can get published w/o it occurring.
context.getBusinessObject(TradeSLSBLocal.class).publishQuotePriceChange(quote, oldPrice, changeFactor, sharesTraded);
//this.publishQuotePriceChange(quote, oldPrice, changeFactor, sharesTraded);
return quote;
}
示例11: getPlatformSessionForSessionId
import javax.persistence.Query; //导入方法依赖的package包/类
@Override
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public Session getPlatformSessionForSessionId(String sessionId) {
logger.logDebug("getPlatformSessionForSessionId(String) sessionId");
// find all entries for the given session id
Query query = dm.createNamedQuery("Session.findEntriesForSessionId");
query.setParameter("sessionId", sessionId);
query.setParameter("sessionType", SessionType.PLATFORM_SESSION);
return (Session) query.getSingleResult();
}
示例12: findByEmail
import javax.persistence.Query; //导入方法依赖的package包/类
@Override
@Transactional
public User findByEmail(String email) throws BusinessException {
try{
Query query = em.createQuery("from User u where u.email = :email");
query.setParameter("email", email);
return (User) query.getSingleResult();
} catch (NoResultException e) {
throw new BusinessException("No Result", e);
}
}
示例13: findById
import javax.persistence.Query; //导入方法依赖的package包/类
public Usuario findById(String usuario, String senha) {
try {
byte[] senhaCriptografada = criptografia.criptografar(senha, "MD5");
Query query = manager.createQuery("Select p from Usuario p where p.email = :pEmail and p.senha = :pSenha");
query.setParameter("pEmail", usuario);
query.setParameter("pSenha", senhaCriptografada);
return (Usuario) query.getSingleResult();
} catch (Exception e) {
System.err.println(e.getMessage());
}
return null;
}
示例14: getRoleAssignmentByUserAndGroup
import javax.persistence.Query; //导入方法依赖的package包/类
public UnitRoleAssignment getRoleAssignmentByUserAndGroup(long groupKey,
String userId) {
Query query = dm
.createNamedQuery("UnitRoleAssignment.findByUserAndGroup");
query.setParameter("usergroup_tkey", Long.valueOf(groupKey));
query.setParameter("userId", userId);
UnitRoleAssignment unitRoleAssignment = null;
try {
unitRoleAssignment = (UnitRoleAssignment) query.getSingleResult();
} catch (NoResultException nre) {
return null;
}
return unitRoleAssignment;
}
示例15: getWebServerCount
import javax.persistence.Query; //导入方法依赖的package包/类
@Override
public Long getWebServerCount(final String groupName) {
final Query query = entityManager.createNamedQuery(JpaWebServer.QUERY_GET_WS_COUNT_BY_GROUP_NAME);
query.setParameter(JpaWebServer.QUERY_PARAM_GROUP_NAME, groupName);
return (Long) query.getSingleResult();
}