当前位置: 首页>>代码示例>>Java>>正文


Java Query.getSingleResult方法代码示例

本文整理汇总了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);
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:26,代码来源:JpaDao.java

示例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();
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:18,代码来源:UserSubscriptionDao.java

示例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();
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:13,代码来源:SubscriptionDao.java

示例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);
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:30,代码来源:CategorizationServiceBean.java

示例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;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:24,代码来源:IdentityServiceBean.java

示例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;
}
 
开发者ID:ISIS2503,项目名称:ThermalComfortBack,代码行数:13,代码来源:Persistencer.java

示例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;
}
 
开发者ID:erikns,项目名称:webpoll,代码行数:13,代码来源:JpaSurveyRepository.java

示例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;
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:15,代码来源:SharesDataRetrievalServiceBean.java

示例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;
    }
}
 
开发者ID:servicecatalog,项目名称:oscm-app,代码行数:11,代码来源:OperationDAO.java

示例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;
}
 
开发者ID:WASdev,项目名称:sample.daytrader3,代码行数:33,代码来源:TradeSLSBBean.java

示例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();
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:11,代码来源:SessionServiceBean.java

示例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);
   }
}
 
开发者ID:alexander-perucci,项目名称:spring-grow,代码行数:12,代码来源:JPAUserService.java

示例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;
}
 
开发者ID:IsadoraScusselFarias,项目名称:ProjetoFinalInitium,代码行数:13,代码来源:AutenticacaoDao.java

示例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;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:15,代码来源:UserGroupDao.java

示例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();
}
 
开发者ID:cerner,项目名称:jwala,代码行数:7,代码来源:WebServerCrudServiceImpl.java


注:本文中的javax.persistence.Query.getSingleResult方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。