Java Code Examples for javax.persistence.Query.getResultList()

The following are Jave code examples for showing how to use getResultList() of the javax.persistence.Query class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: marathonv5   File: LiveSalesListFacadeREST.java   View Source Code Vote up 16 votes
@GET
@Produces({"application/xml", "application/json"})
@Path("/recent/region/{regionName}/{orderLineId}")
public List<LiveSalesList> findRecentRegionFrom(@PathParam("regionName") String regionName, @PathParam("orderLineId") Integer orderLineId) {
    CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
    javax.persistence.criteria.CriteriaQuery cq = cb.createQuery();
    Root<LiveSalesList> liveSalesList = cq.from(LiveSalesList.class);
    cq.select(liveSalesList);
    cq.where(cb.and(
        cb.equal(liveSalesList.get(LiveSalesList_.region), regionName),
        cb.gt(liveSalesList.get(LiveSalesList_.orderLineId), orderLineId)
    ));
    Query q = getEntityManager().createQuery(cq);
    q.setMaxResults(500);
    return q.getResultList();
}
 
Example 2
Project: marathonv5   File: LiveSalesListFacadeREST.java   View Source Code Vote up 7 votes
@GET
@Produces({"application/xml", "application/json"})
@Path("/recent/region/{regionName}/{orderLineId}")
public List<LiveSalesList> findRecentRegionFrom(@PathParam("regionName") String regionName, @PathParam("orderLineId") Integer orderLineId) {
    CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
    javax.persistence.criteria.CriteriaQuery cq = cb.createQuery();
    Root<LiveSalesList> liveSalesList = cq.from(LiveSalesList.class);
    cq.select(liveSalesList);
    cq.where(cb.and(
        cb.equal(liveSalesList.get(LiveSalesList_.region), regionName),
        cb.gt(liveSalesList.get(LiveSalesList_.orderLineId), orderLineId)
    ));
    Query q = getEntityManager().createQuery(cq);
    q.setMaxResults(500);
    return q.getResultList();
}
 
Example 3
Project: ChronoBike   File: UsuarioJpaController.java   View Source Code Vote up 6 votes
private List<Usuario> findPersonaEntities(boolean all, int maxResults, int firstResult) {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(Usuario.class));
        Query q = em.createQuery(cq);
        if (!all) {
            q.setMaxResults(maxResults);
            q.setFirstResult(firstResult);
        }
        return q.getResultList();
    } finally {
        em.close();
    }
}
 
Example 4
Project: xsharing-services-router   File: MBDataRepositoryImpl.java   View Source Code Vote up 6 votes
@Override
@Transactional
public List<MBPlaceEntity> getAllIXSICarStations() {
    log.debug("getting IXSI car sharing stations.");

    Query q = entityManager.createNativeQuery(SELECTION, MBPlaceEntity.class)
                           .setParameter("clazz", CAR);

    List<MBPlaceEntity> places = q.getResultList();

    return places;
}
 
Example 5
Project: marathonv5   File: LiveSalesListFacadeREST.java   View Source Code Vote up 5 votes
@GET
@Produces({"application/xml", "application/json"})
@Path("/recent/")
public List<LiveSalesList> findRecent() {
    javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
    cq.select(cq.from(LiveSalesList.class));
    Query q = getEntityManager().createQuery(cq);
    q.setMaxResults(500);
    return q.getResultList();
}
 
Example 6
Project: Trabalhos-FIAP   File: SeguroHelper.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
public List<Veiculo> listarVeiculos(){
	Query query = em.createNamedQuery("Veiculo.findAll");
	return query.getResultList();
}
 
Example 7
Project: esup-sgc   File: User.java   View Source Code Vote up 5 votes
public static List<Object[]> countYesterdayCardsByPopulationCrous(String isMonday, String typeDate) {
    EntityManager em = User.entityManager();
    
    String mondayorNot = " AND to_date(to_char(" + typeDate + ", 'DD-MM-YYYY'), 'DD-MM-YYYY')= TIMESTAMP 'yesterday'";
    if("true".equals(isMonday)){
    	mondayorNot = " AND to_char(" + typeDate + ", 'DD-MM-YYYY') = to_char((now() - interval '3 day'), 'DD-MM-YYYY')";
    }
    String sql = "SELECT cnous_reference_statut AS eppa, count(*) as count "
    		+ "FROM card, user_account WHERE card.user_account=user_account.id "
    		+ mondayorNot + " GROUP BY cnous_reference_statut";

    Query q = em.createNativeQuery(sql);

    return q.getResultList();
}
 
Example 8
Project: oscm-app   File: APPConfigurationServiceBean.java   View Source Code Vote up 5 votes
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public HashMap<String, Setting> getAllProxyConfigurationSettings()
        throws ConfigurationException {
    LOGGER.debug("Retrieving all configuration settings for proxy");
    HashMap<String, Setting> result = new HashMap<>();
    Query query = em.createNamedQuery("ConfigurationSetting.getAllProxy");
    List<?> resultList = query.getResultList();
    for (Object entry : resultList) {
        ConfigurationSetting currentCs = (ConfigurationSetting) entry;
        result.put(currentCs.getSettingKey(), new Setting(
                currentCs.getSettingKey(), currentCs.getDecryptedValue()));
    }
    PlatformConfigurationKey[] keys = PlatformConfigurationKey.values();
    StringBuffer missing = new StringBuffer();
    for (int i = 0; i < keys.length; i++) {
        if (keys[i].isMandatory() && !result.containsKey(keys[i].name())) {
            if (missing.length() > 0) {
                missing.append(", ");
            }
            missing.append(keys[i].name());
        }
    }
    if (missing.length() > 0) {
        throw new ConfigurationException(
                "The configuration is missing the following parameter(s): "
                        + missing.toString(),
                missing.toString());
    }
    return result;
}
 
Example 9
Project: git-rekt   File: GuestFeedbackService.java   View Source Code Vote up 5 votes
/**
 * @return All guest feedback reports from the database that are not yet marked resolved.
 */
public List<GuestFeedback> getUnresolvedGuestFeedback() {
    String query = "FROM GuestFeedback WHERE isResolved = :param";
    Query q = entityManager.createQuery(query);
    q.setParameter("param", false);
    return q.getResultList();
}
 
Example 10
Project: jwala   File: GroupCrudServiceImpl.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
@Override
public JpaGroup getGroup(final String name) throws NotFoundException {
    final Query query = entityManager.createQuery("SELECT g FROM JpaGroup g WHERE lower(g.name) = lower(:groupName)");
    query.setParameter("groupName", name);
    List<JpaGroup> jpaGroups = query.getResultList();
    if (jpaGroups == null || jpaGroups.isEmpty()) {
        LOGGER.error("Error getting the group {}", name);
        throw new NotFoundException(FaultType.GROUP_NOT_FOUND, "Group not found: " + name);
    }
    return jpaGroups.get(0);
}
 
Example 11
Project: oscm   File: IdentityServiceBean.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
private List<OnBehalfUserReference> findInactiveOnBehalfUsers(
        Long lowerPeriodBound) {
    Query query = dm.createNamedQuery(
            "OnBehalfUserReference.findInactiveBeforePeriod");
    query.setParameter("leastPermittedTime", lowerPeriodBound);
    return query.getResultList();
}
 
Example 12
Project: Monsters_Portal   File: JpaPedidoDao.java   View Source Code Vote up 5 votes
public List<Object> read() {
   	Query query = manager
	        .createQuery("SELECT ped "
	        		+ "FROM Pedido ped "
	        		+ "ORDER BY ped.created_at DESC");

	@SuppressWarnings("unchecked")
	List<Object> pedidos = query.getResultList();
	return pedidos;
}
 
Example 13
Project: esup-sgc   File: Card.java   View Source Code Vote up 5 votes
public static List<Object> countNbRejetsByMonth(String userType) {
    String sql = "SELECT to_char(date_etat, 'MM-YYYY') tochar, count(*) FROM card WHERE etat='REJECTED' GROUP BY tochar ORDER BY to_date(to_char(date_etat, 'MM-YYYY'), 'MM-YYYY')";
    if (!userType.isEmpty()) {
        sql = "SELECT to_char(date_etat, 'MM-YYYY') tochar, count(*) FROM card, user_account WHERE card.user_account= user_account.id " + "AND etat='REJECTED' AND user_type = :userType GROUP BY tochar ORDER BY to_date(to_char(date_etat, 'MM-YYYY'), 'MM-YYYY')";
    }
    EntityManager em = Card.entityManager();

    Query q = em.createNativeQuery(sql);
    if (!userType.isEmpty()) {
        q.setParameter("userType", userType);
    }        

    return q.getResultList();
}
 
Example 14
Project: Monsters_Portal   File: JpaDashboardDao.java   View Source Code Vote up 5 votes
public List<Pedido> Pedidos_por_semana() {
	// Escreve a SQL
	Query query = manager
		.createQuery("SELECT COUNT(ped.id_pedido) as count, ped.data_pedido "
				+ "FROM Pedido as ped "
				+ "WHERE ped.data_pedido BETWEEN CURRENT_DATE -7 AND CURRENT_DATE "
				+ "GROUP BY ped.data_pedido "
				+ "ORDER BY ped.data_pedido");
				
	@SuppressWarnings("unchecked")
	List<Pedido> pedidos = query.getResultList();

	return pedidos;
}
 
Example 15
Project: Java_Swing_Programming   File: Soru1.java   View Source Code Vote up 5 votes
private void SİLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SİLActionPerformed
    // TODO add your handling code here:
    
    //SİLME
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("BP2_LAB2PU");
    EntityManager em = emf.createEntityManager();

    Query q = em.createQuery("DELETE FROM Hasta h WHERE h.id=:id");

    q.setParameter("id", tbl_hastalar.getValueAt(tbl_hastalar.getSelectedRow(), 0));
    em.getTransaction().begin();
    q.executeUpdate();
    em.getTransaction().commit();
    //
    
    // SELECT
    dtm.setRowCount(0);
    q = em.createQuery("SELECT h FROM Hasta h");

    List<Hasta> hastalar = q.getResultList();
    for (Hasta hs : hastalar) {
        dtm.addRow(new Object[]{hs.getId(), hs.getAdi(), hs.getSoyadi(), hs.getIdDoktor()});
    }
    tbl_hastalar.setModel(dtm);
    
    //7
}
 
Example 16
Project: sucok-framework   File: BaseDao.java   View Source Code Vote up 5 votes
/**
 * 执行原生SQL查询
 * @param sql
 * @param params sql参数
 * @return 结果集并影射成Map
 */
public List<Map<String,Object>> queryByNativeSQL(String sql,Map<String,Object> params){
	Query query=em.createNativeQuery(sql);
	if(params!=null&&params.size()>0){
		for(String param:params.keySet() ){
			query.setParameter(param,params.get(param));
		}
	}
	query.unwrap(SQLQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
	return query.getResultList();
}
 
Example 17
Project: agendamlgr   File: CategoriaFacade.java   View Source Code Vote up 4 votes
@SuppressWarnings("unchecked")
public List<Categoria> buscarPreferenciasUsuario(Usuario usuario) {
    Query q = this.em.createQuery("select c from Categoria c where :usuario member of c.usuarioList");
    q.setParameter("usuario", usuario);
    return (List<Categoria>) q.getResultList();
}
 
Example 18
Project: esup-sgc   File: Card.java   View Source Code Vote up 4 votes
public static List<BigInteger> selectIdforValidation() {
    EntityManager em = Card.entityManager();
    String sql = "SELECT id FROM card WHERE etat='ENABLED' OR etat='CADUC' OR etat='DISABLED'";
    Query q = em.createNativeQuery(sql);
    return q.getResultList();
}
 
Example 19
Project: ProjetoFinalInitium   File: CandidatoDao.java   View Source Code Vote up 4 votes
public List<Candidato> findByName(String nome) {
	Query query = manager.createQuery("Select u from Candidato u where u.nome like :pNome");
	query.setParameter("pNome", "%" + nome + "%");
	return query.getResultList();
}
 
Example 20
Project: esup-sgc   File: User.java   View Source Code Vote up 4 votes
public static List<Object> countNbVerso5() {
    EntityManager em = User.entityManager();
    String sql = "SELECT CASE WHEN verso5 like '' THEN 'VIDE' ELSE verso5  END AS verso5, COUNT(*) FROM user_account GROUP BY verso5 ORDER BY COUNT DESC";
    Query q = em.createNativeQuery(sql);
    return q.getResultList();
}